com.cybermkd.route.valid.ValidResult Maven / Gradle / Ivy
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){
return this.mongoValid(validate);
}
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 boolean isError(){
return errors.size() > 0;
}
}