Resolved conflicts
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.ValidationException;
|
||||
|
||||
public class FieldValidator {
|
||||
|
||||
private final List<String> errors = new ArrayList<>();
|
||||
|
||||
public static FieldValidator create() {
|
||||
return new FieldValidator();
|
||||
}
|
||||
|
||||
public FieldValidator notNull(Object object, String fieldName) {
|
||||
if (Objects.isNull(object)) {
|
||||
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_NOT_NULL), fieldName));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldValidator notEmpty(List<?> list, String fieldName) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
errors.add(MessageFormat.format(Translator.toLocale(GepafinConstant.FIELD_NOT_EMPTY), fieldName));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
if (!errors.isEmpty()) {
|
||||
throw new ValidationException(Status.VALIDATION_ERROR, errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package net.gepafin.tendermanagement.util;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ObjectUtils {
|
||||
|
||||
public static <T> void setIfNotNull(Consumer<T> setter, T value) {
|
||||
if (value != null) {
|
||||
setter.accept(value);
|
||||
}
|
||||
}
|
||||
public static <T> void setIfUpdated(Supplier<T> getter, Consumer<T> setter, T newValue) {
|
||||
T currentValue = getter.get();
|
||||
if (newValue != null && !newValue.equals(currentValue)) {
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Utils {
|
||||
@@ -68,5 +70,17 @@ public class Utils {
|
||||
byte[] decode = Base64.getDecoder().decode(decodedString.getBytes(StandardCharsets.UTF_8));
|
||||
return new String(decode, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static <T> void setIfNotNull(Consumer<T> setter, T value) {
|
||||
if (value != null) {
|
||||
setter.accept(value);
|
||||
}
|
||||
}
|
||||
public static <T> void setIfUpdated(Supplier<T> getter, Consumer<T> setter, T newValue) {
|
||||
T currentValue = getter.get();
|
||||
if (newValue != null && !newValue.equals(currentValue)) {
|
||||
setter.accept(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user