Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring
This commit is contained in:
commit
128fc3d29e
|
@ -0,0 +1,115 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.specification.*;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
|
import org.springframework.validation.BeanPropertyBindingResult;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
import org.springframework.validation.FieldError;
|
||||||
|
import org.springframework.validation.ValidationUtils;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public abstract class AbstractValidator<T> implements Validator {
|
||||||
|
private BeanPropertyBindingResult bindingResult;
|
||||||
|
|
||||||
|
protected abstract Class<T> modelClass();
|
||||||
|
|
||||||
|
protected abstract List<Specification> specifications(T item);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supports(Class clazz) {
|
||||||
|
return clazz == null ? false : this.modelClass().equals(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(Object obj, Errors e) {
|
||||||
|
if (obj == null) return;
|
||||||
|
T item = this.modelClass().cast(obj);
|
||||||
|
List<Specification> specifications = this.specifications(item);
|
||||||
|
if (specifications == null) return;;
|
||||||
|
List<PropertySpecification> propertySpecifications = specifications.stream().filter(x-> x instanceof PropertySpecification).map(x-> (PropertySpecification)x).toList();
|
||||||
|
for (PropertySpecification propertySpecification : propertySpecifications){
|
||||||
|
if ((propertySpecification.getPrecondition() == null || propertySpecification.getPrecondition().get()) &&
|
||||||
|
(propertySpecification.getSpecification() == null || !propertySpecification.getSpecification().get())
|
||||||
|
){
|
||||||
|
e.rejectValue(propertySpecification.getErrorKey(), propertySpecification.getErrorCode(), propertySpecification.getErrorMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<NavigationReferenceSpecification> navigationReferenceSpecifications = specifications.stream().filter(x-> x instanceof NavigationReferenceSpecification).map(x-> (NavigationReferenceSpecification)x).toList();
|
||||||
|
for (NavigationReferenceSpecification navigationReferenceSpecification : navigationReferenceSpecifications){
|
||||||
|
if (navigationReferenceSpecification.getReference() != null && (navigationReferenceSpecification.getPrecondition() == null || navigationReferenceSpecification.getPrecondition().get())){
|
||||||
|
try {
|
||||||
|
e.pushNestedPath(navigationReferenceSpecification.getKey());
|
||||||
|
ValidationUtils.invokeValidator(navigationReferenceSpecification.getValidator().get(), navigationReferenceSpecification.getReference(), e);
|
||||||
|
} finally {
|
||||||
|
e.popNestedPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<NavigationDetailsSpecification> navigationDetailsSpecifications = specifications.stream().filter(x-> x instanceof NavigationDetailsSpecification).map(x-> (NavigationDetailsSpecification)x).toList();
|
||||||
|
for (NavigationDetailsSpecification navigationDetailsSpecification : navigationDetailsSpecifications){
|
||||||
|
if (navigationDetailsSpecification.getDetails() != null && (navigationDetailsSpecification.getPrecondition() == null || navigationDetailsSpecification.getPrecondition().get())){
|
||||||
|
|
||||||
|
for (int i = 0; i < navigationDetailsSpecification.getDetails().size(); i++) {
|
||||||
|
try {
|
||||||
|
e.pushNestedPath(MessageFormat.format("{0}[{1}]", navigationDetailsSpecification.getKey(), i));
|
||||||
|
ValidationUtils.invokeValidator(navigationDetailsSpecification.getValidator().get(), navigationDetailsSpecification.getDetails().get(i), e);
|
||||||
|
} finally {
|
||||||
|
e.popNestedPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(Object target){
|
||||||
|
this.bindingResult = new BeanPropertyBindingResult(target, target.getClass().getName());
|
||||||
|
this.validate(target, this.bindingResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ValidationResult result() {
|
||||||
|
ValidationResult validationResult = new ValidationResult();
|
||||||
|
if (this.bindingResult != null && bindingResult.hasErrors()){
|
||||||
|
for (FieldError fieldError : bindingResult.getFieldErrors()){
|
||||||
|
validationResult.add(new ValidationFailure(fieldError.getField(), fieldError.getDefaultMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<Map.Entry<String, List<String>>> flattenValidationResult() {
|
||||||
|
ValidationResult result = result();
|
||||||
|
List<Map.Entry<String, List<String>>> errorsMap = new ArrayList<>();
|
||||||
|
for (ValidationFailure fieldError : result.getErrors()){
|
||||||
|
Map.Entry<String, List<String>> entry = errorsMap.stream().filter(x-> Objects.equals(x.getKey(), fieldError.getErrorKey())).findFirst().orElse(null);
|
||||||
|
if (entry == null) {
|
||||||
|
entry = new AbstractMap.SimpleEntry<>(fieldError.getErrorKey(), new ArrayList<>());
|
||||||
|
errorsMap.add(entry);
|
||||||
|
}
|
||||||
|
entry.getValue().add(fieldError.getErrorMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PropertySpecificationBuilder spec() {
|
||||||
|
return new PropertySpecificationBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected NavigationReferenceSpecificationBuilder refSpec() {
|
||||||
|
return new NavigationReferenceSpecificationBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected NavigationDetailsSpecificationBuilder navSpec()
|
||||||
|
{
|
||||||
|
return new NavigationDetailsSpecificationBuilder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,47 +1,42 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
||||||
import org.springframework.validation.BeanPropertyBindingResult;
|
import java.util.*;
|
||||||
import org.springframework.validation.Errors;
|
|
||||||
import org.springframework.validation.FieldError;
|
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
public abstract class BaseValidator<T> extends AbstractValidator<T> {
|
||||||
import java.util.ArrayList;
|
protected final ConventionService conventionService;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class BaseValidator implements ModelValidator {
|
|
||||||
private BeanPropertyBindingResult result;
|
|
||||||
protected final ErrorThesaurusProperties errors;
|
protected final ErrorThesaurusProperties errors;
|
||||||
|
|
||||||
protected BaseValidator(ErrorThesaurusProperties errors) {
|
protected BaseValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
|
||||||
|
this.conventionService = conventionService;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate(Object target){
|
|
||||||
this.result = new org.springframework.validation.BeanPropertyBindingResult(target, target.getClass().getName());
|
|
||||||
this.validate(target, this.result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateForce(Object target) {
|
public void validateForce(Object target) {
|
||||||
this.validate(target);
|
this.validate(target);
|
||||||
|
ValidationResult result = result();
|
||||||
if (this.result != null && result.hasErrors()){
|
if (!result.isValid()) {
|
||||||
List<Map.Entry<String, List<String>>> errorsMap = new ArrayList<>();
|
List<Map.Entry<String, List<String>>> errorsMap = this.flattenValidationResult();
|
||||||
for (FieldError fieldError : result.getFieldErrors()){
|
|
||||||
errorsMap.add(new AbstractMap.SimpleEntry<>(fieldError.getField(), List.of(fieldError.getDefaultMessage())));
|
|
||||||
}
|
|
||||||
throw new MyValidationException(this.errors.getModelValidation().getCode(), errorsMap);
|
throw new MyValidationException(this.errors.getModelValidation().getCode(), errorsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected Boolean isValidGuid(UUID guid) {
|
||||||
public Errors result() {
|
return this.conventionService.isValidGuid(guid);
|
||||||
return this.result;
|
}
|
||||||
|
|
||||||
|
protected Boolean isValidHash(String hash) {
|
||||||
|
return this.conventionService.isValidHash(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Boolean isEmpty(String value) {
|
||||||
|
return this.conventionService.isNullOrEmpty(value);
|
||||||
|
}
|
||||||
|
protected Boolean lessEqual(String value, int size) {
|
||||||
|
return value.length() <= size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
public class ValidationFailure {
|
||||||
|
public String errorKey;
|
||||||
|
|
||||||
|
public String errorMessage;
|
||||||
|
|
||||||
|
public ValidationFailure(String errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationFailure(String errorKey, String errorMessage) {
|
||||||
|
this.errorKey = errorKey;
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorKey() {
|
||||||
|
return errorKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ValidationResult {
|
||||||
|
private final List<ValidationFailure> errors;
|
||||||
|
|
||||||
|
public ValidationResult() {
|
||||||
|
this.errors = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isValid() {
|
||||||
|
return this.errors.isEmpty();
|
||||||
|
}
|
||||||
|
public ValidationResult add(ValidationFailure failure) {
|
||||||
|
if (failure != null) {
|
||||||
|
errors.add(failure);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationResult addAll(List<ValidationFailure> failures) {
|
||||||
|
if (failures != null) {
|
||||||
|
errors.addAll(failures);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ValidationFailure> getErrors() {
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.validation.Validator;
|
|
||||||
|
|
||||||
public interface ModelValidator extends Validator {
|
public interface Validator extends org.springframework.validation.Validator {
|
||||||
void validate(Object target);
|
void validate(Object target);
|
||||||
void validateForce(Object target);
|
void validateForce(Object target);
|
||||||
Errors result();
|
ValidationResult result();
|
||||||
}
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package eu.eudat.commons.validation;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ValidatorFactory {
|
||||||
|
|
||||||
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
public ValidatorFactory(ApplicationContext applicationContext) {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Validator> T validator(Class<T> type){
|
||||||
|
|
||||||
|
T item = this.applicationContext.getBean(type);
|
||||||
|
|
||||||
|
if (item == null || !(item instanceof Validator)) throw new RuntimeException("unrecognized validator " + type.getSimpleName());
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Validator validator(String validtor){
|
||||||
|
|
||||||
|
Validator item = this.applicationContext.getBean(validtor, Validator.class);
|
||||||
|
|
||||||
|
if (item == null || !(item instanceof Validator)) throw new RuntimeException("unrecognized validator " + validtor);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
import jakarta.validation.ConstraintValidator;
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
import jakarta.validation.ConstraintValidatorContext;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint;
|
import jakarta.validation.Constraint;
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import org.springframework.beans.BeanWrapperImpl;
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
import jakarta.validation.ConstraintValidator;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
import jakarta.validation.Constraint;
|
import jakarta.validation.Constraint;
|
||||||
import jakarta.validation.Payload;
|
import jakarta.validation.Payload;
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.old.FieldsValueMatch;
|
||||||
import org.springframework.beans.BeanWrapperImpl;
|
import org.springframework.beans.BeanWrapperImpl;
|
||||||
|
|
||||||
import jakarta.validation.ConstraintValidator;
|
import jakarta.validation.ConstraintValidator;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
import jakarta.validation.Constraint;
|
import jakarta.validation.Constraint;
|
||||||
import jakarta.validation.Payload;
|
import jakarta.validation.Payload;
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.old.RequiredOneField;
|
||||||
import jakarta.validation.ConstraintValidator;
|
import jakarta.validation.ConstraintValidator;
|
||||||
import jakarta.validation.ConstraintValidatorContext;
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
import org.apache.commons.beanutils.PropertyUtils;
|
import org.apache.commons.beanutils.PropertyUtils;
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.old.EnumNotNull;
|
||||||
import jakarta.validation.Constraint;
|
import jakarta.validation.Constraint;
|
||||||
import jakarta.validation.Payload;
|
import jakarta.validation.Payload;
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint;
|
import jakarta.validation.Constraint;
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.commons.validation;
|
package eu.eudat.commons.validation.old;
|
||||||
|
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.MyValidationException;
|
|
@ -0,0 +1,16 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.Validator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface NavigationDetailsSpecification extends Specification {
|
||||||
|
Supplier<Boolean> getPrecondition();
|
||||||
|
|
||||||
|
String getKey();
|
||||||
|
|
||||||
|
List<?> getDetails();
|
||||||
|
|
||||||
|
Supplier<Validator> getValidator();
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.Validator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class NavigationDetailsSpecificationBuilder implements NavigationDetailsSpecification {
|
||||||
|
private Supplier<Boolean> precondition;
|
||||||
|
private String key;
|
||||||
|
private List<?> details;
|
||||||
|
private Supplier<Validator> validator;
|
||||||
|
|
||||||
|
public NavigationDetailsSpecificationBuilder iff(Supplier<Boolean> value){
|
||||||
|
this.precondition = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationDetailsSpecificationBuilder on(String value){
|
||||||
|
this.key = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationDetailsSpecificationBuilder over(List<?> value){
|
||||||
|
this.details = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationDetailsSpecificationBuilder using(Supplier<Validator> value){
|
||||||
|
this.validator = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Boolean> getPrecondition() {
|
||||||
|
return precondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<?> getDetails() {
|
||||||
|
return details;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Validator> getValidator() {
|
||||||
|
return validator;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.Validator;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface NavigationReferenceSpecification extends Specification{
|
||||||
|
Supplier<Boolean> getPrecondition();
|
||||||
|
|
||||||
|
String getKey();
|
||||||
|
|
||||||
|
Object getReference();
|
||||||
|
|
||||||
|
Supplier<Validator> getValidator();
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.Validator;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class NavigationReferenceSpecificationBuilder implements NavigationReferenceSpecification {
|
||||||
|
private Supplier<Boolean> precondition;
|
||||||
|
private String key;
|
||||||
|
private Object reference;
|
||||||
|
private Supplier<Validator> validator;
|
||||||
|
|
||||||
|
public NavigationReferenceSpecificationBuilder iff(Supplier<Boolean> value){
|
||||||
|
this.precondition = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationReferenceSpecificationBuilder on(String value){
|
||||||
|
this.key = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationReferenceSpecificationBuilder over(Object value){
|
||||||
|
this.reference = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NavigationReferenceSpecificationBuilder using(Supplier<Validator> value){
|
||||||
|
this.validator = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Boolean> getPrecondition() {
|
||||||
|
return precondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getReference() {
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Validator> getValidator() {
|
||||||
|
return validator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface PropertySpecification extends Specification {
|
||||||
|
|
||||||
|
Supplier<Boolean> getPrecondition();
|
||||||
|
|
||||||
|
Supplier<Boolean> getSpecification();
|
||||||
|
|
||||||
|
String getErrorKey();
|
||||||
|
|
||||||
|
String getErrorMessage();
|
||||||
|
String getErrorCode();
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class PropertySpecificationBuilder implements PropertySpecification{
|
||||||
|
private Supplier<Boolean> precondition;
|
||||||
|
private Supplier<Boolean> specification;
|
||||||
|
private String errorKey;
|
||||||
|
private String errorMessage;
|
||||||
|
private String errorCode = "validationerror";
|
||||||
|
|
||||||
|
public PropertySpecificationBuilder iff(Supplier<Boolean> value){
|
||||||
|
this.precondition = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertySpecificationBuilder must(Supplier<Boolean> value){
|
||||||
|
this.specification = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertySpecificationBuilder failOn(String value){
|
||||||
|
this.errorKey = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertySpecificationBuilder failWith(String value){
|
||||||
|
this.errorMessage = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PropertySpecificationBuilder failWithCode(String value){
|
||||||
|
this.errorCode = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Boolean> getPrecondition() {
|
||||||
|
return precondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Boolean> getSpecification() {
|
||||||
|
return specification;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getErrorKey() {
|
||||||
|
return errorKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getErrorCode() {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package eu.eudat.commons.validation.specification;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface Specification {
|
||||||
|
}
|
|
@ -2,9 +2,9 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.ActionConfirmationStatus;
|
import eu.eudat.commons.enums.ActionConfirmationStatus;
|
||||||
import eu.eudat.commons.enums.ActionConfirmationType;
|
import eu.eudat.commons.enums.ActionConfirmationType;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist;
|
import eu.eudat.model.persist.actionconfirmation.DmpInvitationPersist;
|
||||||
import eu.eudat.model.persist.actionconfirmation.EmailConfirmationPersist;
|
import eu.eudat.model.persist.actionconfirmation.EmailConfirmationPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.apache.commons.compress.utils.Lists;
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
import eu.eudat.data.DescriptionEntity;
|
||||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
|
||||||
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||||
|
|
|
@ -1,17 +1,12 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionStatus;
|
import eu.eudat.commons.enums.DescriptionStatus;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
|
||||||
import eu.eudat.model.persist.descriptionproperties.PropertyDefinitionPersist;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||||
|
|
|
@ -2,19 +2,15 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
||||||
import eu.eudat.commons.enums.UserDescriptionTemplateRole;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import org.springframework.validation.Errors;
|
|
||||||
import org.springframework.validation.ValidationUtils;
|
|
||||||
import org.springframework.validation.Validator;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -2,47 +2,44 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
||||||
import eu.eudat.commons.validation.BaseValidator;
|
import eu.eudat.commons.validation.*;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
|
||||||
|
|
||||||
|
import eu.eudat.commons.validation.specification.Specification;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||||
import eu.eudat.model.Description;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.MessageSource;
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.validation.Errors;
|
import java.util.Arrays;
|
||||||
import org.springframework.validation.ValidationUtils;
|
|
||||||
import org.springframework.validation.Validator;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
|
||||||
public class DescriptionTemplateTypePersist {
|
public class DescriptionTemplateTypePersist {
|
||||||
|
|
||||||
@ValidId(message = "{validation.invalidid}")
|
|
||||||
private UUID id;
|
private UUID id;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
public final static String _id = "id";
|
||||||
@NotEmpty(message = "{validation.empty}")
|
|
||||||
@Size(max = DescriptionTemplateTypeEntity._nameLength, message = "{validation.largerthanmax}")
|
|
||||||
private String name = null;
|
private String name = null;
|
||||||
|
|
||||||
|
public final static String _name = "name";
|
||||||
|
|
||||||
private String hash;
|
private String hash;
|
||||||
|
|
||||||
@ValidEnum(message = "{validation.empty}")
|
public final static String _hash = "hash";
|
||||||
|
|
||||||
private DescriptionTemplateTypeStatus status;
|
private DescriptionTemplateTypeStatus status;
|
||||||
|
|
||||||
private List<DescriptionTemplateTypePersist> nested;
|
// private List<DescriptionTemplateTypePersist> nested;
|
||||||
|
//
|
||||||
private DescriptionTemplateTypePersist obj;
|
// public final static String _nested = "nested";
|
||||||
|
//
|
||||||
|
// private DescriptionTemplateTypePersist obj;
|
||||||
|
//
|
||||||
|
// public final static String _obj = "obj";
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -76,79 +73,52 @@ public class DescriptionTemplateTypePersist {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DescriptionTemplateTypePersist> getNested() {
|
|
||||||
return nested;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNested(List<DescriptionTemplateTypePersist> nested) {
|
|
||||||
this.nested = nested;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptionTemplateTypePersist getObj() {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setObj(DescriptionTemplateTypePersist obj) {
|
|
||||||
this.obj = obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component(DescriptionTemplateTypePersistValidator.ValidatorName)
|
@Component(DescriptionTemplateTypePersistValidator.ValidatorName)
|
||||||
public static class DescriptionTemplateTypePersistValidator extends BaseValidator {
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
public static class DescriptionTemplateTypePersistValidator extends BaseValidator<DescriptionTemplateTypePersist> {
|
||||||
@Autowired
|
|
||||||
private DescriptionTemplateTypePersistValidator1 descriptionTemplateTypePersistValidator;
|
|
||||||
public static final String ValidatorName = "DescriptionTemplateTypePersistValidator";
|
public static final String ValidatorName = "DescriptionTemplateTypePersistValidator";
|
||||||
|
|
||||||
private final MessageSource messageSource;
|
private final MessageSource messageSource;
|
||||||
|
|
||||||
public DescriptionTemplateTypePersistValidator(MessageSource messageSource, ErrorThesaurusProperties errors) {
|
public DescriptionTemplateTypePersistValidator(MessageSource messageSource, ConventionService conventionService, ErrorThesaurusProperties errors) {
|
||||||
super(errors);
|
super(conventionService, errors);
|
||||||
this.messageSource = messageSource;
|
this.messageSource = messageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supports(Class clazz) {
|
@Override
|
||||||
return DescriptionTemplateTypePersist.class.equals(clazz);
|
protected Class<DescriptionTemplateTypePersist> modelClass() {
|
||||||
|
return DescriptionTemplateTypePersist.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validate(Object obj, Errors e) {
|
@Override
|
||||||
e.rejectValue("name", "negativevalue", messageSource.getMessage("General_ItemNotFound", new Object[]{"aaa", Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
protected List<Specification> specifications(DescriptionTemplateTypePersist item) {
|
||||||
DescriptionTemplateTypePersist p = (DescriptionTemplateTypePersist) obj;
|
return Arrays.asList(
|
||||||
try {
|
this.spec()
|
||||||
e.pushNestedPath("obj");
|
.iff(() -> this.isValidGuid(item.getId()))
|
||||||
ValidationUtils.invokeValidator(descriptionTemplateTypePersistValidator, p.getObj(), e);
|
.must(() -> this.isValidHash(item.getHash()))
|
||||||
} finally {
|
.failOn(DescriptionTemplateTypePersist._hash).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplateTypePersist._hash}, LocaleContextHolder.getLocale())),
|
||||||
e.popNestedPath();
|
this.spec()
|
||||||
}
|
.iff(() -> !this.isValidGuid(item.getId()))
|
||||||
|
.must(() -> !this.isValidHash(item.getHash()))
|
||||||
|
.failOn(DescriptionTemplateTypePersist._hash).failWith(messageSource.getMessage("Validation_OverPosting", new Object[]{}, LocaleContextHolder.getLocale())),
|
||||||
for (int i = 0; i < p.getNested().size(); i++) {
|
this.spec()
|
||||||
try {
|
.must(() -> !this.isEmpty(item.getName()))
|
||||||
e.pushNestedPath("nested["+i+"]");
|
.failOn(DescriptionTemplateTypePersist._name).failWith(messageSource.getMessage("Validation_Required", new Object[]{DescriptionTemplateTypePersist._name}, LocaleContextHolder.getLocale())),
|
||||||
ValidationUtils.invokeValidator(descriptionTemplateTypePersistValidator, p.getObj(), e);
|
this.spec()
|
||||||
} finally {
|
.iff(() -> !this.isEmpty(item.getName()))
|
||||||
e.popNestedPath();
|
.must(() -> this.lessEqual(item.getName(), DescriptionTemplateTypeEntity._nameLength))
|
||||||
}
|
.failOn(DescriptionTemplateTypePersist._name).failWith(messageSource.getMessage("Validation_MaxLength", new Object[]{DescriptionTemplateTypePersist._name}, LocaleContextHolder.getLocale()))
|
||||||
}
|
// this.refSpec()
|
||||||
}
|
// .iff(() -> item.getObj() != null)
|
||||||
}
|
// .on(DescriptionTemplateTypePersist._obj)
|
||||||
|
// .over(item.getObj())
|
||||||
@Component(DescriptionTemplateTypePersistValidator1.ValidatorName)
|
// .using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class)),
|
||||||
public static class DescriptionTemplateTypePersistValidator1 extends BaseValidator {
|
// this.navSpec()
|
||||||
|
// .iff(() -> item.getNested() != null)
|
||||||
public static final String ValidatorName = "DescriptionTemplateTypePersistValidator1";
|
// .on(DescriptionTemplateTypePersist._nested)
|
||||||
private final MessageSource messageSource;
|
// .over(item.getNested())
|
||||||
|
// .using(() -> this.validatorFactory.validator(DescriptionTemplateTypePersistValidator.class))
|
||||||
public DescriptionTemplateTypePersistValidator1(MessageSource messageSource, ErrorThesaurusProperties errors) {
|
);
|
||||||
super(errors);
|
|
||||||
this.messageSource = messageSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean supports(Class clazz) {
|
|
||||||
return DescriptionTemplateTypePersist.class.equals(clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate(Object obj, Errors e) {
|
|
||||||
e.rejectValue("name", "negativevalue", messageSource.getMessage("General_ItemNotFound", new Object[]{"aaa", Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
import eu.eudat.commons.enums.DmpBlueprintStatus;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.DmpBlueprintEntity;
|
import eu.eudat.data.DmpBlueprintEntity;
|
||||||
import eu.eudat.model.dmpblueprintdefinition.Definition;
|
|
||||||
import eu.eudat.model.persist.dmpblueprintdefinition.DefinitionPersist;
|
import eu.eudat.model.persist.dmpblueprintdefinition.DefinitionPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -2,10 +2,9 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpAccessType;
|
import eu.eudat.commons.enums.DmpAccessType;
|
||||||
import eu.eudat.commons.enums.DmpStatus;
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.DescriptionEntity;
|
|
||||||
import eu.eudat.data.DmpEntity;
|
import eu.eudat.data.DmpEntity;
|
||||||
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpUserRole;
|
import eu.eudat.commons.enums.DmpUserRole;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.RequiredOneField;
|
import eu.eudat.commons.validation.old.RequiredOneField;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpAccessType;
|
|
||||||
import eu.eudat.commons.enums.DmpStatus;
|
|
||||||
import eu.eudat.commons.enums.DmpUserRole;
|
import eu.eudat.commons.enums.DmpUserRole;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
|
||||||
import eu.eudat.data.DmpEntity;
|
|
||||||
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DmpUserRemovePersist {
|
public class DmpUserRemovePersist {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.LockTargetType;
|
import eu.eudat.commons.enums.LockTargetType;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -2,9 +2,9 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
import eu.eudat.commons.enums.DescriptionTemplateStatus;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.DescriptionTemplateEntity;
|
import eu.eudat.data.DescriptionTemplateEntity;
|
||||||
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
import eu.eudat.model.persist.descriptiontemplatedefinition.DefinitionPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.apache.commons.compress.utils.Lists;
|
import org.apache.commons.compress.utils.Lists;
|
||||||
|
|
|
@ -2,9 +2,9 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.ReferenceType;
|
import eu.eudat.commons.enums.ReferenceType;
|
||||||
import eu.eudat.commons.enums.ReferenceSourceType;
|
import eu.eudat.commons.enums.ReferenceSourceType;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
|
import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.model.persist.referencetypedefinition.ReferenceTypeDefinitionPersist;
|
import eu.eudat.model.persist.referencetypedefinition.ReferenceTypeDefinitionPersist;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.StorageType;
|
import eu.eudat.commons.enums.StorageType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.data.StorageFileEntity;
|
import eu.eudat.data.StorageFileEntity;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.SupportiveMaterialFieldType;
|
import eu.eudat.commons.enums.SupportiveMaterialFieldType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.DmpBlueprintEntity;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.model.persist.tenantconfig.TenantConfigPersist;
|
import eu.eudat.model.persist.tenantconfig.TenantConfigPersist;
|
||||||
import jakarta.validation.constraints.*;
|
import jakarta.validation.constraints.*;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.UserDescriptionTemplateRole;
|
import eu.eudat.commons.enums.UserDescriptionTemplateRole;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -1,25 +1,14 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DescriptionTemplateTypeStatus;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.enums.IsActive;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
|
||||||
import eu.eudat.data.DescriptionEntity;
|
|
||||||
import eu.eudat.data.DescriptionTemplateTypeEntity;
|
|
||||||
import eu.eudat.data.UserEntity;
|
import eu.eudat.data.UserEntity;
|
||||||
import eu.eudat.model.UserAdditionalInfo;
|
|
||||||
import eu.eudat.model.UserContactInfo;
|
|
||||||
import eu.eudat.model.UserCredential;
|
|
||||||
import eu.eudat.model.UserRole;
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import eu.eudat.data.UserEntity;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package eu.eudat.model.persist;
|
package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.UserSettingsType;
|
import eu.eudat.commons.enums.UserSettingsType;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
package eu.eudat.model.persist.actionconfirmation;
|
package eu.eudat.model.persist.actionconfirmation;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpUserRole;
|
import eu.eudat.commons.enums.DmpUserRole;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
|
||||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
|
||||||
import jakarta.xml.bind.annotation.XmlAttribute;
|
|
||||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.model.persist.deposit;
|
package eu.eudat.model.persist.deposit;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import gr.cite.tools.fieldset.BaseFieldSet;
|
import gr.cite.tools.fieldset.BaseFieldSet;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
||||||
|
|
||||||
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
|
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import eu.eudat.commons.enums.FieldType;
|
import eu.eudat.commons.enums.FieldType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package eu.eudat.model.persist.descriptiontemplatedefinition.fielddata;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.enums.FieldDataExternalDatasetType;
|
import eu.eudat.commons.enums.FieldDataExternalDatasetType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class ExternalDatasetDataPersist extends BaseFieldDataPersist {
|
public class ExternalDatasetDataPersist extends BaseFieldDataPersist {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
|
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
|
|
||||||
|
|
||||||
public class ExtraFieldPersist extends FieldPersist {
|
public class ExtraFieldPersist extends FieldPersist {
|
||||||
|
|
|
@ -3,8 +3,8 @@ package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
|
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.dmpblueprintdefinition;
|
package eu.eudat.model.persist.dmpblueprintdefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
|
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
|
|
||||||
public class SystemFieldPersist extends FieldPersist {
|
public class SystemFieldPersist extends FieldPersist {
|
||||||
@ValidEnum(message = "{validation.empty}")
|
@ValidEnum(message = "{validation.empty}")
|
||||||
|
|
|
@ -4,8 +4,8 @@ import eu.eudat.commons.enums.notification.NotificationContactType;
|
||||||
import eu.eudat.commons.enums.notification.NotificationNotifyState;
|
import eu.eudat.commons.enums.notification.NotificationNotifyState;
|
||||||
import eu.eudat.commons.enums.notification.NotificationTrackingProcess;
|
import eu.eudat.commons.enums.notification.NotificationTrackingProcess;
|
||||||
import eu.eudat.commons.enums.notification.NotificationTrackingState;
|
import eu.eudat.commons.enums.notification.NotificationTrackingState;
|
||||||
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
|
import eu.eudat.commons.validation.old.FieldNotNullIfOtherSet;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.old.ValidId;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.referencedefinition;
|
package eu.eudat.model.persist.referencedefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.referencetypedefinition;
|
package eu.eudat.model.persist.referencetypedefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
public class AuthenticationConfigurationPersist {
|
public class AuthenticationConfigurationPersist {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package eu.eudat.model.persist.referencetypedefinition;
|
package eu.eudat.model.persist.referencetypedefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
import eu.eudat.commons.enums.ReferenceFieldDataType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package eu.eudat.model.persist.referencetypedefinition;
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package eu.eudat.model.persist.referencetypedefinition;
|
package eu.eudat.model.persist.referencetypedefinition;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
import eu.eudat.commons.enums.ReferenceTypeExternalApiHTTPMethodType;
|
||||||
import eu.eudat.commons.enums.ReferenceTypeSourceType;
|
import eu.eudat.commons.validation.old.ValidEnum;
|
||||||
import eu.eudat.commons.validation.ValidEnum;
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
|
@ -5,7 +5,7 @@ import gr.cite.notification.data.conventers.DatabaseEnum;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public enum DataType implements DatabaseEnum<Short> {
|
public enum NotificationDataType implements DatabaseEnum<Short> {
|
||||||
Integer((short)0),
|
Integer((short)0),
|
||||||
Decimal((short)1),
|
Decimal((short)1),
|
||||||
Double((short)2),
|
Double((short)2),
|
||||||
|
@ -14,7 +14,7 @@ public enum DataType implements DatabaseEnum<Short> {
|
||||||
String((short)5);
|
String((short)5);
|
||||||
private final Short value;
|
private final Short value;
|
||||||
|
|
||||||
DataType(Short value) {
|
NotificationDataType(Short value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ public enum DataType implements DatabaseEnum<Short> {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<Short, DataType> map = EnumUtils.getEnumValueMap(DataType.class);
|
private static final Map<Short, NotificationDataType> map = EnumUtils.getEnumValueMap(NotificationDataType.class);
|
||||||
|
|
||||||
public static DataType of(Short i) {
|
public static NotificationDataType of(Short i) {
|
||||||
return map.get(i);
|
return map.get(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
package gr.cite.notification.common.types.notification;
|
package gr.cite.notification.common.types.notification;
|
||||||
|
|
||||||
import gr.cite.notification.common.enums.DataType;
|
import gr.cite.notification.common.enums.NotificationDataType;
|
||||||
|
|
||||||
public class FieldInfo {
|
public class FieldInfo {
|
||||||
private String key;
|
private String key;
|
||||||
public final static String _key = "key";
|
public final static String _key = "key";
|
||||||
private DataType type;
|
private NotificationDataType type;
|
||||||
public final static String _type = "type";
|
public final static String _type = "type";
|
||||||
private String value;
|
private String value;
|
||||||
public final static String _value = "value";
|
public final static String _value = "value";
|
||||||
|
|
||||||
public FieldInfo(String key, DataType type, String value) {
|
public FieldInfo(String key, NotificationDataType type, String value) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -27,11 +27,11 @@ public class FieldInfo {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataType getType() {
|
public NotificationDataType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(DataType type) {
|
public void setType(NotificationDataType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package gr.cite.notification.common.types.notificationtemplate;
|
package gr.cite.notification.common.types.notificationtemplate;
|
||||||
|
|
||||||
import gr.cite.notification.common.enums.DataType;
|
import gr.cite.notification.common.enums.NotificationDataType;
|
||||||
|
|
||||||
public class FieldInfoEntity {
|
public class FieldInfoEntity {
|
||||||
private String key;
|
private String key;
|
||||||
private DataType type;
|
private NotificationDataType type;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public FieldInfoEntity(String key, DataType type, String value) {
|
public FieldInfoEntity(String key, NotificationDataType type, String value) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -24,11 +24,11 @@ public class FieldInfoEntity {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataType getType() {
|
public NotificationDataType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(DataType type) {
|
public void setType(NotificationDataType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ public class NotificationTemplatePersist {
|
||||||
@ValidEnum
|
@ValidEnum
|
||||||
private NotificationTemplateChannel channel;
|
private NotificationTemplateChannel channel;
|
||||||
|
|
||||||
@NotNull(message = "{validation.empty}")
|
|
||||||
@Valid
|
|
||||||
private UUID notificationType;
|
private UUID notificationType;
|
||||||
|
|
||||||
@ValidEnum
|
@ValidEnum
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package gr.cite.notification.model.persist.notificationtemplate;
|
package gr.cite.notification.model.persist.notificationtemplate;
|
||||||
|
|
||||||
import gr.cite.notification.common.enums.DataType;
|
import gr.cite.notification.common.enums.NotificationDataType;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
@ -13,13 +13,13 @@ public class FieldInfoPersist {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private DataType type;
|
private NotificationDataType type;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public FieldInfoPersist(String key, DataType type, String value) {
|
public FieldInfoPersist(String key, NotificationDataType type, String value) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -36,11 +36,11 @@ public class FieldInfoPersist {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataType getType() {
|
public NotificationDataType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(DataType type) {
|
public void setType(NotificationDataType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class NotificationTemplateQuery extends QueryBase<NotificationTemplateEnt
|
||||||
else if (item.match(NotificationTemplate._createdAt)) return NotificationTemplateEntity._createdAt;
|
else if (item.match(NotificationTemplate._createdAt)) return NotificationTemplateEntity._createdAt;
|
||||||
else if (item.match(NotificationTemplate._updatedAt)) return NotificationTemplateEntity._updatedAt;
|
else if (item.match(NotificationTemplate._updatedAt)) return NotificationTemplateEntity._updatedAt;
|
||||||
else if (item.match(NotificationTemplate._isActive)) return NotificationTemplateEntity._isActive;
|
else if (item.match(NotificationTemplate._isActive)) return NotificationTemplateEntity._isActive;
|
||||||
else if (item.match(NotificationTemplate._tenant)) return NotificationTemplateEntity._tenantId;
|
else if (item.prefix(NotificationTemplate._tenant)) return NotificationTemplateEntity._tenantId;
|
||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import gr.cite.notification.common.JsonHandlingService;
|
||||||
import gr.cite.notification.common.StringUtils;
|
import gr.cite.notification.common.StringUtils;
|
||||||
import gr.cite.notification.common.enums.IsActive;
|
import gr.cite.notification.common.enums.IsActive;
|
||||||
import gr.cite.notification.common.scope.tenant.TenantScope;
|
import gr.cite.notification.common.scope.tenant.TenantScope;
|
||||||
import gr.cite.notification.common.enums.DataType;
|
import gr.cite.notification.common.enums.NotificationDataType;
|
||||||
import gr.cite.notification.common.types.notification.FieldInfo;
|
import gr.cite.notification.common.types.notification.FieldInfo;
|
||||||
import gr.cite.notification.common.types.notification.NotificationFieldData;
|
import gr.cite.notification.common.types.notification.NotificationFieldData;
|
||||||
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer;
|
import gr.cite.notification.common.types.tenantconfiguration.DefaultUserLocaleConfigurationDataContainer;
|
||||||
|
@ -73,7 +73,7 @@ public class MessageBuilderServiceImpl implements MessageInfoBuilderService {
|
||||||
.map(field -> {
|
.map(field -> {
|
||||||
FieldInfo fieldInfo = new FieldInfo();
|
FieldInfo fieldInfo = new FieldInfo();
|
||||||
fieldInfo.setKey(field.getKey());
|
fieldInfo.setKey(field.getKey());
|
||||||
fieldInfo.setType(DataType.valueOf(field.getType()));
|
fieldInfo.setType(NotificationDataType.valueOf(field.getType()));
|
||||||
fieldInfo.setValue(field.getValue());
|
fieldInfo.setValue(field.getValue());
|
||||||
return fieldInfo;
|
return fieldInfo;
|
||||||
}).collect(Collectors.toList()));
|
}).collect(Collectors.toList()));
|
||||||
|
|
|
@ -92,16 +92,19 @@ public class NotificationServiceTemplateImpl implements NotificationTemplateServ
|
||||||
data = this.entityManager.find(NotificationTemplateEntity.class, model.getId());
|
data = this.entityManager.find(NotificationTemplateEntity.class, model.getId());
|
||||||
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), NotificationTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), NotificationTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
||||||
|
if (model.getNotificationType() != null){
|
||||||
|
data.setNotificationType(model.getNotificationType());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data = new NotificationTemplateEntity();
|
data = new NotificationTemplateEntity();
|
||||||
data.setId(UUID.randomUUID());
|
data.setId(UUID.randomUUID());
|
||||||
data.setIsActive(IsActive.Active);
|
data.setIsActive(IsActive.Active);
|
||||||
data.setCreatedAt(Instant.now());
|
data.setCreatedAt(Instant.now());
|
||||||
|
data.setNotificationType(UUID.randomUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setChannel(model.getChannel());
|
data.setChannel(model.getChannel());
|
||||||
data.setKind(model.getKind());
|
data.setKind(model.getKind());
|
||||||
data.setNotificationType(model.getNotificationType());
|
|
||||||
data.setLanguageId(model.getLanguageId());
|
data.setLanguageId(model.getLanguageId());
|
||||||
data.setValue(this.jsonHandlingService.toJsonSafe(this.buildNotificationTemplateValueEntity(model.getValue())));
|
data.setValue(this.jsonHandlingService.toJsonSafe(this.buildNotificationTemplateValueEntity(model.getValue())));
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
|
|
|
@ -1,30 +1,191 @@
|
||||||
package eu.eudat.controllers.controllerhandler;
|
package eu.eudat.controllers.controllerhandler;
|
||||||
|
|
||||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
import eu.eudat.commons.JsonHandlingService;
|
||||||
import gr.cite.tools.exception.MyValidationException;
|
import gr.cite.tools.exception.*;
|
||||||
|
import gr.cite.tools.logging.LoggerService;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(GlobalExceptionHandler.class));
|
||||||
|
|
||||||
private final ErrorThesaurusProperties errors;
|
private final JsonHandlingService jsonHandlingService;
|
||||||
|
|
||||||
public GlobalExceptionHandler(ErrorThesaurusProperties errors) {
|
public GlobalExceptionHandler(JsonHandlingService jsonHandlingService) {
|
||||||
this.errors = errors;
|
this.jsonHandlingService = jsonHandlingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
@ExceptionHandler(Exception.class)
|
||||||
public ResponseEntity<?> handleUnexpectedErrors(Exception e, WebRequest request) throws Exception {
|
public ResponseEntity<?> handleUnexpectedErrors(Exception exception, WebRequest request) throws Exception {
|
||||||
if (e instanceof MyValidationException argumentNotValidException) {
|
HandledException handled = this.handleException(exception, request);
|
||||||
return new ResponseEntity<>(argumentNotValidException.getErrors(), HttpStatus.BAD_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());
|
||||||
else {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package eu.eudat.controllers.controllerhandler;
|
package eu.eudat.controllers.controllerhandler;
|
||||||
|
|
||||||
import eu.eudat.commons.validation.BaseValidator;
|
import eu.eudat.commons.validation.Validator;
|
||||||
|
import eu.eudat.commons.validation.ValidatorFactory;
|
||||||
import eu.eudat.commons.validation.ValidationFilterAnnotation;
|
import eu.eudat.commons.validation.ValidationFilterAnnotation;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.http.HttpInputMessage;
|
import org.springframework.http.HttpInputMessage;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
@ -19,22 +18,28 @@ import java.util.Objects;
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
|
public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
|
||||||
@Autowired
|
private final ValidatorFactory validatorFactory;
|
||||||
private ApiContext apiContext;
|
|
||||||
|
public ValidatorRequestBodyAdvice(ValidatorFactory validatorFactory) {
|
||||||
|
this.validatorFactory = validatorFactory;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,
|
||||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
if (parameter.getMethod() != null) {
|
if (parameter.getMethod() != null) {
|
||||||
ValidationFilterAnnotation annotation = parameter.getMethod().getAnnotation((ValidationFilterAnnotation.class));
|
ValidationFilterAnnotation[] annotations = parameter.getMethod().getAnnotationsByType((ValidationFilterAnnotation.class));
|
||||||
|
|
||||||
if (annotation == null || !Objects.equals(parameter.getParameterName(), annotation.argumentName())) return body;
|
if (annotations == null) return body;
|
||||||
|
for (ValidationFilterAnnotation annotation : annotations){
|
||||||
|
if (!Objects.equals(parameter.getParameterName(), annotation.argumentName())) continue;
|
||||||
|
|
||||||
BaseValidator validator = this.apiContext.getOperationsContext().getApplicationContext().getBean(annotation.validator(), BaseValidator.class);
|
Validator validator = validatorFactory.validator(annotation.validator());
|
||||||
if (validator == null) throw new MyApplicationException("validator not provided");
|
if (validator == null) throw new MyApplicationException("validator not provided");
|
||||||
|
|
||||||
validator.validateForce(body);
|
validator.validateForce(body);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +49,8 @@ public class ValidatorRequestBodyAdvice implements RequestBodyAdvice {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
public boolean supports(MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||||
return true;
|
return parameter.getMethod() != null && parameter.getMethod().isAnnotationPresent((ValidationFilterAnnotation.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,3 +17,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}
|
|
@ -278,6 +278,18 @@ const appRoutes: Routes = [
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'notification-templates',
|
||||||
|
loadChildren: () => import('./ui/admin/notification-template/notification-template.module').then(m => m.NotificationTemplateModule),
|
||||||
|
data: {
|
||||||
|
authContext: {
|
||||||
|
permissions: [AppPermission.ViewNotificationTemplatePage]
|
||||||
|
},
|
||||||
|
...BreadcrumbService.generateRouteDataConfiguration({
|
||||||
|
title: 'BREADCRUMBS.NOTIFICATION-TEMPLATES'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'index-managment',
|
path: 'index-managment',
|
||||||
loadChildren: () => import('./ui/admin/index-managment/index-managment.module').then(m => m.IndexManagmentModule),
|
loadChildren: () => import('./ui/admin/index-managment/index-managment.module').then(m => m.IndexManagmentModule),
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
export enum EmailOverrideMode {
|
||||||
|
NotOverride = 0,
|
||||||
|
Additive = 1,
|
||||||
|
Replace = 2
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
export enum NotificationDataType {
|
||||||
|
Integer = 0,
|
||||||
|
Demical = 1,
|
||||||
|
Double = 2,
|
||||||
|
DateTime = 3,
|
||||||
|
String = 5
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
export enum NotificationTemplateChannel {
|
||||||
|
Email = 0,
|
||||||
|
InApp = 1,
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
export enum NotificationTemplateKind {
|
||||||
|
Draft = 0,
|
||||||
|
Secondary = 1,
|
||||||
|
Primary = 2,
|
||||||
|
Default = 3
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ export enum AppPermission {
|
||||||
ViewReferencePage = 'ViewReferencePage',
|
ViewReferencePage = 'ViewReferencePage',
|
||||||
ViewTenantPage = 'ViewTenantPage',
|
ViewTenantPage = 'ViewTenantPage',
|
||||||
ViewLanguagePage = "ViewLanguagePage",
|
ViewLanguagePage = "ViewLanguagePage",
|
||||||
|
ViewNotificationTemplatePage = "ViewNotificationTemplatePage",
|
||||||
|
|
||||||
//ReferenceType
|
//ReferenceType
|
||||||
BrowseReferenceType = "BrowseReferenceType",
|
BrowseReferenceType = "BrowseReferenceType",
|
||||||
|
@ -54,5 +55,10 @@ export enum AppPermission {
|
||||||
BrowseLanguage = "BrowseLanguage",
|
BrowseLanguage = "BrowseLanguage",
|
||||||
EditLanguage = "EditLanguage",
|
EditLanguage = "EditLanguage",
|
||||||
DeleteLanguage = "DeleteLanguage",
|
DeleteLanguage = "DeleteLanguage",
|
||||||
|
|
||||||
|
//Notification Template
|
||||||
|
BrowseNotificationTemplate = "BrowseNotificationTemplate",
|
||||||
|
EditNotificationTemplate = "EditNotificationTemplate",
|
||||||
|
DeleteNotificationTemplate = "DeleteNotificationTemplate",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ import { QueryParamsService } from './services/utilities/query-params.service';
|
||||||
import { LanguageHttpService } from './services/language/language.http.service';
|
import { LanguageHttpService } from './services/language/language.http.service';
|
||||||
import { DescriptionService } from './services/description/description.service';
|
import { DescriptionService } from './services/description/description.service';
|
||||||
import { MaintenanceService } from './services/maintenance/maintenance.service';
|
import { MaintenanceService } from './services/maintenance/maintenance.service';
|
||||||
|
import { NotificationTemplateService } from './services/notification-template/notification-template.service';
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// This is shared module that provides all the services. Its imported only once on the AppModule.
|
// This is shared module that provides all the services. Its imported only once on the AppModule.
|
||||||
|
@ -145,7 +146,8 @@ export class CoreServiceModule {
|
||||||
LanguageHttpService,
|
LanguageHttpService,
|
||||||
DmpServiceNew,
|
DmpServiceNew,
|
||||||
DescriptionService,
|
DescriptionService,
|
||||||
MaintenanceService
|
MaintenanceService,
|
||||||
|
NotificationTemplateService
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
import { NotificationTemplateChannel } from "@app/core/common/enum/notification-template-channel";
|
||||||
|
import { NotificationTemplateKind } from "@app/core/common/enum/notification-template-kind";
|
||||||
|
import { BaseEntity, BaseEntityPersist } from "@common/base/base-entity.model";
|
||||||
|
import { Guid } from "@common/types/guid";
|
||||||
|
import { Language } from "../language/language";
|
||||||
|
import { NotificationDataType } from "@app/core/common/enum/notification-data-type";
|
||||||
|
import { EmailOverrideMode } from "@app/core/common/enum/email-override-mode";
|
||||||
|
|
||||||
|
export interface NotificationTemplate extends BaseEntity{
|
||||||
|
channel: NotificationTemplateChannel;
|
||||||
|
notificationType: Guid;
|
||||||
|
kind: NotificationTemplateKind;
|
||||||
|
language: Language;
|
||||||
|
value: NotificationTemplateValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationTemplateValue {
|
||||||
|
subjectText: string;
|
||||||
|
subjectKey: string;
|
||||||
|
subjectFieldOptions: NotificationFieldOptions;
|
||||||
|
bodyText: string;
|
||||||
|
bodyKey: string;
|
||||||
|
priorityKey: string;
|
||||||
|
allowAttachments: Boolean;
|
||||||
|
cc: string[];
|
||||||
|
ccMode: EmailOverrideMode;
|
||||||
|
bcc: string[];
|
||||||
|
bccMode: EmailOverrideMode;
|
||||||
|
extraDataKeys: string[];
|
||||||
|
bodyFieldOptions: NotificationFieldOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationFieldOptions {
|
||||||
|
mandatory?: string[];
|
||||||
|
options?: NotificationFieldInfo[];
|
||||||
|
formatting?: { [key: string]: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationFieldInfo {
|
||||||
|
key: string;
|
||||||
|
dataType: NotificationDataType,
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Persist
|
||||||
|
|
||||||
|
export interface NotificationTemplatePersist extends BaseEntityPersist{
|
||||||
|
channel: NotificationTemplateChannel;
|
||||||
|
kind: NotificationTemplateKind;
|
||||||
|
languageId: Guid;
|
||||||
|
value: NotificationTemplateValuePersist;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationTemplateValuePersist {
|
||||||
|
subjectText: string;
|
||||||
|
subjectKey: string;
|
||||||
|
subjectFieldOptions: NotificationFieldOptionsPersist;
|
||||||
|
bodyText: string;
|
||||||
|
bodyKey: string;
|
||||||
|
priorityKey: string;
|
||||||
|
allowAttachments: Boolean;
|
||||||
|
cc: string[];
|
||||||
|
ccMode: EmailOverrideMode;
|
||||||
|
bcc: string[];
|
||||||
|
bccMode: EmailOverrideMode;
|
||||||
|
extraDataKeys: string[];
|
||||||
|
bodyFieldOptions: NotificationFieldOptionsPersist;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationFieldOptionsPersist {
|
||||||
|
mandatory?: string[];
|
||||||
|
options?: NotificationFieldInfoPersist[];
|
||||||
|
formatting?: { [key: string]: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationFieldInfoPersist {
|
||||||
|
key: string;
|
||||||
|
dataType: NotificationDataType,
|
||||||
|
value: string;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { Lookup } from "@common/model/lookup";
|
||||||
|
import { Guid } from "@common/types/guid";
|
||||||
|
import { IsActive } from "../common/enum/is-active.enum";
|
||||||
|
import { NotificationTemplateKind } from "../common/enum/notification-template-kind";
|
||||||
|
import { NotificationTemplateChannel } from "../common/enum/notification-template-channel";
|
||||||
|
|
||||||
|
export class NotificationTemplateLookup extends Lookup implements NotificationTemplateFilter {
|
||||||
|
ids: Guid[];
|
||||||
|
excludedIds: Guid[];
|
||||||
|
isActive: IsActive[];
|
||||||
|
kinds: NotificationTemplateKind[];
|
||||||
|
channels: NotificationTemplateChannel[];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NotificationTemplateFilter {
|
||||||
|
ids: Guid[];
|
||||||
|
excludedIds: Guid[];
|
||||||
|
isActive: IsActive[];
|
||||||
|
kinds: NotificationTemplateKind[];
|
||||||
|
channels: NotificationTemplateChannel[];
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { QueryResult } from '@common/model/query-result';
|
||||||
|
import { Guid } from '@common/types/guid';
|
||||||
|
import { NotificationTemplateKind } from '@app/core/common/enum/notification-template-kind';
|
||||||
|
import { NotificationTemplateLookup } from '@app/core/query/notification-template.lookup';
|
||||||
|
import { Observable, throwError } from 'rxjs';
|
||||||
|
import { catchError } from 'rxjs/operators';
|
||||||
|
import { NotificationTemplate, NotificationTemplatePersist } from '@app/core/model/notification-template/notification-template';
|
||||||
|
import { BaseHttpV2Service } from '../http/base-http-v2.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NotificationTemplateService {
|
||||||
|
|
||||||
|
constructor(private http: BaseHttpV2Service) {
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO ADD CONIFG URL
|
||||||
|
private get apiBase(): string { return `http://localhost:8081/api/notification-template`; }
|
||||||
|
|
||||||
|
query(q: NotificationTemplateLookup): Observable<QueryResult<NotificationTemplate>> {
|
||||||
|
const url = `${this.apiBase}/query`;
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.post<QueryResult<NotificationTemplate>>(url, q).pipe(
|
||||||
|
catchError((error: any) => throwError(error)));
|
||||||
|
}
|
||||||
|
|
||||||
|
getSingle(id: Guid, reqFields: string[] = []): Observable<NotificationTemplate> {
|
||||||
|
const url = `${this.apiBase}/${id}`;
|
||||||
|
const options = { params: { f: reqFields } };
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.get<NotificationTemplate>(url, options).pipe(
|
||||||
|
catchError((error: any) => throwError(error)));
|
||||||
|
}
|
||||||
|
|
||||||
|
updateKind(id: Guid, kind: NotificationTemplateKind): Observable<NotificationTemplate> {
|
||||||
|
const url = `${this.apiBase}/${id}/${kind}`;
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.post<NotificationTemplate>(url, {}).pipe(
|
||||||
|
catchError((error: any) => throwError(error)));
|
||||||
|
}
|
||||||
|
|
||||||
|
persist(item: NotificationTemplatePersist): Observable<NotificationTemplate> {
|
||||||
|
const url = `${this.apiBase}/persist`;
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.post<NotificationTemplate>(url, item).pipe(
|
||||||
|
catchError((error: any) => throwError(error)));
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(id: Guid): Observable<NotificationTemplate> {
|
||||||
|
const url = `${this.apiBase}/${id}`;
|
||||||
|
|
||||||
|
return this.http
|
||||||
|
.delete<NotificationTemplate>(url).pipe(
|
||||||
|
catchError((error: any) => throwError(error)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,10 @@ import { DmpStatus } from '../../common/enum/dmp-status';
|
||||||
import { ValidationType } from '../../common/enum/validation-type';
|
import { ValidationType } from '../../common/enum/validation-type';
|
||||||
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
||||||
import { DmpUserRole } from '@app/core/common/enum/dmp-user-role';
|
import { DmpUserRole } from '@app/core/common/enum/dmp-user-role';
|
||||||
|
import { NotificationTemplateKind } from '@app/core/common/enum/notification-template-kind';
|
||||||
|
import { NotificationTemplateChannel } from '@app/core/common/enum/notification-template-channel';
|
||||||
|
import { NotificationDataType } from '@app/core/common/enum/notification-data-type';
|
||||||
|
import { EmailOverrideMode } from '@app/core/common/enum/email-override-mode';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EnumUtils {
|
export class EnumUtils {
|
||||||
|
@ -376,4 +380,38 @@ export class EnumUtils {
|
||||||
case DmpUserRole.User: return this.language.instant('TYPES.DMP-USER-ROLE.USER');
|
case DmpUserRole.User: return this.language.instant('TYPES.DMP-USER-ROLE.USER');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toNotificationTemplateKindString(status: NotificationTemplateKind): string {
|
||||||
|
switch (status) {
|
||||||
|
case NotificationTemplateKind.Draft: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-KIND.DRAFT');
|
||||||
|
case NotificationTemplateKind.Secondary: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-KIND.SECONDARY');
|
||||||
|
case NotificationTemplateKind.Primary: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-KIND.PRIMARY');
|
||||||
|
case NotificationTemplateKind.Default: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-KIND.DEFAULT');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toNotificationTemplateChannelString(status: NotificationTemplateChannel): string {
|
||||||
|
switch (status) {
|
||||||
|
case NotificationTemplateChannel.Email: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-CHANNEL.EMAIL');
|
||||||
|
case NotificationTemplateChannel.InApp: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-CHANNEL.INAPP');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toNotificationTemplateDataTypeString(status: NotificationDataType): string {
|
||||||
|
switch (status) {
|
||||||
|
case NotificationDataType.Integer: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-DATA-TYPE.INTEGER');
|
||||||
|
case NotificationDataType.Demical: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-DATA-TYPE.DEMICAL');
|
||||||
|
case NotificationDataType.Double: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-DATA-TYPE.DOUBLE');
|
||||||
|
case NotificationDataType.DateTime: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-DATA-TYPE.DATE-TIME');
|
||||||
|
case NotificationDataType.String: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-DATA-TYPE.STRING');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toEmailOverrideModeString(status: EmailOverrideMode): string {
|
||||||
|
switch (status) {
|
||||||
|
case EmailOverrideMode.NotOverride: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-EMAIL-OVERRIDE-MODE.NOT');
|
||||||
|
case EmailOverrideMode.Additive: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-EMAIL-OVERRIDE-MODE.ADDITIVE');
|
||||||
|
case EmailOverrideMode.Replace: return this.language.instant('TYPES.NOTIFICATION-TEMPLATE-EMAIL-OVERRIDE-MODE.REPLACE');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,345 @@
|
||||||
|
<div class="notification-template-editor">
|
||||||
|
<div class="col-md-10 offset-md-1 colums-gapped">
|
||||||
|
|
||||||
|
<div class="row align-items-center mb-4" *ngIf="formGroup">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3 *ngIf="isNew && !isClone">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.NEW' | translate}}</h3>
|
||||||
|
<app-navigation-breadcrumb />
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button mat-button class="action-btn" (click)="cancel()" type="button">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.ACTIONS.CANCEL' | translate}}</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto" *ngIf="!isNew">
|
||||||
|
<button mat-button class="action-btn" type="button" (click)="delete()">
|
||||||
|
<mat-icon>delete</mat-icon>
|
||||||
|
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.ACTIONS.DELETE' | translate}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-auto" *ngIf="canSave">
|
||||||
|
<button mat-button class="action-btn" (click)="formSubmit()">
|
||||||
|
<mat-icon>save</mat-icon>
|
||||||
|
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.ACTIONS.SAVE' | translate}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form *ngIf="formGroup" (ngSubmit)="formSubmit()">
|
||||||
|
<mat-card appearance="outlined">
|
||||||
|
<mat-card-header>
|
||||||
|
<mat-card-title *ngIf="isNew">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.NEW' | translate}}</mat-card-title>
|
||||||
|
</mat-card-header>
|
||||||
|
<mat-card-content>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="w-100">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.LANGUAGE' | translate}}</mat-label>
|
||||||
|
<mat-select (selectionChange)="selectedLangChanged($event.value)" name="language" [formControl]="formGroup.get('language')">
|
||||||
|
<mat-option *ngFor="let languageCode of availableLanguageCodes" [value]="languageCode">
|
||||||
|
{{languageCode}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="formGroup.get('language').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="w-100">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KIND' | translate}}</mat-label>
|
||||||
|
<mat-select name="kind" [formControl]="formGroup.get('kind')" required>
|
||||||
|
<mat-option *ngFor="let kind of notificationTemplateKindEnum" [value]="kind">
|
||||||
|
{{enumUtils.toNotificationTemplateKindString(kind)}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="formGroup.get('channel').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="w-100">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.CHANNEL' | translate}}</mat-label>
|
||||||
|
<mat-select name="channel" [formControl]="formGroup.get('channel')" required>
|
||||||
|
<mat-option *ngFor="let channel of notificationTemplateChannelEnum" [value]="channel">
|
||||||
|
{{enumUtils.toNotificationTemplateChannelString(channel)}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="formGroup.get('channel').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Subject -->
|
||||||
|
<div class="row">
|
||||||
|
<h3 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.SUBJECT-SECTION' | translate}}</h3>
|
||||||
|
<mat-form-field class="col-md-12">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.SUBJECT-TEXT' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="formGroup.get('value').get('subjectText')">
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('subjectText').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-md-12">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.SUBJECT-KEY' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="formGroup.get('value').get('subjectKey')">
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('subjectKey').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h4 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.SUBJECT-FIELD-OPTIONS' | translate}}
|
||||||
|
<mat-checkbox (change)="subjectFieldOptionsSelectionChanged($event)"></mat-checkbox>
|
||||||
|
</h4>
|
||||||
|
<div *ngIf="subjectFieldOptionsEnabled == true">
|
||||||
|
<div class="col-6" >
|
||||||
|
<mat-form-field class="chip-list">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY' | translate}}</mat-label>
|
||||||
|
<mat-chip-grid #chipGrid [formControl]="formGroup.get('value').get('subjectFieldOptions').get('mandatory')">
|
||||||
|
<mat-chip-row *ngFor="let field of subjectMandatoryFields"
|
||||||
|
(removed)="removeChipListValues('subject', field)"
|
||||||
|
[editable]="true"
|
||||||
|
(edited)="editChipListValues('subject', $event, field)">
|
||||||
|
{{field}}
|
||||||
|
<button matChipRemove>
|
||||||
|
<mat-icon>cancel</mat-icon>
|
||||||
|
</button>
|
||||||
|
</mat-chip-row>
|
||||||
|
<input placeholder="{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY-PLACEHOLDER' | translate}}"
|
||||||
|
[matChipInputFor]="chipGrid"
|
||||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
|
||||||
|
[matChipInputAddOnBlur]="true"
|
||||||
|
(matChipInputTokenEnd)="addChipListValues('subject', $event)"/>
|
||||||
|
</mat-chip-grid>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<h4 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.OPTIONAL-TITLE' | translate}}</h4>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="row" *ngFor="let subjectOptions of formGroup.get('value').get('subjectFieldOptions').get('options')['controls']; let i = index">
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-auto">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="subjectOptions.get('key')">
|
||||||
|
<mat-error *ngIf="subjectOptions.get('key').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-auto">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.DATA-TYPE' | translate}}</mat-label>
|
||||||
|
<mat-select name="channel" [formControl]="subjectOptions.get('dataType')">
|
||||||
|
<mat-option *ngFor="let type of notificationDataTypeEnum" [value]="type">
|
||||||
|
{{enumUtils.toNotificationTemplateDataTypeString(type)}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="subjectOptions.get('dataType').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="subjectOptions.get('value')">
|
||||||
|
<mat-error *ngIf="subjectOptions.get('value').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button mat-icon-button (click)="removeOptionalItem(formGroup.get('value').get('subjectFieldOptions'),i)" [disabled]="formGroup.disabled">
|
||||||
|
<mat-icon>remove</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<button mat-icon-button (click)="addOptionalItem(formGroup.get('value').get('subjectFieldOptions'))" [disabled]="formGroup.disabled">
|
||||||
|
<mat-icon>add</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Body -->
|
||||||
|
<div class="row">
|
||||||
|
<h3 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-SECTION' | translate}}</h3>
|
||||||
|
<mat-form-field class="col-md-12">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-TEXT' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="formGroup.get('value').get('bodyText')">
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('bodyText').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-md-12">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-KEY' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="formGroup.get('value').get('bodyKey')">
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('bodyKey').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h4 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-FIELD-OPTIONS' | translate}}
|
||||||
|
<mat-checkbox (change)="bodyFieldOptionsSelectionChanged($event)"></mat-checkbox>
|
||||||
|
</h4>
|
||||||
|
<div *ngIf="bodyFieldOptionsEnabled == true">
|
||||||
|
<div class="col-6" >
|
||||||
|
<mat-form-field class="chip-list">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY' | translate}}</mat-label>
|
||||||
|
<mat-chip-grid #chipGrid [formControl]="formGroup.get('value').get('bodyFieldOptions').get('mandatory')">
|
||||||
|
<mat-chip-row *ngFor="let field of bodyMandatoryFields"
|
||||||
|
(removed)="removeChipListValues('body', field)"
|
||||||
|
[editable]="true"
|
||||||
|
(edited)="editChipListValues('body', $event, field)">
|
||||||
|
{{field}}
|
||||||
|
<button matChipRemove>
|
||||||
|
<mat-icon>cancel</mat-icon>
|
||||||
|
</button>
|
||||||
|
</mat-chip-row>
|
||||||
|
<input placeholder="{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY-PLACEHOLDER' | translate}}"
|
||||||
|
[matChipInputFor]="chipGrid"
|
||||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
|
||||||
|
[matChipInputAddOnBlur]="true"
|
||||||
|
(matChipInputTokenEnd)="addChipListValues('body',$event)"/>
|
||||||
|
</mat-chip-grid>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<h4 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.OPTIONAL-TITLE' | translate}}</h4>
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="row" *ngFor="let bodyOptions of formGroup.get('value').get('bodyFieldOptions').get('options')['controls']; let i = index">
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-auto">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="bodyOptions.get('key')">
|
||||||
|
<mat-error *ngIf="bodyOptions.get('key').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-auto">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.DATA-TYPE' | translate}}</mat-label>
|
||||||
|
<mat-select name="channel" [formControl]="bodyOptions.get('dataType')">
|
||||||
|
<mat-option *ngFor="let type of notificationDataTypeEnum" [value]="type">
|
||||||
|
{{enumUtils.toNotificationTemplateDataTypeString(type)}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="bodyOptions.get('dataType').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="bodyOptions.get('value')">
|
||||||
|
<mat-error *ngIf="bodyOptions.get('value').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
<div class="col-auto">
|
||||||
|
<button mat-icon-button (click)="removeOptionalItem(formGroup.get('value').get('bodyFieldOptions'),i)" [disabled]="formGroup.disabled">
|
||||||
|
<mat-icon>remove</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<button mat-icon-button (click)="addOptionalItem(formGroup.get('value').get('bodyFieldOptions'))" [disabled]="formGroup.disabled">
|
||||||
|
<mat-icon>add</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!--Extra Options -->
|
||||||
|
<div class="row">
|
||||||
|
<h3 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.EXTRA-OPTIONS' | translate}}</h3>
|
||||||
|
<div>
|
||||||
|
<h4 class="col-md-12">{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.ALLOW-ATTACHMENTS' | translate}}
|
||||||
|
<mat-checkbox [formControl]="formGroup.get('value').get('allowAttachments')"></mat-checkbox>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-md-12">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.PRIORITY-KEY' | translate}}</mat-label>
|
||||||
|
<input matInput [formControl]="formGroup.get('value').get('priorityKey')">
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('priorityKey').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4" >
|
||||||
|
<mat-form-field class="chip-list">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.CC' | translate}}</mat-label>
|
||||||
|
<mat-chip-grid #chipGrid [formControl]="formGroup.get('value').get('cc')">
|
||||||
|
<mat-chip-row *ngFor="let field of ccValues"
|
||||||
|
(removed)="removeChipListValues('cc', field)"
|
||||||
|
[editable]="true"
|
||||||
|
(edited)="editChipListValues('cc', $event, field)">
|
||||||
|
{{field}}
|
||||||
|
<button matChipRemove>
|
||||||
|
<mat-icon>cancel</mat-icon>
|
||||||
|
</button>
|
||||||
|
</mat-chip-row>
|
||||||
|
<input placeholder="{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY-PLACEHOLDER' | translate}}"
|
||||||
|
[matChipInputFor]="chipGrid"
|
||||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
|
||||||
|
[matChipInputAddOnBlur]="true"
|
||||||
|
(matChipInputTokenEnd)="addChipListValues('cc',$event)"/>
|
||||||
|
</mat-chip-grid>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-auto">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.CC-MODE' | translate}}</mat-label>
|
||||||
|
<mat-select name="ccMode" [formControl]="formGroup.get('value').get('ccMode')">
|
||||||
|
<mat-option *ngFor="let emailOverrideMode of emailOverrideModeEnum" [value]="emailOverrideMode">
|
||||||
|
{{enumUtils.toEmailOverrideModeString(emailOverrideMode)}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('ccMode').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- <div class="col-4" >
|
||||||
|
<mat-form-field class="chip-list">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BCC' | translate}}</mat-label>
|
||||||
|
<mat-chip-grid #chipGrid [formControl]="formGroup.get('value').get('bcc')">
|
||||||
|
<mat-chip-row *ngFor="let field of bccValues"
|
||||||
|
(removed)="removeChipListValues('bcc', field)"
|
||||||
|
[editable]="true"
|
||||||
|
(edited)="editChipListValues('bcc', $event, field)">
|
||||||
|
{{field}}
|
||||||
|
<button matChipRemove>
|
||||||
|
<mat-icon>cancel</mat-icon>
|
||||||
|
</button>
|
||||||
|
</mat-chip-row>
|
||||||
|
<input placeholder="{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY-PLACEHOLDER' | translate}}"
|
||||||
|
[matChipInputFor]="chipGrid"
|
||||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
|
||||||
|
[matChipInputAddOnBlur]="true"
|
||||||
|
(matChipInputTokenEnd)="addChipListValues('bcc',$event)"/>
|
||||||
|
</mat-chip-grid>
|
||||||
|
</mat-form-field>
|
||||||
|
</div> -->
|
||||||
|
<div class="col-4">
|
||||||
|
<mat-form-field class="col-auto">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BCC-MODE' | translate}}</mat-label>
|
||||||
|
<mat-select name="bccMode" [formControl]="formGroup.get('value').get('bccMode')">
|
||||||
|
<mat-option *ngFor="let emailOverrideMode of emailOverrideModeEnum" [value]="emailOverrideMode">
|
||||||
|
{{enumUtils.toEmailOverrideModeString(emailOverrideMode)}}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="formGroup.get('value').get('bccMode').hasError('required')">{{'COMMONS.VALIDATION.REQUIRED' | translate}}</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
<!-- <div class="col-4" >
|
||||||
|
<mat-form-field class="chip-list">
|
||||||
|
<mat-label>{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.EXTRA-DATA-KEYS' | translate}}</mat-label>
|
||||||
|
<mat-chip-grid #chipGrid [formControl]="formGroup.get('value').get('extraDataKeys')">
|
||||||
|
<mat-chip-row *ngFor="let field of extraDataKeys"
|
||||||
|
(removed)="removeChipListValues('extraDataKeys', field)"
|
||||||
|
[editable]="true"
|
||||||
|
(edited)="editChipListValues('extraDataKeys', $event, field)">
|
||||||
|
{{field}}
|
||||||
|
<button matChipRemove>
|
||||||
|
<mat-icon>cancel</mat-icon>
|
||||||
|
</button>
|
||||||
|
</mat-chip-row>
|
||||||
|
<input placeholder="{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY-PLACEHOLDER' | translate}}"
|
||||||
|
[matChipInputFor]="chipGrid"
|
||||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
|
||||||
|
[matChipInputAddOnBlur]="true"
|
||||||
|
(matChipInputTokenEnd)="addChipListValues('extraDataKeys',$event)"/>
|
||||||
|
</mat-chip-grid>
|
||||||
|
</mat-form-field>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
|
</mat-card-content>
|
||||||
|
</mat-card>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
.notification-template-editor {
|
||||||
|
margin-top: 1.3rem;
|
||||||
|
margin-left: 1em;
|
||||||
|
margin-right: 3em;
|
||||||
|
|
||||||
|
.remove {
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add {
|
||||||
|
background-color: white;
|
||||||
|
color: #009700;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .mat-checkbox-checked.mat-accent .mat-checkbox-background, .mat-checkbox-indeterminate.mat-accent .mat-checkbox-background {
|
||||||
|
background-color: var(--primary-color-3);
|
||||||
|
// background-color: #0070c0;
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep .mat-checkbox-disabled.mat-checkbox-checked .mat-checkbox-background, .mat-checkbox-disabled.mat-checkbox-indeterminate .mat-checkbox-background {
|
||||||
|
background-color: #b0b0b0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
border-radius: 30px;
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding-left: 2em;
|
||||||
|
padding-right: 2em;
|
||||||
|
box-shadow: 0px 3px 6px #1E202029;
|
||||||
|
|
||||||
|
transition-property: background-color, color;
|
||||||
|
transition-duration: 200ms;
|
||||||
|
transition-delay: 50ms;
|
||||||
|
transition-timing-function: ease-in-out;
|
||||||
|
&:disabled{
|
||||||
|
background-color: #CBCBCB;
|
||||||
|
color: #FFF;
|
||||||
|
border: 0px;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormArray, UntypedFormGroup } from '@angular/forms';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
||||||
|
import { FormService } from '@common/forms/form-service';
|
||||||
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
||||||
|
import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service';
|
||||||
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { NotificationTemplateKind } from '@app/core/common/enum/notification-template-kind';
|
||||||
|
import { AppPermission } from '@app/core/common/enum/permission.enum';
|
||||||
|
import { NotificationTemplate, NotificationTemplatePersist } from '@app/core/model/notification-template/notification-template';
|
||||||
|
import { NotificationTemplateService } from '@app/core/services/notification-template/notification-template.service';
|
||||||
|
import { NotificationFieldInfoEditorModel, NotificationFieldOptionsEditorModel, NotificationTemplateEditorModel } from './notification-template-editor.model';
|
||||||
|
import { map, takeUntil } from 'rxjs/operators';
|
||||||
|
import { BaseEditor } from '@common/base/base-editor';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { FilterService } from '@common/modules/text-filter/filter-service';
|
||||||
|
import { DatePipe } from '@angular/common';
|
||||||
|
import { QueryParamsService } from '@app/core/services/utilities/query-params.service';
|
||||||
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
||||||
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
||||||
|
import { NotificationTemplateEditorService } from './notification-template-editor.service';
|
||||||
|
import { Guid } from '@common/types/guid';
|
||||||
|
import { NotificationTemplateEditorResolver } from './notification-template-editor.resolver';
|
||||||
|
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
||||||
|
import { LoggingService } from '@app/core/services/logging/logging-service';
|
||||||
|
import { LanguageHttpService } from '@app/core/services/language/language.http.service';
|
||||||
|
import { Language } from '@app/core/model/language/language';
|
||||||
|
import { nameof } from 'ts-simple-nameof';
|
||||||
|
import { NotificationTemplateChannel } from '@app/core/common/enum/notification-template-channel';
|
||||||
|
import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips';
|
||||||
|
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||||
|
import { NotificationDataType } from '@app/core/common/enum/notification-data-type';
|
||||||
|
import { EmailOverrideMode } from '@app/core/common/enum/email-override-mode';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-notification-template-editor',
|
||||||
|
templateUrl: './notification-template-editor.component.html',
|
||||||
|
styleUrls: ['./notification-template-editor.component.scss'],
|
||||||
|
providers: [NotificationTemplateEditorService]
|
||||||
|
})
|
||||||
|
export class NotificationTemplateEditorComponent extends BaseEditor<NotificationTemplateEditorModel, NotificationTemplate> implements OnInit {
|
||||||
|
|
||||||
|
isNew = true;
|
||||||
|
isDeleted = false;
|
||||||
|
formGroup: UntypedFormGroup = null;
|
||||||
|
availableLanguageCodes: string[] = [];
|
||||||
|
selectedLangId: Guid = null;
|
||||||
|
subjectMandatoryFields: string[] = [];
|
||||||
|
bodyMandatoryFields: string[] = [];
|
||||||
|
subjectFieldOptionsEnabled: Boolean = false;
|
||||||
|
bodyFieldOptionsEnabled: Boolean = false;
|
||||||
|
ccValues: string[] = [];
|
||||||
|
bccValues: string[] = [];
|
||||||
|
extraDataKeys: string[] = [];
|
||||||
|
public notificationTemplateKindEnum = this.enumUtils.getEnumValues(NotificationTemplateKind);
|
||||||
|
public notificationTemplateChannelEnum = this.enumUtils.getEnumValues(NotificationTemplateChannel);
|
||||||
|
public notificationDataTypeEnum = this.enumUtils.getEnumValues(NotificationDataType);
|
||||||
|
public emailOverrideModeEnum = this.enumUtils.getEnumValues(EmailOverrideMode);
|
||||||
|
|
||||||
|
protected get canDelete(): boolean {
|
||||||
|
return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteNotificationTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get canSave(): boolean {
|
||||||
|
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditNotificationTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private hasPermission(permission: AppPermission): boolean {
|
||||||
|
return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
// BaseFormEditor injected dependencies
|
||||||
|
protected dialog: MatDialog,
|
||||||
|
protected language: TranslateService,
|
||||||
|
protected formService: FormService,
|
||||||
|
protected router: Router,
|
||||||
|
protected uiNotificationService: UiNotificationService,
|
||||||
|
protected httpErrorHandlingService: HttpErrorHandlingService,
|
||||||
|
protected filterService: FilterService,
|
||||||
|
protected datePipe: DatePipe,
|
||||||
|
protected route: ActivatedRoute,
|
||||||
|
protected queryParamsService: QueryParamsService,
|
||||||
|
// Rest dependencies. Inject any other needed deps here:
|
||||||
|
public authService: AuthService,
|
||||||
|
public enumUtils: EnumUtils,
|
||||||
|
private languageHttpService: LanguageHttpService,
|
||||||
|
private notificationTemplateService: NotificationTemplateService,
|
||||||
|
private notificationTemplateEditorService: NotificationTemplateEditorService,
|
||||||
|
private logger: LoggingService,
|
||||||
|
private matomoService: MatomoService
|
||||||
|
) {
|
||||||
|
super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ngOnInit(): void {
|
||||||
|
// this.editorModel = new NotificationTemplateEditorModel().fromModel(this.notificationTemplate);
|
||||||
|
// this.formGroup = this.editorModel.buildForm(null, this.editorModel.kind === NotificationTemplateKind.Default ? true : !this.authService.permissionEnum.EditDescription);
|
||||||
|
// }
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.matomoService.trackPageView('Admin: Notification Tempplates');
|
||||||
|
super.ngOnInit();
|
||||||
|
this.languageHttpService.queryAvailableCodes(this.languageHttpService.buildAutocompleteLookup())
|
||||||
|
.pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe(
|
||||||
|
data => this.availableLanguageCodes = data.items,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getItem(itemId: Guid, successFunction: (item: NotificationTemplate) => void) {
|
||||||
|
this.notificationTemplateService.getSingle(itemId, NotificationTemplateEditorResolver.lookupFields())
|
||||||
|
.pipe(map(data => data as NotificationTemplate), takeUntil(this._destroyed))
|
||||||
|
.subscribe(
|
||||||
|
data => successFunction(data),
|
||||||
|
error => this.onCallbackError(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareForm(data: NotificationTemplate) {
|
||||||
|
try {
|
||||||
|
this.editorModel = data ? new NotificationTemplateEditorModel().fromModel(data) : new NotificationTemplateEditorModel();
|
||||||
|
|
||||||
|
if(data){
|
||||||
|
if(data.value && data.value.subjectFieldOptions){
|
||||||
|
this.subjectFieldOptionsEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
|
||||||
|
this.buildForm();
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('Could not parse Tenant item: ' + data + error);
|
||||||
|
this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm() {
|
||||||
|
this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditNotificationTemplate));
|
||||||
|
this.notificationTemplateEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshData(): void {
|
||||||
|
this.getItem(this.editorModel.id, (data: NotificationTemplate) => this.prepareForm(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshOnNavigateToData(id?: Guid): void {
|
||||||
|
this.formGroup.markAsPristine();
|
||||||
|
let route = [];
|
||||||
|
|
||||||
|
if (id === null) {
|
||||||
|
route.push('../..');
|
||||||
|
} else if (this.isNew) {
|
||||||
|
route.push('../' + id);
|
||||||
|
} else {
|
||||||
|
route.push('..');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.router.navigate(route, { queryParams: { 'lookup': this.queryParamsService.serializeLookup(this.lookupParams), 'lv': ++this.lv }, replaceUrl: true, relativeTo: this.route });
|
||||||
|
}
|
||||||
|
|
||||||
|
persistEntity(onSuccess?: (response) => void): void {
|
||||||
|
const formData = this.formService.getValue(this.formGroup.value) as NotificationTemplatePersist;
|
||||||
|
|
||||||
|
this.notificationTemplateService.persist(formData)
|
||||||
|
.pipe(takeUntil(this._destroyed)).subscribe(
|
||||||
|
complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete),
|
||||||
|
error => this.onCallbackError(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
formSubmit(): void {
|
||||||
|
this.formService.touchAllFormFields(this.formGroup);
|
||||||
|
if (!this.isFormValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.persistEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
public delete() {
|
||||||
|
const value = this.formGroup.value;
|
||||||
|
if (value.id) {
|
||||||
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
||||||
|
maxWidth: '300px',
|
||||||
|
data: {
|
||||||
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
||||||
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
||||||
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
||||||
|
if (result) {
|
||||||
|
this.notificationTemplateService.delete(value.id).pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe(
|
||||||
|
complete => this.onCallbackSuccess(),
|
||||||
|
error => this.onCallbackError(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearErrorModel() {
|
||||||
|
this.editorModel.validationErrorModel.clear();
|
||||||
|
this.formService.validateAllFormFields(this.formGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedLangChanged(code: string){
|
||||||
|
|
||||||
|
this.languageHttpService.getSingleWithCode(code, [nameof<Language>(x => x.id),nameof<Language>(x => x.code)])
|
||||||
|
.pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe(
|
||||||
|
data => {
|
||||||
|
this.selectedLangId = data.id
|
||||||
|
console.log(this.formGroup);}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
subjectFieldOptionsSelectionChanged(matCheckBox: MatCheckboxChange){
|
||||||
|
if(matCheckBox.checked == true){
|
||||||
|
this.subjectFieldOptionsEnabled = true;
|
||||||
|
}else{
|
||||||
|
this.subjectFieldOptionsEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bodyFieldOptionsSelectionChanged(matCheckBox: MatCheckboxChange){
|
||||||
|
if(matCheckBox.checked == true){
|
||||||
|
this.bodyFieldOptionsEnabled = true;
|
||||||
|
}else{
|
||||||
|
this.bodyFieldOptionsEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// subject mandatory
|
||||||
|
|
||||||
|
addSubjectMandatory(event: MatChipInputEvent): void {
|
||||||
|
const value = (event.value || '').trim();
|
||||||
|
|
||||||
|
if (value) this.subjectMandatoryFields.push(value)
|
||||||
|
event.chipInput!.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeSubjectMandatory(field: string): void {
|
||||||
|
const index = this.subjectMandatoryFields.indexOf(field);
|
||||||
|
|
||||||
|
if (index >= 0) this.subjectMandatoryFields.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
editSubjectMandatory(field: string, event: MatChipEditedEvent) {
|
||||||
|
const value = event.value.trim();
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
this.removeSubjectMandatory(field);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = this.subjectMandatoryFields.indexOf(field);
|
||||||
|
if (index >= 0) this.subjectMandatoryFields[index] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// chip lists
|
||||||
|
|
||||||
|
addChipListValues(type: string, event: MatChipInputEvent){
|
||||||
|
if(type == "cc"){
|
||||||
|
this.ccValues = this.add(event, this.ccValues);
|
||||||
|
}else if(type == "bcc"){
|
||||||
|
this.bccValues = this.add(event, this.bccValues);
|
||||||
|
}else if(type == "extraDataKeys"){
|
||||||
|
this.extraDataKeys = this.add(event, this.extraDataKeys);
|
||||||
|
}else if(type == "subject"){
|
||||||
|
this.subjectMandatoryFields = this.add(event, this.subjectMandatoryFields);
|
||||||
|
}else if(type == "body"){
|
||||||
|
this.bodyMandatoryFields = this.add(event, this.bodyMandatoryFields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
editChipListValues(type: string, event: MatChipEditedEvent, field: string){
|
||||||
|
if(type == "cc"){
|
||||||
|
this.ccValues = this.edit(field, this.ccValues, event);
|
||||||
|
}else if(type == "bcc"){
|
||||||
|
this.bccValues = this.edit(field, this.bccValues, event);
|
||||||
|
}else if(type == "extraDataKeys"){
|
||||||
|
this.extraDataKeys = this.edit(field, this.extraDataKeys, event);
|
||||||
|
}else if(type == "subject"){
|
||||||
|
this.subjectMandatoryFields = this.edit(field, this.subjectMandatoryFields, event);
|
||||||
|
}else if(type == "body"){
|
||||||
|
this.bodyMandatoryFields = this.edit(field, this.bodyMandatoryFields, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeChipListValues(type: string, field: string){
|
||||||
|
if(type == "cc"){
|
||||||
|
this.ccValues = this.remove(field, this.ccValues);
|
||||||
|
}else if(type == "bcc"){
|
||||||
|
this.bccValues = this.remove(field, this.bccValues);
|
||||||
|
}else if(type == "extraDataKeys"){
|
||||||
|
this.extraDataKeys = this.remove(field, this.extraDataKeys);
|
||||||
|
}else if(type == "subject"){
|
||||||
|
this.subjectMandatoryFields = this.remove(field, this.subjectMandatoryFields);
|
||||||
|
}else if(type == "body"){
|
||||||
|
this.bodyMandatoryFields = this.remove(field, this.bodyMandatoryFields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add(event: MatChipInputEvent, values: string[]) {
|
||||||
|
const value = (event.value || '').trim();
|
||||||
|
|
||||||
|
if (value) values.push(value)
|
||||||
|
event.chipInput!.clear();
|
||||||
|
return values;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(field: string, values: string[]) {
|
||||||
|
const index = values.indexOf(field);
|
||||||
|
|
||||||
|
if (index >= 0) values.splice(index, 1);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
edit(field: string, values: string[], event: MatChipEditedEvent) {
|
||||||
|
const value = event.value.trim();
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
values = this.remove(field, values);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = values.indexOf(field);
|
||||||
|
if (index >= 0) values[index] = value
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
//options fields
|
||||||
|
|
||||||
|
addOptionalItem(formGroup: UntypedFormGroup) {
|
||||||
|
const fieldInfo: NotificationFieldInfoEditorModel = new NotificationFieldInfoEditorModel();
|
||||||
|
(formGroup.get('options') as FormArray).push(fieldInfo.buildForm());
|
||||||
|
}
|
||||||
|
|
||||||
|
removeOptionalItem(formGroup: UntypedFormGroup, optionalIndex: number): void {
|
||||||
|
(formGroup.get('options') as FormArray).removeAt(optionalIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,289 @@
|
||||||
|
import { FormArray, FormControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||||
|
import { NotificationFieldInfo, NotificationFieldInfoPersist, NotificationFieldOptions, NotificationFieldOptionsPersist, NotificationTemplate, NotificationTemplatePersist, NotificationTemplateValue, NotificationTemplateValuePersist } from '@app/core/model/notification-template/notification-template';
|
||||||
|
import { BackendErrorValidator } from '@common/forms/validation/custom-validator';
|
||||||
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
||||||
|
import { Validation, ValidationContext } from '@common/forms/validation/validation-context';
|
||||||
|
import { Guid } from '@common/types/guid';
|
||||||
|
import { NotificationTemplateChannel } from '@app/core/common/enum/notification-template-channel';
|
||||||
|
import { NotificationTemplateKind } from '@app/core/common/enum/notification-template-kind';
|
||||||
|
import { NotificationDataType } from '@app/core/common/enum/notification-data-type';
|
||||||
|
import { EmailOverrideMode } from '@app/core/common/enum/email-override-mode';
|
||||||
|
import { BaseEditorModel } from '@common/base/base-form-editor-model';
|
||||||
|
|
||||||
|
export class NotificationTemplateEditorModel extends BaseEditorModel implements NotificationTemplatePersist {
|
||||||
|
channel: NotificationTemplateChannel;
|
||||||
|
notificationType: Guid;
|
||||||
|
kind: NotificationTemplateKind;
|
||||||
|
languageId: Guid;
|
||||||
|
value: NotificationTemplateValueEditorModel = new NotificationTemplateValueEditorModel();
|
||||||
|
permissions: string[];
|
||||||
|
|
||||||
|
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
|
||||||
|
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||||
|
|
||||||
|
constructor() { super();}
|
||||||
|
|
||||||
|
public fromModel(item: NotificationTemplate): NotificationTemplateEditorModel {
|
||||||
|
if(item){
|
||||||
|
super.fromModel(item);
|
||||||
|
this.channel = item.channel;
|
||||||
|
this.notificationType = item.notificationType;
|
||||||
|
this.kind = item.kind;
|
||||||
|
if(item.language) //TODO this.language = item.language;
|
||||||
|
if (item.value) { this.value = new NotificationTemplateValueEditorModel().fromModel(item.value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup {
|
||||||
|
if (context == null) { context = this.createValidationContext(); }
|
||||||
|
|
||||||
|
return this.formBuilder.group({
|
||||||
|
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
|
||||||
|
channel: [{ value: this.channel, disabled: disabled }, context.getValidation('channel').validators],
|
||||||
|
notificationType: [{ value: this.notificationType, disabled: disabled }, context.getValidation('notificationType').validators],
|
||||||
|
kind: [{ value: this.kind, disabled: disabled }, context.getValidation('kind').validators],
|
||||||
|
language: [{ value: this.languageId, disabled: disabled }, context.getValidation('language').validators],
|
||||||
|
value: this.value.buildForm({
|
||||||
|
rootPath: `value.`
|
||||||
|
}),
|
||||||
|
hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createValidationContext(): ValidationContext {
|
||||||
|
const baseContext: ValidationContext = new ValidationContext();
|
||||||
|
const baseValidationArray: Validation[] = new Array<Validation>();
|
||||||
|
baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] });
|
||||||
|
baseValidationArray.push({ key: 'channel', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'channel')] });
|
||||||
|
baseValidationArray.push({ key: 'notificationType', validators: [BackendErrorValidator(this.validationErrorModel, 'notificationType')] });
|
||||||
|
baseValidationArray.push({ key: 'kind', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'kind')] });
|
||||||
|
baseValidationArray.push({ key: 'language', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'language')] });
|
||||||
|
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'value')] });
|
||||||
|
baseValidationArray.push({ key: 'hash', validators: [] });
|
||||||
|
|
||||||
|
baseContext.validation = baseValidationArray;
|
||||||
|
return baseContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NotificationTemplateValueEditorModel implements NotificationTemplateValuePersist {
|
||||||
|
subjectText: string;
|
||||||
|
subjectKey: string;
|
||||||
|
subjectFieldOptions: NotificationFieldOptionsEditorModel = new NotificationFieldOptionsEditorModel();
|
||||||
|
bodyText: string;
|
||||||
|
bodyKey: string;
|
||||||
|
priorityKey: string;
|
||||||
|
allowAttachments: Boolean = false;
|
||||||
|
cc: string[] = [];
|
||||||
|
ccMode: EmailOverrideMode;
|
||||||
|
bcc: string[] = [];
|
||||||
|
bccMode: EmailOverrideMode;
|
||||||
|
extraDataKeys: string[] = [];
|
||||||
|
bodyFieldOptions: NotificationFieldOptionsEditorModel = new NotificationFieldOptionsEditorModel();
|
||||||
|
|
||||||
|
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public fromModel(item: NotificationTemplateValue): NotificationTemplateValueEditorModel {
|
||||||
|
if (item) {
|
||||||
|
this.subjectText = item.subjectText;
|
||||||
|
this.subjectKey = item.subjectKey;
|
||||||
|
if (item.subjectFieldOptions) this.subjectFieldOptions = new NotificationFieldOptionsEditorModel().fromModel(item.subjectFieldOptions);
|
||||||
|
this.bodyText = item.bodyText;
|
||||||
|
this.bodyKey = item.bodyKey;
|
||||||
|
this.priorityKey = item.priorityKey;
|
||||||
|
this.allowAttachments = item.allowAttachments;
|
||||||
|
this.cc = item.cc;
|
||||||
|
this.ccMode = item.ccMode;
|
||||||
|
this.bcc = item.bcc;
|
||||||
|
this.bccMode = item.bccMode;
|
||||||
|
this.extraDataKeys = item.extraDataKeys;
|
||||||
|
if (item.bodyFieldOptions) this.bodyFieldOptions = new NotificationFieldOptionsEditorModel().fromModel(item.bodyFieldOptions);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm(params?: {
|
||||||
|
context?: ValidationContext,
|
||||||
|
disabled?: boolean,
|
||||||
|
rootPath?: string
|
||||||
|
}): UntypedFormGroup {
|
||||||
|
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||||
|
if (context == null) {
|
||||||
|
context = NotificationTemplateValueEditorModel.createValidationContext({
|
||||||
|
validationErrorModel: this.validationErrorModel,
|
||||||
|
rootPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.formBuilder.group({
|
||||||
|
subjectText: [{ value: this.subjectText, disabled: disabled }, context.getValidation('subjectText').validators],
|
||||||
|
subjectKey: [{ value: this.subjectKey, disabled: disabled }, context.getValidation('subjectKey').validators],
|
||||||
|
subjectFieldOptions: this.subjectFieldOptions.buildForm({
|
||||||
|
rootPath: `subjectFieldOptions.`
|
||||||
|
}),
|
||||||
|
bodyText: [{ value: this.bodyText, disabled: disabled }, context.getValidation('bodyText').validators],
|
||||||
|
bodyKey: [{ value: this.bodyKey, disabled: disabled }, context.getValidation('bodyKey').validators],
|
||||||
|
priorityKey: [{ value: this.priorityKey, disabled: disabled }, context.getValidation('priorityKey').validators],
|
||||||
|
allowAttachments: [{ value: this.allowAttachments, disabled: disabled }, context.getValidation('allowAttachments').validators],
|
||||||
|
cc: [{ value: this.cc, disabled: disabled }, context.getValidation('cc').validators],
|
||||||
|
ccMode: [{ value: this.ccMode, disabled: disabled }, context.getValidation('ccMode').validators],
|
||||||
|
bcc: [{ value: this.bcc, disabled: disabled }, context.getValidation('bcc').validators],
|
||||||
|
bccMode: [{ value: this.bccMode, disabled: disabled }, context.getValidation('bccMode').validators],
|
||||||
|
extraDataKeys: [{ value: this.extraDataKeys, disabled: disabled }, context.getValidation('extraDataKeys').validators],
|
||||||
|
bodyFieldOptions: this.bodyFieldOptions.buildForm({
|
||||||
|
rootPath: `bodyFieldOptions.`
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static createValidationContext(params: {
|
||||||
|
rootPath?: string,
|
||||||
|
validationErrorModel: ValidationErrorModel
|
||||||
|
}): ValidationContext {
|
||||||
|
const { rootPath = '', validationErrorModel } = params;
|
||||||
|
|
||||||
|
const baseContext: ValidationContext = new ValidationContext();
|
||||||
|
const baseValidationArray: Validation[] = new Array<Validation>();
|
||||||
|
baseValidationArray.push({ key: 'subjectText', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}subjectText`)] });
|
||||||
|
baseValidationArray.push({ key: 'subjectKey', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}subjectKey`)] });
|
||||||
|
baseValidationArray.push({ key: 'bodyText', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}bodyText`)] });
|
||||||
|
baseValidationArray.push({ key: 'bodyKey', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}bodyKey`)] });
|
||||||
|
baseValidationArray.push({ key: 'priorityKey', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}priorityKey`)] });
|
||||||
|
baseValidationArray.push({ key: 'allowAttachments', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}allowAttachments`)] });
|
||||||
|
baseValidationArray.push({ key: 'cc', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}cc`)] });
|
||||||
|
baseValidationArray.push({ key: 'ccMode', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}ccMode`)] });
|
||||||
|
baseValidationArray.push({ key: 'bcc', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}bcc`)] });
|
||||||
|
baseValidationArray.push({ key: 'bccMode', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}bccMode`)] });
|
||||||
|
baseValidationArray.push({ key: 'extraDataKeys', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}extraDataKeys`)] });
|
||||||
|
|
||||||
|
baseContext.validation = baseValidationArray;
|
||||||
|
return baseContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NotificationFieldOptionsEditorModel implements NotificationFieldOptionsPersist {
|
||||||
|
mandatory?: string[] = [];
|
||||||
|
options?: NotificationFieldInfoEditorModel[] = [];
|
||||||
|
formatting?: { [key: string]: string };
|
||||||
|
|
||||||
|
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public fromModel(item: NotificationFieldOptions): NotificationFieldOptionsEditorModel {
|
||||||
|
if (item) {
|
||||||
|
this.mandatory = item.mandatory;
|
||||||
|
if(item.options) { item.options.map(x => this.options.push(new NotificationFieldInfoEditorModel().fromModel(x))); }
|
||||||
|
this.formatting = item.formatting;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm(params?: {
|
||||||
|
context?: ValidationContext,
|
||||||
|
disabled?: boolean,
|
||||||
|
rootPath?: string
|
||||||
|
}): UntypedFormGroup {
|
||||||
|
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||||
|
if (context == null) {
|
||||||
|
context = NotificationFieldOptionsEditorModel.createValidationContext({
|
||||||
|
validationErrorModel: this.validationErrorModel,
|
||||||
|
rootPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.formBuilder.group({
|
||||||
|
mandatory: [{ value: this.mandatory, disabled: disabled }, context.getValidation('mandatory').validators],
|
||||||
|
formatting: [{ value: this.formatting, disabled: disabled }, context.getValidation('formatting').validators],
|
||||||
|
options: this.formBuilder.array(
|
||||||
|
(this.options ?? []).map(
|
||||||
|
(item, index) => new NotificationFieldInfoEditorModel(
|
||||||
|
this.validationErrorModel
|
||||||
|
).fromModel(item).buildForm({
|
||||||
|
rootPath: `options[${index}].`
|
||||||
|
}), context.getValidation('options')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static createValidationContext(params: {
|
||||||
|
rootPath?: string,
|
||||||
|
validationErrorModel: ValidationErrorModel
|
||||||
|
}): ValidationContext {
|
||||||
|
const { rootPath = '', validationErrorModel } = params;
|
||||||
|
|
||||||
|
const baseContext: ValidationContext = new ValidationContext();
|
||||||
|
const baseValidationArray: Validation[] = new Array<Validation>();
|
||||||
|
baseValidationArray.push({ key: 'mandatory', validators: [BackendErrorValidator(validationErrorModel,`${rootPath}mandatory`)] });
|
||||||
|
baseValidationArray.push({ key: 'options', validators: [BackendErrorValidator(validationErrorModel,`${rootPath}options`)] });
|
||||||
|
baseValidationArray.push({ key: 'formatting', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}formatting`)] });
|
||||||
|
baseContext.validation = baseValidationArray;
|
||||||
|
return baseContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NotificationFieldInfoEditorModel implements NotificationFieldInfoPersist {
|
||||||
|
key: string;
|
||||||
|
dataType: NotificationDataType;
|
||||||
|
value: string;
|
||||||
|
|
||||||
|
protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder();
|
||||||
|
|
||||||
|
constructor(public validationErrorModel: ValidationErrorModel = new ValidationErrorModel()
|
||||||
|
) { }
|
||||||
|
|
||||||
|
public fromModel(item: NotificationFieldInfo): NotificationFieldInfoEditorModel {
|
||||||
|
if (item) {
|
||||||
|
this.key = item.key;
|
||||||
|
this.dataType = item.dataType;
|
||||||
|
this.value = item.value;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm(params?: {
|
||||||
|
context?: ValidationContext,
|
||||||
|
disabled?: boolean,
|
||||||
|
rootPath?: string
|
||||||
|
}): UntypedFormGroup {
|
||||||
|
let { context = null, disabled = false, rootPath } = params ?? {}
|
||||||
|
if (context == null) {
|
||||||
|
context = NotificationFieldInfoEditorModel.createValidationContext({
|
||||||
|
validationErrorModel: this.validationErrorModel,
|
||||||
|
rootPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this.formBuilder.group({
|
||||||
|
key: [{ value: this.key, disabled: disabled }, context.getValidation('key').validators],
|
||||||
|
dataType: [{ value: this.dataType, disabled: disabled }, context.getValidation('dataType').validators],
|
||||||
|
value: [{ value: this.value, disabled: disabled }, context.getValidation('value').validators],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static createValidationContext(params: {
|
||||||
|
rootPath?: string,
|
||||||
|
validationErrorModel: ValidationErrorModel
|
||||||
|
}): ValidationContext {
|
||||||
|
const { rootPath = '', validationErrorModel } = params;
|
||||||
|
|
||||||
|
const baseContext: ValidationContext = new ValidationContext();
|
||||||
|
const baseValidationArray: Validation[] = new Array<Validation>();
|
||||||
|
|
||||||
|
baseValidationArray.push({ key: 'key', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}key`)] });
|
||||||
|
baseValidationArray.push({ key: 'dataType', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] });
|
||||||
|
baseValidationArray.push({ key: 'value', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}value`)] });
|
||||||
|
|
||||||
|
baseContext.validation = baseValidationArray;
|
||||||
|
return baseContext;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
||||||
|
import { NotificationTemplate } from '@app/core/model/notification-template/notification-template';
|
||||||
|
import { NotificationTemplateService } from '@app/core/services/notification-template/notification-template.service';
|
||||||
|
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
|
||||||
|
import { BaseEditorResolver } from '@common/base/base-editor.resolver';
|
||||||
|
import { Guid } from '@common/types/guid';
|
||||||
|
import { takeUntil, tap } from 'rxjs/operators';
|
||||||
|
import { nameof } from 'ts-simple-nameof';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NotificationTemplateEditorResolver extends BaseEditorResolver {
|
||||||
|
|
||||||
|
constructor(private notificationTemplateService: NotificationTemplateService, private breadcrumbService: BreadcrumbService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static lookupFields(): string[] {
|
||||||
|
return [
|
||||||
|
...BaseEditorResolver.lookupFields(),
|
||||||
|
nameof<NotificationTemplate>(x => x.id),
|
||||||
|
nameof<NotificationTemplate>(x => x.channel),
|
||||||
|
nameof<NotificationTemplate>(x => x.notificationType),
|
||||||
|
nameof<NotificationTemplate>(x => x.kind),
|
||||||
|
nameof<NotificationTemplate>(x => x.language),
|
||||||
|
nameof<NotificationTemplate>(x => x.createdAt),
|
||||||
|
nameof<NotificationTemplate>(x => x.updatedAt),
|
||||||
|
nameof<NotificationTemplate>(x => x.hash),
|
||||||
|
nameof<NotificationTemplate>(x => x.isActive)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||||
|
|
||||||
|
const fields = [
|
||||||
|
...NotificationTemplateEditorResolver.lookupFields()
|
||||||
|
];
|
||||||
|
const id = route.paramMap.get('id');
|
||||||
|
|
||||||
|
if (id != null) {
|
||||||
|
return this.notificationTemplateService.getSingle(Guid.parse(id), fields).pipe(tap(x => this.breadcrumbService.addIdResolvedValue(x.id?.toString(), x.language.code)), takeUntil(this._destroyed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { ValidationErrorModel } from "@common/forms/validation/error-model/validation-error-model";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NotificationTemplateEditorService {
|
||||||
|
private validationErrorModel: ValidationErrorModel;
|
||||||
|
|
||||||
|
public setValidationErrorModel(validationErrorModel: ValidationErrorModel): void {
|
||||||
|
this.validationErrorModel = validationErrorModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getValidationErrorModel(): ValidationErrorModel {
|
||||||
|
return this.validationErrorModel;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<div class="d-flex align-items-center gap-1-rem">
|
||||||
|
|
||||||
|
<button mat-flat-button [matMenuTriggerFor]="filterMenu" #filterMenuTrigger="matMenuTrigger" (click)="updateFilters()" class="filter-button">
|
||||||
|
<mat-icon aria-hidden="false" [matBadgeHidden]="!appliedFilterCount" [matBadge]="appliedFilterCount" matBadgeColor="warn" matBadgeSize="small">filter_alt</mat-icon>
|
||||||
|
{{'COMMONS.LISTING-COMPONENT.SEARCH-FILTER-BTN' | translate}}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
|
<mat-menu #filterMenu>
|
||||||
|
<div class="p-3" (click)="$event?.stopPropagation?.()">
|
||||||
|
<div class="search-listing-filters-container">
|
||||||
|
<div class="d-flex align-items-center justify-content-between">
|
||||||
|
<h4>{{'NOTIFICATION-TEMPLATE-LISTING.FILTER.TITLE' | translate}}</h4>
|
||||||
|
<button color="accent" mat-button (click)="clearFilters()">
|
||||||
|
{{'COMMONS.LISTING-COMPONENT.CLEAR-ALL-FILTERS' | translate}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<mat-slide-toggle labelPosition="before" [(ngModel)]="internalFilters.isActive">
|
||||||
|
{{'NOTIFICATION-TEMPLATE-LISTING.FILTER.IS-ACTIVE' | translate}}
|
||||||
|
</mat-slide-toggle>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-end align-items-center mt-4 gap-1-rem">
|
||||||
|
<button mat-stroked-button color="primary" (click)="filterMenuTrigger?.closeMenu()">
|
||||||
|
{{'NOTIFICATION-TEMPLATE-LISTING.FILTER.CANCEL' | translate}}
|
||||||
|
</button>
|
||||||
|
<button mat-raised-button color="primary" (click)="filterMenuTrigger.closeMenu(); applyFilters();">
|
||||||
|
{{'NOTIFICATION-TEMPLATE-LISTING.FILTER.APPLY-FILTERS' | translate}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</mat-menu>
|
||||||
|
|
||||||
|
<!-- <app-expandable-search-field [(value)]=internalFilters.like (valueChange)="onSearchTermChange($event)" /> -->
|
||||||
|
</div>
|
|
@ -0,0 +1,25 @@
|
||||||
|
.description-template-type-listing-filters {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
::ng-deep.mat-mdc-menu-panel {
|
||||||
|
max-width: 100% !important;
|
||||||
|
height: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host::ng-deep.mat-mdc-menu-content:not(:empty) {
|
||||||
|
padding-top: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.filter-button{
|
||||||
|
padding-top: .6rem;
|
||||||
|
padding-bottom: .6rem;
|
||||||
|
// .mat-icon{
|
||||||
|
// font-size: 1.5em;
|
||||||
|
// width: 1.2em;
|
||||||
|
// height: 1.2em;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
|
||||||
|
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
||||||
|
import { NotificationTemplateFilter } from '@app/core/query/notification-template.lookup';
|
||||||
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
||||||
|
import { BaseComponent } from '@common/base/base.component';
|
||||||
|
import { nameof } from 'ts-simple-nameof';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-notification-template-listing-filters',
|
||||||
|
templateUrl: './notification-template-listing-filters.component.html',
|
||||||
|
styleUrls: ['./notification-template-listing-filters.component.scss']
|
||||||
|
})
|
||||||
|
export class NotificationTemplateListingFiltersComponent extends BaseComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
|
@Input() readonly filter: NotificationTemplateFilter;
|
||||||
|
@Output() filterChange = new EventEmitter<NotificationTemplateFilter>();
|
||||||
|
|
||||||
|
// * State
|
||||||
|
internalFilters: TenantListingFilters = this._getEmptyFilters();
|
||||||
|
|
||||||
|
protected appliedFilterCount: number = 0;
|
||||||
|
constructor(
|
||||||
|
public enumUtils: EnumUtils,
|
||||||
|
) { super(); }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
const filterChange = changes[nameof<NotificationTemplateListingFiltersComponent>(x => x.filter)]?.currentValue as NotificationTemplateFilter;
|
||||||
|
if (filterChange) {
|
||||||
|
this.updateFilters()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
onSearchTermChange(searchTerm: string): void {
|
||||||
|
this.applyFilters()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected updateFilters(): void {
|
||||||
|
this.internalFilters = this._parseToInternalFilters(this.filter);
|
||||||
|
this.appliedFilterCount = this._computeAppliedFilters(this.internalFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected applyFilters(): void {
|
||||||
|
const { isActive } = this.internalFilters ?? {}
|
||||||
|
this.filterChange.emit({
|
||||||
|
...this.filter,
|
||||||
|
// like,
|
||||||
|
isActive: isActive ? [IsActive.Active] : [IsActive.Inactive]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private _parseToInternalFilters(inputFilter: NotificationTemplateFilter): TenantListingFilters {
|
||||||
|
if (!inputFilter) {
|
||||||
|
return this._getEmptyFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
let { excludedIds, ids, isActive } = inputFilter;
|
||||||
|
|
||||||
|
return {
|
||||||
|
isActive: (isActive ?? [])?.includes(IsActive.Active) || !isActive?.length,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getEmptyFilters(): TenantListingFilters {
|
||||||
|
return {
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _computeAppliedFilters(filters: TenantListingFilters): number {
|
||||||
|
let count = 0;
|
||||||
|
if (filters?.isActive) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearFilters() {
|
||||||
|
this.internalFilters = this._getEmptyFilters();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TenantListingFilters {
|
||||||
|
isActive: boolean;
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue