add notification service persist validators

This commit is contained in:
amentis 2024-01-22 11:27:24 +02:00
parent dcf5a5d690
commit c26c472ea8
33 changed files with 950 additions and 442 deletions

View File

@ -0,0 +1,193 @@
package gr.cite.notification.web.controllerhandler;
import gr.cite.notification.common.JsonHandlingService;
import gr.cite.tools.exception.*;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import java.text.MessageFormat;
import java.util.Map;
@RestControllerAdvice
@ControllerAdvice
public class GlobalExceptionHandler {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(GlobalExceptionHandler.class));
private final JsonHandlingService jsonHandlingService;
public GlobalExceptionHandler(JsonHandlingService jsonHandlingService) {
this.jsonHandlingService = jsonHandlingService;
}
@ExceptionHandler(Exception.class)
public ResponseEntity<?> handleUnexpectedErrors(Exception exception, WebRequest request) throws Exception {
HandledException handled = this.handleException(exception, request);
this.log(handled.getLevel(), exception, MessageFormat.format("returning code {0} and payload {1}", handled.getStatusCode(), handled.getMessage()));
return new ResponseEntity<>(handled.getMessage(), handled.getStatusCode());
}
public void log(System.Logger.Level level, Exception e, String message) {
if (level != null) {
switch (level) {
case TRACE:
logger.trace(message, e);
break;
case DEBUG:
logger.debug(message, e);
break;
case INFO:
logger.info(message, e);
break;
case WARNING:
logger.warn(message, e);
break;
case ERROR:
logger.error(message, e);
break;
}
}
}
public HandledException handleException(Exception exception, WebRequest request) throws Exception {
HttpStatus statusCode;
Map<String, Object> result;
System.Logger.Level logLevel;
switch (exception){
case MyNotFoundException myNotFoundException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.NOT_FOUND;
int code = myNotFoundException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myNotFoundException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myNotFoundException.getMessage())
);
}
}
case MyUnauthorizedException myUnauthorizedException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.UNAUTHORIZED;
int code = myUnauthorizedException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myUnauthorizedException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myUnauthorizedException.getMessage())
);
}
}
case MyForbiddenException myForbiddenException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.FORBIDDEN;
int code = myForbiddenException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myForbiddenException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myForbiddenException.getMessage())
);
}
}
case MyValidationException myValidationException -> {
logLevel = System.Logger.Level.DEBUG;
statusCode = HttpStatus.BAD_REQUEST;
int code = myValidationException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myValidationException.getMessage()),
Map.entry("message", myValidationException.getErrors())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myValidationException.getMessage()),
Map.entry("message", myValidationException.getErrors())
);
}
}
case MyApplicationException myApplicationException -> {
logLevel = System.Logger.Level.ERROR;
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
int code = myApplicationException.getCode();
if (code > 0) {
result = Map.ofEntries(
Map.entry("code", code),
Map.entry("error", myApplicationException.getMessage())
);
}
else {
result = Map.ofEntries(
Map.entry("error", myApplicationException.getMessage())
);
}
}
default -> {
logLevel = System.Logger.Level.ERROR;
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
result = Map.ofEntries(
Map.entry("error", "System error")
);
}
};
String serialization = this.jsonHandlingService.toJsonSafe(result);
return new HandledException(statusCode, serialization, logLevel);
}
public static class HandledException{
public HttpStatus statusCode;
public String message;
public System.Logger.Level level;
public HandledException(HttpStatus statusCode, String message, System.Logger.Level level) {
this.statusCode = statusCode;
this.message = message;
this.level = level;
}
public HttpStatus getStatusCode() {
return statusCode;
}
public void setStatusCode(HttpStatus statusCode) {
this.statusCode = statusCode;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public System.Logger.Level getLevel() {
return level;
}
public void setLevel(System.Logger.Level level) {
this.level = level;
}
}
}

View File

@ -21,7 +21,7 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate; import gr.cite.tools.validation.ValidationFilterAnnotation;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -97,7 +97,8 @@ public class NotificationController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public Notification Persist(@MyValidate @RequestBody NotificationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { @ValidationFilterAnnotation(validator = NotificationPersist.NotificationPersistValidator.ValidatorName, argumentName = "model")
public Notification Persist(@RequestBody NotificationPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + Notification.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + Notification.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Notification persisted = this.notificationService.persist(model, fieldSet); Notification persisted = this.notificationService.persist(model, fieldSet);

View File

@ -21,7 +21,7 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate; import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -76,7 +76,6 @@ public class NotificationTemplateController {
} }
@GetMapping("{id}") @GetMapping("{id}")
@Transactional
public NotificationTemplate get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { public NotificationTemplate get(@PathVariable UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + NotificationTemplate.class.getSimpleName()).And("id", id).And("fields", fieldSet)); logger.debug(new MapLogEntry("retrieving" + NotificationTemplate.class.getSimpleName()).And("id", id).And("fields", fieldSet));
@ -97,7 +96,8 @@ public class NotificationTemplateController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public NotificationTemplate persist(@MyValidate @RequestBody NotificationTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { @ValidationFilterAnnotation(validator = NotificationTemplatePersist.NotificationTemplatePersistValidator.ValidatorName, argumentName = "model")
public NotificationTemplate persist(@RequestBody NotificationTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + NotificationTemplate.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); logger.debug(new MapLogEntry("persisting" + NotificationTemplate.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
NotificationTemplate persisted = this.notificationTemplateService.persist(model, fieldSet); NotificationTemplate persisted = this.notificationTemplateService.persist(model, fieldSet);

View File

@ -8,6 +8,7 @@ import gr.cite.notification.data.TenantConfigurationEntity;
import gr.cite.notification.model.TenantConfiguration; import gr.cite.notification.model.TenantConfiguration;
import gr.cite.notification.model.builder.TenantConfigurationBuilder; import gr.cite.notification.model.builder.TenantConfigurationBuilder;
import gr.cite.notification.model.censorship.TenantConfigurationCensor; import gr.cite.notification.model.censorship.TenantConfigurationCensor;
import gr.cite.notification.model.persist.NotificationTemplatePersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist; import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationEmailClientPersist;
import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist; import gr.cite.notification.model.persist.tenantconfiguration.TenantConfigurationNotifierListPersist;
import gr.cite.notification.query.TenantConfigurationQuery; import gr.cite.notification.query.TenantConfigurationQuery;
@ -25,6 +26,7 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -101,7 +103,8 @@ public class TenantConfigurationController {
@PostMapping("persist/email-client") @PostMapping("persist/email-client")
@Transactional @Transactional
public TenantConfiguration persist(@RequestBody @Valid TenantConfigurationEmailClientPersist model, FieldSet fieldSet) @ValidationFilterAnnotation(validator = TenantConfigurationEmailClientPersist.TenantConfigurationEmailClientPersistValidator.ValidatorName, argumentName = "model")
public TenantConfiguration persist(@RequestBody TenantConfigurationEmailClientPersist model, FieldSet fieldSet)
{ {
logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION).And("model", model).And("fields", fieldSet)); logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.EMAIL_CLIENT_CONFIGURATION).And("model", model).And("fields", fieldSet));
@ -134,7 +137,8 @@ public class TenantConfigurationController {
@PostMapping("persist/notifier-list") @PostMapping("persist/notifier-list")
@Transactional @Transactional
public TenantConfiguration persist(@RequestBody @Valid TenantConfigurationNotifierListPersist model, FieldSet fieldSet) @ValidationFilterAnnotation(validator = TenantConfigurationNotifierListPersist.TenantConfigurationNotifierListPersistValidator.ValidatorName, argumentName = "model")
public TenantConfiguration persist(@RequestBody TenantConfigurationNotifierListPersist model, FieldSet fieldSet)
{ {
logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet)); logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet));

View File

@ -25,7 +25,7 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry; import gr.cite.tools.logging.MapLogEntry;
import jakarta.validation.Valid; import gr.cite.tools.validation.ValidationFilterAnnotation;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@ -116,7 +116,8 @@ public class UserNotificationPreferenceController {
@PostMapping("persist") @PostMapping("persist")
@Transactional @Transactional
public List<UserNotificationPreference> persist(@RequestBody @Valid UserNotificationPreferencePersist model, FieldSet fieldSet) @ValidationFilterAnnotation(validator = UserNotificationPreferencePersist.UserNotificationPreferencePersistValidator.ValidatorName, argumentName = "model")
public List<UserNotificationPreference> persist(@RequestBody UserNotificationPreferencePersist model, FieldSet fieldSet)
{ {
logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet)); logger.debug(new MapLogEntry("persisting").And("type", TenantConfigurationType.NOTIFIER_LIST).And("model", model).And("fields", fieldSet));

View File

@ -5,3 +5,6 @@ validation.largerthanmax=Value must be less than {value}
validation.invalidid=Not valid id validation.invalidid=Not valid id
General_ItemNotFound=Item {0} of type {1} not found General_ItemNotFound=Item {0} of type {1} not found
Validation_Required={0} is required Validation_Required={0} is required
Validation_OverPosting=Too much info
Validation_MaxLength={0} too long
Validation_UnexpectedValue=Unexpected value in field {0}

View File

@ -0,0 +1,63 @@
package gr.cite.notification.common.validation;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.validation.AbstractValidator;
import gr.cite.tools.validation.ValidationResult;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public abstract class BaseValidator<T> extends AbstractValidator<T> {
protected final ConventionService conventionService;
protected final ErrorThesaurusProperties errors;
protected BaseValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
this.conventionService = conventionService;
this.errors = errors;
}
@Override
public void validateForce(Object target) {
this.validate(target);
ValidationResult result = result();
if (!result.isValid()) {
List<Map.Entry<String, List<String>>> errorsMap = this.flattenValidationResult();
throw new MyValidationException(this.errors.getModelValidation().getCode(), errorsMap);
}
}
protected Boolean isValidGuid(UUID guid) {
return this.conventionService.isValidGuid(guid);
}
protected Boolean isValidHash(String hash) {
return this.conventionService.isValidHash(hash);
}
protected Boolean isEmpty(String value) {
return this.conventionService.isNullOrEmpty(value);
}
protected Boolean isListNullOrEmpty(List<?> value) {
return this.conventionService.isListNullOrEmpty(value);
}
protected Boolean isNull(Object value) {
return value == null;
}
protected Boolean isNull(Collection<?> value) {
return value == null;
}
protected Boolean lessEqualLength(String value, int size) {
return value.length() <= size;
}
protected Boolean lessEqual(Integer value, int target) {
return value <= target;
}
}

View File

@ -1,11 +0,0 @@
package gr.cite.notification.common.validation;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
public class EnumNotNull implements ConstraintValidator<ValidEnum,Object> {
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
return value != null;
}
}

View File

@ -1,22 +0,0 @@
package gr.cite.notification.common.validation;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.*;
@Constraint( validatedBy = { FieldNotNullIfOtherSetValidator.class } )
@Documented
@Target( { ElementType.TYPE } )
@Retention( RetentionPolicy.RUNTIME )
public @interface FieldNotNullIfOtherSet {
Class<?>[] groups () default {};
String notNullField() default "id";
String otherSetField() default "hash";
String failOn() default "hash";
String message () default "hash is required if id is set";
Class<? extends Payload>[] payload () default {};
}

View File

@ -1,35 +0,0 @@
package gr.cite.notification.common.validation;
import org.springframework.beans.BeanWrapperImpl;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.Objects;
public class FieldNotNullIfOtherSetValidator implements ConstraintValidator<FieldNotNullIfOtherSet, Object> {
private String notNullField;
private String otherSetField;
@Override
public void initialize(FieldNotNullIfOtherSet constraintAnnotation) {
this.notNullField = constraintAnnotation.notNullField();
this.otherSetField = constraintAnnotation.otherSetField();
}
@Override
public boolean isValid(Object entity, ConstraintValidatorContext context) {
Object notNullValue = new BeanWrapperImpl(entity)
.getPropertyValue(this.notNullField);
Object otherSetValue = new BeanWrapperImpl(entity)
.getPropertyValue(this.otherSetField);
boolean hashIsString = Objects.equals(new BeanWrapperImpl(entity)
.getPropertyType(this.otherSetField), String.class);
boolean hashValueEmpty = otherSetValue == null || (hashIsString && ((String)otherSetValue).isBlank());
if (notNullValue != null && hashValueEmpty) return false;
return true;
}
}

View File

@ -1,29 +0,0 @@
package gr.cite.notification.common.validation;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Constraint(validatedBy = FieldsValueMatchValidator.class)
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface FieldsValueMatch {
Class<?>[] groups () default {};
String field();
String fieldMatch();
String failOn();
String message() default "Fields values don't match!";
Class<? extends Payload>[] payload () default {};
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@interface List {
FieldsValueMatch[] value();
}
}

View File

@ -1,31 +0,0 @@
package gr.cite.notification.common.validation;
import org.springframework.beans.BeanWrapperImpl;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
public class FieldsValueMatchValidator implements ConstraintValidator<FieldsValueMatch, Object> {
private String field;
private String fieldMatch;
@Override
public void initialize(FieldsValueMatch constraintAnnotation) {
this.field = constraintAnnotation.field();
this.fieldMatch = constraintAnnotation.fieldMatch();
}
@Override
public boolean isValid(Object entity, ConstraintValidatorContext context) {
Object fieldValue = new BeanWrapperImpl(entity).getPropertyValue(field);
Object fieldMatchValue = new BeanWrapperImpl(entity).getPropertyValue(fieldMatch);
if (fieldValue != null) {
return fieldValue.equals(fieldMatchValue);
} else {
return fieldMatchValue == null;
}
}
}

View File

@ -1,16 +0,0 @@
package gr.cite.notification.common.validation;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.*;
@Constraint(validatedBy = EnumNotNull.class)
@Documented
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidEnum {
String message() default "enum is required";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}

View File

@ -1,18 +0,0 @@
package gr.cite.notification.common.validation;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.*;
@Constraint( validatedBy = { ValidIdValidator.class } )
@Documented
@Target( { ElementType.FIELD } )
@Retention( RetentionPolicy.RUNTIME )
public @interface ValidId {
Class<?>[] groups() default {};
String message() default "id set but not valid";
Class<? extends Payload>[] payload() default {};
}

View File

@ -1,40 +0,0 @@
package gr.cite.notification.common.validation;
import gr.cite.notification.convention.ConventionService;
import org.springframework.beans.factory.annotation.Autowired;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.UUID;
public class ValidIdValidator implements ConstraintValidator<ValidId, Object> {
@Autowired
private ConventionService conventionService;
@Override
public void initialize(ValidId constraintAnnotation) { }
@Override
public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
if(o == null) return true;
else if(o instanceof UUID){
UUID uuidId = (UUID)o;
return this.conventionService.isValidGuid(uuidId);
}
else if(o instanceof Integer){
Integer intId = (Integer)o;
return this.conventionService.isValidId(intId);
}
else{
String stringId = o.toString();
UUID uuidId = null;
try {
uuidId = UUID.fromString(stringId);
}catch (Exception ex){
return false;
}
return this.conventionService.isValidGuid(uuidId);
}
}
}

View File

@ -1,36 +0,0 @@
package gr.cite.notification.common.validation;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.validation.BaseValidationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import jakarta.validation.Validator;
import java.util.List;
import java.util.Map;
@Service
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ValidationServiceImpl extends BaseValidationService {
private ErrorThesaurusProperties errors;
@Autowired
public ValidationServiceImpl(Validator validator, ErrorThesaurusProperties errors){
super(validator);
this.errors = errors;
}
@Override
public <T> void validateForce(T item, Class<?>... groups) {
List<Map.Entry<String, List<String>>> validationErrors = this.validate(item, groups);
if (validationErrors != null && !validationErrors.isEmpty()) {
throw new MyValidationException(this.errors.getModelValidation().getCode(),
this.errors.getModelValidation().getMessage(),
validationErrors);
}
}
}

View File

@ -18,6 +18,7 @@ public class NotificationEntity extends TenantScopedBaseEntity {
public static final String _type = "type"; public static final String _type = "type";
public static final String _contactTypeHint = "contactTypeHint"; public static final String _contactTypeHint = "contactTypeHint";
public static final String _contactHint = "contactHint"; public static final String _contactHint = "contactHint";
public static final int _contactHintLength = 200;
public final static String _notifiedAt = "notifiedAt"; public final static String _notifiedAt = "notifiedAt";
public final static String _isActive = "isActive"; public final static String _isActive = "isActive";
public final static String _createdAt = "createdAt"; public final static String _createdAt = "createdAt";

View File

@ -11,6 +11,7 @@ import gr.cite.notification.model.persist.TenantTouchedIntegrationEventPersist;
import gr.cite.notification.service.tenant.TenantService; import gr.cite.notification.service.tenant.TenantService;
import gr.cite.tools.auditing.AuditService; import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.validation.ValidatorFactory;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction; import jakarta.persistence.EntityTransaction;
@ -33,10 +34,12 @@ public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIn
protected final ApplicationContext applicationContext; protected final ApplicationContext applicationContext;
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final ValidatorFactory validatorFactory;
public TenantTouchedIntegrationEventHandlerImpl(ApplicationContext applicationContext, JsonHandlingService jsonHandlingService) { public TenantTouchedIntegrationEventHandlerImpl(ApplicationContext applicationContext, JsonHandlingService jsonHandlingService, ValidatorFactory validatorFactory) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.jsonHandlingService = jsonHandlingService; this.jsonHandlingService = jsonHandlingService;
this.validatorFactory = validatorFactory;
} }
@Override @Override
@ -48,6 +51,7 @@ public class TenantTouchedIntegrationEventHandlerImpl implements TenantTouchedIn
TenantTouchedIntegrationEventPersist model = new TenantTouchedIntegrationEventPersist(); TenantTouchedIntegrationEventPersist model = new TenantTouchedIntegrationEventPersist();
model.setId(event.getId()); model.setId(event.getId());
model.setCode(event.getCode()); model.setCode(event.getCode());
this.validatorFactory.validator(TenantTouchedIntegrationEventPersist.TenantTouchedIntegrationEventPersistValidator.class).validateForce(model);
EntityManager entityManager = null; EntityManager entityManager = null;
EntityTransaction transaction = null; EntityTransaction transaction = null;

View File

@ -17,6 +17,7 @@ import gr.cite.tools.auditing.AuditService;
import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.fieldset.BaseFieldSet; import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.validation.ValidatorFactory;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction; import jakarta.persistence.EntityTransaction;
@ -39,13 +40,16 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
protected final ApplicationContext applicationContext; protected final ApplicationContext applicationContext;
private final JsonHandlingService jsonHandlingService; private final JsonHandlingService jsonHandlingService;
private final ValidatorFactory validatorFactory;
public UserTouchedIntegrationEventHandlerImpl( public UserTouchedIntegrationEventHandlerImpl(
JsonHandlingService jsonHandlingService, JsonHandlingService jsonHandlingService,
ApplicationContext applicationContext ApplicationContext applicationContext,
) { ValidatorFactory validatorFactory) {
this.jsonHandlingService = jsonHandlingService; this.jsonHandlingService = jsonHandlingService;
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
this.validatorFactory = validatorFactory;
} }
@Override @Override
@ -58,6 +62,7 @@ public class UserTouchedIntegrationEventHandlerImpl implements UserTouchedIntegr
model.setId(event.getId()); model.setId(event.getId());
model.setFirstName(event.getFirstName()); model.setFirstName(event.getFirstName());
model.setLastName(event.getLastName()); model.setLastName(event.getLastName());
this.validatorFactory.validator(UserTouchedIntegrationEventPersist.UserTouchedIntegrationEventPersistValidator.class).validateForce(model);
EntityManager entityManager = null; EntityManager entityManager = null;
EntityTransaction transaction = null; EntityTransaction transaction = null;

View File

@ -2,7 +2,6 @@ package gr.cite.notification.model.deleter;
import gr.cite.notification.data.TenantScopedEntityManager; import gr.cite.notification.data.TenantScopedEntityManager;
import gr.cite.notification.data.UserContactInfoEntity; import gr.cite.notification.data.UserContactInfoEntity;
import gr.cite.notification.model.persist.UserContactInfoPersist;
import gr.cite.notification.query.UserContactInfoQuery; import gr.cite.notification.query.UserContactInfoQuery;
import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.deleter.DeleterFactory;

View File

@ -4,10 +4,21 @@ import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.enums.NotificationNotifyState; import gr.cite.notification.common.enums.NotificationNotifyState;
import gr.cite.notification.common.enums.NotificationTrackingProcess; import gr.cite.notification.common.enums.NotificationTrackingProcess;
import gr.cite.notification.common.enums.NotificationTrackingState; import gr.cite.notification.common.enums.NotificationTrackingState;
import gr.cite.notification.common.validation.ValidId; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.data.NotificationEntity;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.constraints.NotNull;
import java.time.Instant; import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class NotificationPersist { public class NotificationPersist {
@ -23,17 +34,20 @@ public class NotificationPersist {
public final static String _notifiedWith = "notifiedWith"; public final static String _notifiedWith = "notifiedWith";
public final static String _data = "data"; public final static String _data = "data";
public final static String _retryCount = "retryCount"; public final static String _retryCount = "retryCount";
public final static String _trackingState = "trackingState";
public final static String _trackingProcess = "trackingProcess";
public final static String _trackingData = "trackingData";
public final static String _provenanceRef = "provenanceRef";
public static final String _hash = "hash";
} }
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
@NotNull(message = "{validation.empty}")
private UUID userId; private UUID userId;
private UUID type; private UUID type;
private gr.cite.notification.common.enums.NotificationContactType contactTypeHint; private NotificationContactType contactTypeHint;
private String contactHint; private String contactHint;
@ -176,4 +190,50 @@ public class NotificationPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(NotificationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class NotificationPersistValidator extends BaseValidator<NotificationPersist> {
public static final String ValidatorName = "NotificationPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected NotificationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<NotificationPersist> modelClass() {
return NotificationPersist.class;
}
@Override
protected List<Specification> specifications(NotificationPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(NotificationPersist.Field._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist.Field._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(NotificationPersist.Field._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getUserId()))
.failOn(NotificationPersist.Field._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationPersist.Field._userId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(Field._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{Field._type}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getContactHint()))
.must(() -> this.lessEqualLength(item.getContactHint(), NotificationEntity.Field._contactHintLength))
.failOn(Field._contactHint).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{Field._contactHint}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -2,38 +2,44 @@ package gr.cite.notification.model.persist;
import gr.cite.notification.common.enums.NotificationTemplateChannel; import gr.cite.notification.common.enums.NotificationTemplateChannel;
import gr.cite.notification.common.enums.NotificationTemplateKind; import gr.cite.notification.common.enums.NotificationTemplateKind;
import gr.cite.notification.common.validation.ValidEnum; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.common.validation.ValidId; import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.notification.model.persist.notificationtemplate.NotificationTemplateValuePersist; import gr.cite.notification.model.persist.notificationtemplate.NotificationTemplateValuePersist;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.Valid; import java.util.Arrays;
import jakarta.validation.constraints.NotNull; import java.util.List;
import java.util.UUID; import java.util.UUID;
public class NotificationTemplatePersist { public class NotificationTemplatePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
public static final String _id = "id";
@ValidEnum
private NotificationTemplateChannel channel; private NotificationTemplateChannel channel;
public static final String _channel = "channel";
@NotNull
@Valid
private UUID notificationType; private UUID notificationType;
public static final String _notificationType = "notificationType";
@ValidEnum
private NotificationTemplateKind kind; private NotificationTemplateKind kind;
public static final String _kind = "kind";
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID languageId; private UUID languageId;
public static final String _languageId = "languageId";
@NotNull(message = "{validation.empty}")
@Valid
private NotificationTemplateValuePersist value; private NotificationTemplateValuePersist value;
public static final String _value = "value";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
@ -90,4 +96,60 @@ public class NotificationTemplatePersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(NotificationTemplatePersist.NotificationTemplatePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class NotificationTemplatePersistValidator extends BaseValidator<NotificationTemplatePersist> {
public static final String ValidatorName = "NotificationTemplatePersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected NotificationTemplatePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<NotificationTemplatePersist> modelClass() {
return NotificationTemplatePersist.class;
}
@Override
protected List<Specification> specifications(NotificationTemplatePersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(NotificationTemplatePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplatePersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(NotificationTemplatePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getLanguageId()))
.failOn(NotificationTemplatePersist._languageId).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplatePersist._languageId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getNotificationType()))
.failOn(NotificationTemplatePersist._notificationType).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplatePersist._notificationType}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getKind()))
.failOn(NotificationTemplatePersist._kind).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplatePersist._kind}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getChannel()))
.failOn(NotificationTemplatePersist._channel).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplatePersist._channel}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getValue()))
.failOn(NotificationTemplatePersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplatePersist._value}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getValue()))
.on(NotificationTemplatePersist._value)
.over(item.getValue())
.using(() -> this.validatorFactory.validator(NotificationTemplateValuePersist.NotificationTemplateValuePersistValidator.class))
);
}
}
} }

View File

@ -1,22 +1,27 @@
package gr.cite.notification.model.persist; package gr.cite.notification.model.persist;
import gr.cite.notification.common.validation.ValidId; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.constraints.NotEmpty; import java.util.Arrays;
import jakarta.validation.constraints.NotNull; import java.util.List;
import jakarta.validation.constraints.Size;
import java.util.UUID; import java.util.UUID;
public class TenantTouchedIntegrationEventPersist { public class TenantTouchedIntegrationEventPersist {
@ValidId(message = "{validation.invalidid}")
@NotNull(message = "{validation.empty}")
private UUID id; private UUID id;
public static final String _id = "id";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 50, message = "{validation.largerthanmax}")
private String code; private String code;
public static final String _code = "code";
public static final int _codeLength = 50;
public UUID getId() { public UUID getId() {
return id; return id;
@ -34,4 +39,40 @@ public class TenantTouchedIntegrationEventPersist {
this.code = code; this.code = code;
} }
@Component(TenantTouchedIntegrationEventPersist.TenantTouchedIntegrationEventPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantTouchedIntegrationEventPersistValidator extends BaseValidator<TenantTouchedIntegrationEventPersist> {
public static final String ValidatorName = "TenantTouchedIntegrationEventPersistValidator";
private final MessageSource messageSource;
protected TenantTouchedIntegrationEventPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantTouchedIntegrationEventPersist> modelClass() {
return TenantTouchedIntegrationEventPersist.class;
}
@Override
protected List<Specification> specifications(TenantTouchedIntegrationEventPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> !this.isNull(item.getId()))
.must(() -> this.isValidGuid(item.getId()))
.failOn(TenantTouchedIntegrationEventPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantTouchedIntegrationEventPersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCode()))
.failOn(TenantTouchedIntegrationEventPersist._code).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantTouchedIntegrationEventPersist._code}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getCode()))
.must(() -> this.lessEqualLength(item.getCode(), TenantTouchedIntegrationEventPersist._codeLength))
.failOn(TenantTouchedIntegrationEventPersist._code).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{TenantTouchedIntegrationEventPersist._code}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,117 +0,0 @@
package gr.cite.notification.model.persist;
import gr.cite.notification.common.enums.ContactInfoType;
import gr.cite.notification.common.enums.IsActive;
import gr.cite.notification.common.validation.FieldNotNullIfOtherSet;
import gr.cite.notification.common.validation.ValidId;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.time.Instant;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class UserContactInfoPersist {
@ValidId(message = "{validation.invalidid}")
private ID id;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String value;
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID tenantId;
private Instant createdAt;
private Instant updatedAt;
private IsActive isActive;
private String hash;
public ID getId() {
return id;
}
public void setId(ID id) {
this.id = id;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public UUID getTenantId() {
return tenantId;
}
public void setTenantId(UUID tenantId) {
this.tenantId = tenantId;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public static class ID {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID userId;
@NotNull(message = "{validation.empty}")
private ContactInfoType type;
public UUID getUserId() {
return userId;
}
public void setUserId(UUID userId) {
this.userId = userId;
}
public ContactInfoType getType() {
return type;
}
public void setType(ContactInfoType type) {
this.type = type;
}
}
}

View File

@ -1,7 +1,17 @@
package gr.cite.notification.model.persist; package gr.cite.notification.model.persist;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -9,7 +19,9 @@ import java.util.UUID;
public class UserNotificationPreferencePersist { public class UserNotificationPreferencePersist {
private UUID userId; private UUID userId;
public static final String _userId = "userId";
private Map<UUID, List<NotificationContactType>> notificationPreferences; private Map<UUID, List<NotificationContactType>> notificationPreferences;
public static final String _notificationPreferences = "notificationPreferences";
public UUID getUserId() { public UUID getUserId() {
return userId; return userId;
@ -26,4 +38,35 @@ public class UserNotificationPreferencePersist {
public void setNotificationPreferences(Map<UUID, List<NotificationContactType>> notificationPreferences) { public void setNotificationPreferences(Map<UUID, List<NotificationContactType>> notificationPreferences) {
this.notificationPreferences = notificationPreferences; this.notificationPreferences = notificationPreferences;
} }
@Component(UserNotificationPreferencePersist.UserNotificationPreferencePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserNotificationPreferencePersistValidator extends BaseValidator<UserNotificationPreferencePersist> {
public static final String ValidatorName = "UserNotificationPreferencePersistValidator";
private final MessageSource messageSource;
protected UserNotificationPreferencePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<UserNotificationPreferencePersist> modelClass() {
return UserNotificationPreferencePersist.class;
}
@Override
protected List<Specification> specifications(UserNotificationPreferencePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getUserId()))
.failOn(UserNotificationPreferencePersist._userId).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserNotificationPreferencePersist._userId}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getNotificationPreferences()))
.failOn(UserNotificationPreferencePersist._notificationPreferences).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserNotificationPreferencePersist._notificationPreferences}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,26 +1,32 @@
package gr.cite.notification.model.persist; package gr.cite.notification.model.persist;
import gr.cite.notification.common.validation.ValidId; import gr.cite.notification.common.validation.BaseValidator;
import jakarta.validation.constraints.NotEmpty; import gr.cite.notification.convention.ConventionService;
import jakarta.validation.constraints.NotNull; import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import jakarta.validation.constraints.Size; import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class UserTouchedIntegrationEventPersist { public class UserTouchedIntegrationEventPersist {
@ValidId(message = "{validation.invalidid}")
@NotNull(message = "{validation.empty}")
private UUID id; private UUID id;
public static final String _id = "id";
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 200, message = "{validation.largerthanmax}")
private String firstName; private String firstName;
public static final String _firstName = "firstName";
public static final int _firstNameLength = 200;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
@Size(max = 200, message = "{validation.largerthanmax}")
private String lastName; private String lastName;
public static final String _lastName = "lastName";
public static final int _lastNameLength = 200;
public UUID getId() { public UUID getId() {
@ -46,4 +52,47 @@ public class UserTouchedIntegrationEventPersist {
public void setLastName(String lastName) { public void setLastName(String lastName) {
this.lastName = lastName; this.lastName = lastName;
} }
@Component(UserTouchedIntegrationEventPersist.UserTouchedIntegrationEventPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class UserTouchedIntegrationEventPersistValidator extends BaseValidator<UserTouchedIntegrationEventPersist> {
public static final String ValidatorName = "UserTouchedIntegrationEventPersistValidator";
private final MessageSource messageSource;
protected UserTouchedIntegrationEventPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<UserTouchedIntegrationEventPersist> modelClass() {
return UserTouchedIntegrationEventPersist.class;
}
@Override
protected List<Specification> specifications(UserTouchedIntegrationEventPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> !this.isNull(item.getId()))
.must(() -> this.isValidGuid(item.getId()))
.failOn(UserTouchedIntegrationEventPersist._id).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserTouchedIntegrationEventPersist._id}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getFirstName()))
.failOn(UserTouchedIntegrationEventPersist._firstName).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserTouchedIntegrationEventPersist._firstName}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getFirstName()))
.must(() -> this.lessEqualLength(item.getFirstName(), UserTouchedIntegrationEventPersist._firstNameLength))
.failOn(UserTouchedIntegrationEventPersist._firstName).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{UserTouchedIntegrationEventPersist._firstName}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getLastName()))
.failOn(UserTouchedIntegrationEventPersist._lastName).failWith(messageSource.getMessage("Validation_Required", new Object[]{UserTouchedIntegrationEventPersist._lastName}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isEmpty(item.getLastName()))
.must(() -> this.lessEqualLength(item.getLastName(), UserTouchedIntegrationEventPersist._lastNameLength))
.failOn(UserTouchedIntegrationEventPersist._lastName).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{UserTouchedIntegrationEventPersist._lastName}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,23 +1,30 @@
package gr.cite.notification.model.persist.notificationtemplate; package gr.cite.notification.model.persist.notificationtemplate;
import gr.cite.notification.common.enums.NotificationDataType; import gr.cite.notification.common.enums.NotificationDataType;
import gr.cite.notification.common.validation.ValidEnum; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.constraints.NotEmpty; import java.util.Arrays;
import jakarta.validation.constraints.NotNull; import java.util.List;
public class FieldInfoPersist { public class FieldInfoPersist {
@NotNull
@NotEmpty
private String key; private String key;
public static final String _key = "key";
@ValidEnum
private NotificationDataType type; private NotificationDataType type;
public static final String _type = "type";
@NotNull
@NotEmpty
private String value; private String value;
public static final String _value = "value";
public FieldInfoPersist(String key, NotificationDataType type, String value) { public FieldInfoPersist(String key, NotificationDataType type, String value) {
this.key = key; this.key = key;
@ -51,4 +58,38 @@ public class FieldInfoPersist {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
@Component(FieldInfoPersist.FieldInfoPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FieldInfoPersistValidator extends BaseValidator<FieldInfoPersist> {
public static final String ValidatorName = " FieldInfoPersistValidator";
private final MessageSource messageSource;
protected FieldInfoPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<FieldInfoPersist> modelClass() {
return FieldInfoPersist.class;
}
@Override
protected List<Specification> specifications(FieldInfoPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getKey()))
.failOn(FieldInfoPersist._key).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldInfoPersist._key}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getType()))
.failOn(FieldInfoPersist._type).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldInfoPersist._type}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getValue()))
.failOn(FieldInfoPersist._value).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldInfoPersist._value}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,20 +1,30 @@
package gr.cite.notification.model.persist.notificationtemplate; package gr.cite.notification.model.persist.notificationtemplate;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.Valid; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class FieldOptionsPersist { public class FieldOptionsPersist {
@Valid
private List<String> mandatory; private List<String> mandatory;
public static final String _mandatory = "mandatory";
@Valid
private List<FieldInfoPersist> optional; private List<FieldInfoPersist> optional;
public static final String _optional = "optional";
@Valid
private Map<String, String> formatting; private Map<String, String> formatting;
public static final String _formatting = "formatting";
public List<String> getMandatory() { public List<String> getMandatory() {
return mandatory; return mandatory;
@ -39,4 +49,43 @@ public class FieldOptionsPersist {
public void setFormatting(Map<String, String> formatting) { public void setFormatting(Map<String, String> formatting) {
this.formatting = formatting; this.formatting = formatting;
} }
@Component(FieldOptionsPersist.FieldOptionsPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class FieldOptionsPersistValidator extends BaseValidator<FieldOptionsPersist> {
public static final String ValidatorName = " FieldOptionsPersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected FieldOptionsPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<FieldOptionsPersist> modelClass() {
return FieldOptionsPersist.class;
}
@Override
protected List<Specification> specifications(FieldOptionsPersist item) {
return Arrays.asList(
this.navSpec()
.iff(() -> !this.isListNullOrEmpty(item.getOptional()))
.on(FieldOptionsPersist._optional)
.over(item.getOptional())
.using((itm) -> this.validatorFactory.validator(FieldInfoPersist.FieldInfoPersistValidator.class)),
this.spec()
.iff(() -> !this.isListNullOrEmpty(item.getMandatory()) || !this.isNull(item.getOptional()))
.must(() -> !this.isNull(item.getFormatting()))
.failOn(FieldOptionsPersist._formatting).failWith(messageSource.getMessage("Validation_Required", new Object[]{FieldOptionsPersist._formatting}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,48 +1,55 @@
package gr.cite.notification.model.persist.notificationtemplate; package gr.cite.notification.model.persist.notificationtemplate;
import gr.cite.notification.common.enums.EmailOverrideMode; import gr.cite.notification.common.enums.EmailOverrideMode;
import gr.cite.notification.common.validation.ValidEnum; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.ValidatorFactory;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import jakarta.validation.Valid; import java.util.Arrays;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List; import java.util.List;
public class NotificationTemplateValuePersist { public class NotificationTemplateValuePersist {
@NotNull
@NotEmpty
private String subjectText; private String subjectText;
public static final String _subjectText = "subjectText";
@NotNull
@NotEmpty
private String subjectKey; private String subjectKey;
public static final String _subjectKey = "subjectKey";
@Valid
private FieldOptionsPersist subjectFieldOptions; private FieldOptionsPersist subjectFieldOptions;
public static final String _subjectFieldOptions = "subjectFieldOptions";
@NotNull
@NotEmpty
private String bodyText; private String bodyText;
public static final String _bodyText = "bodyText";
@NotNull
@NotEmpty
private String bodyKey; private String bodyKey;
public static final String _bodyKey = "bodyKey";
private String priorityKey; private String priorityKey;
@NotNull public static final String _priorityKey = "priorityKey";
private Boolean allowAttachments = false; private Boolean allowAttachments = false;
public static final String _allowAttachments = "allowAttachments";
private List<String> cc; private List<String> cc;
public static final String _cc = "cc";
@ValidEnum
private EmailOverrideMode ccMode; private EmailOverrideMode ccMode;
public static final String _ccMode = "ccMode";
private List<String> bcc; private List<String> bcc;
public static final String _bcc = "bcc";
@ValidEnum
private EmailOverrideMode bccMode; private EmailOverrideMode bccMode;
public static final String _bccMode = "bccMode";
private List<String> extraDataKeys; private List<String> extraDataKeys;
public static final String _extraDataKeys = "extraDataKeys";
@Valid
private FieldOptionsPersist bodyFieldOptions; private FieldOptionsPersist bodyFieldOptions;
public static final String _bodyFieldOptions = "bodyFieldOptions";
public String getSubjectText() { public String getSubjectText() {
return subjectText; return subjectText;
@ -147,4 +154,66 @@ public class NotificationTemplateValuePersist {
public void setBodyFieldOptions(FieldOptionsPersist bodyFieldOptions) { public void setBodyFieldOptions(FieldOptionsPersist bodyFieldOptions) {
this.bodyFieldOptions = bodyFieldOptions; this.bodyFieldOptions = bodyFieldOptions;
} }
@Component(NotificationTemplateValuePersist.NotificationTemplateValuePersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class NotificationTemplateValuePersistValidator extends BaseValidator<NotificationTemplateValuePersist> {
public static final String ValidatorName = "NotificationTemplateValuePersistValidator";
private final MessageSource messageSource;
private final ValidatorFactory validatorFactory;
protected NotificationTemplateValuePersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
this.validatorFactory = validatorFactory;
}
@Override
protected Class<NotificationTemplateValuePersist> modelClass() {
return NotificationTemplateValuePersist.class;
}
@Override
protected List<Specification> specifications(NotificationTemplateValuePersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isEmpty(item.getSubjectKey()))
.failOn(NotificationTemplateValuePersist._subjectKey).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._subjectKey}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getSubjectText()))
.failOn(NotificationTemplateValuePersist._subjectText).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._subjectText}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getSubjectFieldOptions()))
.on(NotificationTemplateValuePersist._subjectFieldOptions)
.over(item.getSubjectFieldOptions())
.using(() -> this.validatorFactory.validator(FieldOptionsPersist.FieldOptionsPersistValidator.class)),
this.spec()
.must(() -> !this.isEmpty(item.getBodyKey()))
.failOn(NotificationTemplateValuePersist._bodyKey).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._bodyKey}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getBodyText()))
.failOn(NotificationTemplateValuePersist._bodyText).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._bodyText}, LocaleContextHolder.getLocale())),
this.refSpec()
.iff(() -> !this.isNull(item.getBodyFieldOptions()))
.on(NotificationTemplateValuePersist._bodyFieldOptions)
.over(item.getBodyFieldOptions())
.using(() -> this.validatorFactory.validator(FieldOptionsPersist.FieldOptionsPersistValidator.class)),
this.spec()
.must(() -> !this.isNull(item.getAllowAttachments()))
.failOn(NotificationTemplateValuePersist._allowAttachments).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._allowAttachments}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getPriorityKey()))
.failOn(NotificationTemplateValuePersist._priorityKey).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._priorityKey}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getCcMode()))
.failOn(NotificationTemplateValuePersist._ccMode).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._ccMode}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getBccMode()))
.failOn(NotificationTemplateValuePersist._bccMode).failWith(messageSource.getMessage("Validation_Required", new Object[]{NotificationTemplateValuePersist._bccMode}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,21 +1,40 @@
package gr.cite.notification.model.persist.tenantconfiguration; package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.validation.ValidId; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class TenantConfigurationEmailClientPersist { public class TenantConfigurationEmailClientPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
public static final String _id = "id";
private Boolean requireCredentials; private Boolean requireCredentials;
public static final String _requireCredentials = "requireCredentials";
private Boolean enableSSL; private Boolean enableSSL;
public static final String _enableSSL = "enableSSL";
private String certificatePath; private String certificatePath;
public static final String _certificatePath = "certificatePath";
private String hostServer; private String hostServer;
public static final String _hostServer = "hostServer";
private Integer hostPortNo; private Integer hostPortNo;
public static final String _hostPortNo = "hostPortNo";
private String emailAddress; private String emailAddress;
public static final String _emailAddress = "emailAddress";
private String emailUserName; private String emailUserName;
public static final String _emailUserName = "emailUserName";
private String emailPassword; private String emailPassword;
public static final String _emailPassword = "emailPassword";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
@ -96,4 +115,63 @@ public class TenantConfigurationEmailClientPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(TenantConfigurationEmailClientPersist.TenantConfigurationEmailClientPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationEmailClientPersistValidator extends BaseValidator<TenantConfigurationEmailClientPersist> {
public static final String ValidatorName = "TenantConfigurationEmailClientPersistValidator";
private final MessageSource messageSource;
protected TenantConfigurationEmailClientPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantConfigurationEmailClientPersist> modelClass() {
return TenantConfigurationEmailClientPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationEmailClientPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantConfigurationEmailClientPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantConfigurationEmailClientPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getRequireCredentials()))
.failOn(TenantConfigurationEmailClientPersist._requireCredentials).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._requireCredentials}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getEnableSSL()))
.failOn(TenantConfigurationEmailClientPersist._enableSSL).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._enableSSL}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getCertificatePath()))
.failOn(TenantConfigurationEmailClientPersist._certificatePath).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._certificatePath}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getHostServer()))
.failOn(TenantConfigurationEmailClientPersist._hostServer).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hostServer}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getHostPortNo()))
.failOn(TenantConfigurationEmailClientPersist._hostPortNo).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._hostPortNo}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmailAddress()))
.failOn(TenantConfigurationEmailClientPersist._emailAddress).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailAddress}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmailUserName()))
.failOn(TenantConfigurationEmailClientPersist._emailUserName).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailUserName}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isEmpty(item.getEmailPassword()))
.failOn(TenantConfigurationEmailClientPersist._emailPassword).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationEmailClientPersist._emailPassword}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,17 +1,28 @@
package gr.cite.notification.model.persist.tenantconfiguration; package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.enums.NotificationContactType; import gr.cite.notification.common.enums.NotificationContactType;
import gr.cite.notification.common.validation.ValidId; import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class TenantConfigurationNotifierListPersist { public class TenantConfigurationNotifierListPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id; private UUID id;
public static final String _id = "id";
private Map<UUID, List<NotificationContactType>> notifiers; private Map<UUID, List<NotificationContactType>> notifiers;
public static final String _notifiers = "notifiers";
private String hash; private String hash;
public static final String _hash = "hash";
public UUID getId() { public UUID getId() {
return id; return id;
@ -36,4 +47,40 @@ public class TenantConfigurationNotifierListPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(TenantConfigurationNotifierListPersist.TenantConfigurationNotifierListPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationNotifierListPersistValidator extends BaseValidator<TenantConfigurationNotifierListPersist> {
public static final String ValidatorName = "TenantConfigurationNotifierListPersistValidator";
private final MessageSource messageSource;
protected TenantConfigurationNotifierListPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantConfigurationNotifierListPersist> modelClass() {
return TenantConfigurationNotifierListPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationNotifierListPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.isValidGuid(item.getId()))
.must(() -> this.isValidHash(item.getHash()))
.failOn(TenantConfigurationNotifierListPersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationNotifierListPersist._hash}, LocaleContextHolder.getLocale())),
this.spec()
.iff(() -> !this.isValidGuid(item.getId()))
.must(() -> !this.isValidHash(item.getHash()))
.failOn(TenantConfigurationNotifierListPersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getNotifiers()))
.failOn(TenantConfigurationNotifierListPersist._notifiers).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationNotifierListPersist._notifiers}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -1,9 +1,25 @@
package gr.cite.notification.model.persist.tenantconfiguration; package gr.cite.notification.model.persist.tenantconfiguration;
import gr.cite.notification.common.validation.BaseValidator;
import gr.cite.notification.convention.ConventionService;
import gr.cite.notification.errorcode.ErrorThesaurusProperties;
import gr.cite.tools.validation.specification.Specification;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
public class TenantConfigurationUserLocaleIntegrationPersist { public class TenantConfigurationUserLocaleIntegrationPersist {
private String language; private String language;
public static final String _language = "language";
private String timeZone; private String timeZone;
public static final String _timeZone = "timeZone";
private String culture; private String culture;
public static final String _culture = "culture";
private String hash; private String hash;
@ -38,4 +54,39 @@ public class TenantConfigurationUserLocaleIntegrationPersist {
public void setHash(String hash) { public void setHash(String hash) {
this.hash = hash; this.hash = hash;
} }
@Component(TenantConfigurationUserLocaleIntegrationPersist.TenantConfigurationUserLocaleIntegrationPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class TenantConfigurationUserLocaleIntegrationPersistValidator extends BaseValidator<TenantConfigurationUserLocaleIntegrationPersist> {
public static final String ValidatorName = "TenantConfigurationUserLocaleIntegrationPersistValidator";
private final MessageSource messageSource;
protected TenantConfigurationUserLocaleIntegrationPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource) {
super(conventionService, errors);
this.messageSource = messageSource;
}
@Override
protected Class<TenantConfigurationUserLocaleIntegrationPersist> modelClass() {
return TenantConfigurationUserLocaleIntegrationPersist.class;
}
@Override
protected List<Specification> specifications(TenantConfigurationUserLocaleIntegrationPersist item) {
return Arrays.asList(
this.spec()
.must(() -> !this.isNull(item.getLanguage()))
.failOn(TenantConfigurationUserLocaleIntegrationPersist._language).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._language}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getTimeZone()))
.failOn(TenantConfigurationUserLocaleIntegrationPersist._timeZone).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._timeZone}, LocaleContextHolder.getLocale())),
this.spec()
.must(() -> !this.isNull(item.getCulture()))
.failOn(TenantConfigurationUserLocaleIntegrationPersist._culture).failWith(messageSource.getMessage("Validation_Required", new Object[]{TenantConfigurationUserLocaleIntegrationPersist._culture}, LocaleContextHolder.getLocale()))
);
}
}
} }

View File

@ -10,7 +10,6 @@ import gr.cite.notification.data.UserContactInfoEntity;
import gr.cite.notification.data.UserEntity; import gr.cite.notification.data.UserEntity;
import gr.cite.notification.model.User; import gr.cite.notification.model.User;
import gr.cite.notification.model.UserContactInfo; import gr.cite.notification.model.UserContactInfo;
import gr.cite.notification.model.persist.UserContactInfoPersist;
import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext; import gr.cite.tools.data.query.QueryContext;