DmpBlueprint refactor

This commit is contained in:
Efstratios Giannopoulos 2023-10-23 10:21:25 +03:00
parent 30bff76163
commit 3ad7441bb5
5 changed files with 344 additions and 120 deletions

View File

@ -20,4 +20,13 @@ public class AuditableAction {
public static final EventId EntityDoi_Delete = new EventId(2003, "EntityDoi_Delete"); public static final EventId EntityDoi_Delete = new EventId(2003, "EntityDoi_Delete");
public static final EventId DmpBlueprint_Query = new EventId(3000, "DmpBlueprint_Query");
public static final EventId DmpBlueprint_Lookup = new EventId(3001, "DmpBlueprint_Lookup");
public static final EventId DmpBlueprint_Persist = new EventId(3002, "DmpBlueprint_Persist");
public static final EventId DmpBlueprint_Delete = new EventId(3003, "DmpBlueprint_Delete");
} }

View File

@ -0,0 +1,69 @@
package eu.eudat.query.lookup;
import eu.eudat.commons.enums.DmpBlueprintStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.query.DmpBlueprintQuery;
import gr.cite.tools.data.query.Lookup;
import gr.cite.tools.data.query.QueryFactory;
import java.util.List;
import java.util.UUID;
public class DmpBlueprintLookup extends Lookup {
private String like;
private List<IsActive> isActive;
private List<DmpBlueprintStatus> statuses;
private List<UUID> ids;
private List<UUID> excludedIds;
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
public List<IsActive> getIsActive() {
return isActive;
}
public void setIsActive(List<IsActive> isActive) {
this.isActive = isActive;
}
public List<UUID> getIds() {
return ids;
}
public void setIds(List<UUID> ids) {
this.ids = ids;
}
public List<UUID> getExcludedIds() {
return excludedIds;
}
public void setExcludedIds(List<UUID> excludeIds) {
this.excludedIds = excludeIds;
}
public DmpBlueprintQuery enrich(QueryFactory queryFactory) {
DmpBlueprintQuery query = queryFactory.query(DmpBlueprintQuery.class);
if (this.like != null) query.like(this.like);
if (this.isActive != null) query.isActive(this.isActive);
if (this.statuses != null) query.statuses(this.statuses);
if (this.ids != null) query.ids(this.ids);
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
this.enrichCommon(query);
return query;
}
}

View File

@ -0,0 +1,19 @@
package eu.eudat.service.dmpblueprint;
import eu.eudat.model.DmpBlueprint;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
import gr.cite.tools.fieldset.FieldSet;
import javax.management.InvalidApplicationException;
import java.util.UUID;
public interface DmpBlueprintService {
// DmpBlueprint persist(DmpBlueprintPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -0,0 +1,129 @@
package eu.eudat.service.dmpblueprint;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.event.EventBroker;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.model.builder.DmpBlueprintBuilder;
import eu.eudat.model.deleter.DmpBlueprintDeleter;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.exception.MyForbiddenException;
import gr.cite.tools.exception.MyNotFoundException;
import gr.cite.tools.exception.MyValidationException;
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 jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Service
public class DmpBlueprintServiceImpl implements DmpBlueprintService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintServiceImpl.class));
private final EntityManager entityManager;
private final AuthorizationService authorizationService;
private final DeleterFactory deleterFactory;
private final BuilderFactory builderFactory;
private final ConventionService conventionService;
private final ErrorThesaurusProperties errors;
private final MessageSource messageSource;
private final EventBroker eventBroker;
private final QueryFactory queryFactory;
private final JsonHandlingService jsonHandlingService;
@Autowired
public DmpBlueprintServiceImpl(
EntityManager entityManager,
AuthorizationService authorizationService,
DeleterFactory deleterFactory,
BuilderFactory builderFactory,
ConventionService conventionService,
ErrorThesaurusProperties errors,
MessageSource messageSource,
EventBroker eventBroker,
QueryFactory queryFactory,
JsonHandlingService jsonHandlingService) {
this.entityManager = entityManager;
this.authorizationService = authorizationService;
this.deleterFactory = deleterFactory;
this.builderFactory = builderFactory;
this.conventionService = conventionService;
this.errors = errors;
this.messageSource = messageSource;
this.eventBroker = eventBroker;
this.queryFactory = queryFactory;
this.jsonHandlingService = jsonHandlingService;
}
// public DmpBlueprint persist(DmpBlueprintPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
// logger.debug(new MapLogEntry("persisting data dmpBlueprint").And("model", model).And("fields", fields));
//
// this.authorizationService.authorizeForce(Permission.EditDmpBlueprint);
//
// Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
//
// DmpBlueprintEntity data;
// if (isUpdate) {
// data = this.entityManager.find(DmpBlueprintEntity.class, model.getId());
// if (data == null)
// throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
// } else {
// data = new DmpBlueprintEntity();
// data.setId(UUID.randomUUID());
// data.setIsActive(IsActive.Active);
// data.setCreatedAt(Instant.now());
// }
//
// data.setName(model.getName());
// data.setStatus(model.getStatus());
// data.setUpdatedAt(Instant.now());
// if (isUpdate)
// this.entityManager.merge(data);
// else
// this.entityManager.persist(data);
//
// this.entityManager.flush();
//
// this.eventBroker.emit(new DmpBlueprintTouchedEvent(data.getId()));
// return this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, DmpBlueprint._id), data);
// }
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting dataset: {}", id);
this.authorizationService.authorizeForce(Permission.DeleteDmpBlueprint);
this.deleterFactory.deleter(DmpBlueprintDeleter.class).deleteAndSaveByIds(List.of(id));
}
}

View File

@ -1,130 +1,128 @@
//package eu.eudat.controllers.v2; package eu.eudat.controllers.v2;
//
//import eu.eudat.audit.AuditableAction; import eu.eudat.audit.AuditableAction;
//import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
//import eu.eudat.data.DescriptionTemplateTypeEntity; import eu.eudat.data.DmpBlueprintEntity;
//import eu.eudat.model.DmpBlueprint; import eu.eudat.model.DmpBlueprint;
//import eu.eudat.model.builder.DescriptionTemplateTypeBuilder; import eu.eudat.model.builder.DmpBlueprintBuilder;
//import eu.eudat.model.censorship.DescriptionTemplateTypeCensor; import eu.eudat.model.censorship.DmpBlueprintCensor;
//import eu.eudat.model.persist.DescriptionTemplateTypePersist; import eu.eudat.model.result.QueryResult;
//import eu.eudat.model.result.QueryResult; import eu.eudat.query.DmpBlueprintQuery;
//import eu.eudat.query.DescriptionTemplateTypeQuery; import eu.eudat.query.lookup.DmpBlueprintLookup;
//import eu.eudat.query.lookup.DescriptionTemplateTypeLookup; import eu.eudat.service.dmpblueprint.DmpBlueprintService;
//import eu.eudat.service.DescriptionTemplateTypeService; import gr.cite.tools.auditing.AuditService;
//import gr.cite.tools.auditing.AuditService; import gr.cite.tools.data.builder.BuilderFactory;
//import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.censor.CensorFactory;
//import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.data.query.QueryFactory;
//import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException;
//import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException;
//import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyNotFoundException;
//import gr.cite.tools.exception.MyNotFoundException; import gr.cite.tools.fieldset.FieldSet;
//import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.LoggerService;
//import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.MapLogEntry;
//import gr.cite.tools.logging.MapLogEntry; import jakarta.transaction.Transactional;
//import gr.cite.tools.validation.MyValidate; import org.slf4j.LoggerFactory;
//import org.slf4j.LoggerFactory; import org.springframework.context.MessageSource;
//import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder;
//import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.*; import javax.management.InvalidApplicationException;
// import java.util.*;
//import javax.management.InvalidApplicationException;
//import java.util.*; @RestController
// @CrossOrigin
//@RestController @RequestMapping(path = "api/dmp-blueprint")
//@CrossOrigin public class DmpBlueprintController {
//@RequestMapping(path = "api/dmp-blueprint")
//public class DmpBlueprintController { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintController.class));
//
// private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpBlueprintController.class)); private final BuilderFactory builderFactory;
//
// private final BuilderFactory builderFactory; private final AuditService auditService;
//
// private final AuditService auditService; private final DmpBlueprintService dmpBlueprintService;
//
// private final DescriptionTemplateTypeService descriptionTemplateTypeService; private final CensorFactory censorFactory;
//
// private final CensorFactory censorFactory; private final QueryFactory queryFactory;
//
// private final QueryFactory queryFactory; private final MessageSource messageSource;
//
// private final MessageSource messageSource; public DmpBlueprintController(
// BuilderFactory builderFactory,
// public DmpBlueprintController( AuditService auditService,
// BuilderFactory builderFactory, DmpBlueprintService dmpBlueprintService,
// AuditService auditService, CensorFactory censorFactory,
// DescriptionTemplateTypeService descriptionTemplateTypeService, QueryFactory queryFactory,
// CensorFactory censorFactory, MessageSource messageSource) {
// QueryFactory queryFactory, this.builderFactory = builderFactory;
// MessageSource messageSource) { this.auditService = auditService;
// this.builderFactory = builderFactory; this.dmpBlueprintService = dmpBlueprintService;
// this.auditService = auditService; this.censorFactory = censorFactory;
// this.descriptionTemplateTypeService = descriptionTemplateTypeService; this.queryFactory = queryFactory;
// this.censorFactory = censorFactory; this.messageSource = messageSource;
// this.queryFactory = queryFactory; }
// this.messageSource = messageSource;
// } @PostMapping("query")
// public QueryResult<DmpBlueprint> Query(@RequestBody DmpBlueprintLookup lookup) throws MyApplicationException, MyForbiddenException {
// @PostMapping("query") logger.debug("querying {}", DmpBlueprint.class.getSimpleName());
// public QueryResult<DmpBlueprint> Query(@RequestBody DescriptionTemplateTypeLookup lookup) throws MyApplicationException, MyForbiddenException {
// logger.debug("querying {}", DmpBlueprint.class.getSimpleName()); this.censorFactory.censor(DmpBlueprintCensor.class).censor(lookup.getProject(), null);
//
// this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(lookup.getProject(), null); DmpBlueprintQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission);
//
// DescriptionTemplateTypeQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); List<DmpBlueprintEntity> data = query.collectAs(lookup.getProject());
// List<DmpBlueprint> models = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);
// List<DescriptionTemplateTypeEntity> data = query.collectAs(lookup.getProject()); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size();
// List<DmpBlueprint> models = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), data);
// 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);
// this.auditService.track(AuditableAction.DescriptionTemplateType_Query, "lookup", lookup);
// //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return new QueryResult<>(models, count);
// }
// return new QueryResult<>(models, count);
// } @GetMapping("{id}")
// public DmpBlueprint Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
// @GetMapping("{id}") logger.debug(new MapLogEntry("retrieving" + DmpBlueprint.class.getSimpleName()).And("id", id).And("fields", fieldSet));
// public DmpBlueprint Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
// logger.debug(new MapLogEntry("retrieving" + DmpBlueprint.class.getSimpleName()).And("id", id).And("fields", fieldSet)); this.censorFactory.censor(DmpBlueprintCensor.class).censor(fieldSet, null);
//
// this.censorFactory.censor(DescriptionTemplateTypeCensor.class).censor(fieldSet, null); DmpBlueprintQuery query = this.queryFactory.query(DmpBlueprintQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id);
// DmpBlueprint model = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet));
// DescriptionTemplateTypeQuery query = this.queryFactory.query(DescriptionTemplateTypeQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id); if (model == null)
// DmpBlueprint model = this.builderFactory.builder(DescriptionTemplateTypeBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale()));
// if (model == null)
// throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); this.auditService.track(AuditableAction.DmpBlueprint_Lookup, Map.ofEntries(
// new AbstractMap.SimpleEntry<String, Object>("id", id),
// this.auditService.track(AuditableAction.DescriptionTemplateType_Lookup, Map.ofEntries( new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
// new AbstractMap.SimpleEntry<String, Object>("id", id), ));
// new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
// ));
// //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); return model;
// }
// return model;
// }
//
// @PostMapping("persist") // @PostMapping("persist")
// @Transactional // @Transactional
// public DmpBlueprint Persist(@MyValidate @RequestBody DescriptionTemplateTypePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException { // public DmpBlueprint Persist(@MyValidate @RequestBody DmpBlueprintPersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException {
// logger.debug(new MapLogEntry("persisting" + DmpBlueprint.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); // logger.debug(new MapLogEntry("persisting" + DmpBlueprint.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet));
// DmpBlueprint persisted = this.descriptionTemplateTypeService.persist(model, fieldSet); // DmpBlueprint persisted = this.dmpBlueprintService.persist(model, fieldSet);
// //
// this.auditService.track(AuditableAction.DescriptionTemplateType_Persist, Map.ofEntries( // this.auditService.track(AuditableAction.DmpBlueprint_Persist, Map.ofEntries(
// new AbstractMap.SimpleEntry<String, Object>("model", model), // new AbstractMap.SimpleEntry<String, Object>("model", model),
// new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet) // new AbstractMap.SimpleEntry<String, Object>("fields", fieldSet)
// )); // ));
// //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); // //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
// return persisted; // return persisted;
// } // }
//
// @DeleteMapping("{id}") @DeleteMapping("{id}")
// @Transactional @Transactional
// public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { public void Delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException {
// logger.debug(new MapLogEntry("retrieving" + DmpBlueprint.class.getSimpleName()).And("id", id)); logger.debug(new MapLogEntry("retrieving" + DmpBlueprint.class.getSimpleName()).And("id", id));
//
// this.descriptionTemplateTypeService.deleteAndSave(id); this.dmpBlueprintService.deleteAndSave(id);
//
// this.auditService.track(AuditableAction.DescriptionTemplateType_Delete, "id", id); this.auditService.track(AuditableAction.DmpBlueprint_Delete, "id", id);
// //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action);
// } }
//} }