Code cleanup

This commit is contained in:
Thomas Georgios Giannos 2024-01-05 14:02:22 +02:00
parent 897d099c2c
commit b7d1424e0c
9 changed files with 41 additions and 34 deletions

View File

@ -214,7 +214,7 @@ public class DescriptionPersist {
.iff(() -> !this.isNull(item.getProperties()))
.on(DescriptionPersist._properties)
.over(item.getProperties())
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class)),
.using(() -> this.validatorFactory.validator(PropertyDefinitionPersist.PropertyDefinitionPersistValidator.class).setStatus(item.getStatus())),
this.spec()
.iff(() -> item.getStatus() == DescriptionStatus.Finalized)
.must(() -> !this.isNull(item.getReferences()))

View File

@ -1,10 +1,12 @@
package eu.eudat.model.persist.descriptionproperties;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.validation.BaseValidator;
import eu.eudat.commons.validation.ValidatorFactory;
import eu.eudat.commons.validation.specification.Specification;
import eu.eudat.convention.ConventionService;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.model.persist.validation.StatusAware;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Scope;
@ -30,7 +32,7 @@ public class PropertyDefinitionPersist {
@Component(PropertyDefinitionPersistValidator.ValidatorName)
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class PropertyDefinitionPersistValidator extends BaseValidator<PropertyDefinitionPersist> {
public static class PropertyDefinitionPersistValidator extends BaseValidator<PropertyDefinitionPersist> implements StatusAware<DescriptionStatus> {
public static final String ValidatorName = "Description.PropertyDefinitionPersistValidator";
@ -38,6 +40,8 @@ public class PropertyDefinitionPersist {
private final ValidatorFactory validatorFactory;
private DescriptionStatus status;
protected PropertyDefinitionPersistValidator(ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, ValidatorFactory validatorFactory) {
super(conventionService, errors);
this.messageSource = messageSource;
@ -53,15 +57,22 @@ public class PropertyDefinitionPersist {
protected List<Specification> specifications(PropertyDefinitionPersist item) {
return Arrays.asList(
this.spec()
.iff(() -> this.status == DescriptionStatus.Finalized)
.must(() -> !this.isNull(item.getFields()))
.failOn(PropertyDefinitionPersist._fields).failWith(messageSource.getMessage("Validation_Required", new Object[]{PropertyDefinitionPersist._fields}, LocaleContextHolder.getLocale())),
this.navSpec()
.iff(() -> !this.isNull(item.getFields()))
.iff(() -> this.status == DescriptionStatus.Finalized && !this.isNull(item.getFields()))
.on(PropertyDefinitionPersist._fields)
.over(item.getFields())
.using(() -> this.validatorFactory.validator(FieldPersist.FieldPersistValidator.class))
);
}
@Override
public PropertyDefinitionPersistValidator setStatus(DescriptionStatus status) {
this.status = status;
return this;
}
}
}

View File

@ -1,9 +1,7 @@
package eu.eudat.service.user;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.model.DescriptionTemplateType;
import eu.eudat.model.User;
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
import eu.eudat.model.persist.UserPersist;
import eu.eudat.model.persist.UserRolePatchPersist;
import gr.cite.tools.exception.MyApplicationException;
@ -20,8 +18,11 @@ import java.util.UUID;
public interface UserService {
User persist(UserPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JsonProcessingException;
void updateLanguageMine(String language) throws InvalidApplicationException, JsonProcessingException;
void updateTimezoneMine(String timezone) throws JsonProcessingException;
void updateCultureMine(String culture) throws JsonProcessingException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;

View File

@ -35,7 +35,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
@ -155,7 +154,7 @@ public class DescriptionController {
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = DescriptionPersist.DescriptionPersistValidator.ValidatorName, argumentName = "model")
public Description persist(@MyValidate @RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
public Description persist(@RequestBody DescriptionPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JsonProcessingException {
logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Description persisted = this.descriptionService.persist(model, fieldSet);
@ -170,7 +169,7 @@ public class DescriptionController {
@PostMapping("persist-status")
@Transactional
@ValidationFilterAnnotation(validator = DescriptionStatusPersist.DescriptionStatusPersistValidator.ValidatorName, argumentName = "model")
public Description persistStatus(@MyValidate @RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
public Description persistStatus(@RequestBody DescriptionStatusPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("persisting" + Description.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
Description persisted = this.descriptionService.persistStatus(model, fieldSet);

View File

@ -23,7 +23,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
@ -88,7 +87,6 @@ public class DmpBlueprintController {
long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
this.auditService.track(AuditableAction.DmpBlueprint_Query, "lookup", lookup);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return new QueryResult<>(models, count);
}
@ -108,7 +106,6 @@ public class DmpBlueprintController {
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model;
}
@ -116,7 +113,7 @@ public class DmpBlueprintController {
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = DmpBlueprintPersist.DmpBlueprintPersistValidator.ValidatorName, argumentName = "model")
public DmpBlueprint persist(@MyValidate @RequestBody DmpBlueprintPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
public DmpBlueprint persist(@RequestBody DmpBlueprintPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting" + DmpBlueprint.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(DmpBlueprintCensor.class).censor(fieldSet, null);
@ -126,7 +123,7 @@ public class DmpBlueprintController {
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted;
}
@ -138,7 +135,6 @@ public class DmpBlueprintController {
this.dmpBlueprintService.deleteAndSave(id);
this.auditService.track(AuditableAction.DmpBlueprint_Delete, "id", id);
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
}
@GetMapping("clone/{id}")
@ -153,7 +149,6 @@ public class DmpBlueprintController {
new AbstractMap.SimpleEntry<String, Object>("id", id),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model;
}
@ -182,7 +177,6 @@ public class DmpBlueprintController {
new AbstractMap.SimpleEntry<String, Object>("file", file),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return model;
}

View File

@ -5,15 +5,12 @@ import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.data.DmpEntity;
import eu.eudat.file.transformer.model.file.FileFormat;
import eu.eudat.model.Dmp;
import eu.eudat.model.DmpUser;
import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.censorship.DmpCensor;
import eu.eudat.model.file.FileEnvelope;
import eu.eudat.model.persist.*;
import eu.eudat.model.result.QueryResult;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.query.DmpQuery;
import eu.eudat.query.lookup.DmpLookup;
@ -30,7 +27,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;

View File

@ -3,6 +3,7 @@ package eu.eudat.controllers.v2;
import com.fasterxml.jackson.core.JsonProcessingException;
import eu.eudat.audit.AuditableAction;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.validation.ValidationFilterAnnotation;
import eu.eudat.controllers.BaseController;
import eu.eudat.data.ReferenceTypeEntity;
import eu.eudat.logic.services.ApiContext;
@ -26,7 +27,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
@ -46,12 +46,19 @@ import java.util.UUID;
public class ReferenceTypeController extends BaseController {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceTypeController.class));
private final BuilderFactory builderFactory;
private final AuditService auditService;
private final CensorFactory censorFactory;
private final QueryFactory queryFactory;
private final MessageSource messageSource;
private final AuthorizationService authorizationService;
private final ReferenceTypeService referenceTypeService;
@Autowired
@ -85,7 +92,7 @@ public class ReferenceTypeController extends BaseController {
this.auditService.track(AuditableAction.ReferenceType_Query, "lookup", lookup);
return new QueryResult(models, count);
return new QueryResult<>(models, count);
}
@GetMapping("{id}")
@ -128,7 +135,8 @@ public class ReferenceTypeController extends BaseController {
@PostMapping("persist")
@Transactional
public ReferenceType persist(@MyValidate @RequestBody ReferenceTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {
@ValidationFilterAnnotation(validator = ReferenceTypePersist.ReferenceTypePersistValidator.ValidatorName, argumentName = "model")
public ReferenceType persist(@RequestBody ReferenceTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + ReferenceType.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
this.censorFactory.censor(ReferenceTypeCensor.class).censor(fieldSet, null);
@ -138,7 +146,7 @@ public class ReferenceTypeController extends BaseController {
new AbstractMap.SimpleEntry<String, Object>("model", model),
new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
));
//this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
return persisted;
}

View File

@ -33,7 +33,6 @@ import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.xml.bind.JAXBException;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;

View File

@ -23,7 +23,6 @@ import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.LoggerService;
import gr.cite.tools.logging.MapLogEntry;
import gr.cite.tools.validation.MyValidate;
import jakarta.transaction.Transactional;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -112,7 +111,7 @@ public class UserSettingsController {
@PostMapping("persist")
@Transactional
@ValidationFilterAnnotation(validator = UserSettingsPersist.UserSettingsPersistValidator.ValidatorName, argumentName = "model")
public UserSettings Persist(@MyValidate @RequestBody UserSettingsPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
public UserSettings Persist(@RequestBody UserSettingsPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
logger.debug(new MapLogEntry("persisting" + UserSettings.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
UserSettings persisted = this.settingsService.persist(model, fieldSet);