Check-Point

Http request auto validation library for spring framework

Check-Point depends on Jackson Json Processor, Project Lombok, Apache POI

Check-Point is a library that automatically checks the integrity of request messages that developers are most likely to miss during the spring project development.

Null check, minimum, maximum value of message.. You do not need to code anymore, just only need to click the checkbox on the setting page.

I realized that I was born into a person who can not fully handle message exceptions and developed this library.

Are you a diligent person who can handle exceptions for every message?

Installation

1. MAVEN

    <dependency>
        <groupId>com.github.ckpoint</groupId>
        <artifactId>check-point</artifactId>
        <version>0.1.2</version>
    </dependency>

2. GRADLE

  compile group: 'com.github.ckpoint', name: 'check-point', version: '0.1.2'

Check-Point Setting Guide

https://youtu.be/I1aEIztXlhE

Usage

Table of Contents

Add Properties

Add Setting Controller

Add the controller to the project as shown below.


@RestController
@RequestMapping("/uniquepath")
public class CheckPointController extends MsgSettingController { }

Add Annotation

@ValidationParam

  @GetMapping("/find")
    public UserModel findUser(@ValidationParam BaseModel findModel) {
        UserModel userModel = new UserModel();
        userModel.setId(findModel.getId());
        ...
        return userModel;
    }

@ValidationBody

  @PutMapping("/create")
    public OrderModel createOrder(@ValidationBody OrderModel orderModel) {
        ...
        return orderModel;
    }

@ValidationUrlMapping

Add Custom Validation Rule

import hsim.checkpoint.core.component.validationRule.type.BaseValidationCheck; import hsim.checkpoint.core.domain.ValidationData; import hsim.checkpoint.exception.ValidationLibException; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus;

@Slf4j public class EmptyValueCheck implements BaseValidationCheck {

@Override
public boolean check(Object receiveValue, Object standardValue) {

    if (receiveValue instanceof String) {
        return !((String) receiveValue).isEmpty();
    }
    return false;
}

@Override
public Object replace(Object receiveValue, Object standardValue, ValidationData param) {

    if (receiveValue instanceof String && ((String) receiveValue).isEmpty()) {
        return standardValue;
    }
    return receiveValue;
}

@Override
public void exception(ValidationData param, Object inputValue, Object standardValue) {
    throw new ValidationLibException("custom rule check error", HttpStatus.BAD_REQUEST);
}

}


- Then add the rule using CheckPointHelper as below and call flush at the end.

```java
   CheckPointHelper checkPointHelper = new CheckPointHelper();
   checkPointHelper.addValidationRule("emptyValueCheck", StandardValueType.STRING, new EmptyValueCheck(), new AssistType().string());
   checkPointHelper.flush();

Replace Validation Exception

public class MinSizeCallback implements ValidationInvalidCallback { @Override public void exception(ValidationData param, Object inputValue, Object standardValue) { throw new ValidationLibException(param.getName() + " value minimum is " + standardValue + " but, input " + inputValue, HttpStatus.NOT_ACCEPTABLE); } }

- Then replace the callback using CheckPointHelper as below.

```java
public void replaceMinSizeCallback(){
    CheckPointHelper checkPointHelper = new CheckPointHelper();
    checkPointHelper.replaceExceptionCallback(BasicCheckRule.MinSize, new MinSizeCallback());
}

Replace Object Mapper

Client and Validation Setting

https://github.com/ckpoint/CheckPointClient