Implemented service for dmp entity
This commit is contained in:
parent
eeaa35fab5
commit
074ca35970
|
@ -3,6 +3,7 @@ package eu.eudat.event;
|
|||
import java.util.UUID;
|
||||
|
||||
public class DescriptionTemplateTypeTouchedEvent {
|
||||
|
||||
public DescriptionTemplateTypeTouchedEvent() {
|
||||
}
|
||||
|
||||
|
@ -19,4 +20,5 @@ public class DescriptionTemplateTypeTouchedEvent {
|
|||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package eu.eudat.event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class DmpTouchedEvent {
|
||||
|
||||
public DmpTouchedEvent() {
|
||||
}
|
||||
|
||||
public DmpTouchedEvent(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private UUID id;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
|
@ -41,4 +41,9 @@ public class EventBroker {
|
|||
public void emit(EntityDoiTouchedEvent event) {
|
||||
this.applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
|
||||
public void emit(DmpTouchedEvent event) {
|
||||
this.applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -247,4 +247,5 @@ public class Dmp {
|
|||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,182 @@
|
|||
package eu.eudat.model.persist;
|
||||
|
||||
import eu.eudat.commons.enums.DmpStatus;
|
||||
import eu.eudat.commons.validation.ValidId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DmpPersist {
|
||||
|
||||
@ValidId(message = "{validation.invalidid}")
|
||||
private UUID id;
|
||||
|
||||
private String label;
|
||||
|
||||
private Integer version;
|
||||
|
||||
private DmpStatus status;
|
||||
|
||||
private String properties;
|
||||
|
||||
private String dmpProperties;
|
||||
|
||||
private UUID groupId;
|
||||
|
||||
private String description;
|
||||
|
||||
private boolean isPublic;
|
||||
|
||||
private String extraProperties;
|
||||
|
||||
private Instant finalizedAt;
|
||||
|
||||
private Instant publishedAt;
|
||||
|
||||
private UUID grant;
|
||||
|
||||
private UUID profile;
|
||||
|
||||
private UUID creator;
|
||||
|
||||
private UUID project;
|
||||
|
||||
private String hash;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Integer getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Integer version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public DmpStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(DmpStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(String properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String getDmpProperties() {
|
||||
return dmpProperties;
|
||||
}
|
||||
|
||||
public void setDmpProperties(String dmpProperties) {
|
||||
this.dmpProperties = dmpProperties;
|
||||
}
|
||||
|
||||
public UUID getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(UUID groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean getIsPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
public void setIsPublic(boolean aPublic) {
|
||||
isPublic = aPublic;
|
||||
}
|
||||
|
||||
public String getExtraProperties() {
|
||||
return extraProperties;
|
||||
}
|
||||
|
||||
public void setExtraProperties(String extraProperties) {
|
||||
this.extraProperties = extraProperties;
|
||||
}
|
||||
|
||||
public Instant getFinalizedAt() {
|
||||
return finalizedAt;
|
||||
}
|
||||
|
||||
public void setFinalizedAt(Instant finalizedAt) {
|
||||
this.finalizedAt = finalizedAt;
|
||||
}
|
||||
|
||||
public Instant getPublishedAt() {
|
||||
return publishedAt;
|
||||
}
|
||||
|
||||
public void setPublishedAt(Instant publishedAt) {
|
||||
this.publishedAt = publishedAt;
|
||||
}
|
||||
|
||||
public UUID getGrant() {
|
||||
return grant;
|
||||
}
|
||||
|
||||
public void setGrant(UUID grant) {
|
||||
this.grant = grant;
|
||||
}
|
||||
|
||||
public UUID getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
public void setProfile(UUID profile) {
|
||||
this.profile = profile;
|
||||
}
|
||||
|
||||
public UUID getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public void setCreator(UUID creator) {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public UUID getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(UUID project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
package eu.eudat.service.dmp;
|
||||
|
||||
import eu.eudat.model.Dmp;
|
||||
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||
import eu.eudat.model.persist.DmpPersist;
|
||||
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 DmpService {
|
||||
|
||||
Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
|
||||
|
||||
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,146 @@
|
|||
package eu.eudat.service.dmp;
|
||||
|
||||
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.DescriptionTemplateTypeEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
||||
import eu.eudat.event.DescriptionTemplateTypeTouchedEvent;
|
||||
import eu.eudat.event.DmpTouchedEvent;
|
||||
import eu.eudat.event.EventBroker;
|
||||
import eu.eudat.model.DescriptionTemplateType;
|
||||
import eu.eudat.model.Dmp;
|
||||
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
|
||||
import eu.eudat.model.builder.DmpBuilder;
|
||||
import eu.eudat.model.deleter.DescriptionTemplateTypeDeleter;
|
||||
import eu.eudat.model.deleter.DmpDeleter;
|
||||
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
|
||||
import eu.eudat.model.persist.DmpPersist;
|
||||
import eu.eudat.service.descriptiontemplatetype.DescriptionTemplateTypeServiceImpl;
|
||||
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 DmpServiceImpl implements DmpService {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpServiceImpl.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 DmpServiceImpl(
|
||||
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 Dmp persist(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException {
|
||||
logger.debug(new MapLogEntry("persisting data dmp").And("model", model).And("fields", fields));
|
||||
|
||||
this.authorizationService.authorizeForce(Permission.EditDmp);
|
||||
|
||||
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
||||
|
||||
DmpEntity data;
|
||||
if (isUpdate) {
|
||||
data = this.entityManager.find(DmpEntity.class, model.getId());
|
||||
if (data == null)
|
||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||
} else {
|
||||
data = new DmpEntity();
|
||||
data.setId(UUID.randomUUID());
|
||||
data.setIsActive(IsActive.Active);
|
||||
data.setCreatedAt(Instant.now());
|
||||
}
|
||||
|
||||
data.setLabel(model.getLabel());
|
||||
data.setVersion(model.getVersion());
|
||||
data.setStatus(model.getStatus());
|
||||
data.setProperties(model.getProperties());
|
||||
data.setDmpProperties(model.getDmpProperties());
|
||||
data.setGroupId(model.getGroupId());
|
||||
data.setDescription(model.getDescription());
|
||||
data.setIsPublic(model.getIsPublic());
|
||||
data.setExtraProperties(model.getExtraProperties());
|
||||
data.setFinalizedAt(model.getFinalizedAt());
|
||||
data.setPublishedAt(model.getPublishedAt());
|
||||
data.setUpdatedAt(Instant.now());
|
||||
if (isUpdate)
|
||||
this.entityManager.merge(data);
|
||||
else
|
||||
this.entityManager.persist(data);
|
||||
|
||||
this.entityManager.flush();
|
||||
|
||||
this.eventBroker.emit(new DmpTouchedEvent(data.getId()));
|
||||
return this.builderFactory.builder(DmpBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, Dmp._id), data);
|
||||
}
|
||||
|
||||
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
|
||||
logger.debug("deleting dmp: {}", id);
|
||||
|
||||
this.authorizationService.authorizeForce(Permission.DeleteDmp);
|
||||
|
||||
this.deleterFactory.deleter(DmpDeleter.class).deleteAndSaveByIds(List.of(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue