All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cybermkd.route.valid.ValidResult Maven / Gradle / Ivy

There is a newer version: 1.0.1.3
Show newest version
package com.cybermkd.route.valid;

import com.cybermkd.common.http.result.HttpStatus;
import com.cybermkd.common.util.Stringer;
import com.cybermkd.kit.MongoKit;
import com.cybermkd.kit.MongoValidate;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ice on 15-1-26.
 */
public class ValidResult {
    private Map errors = new HashMap();

    private HttpStatus status = HttpStatus.UNPROCESSABLE_ENTITY;

    public ValidResult() {
    }

    public ValidResult(Map errors) {
        this.errors = errors;
    }

    public ValidResult(Map errors, HttpStatus status) {
        this.errors = errors;
        this.status = status;
    }

    public void addError(String name, Object error) {
        this.errors.put(name, error);
    }

    public Map getErrors() {
        return errors;
    }

    public void setErrors(Map errors) {
        this.errors = errors;
    }

    public HttpStatus getStatus() {
        return status;
    }

    public void setStatus(HttpStatus status) {
        this.status = status;
    }


    public ValidResult mongoValid(MongoValidate validate,String... keys){
        return this.mongoValid(validate, "100",keys);
    }
    public ValidResult mongoValid(MongoValidate validate, Object errorValue,String... keys){
        String validateErrorMessage = MongoKit.validation(validate,keys);
        if(Stringer.isBlank(validateErrorMessage)){
            this.addError("error", errorValue);
            this.addError("errorMessage", validateErrorMessage);
        }
        return this;
    }

    public ValidResult mongoValid(MongoValidate validate){
        return this.mongoValid(validate,"100");
    }

    public ValidResult mongoValid(MongoValidate validate,Object errorValue){
        if (!validate.validation()){
            this.addError("error",errorValue);
            this.addError("errorMessage", validate.errorMessage());
        }
        return this;
    }

    public boolean isError(){
        return errors.size() > 0;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy