diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java index 622703c2f..0cdf46f5e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java +++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java @@ -45,5 +45,7 @@ public class AuditableAction { public static final EventId DescriptionTemplate_Lookup = new EventId(8001, "DescriptionTemplate_Lookup"); public static final EventId DescriptionTemplate_Persist = new EventId(8002, "DescriptionTemplate_Persist"); public static final EventId DescriptionTemplate_Delete = new EventId(8003, "DescriptionTemplate_Delete"); + public static final EventId DescriptionTemplate_Clone = new EventId(8004, "DescriptionTemplate_Clone"); + public static final EventId DescriptionTemplate_PersistNewVersion = new EventId(8005, "DescriptionTemplate_PersistNewVersion"); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java index 371460e3c..39599e1ec 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java +++ b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java @@ -27,6 +27,8 @@ public final class Permission { public static String BrowseDescriptionTemplate = "BrowseDescriptionTemplate"; public static String EditDescriptionTemplate = "EditDescriptionTemplate"; public static String DeleteDescriptionTemplate = "DeleteDescriptionTemplate"; + public static String CloneDescriptionTemplate = "CloneDescriptionTemplate"; + public static String CreateNewVersionDescriptionTemplate = "CreateNewVersionDescriptionTemplate"; //DescriptionTemplateType public static String BrowseDescriptionTemplateType = "BrowseDescriptionTemplateType"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java b/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java index 536391a02..929ae2a8f 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java +++ b/dmp-backend/core/src/main/java/eu/eudat/errorcode/ErrorThesaurusProperties.java @@ -45,4 +45,13 @@ public class ErrorThesaurusProperties { this.modelValidation = modelValidation; } + private ErrorDescription DescriptionTemplateNewVersionConflict; + + public ErrorDescription getDescriptionTemplateNewVersionConflict() { + return DescriptionTemplateNewVersionConflict; + } + + public void setDescriptionTemplateNewVersionConflict(ErrorDescription descriptionTemplateNewVersionConflict) { + DescriptionTemplateNewVersionConflict = descriptionTemplateNewVersionConflict; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java index c30ab8780..e26da6fcc 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/DescriptionTemplatePersist.java @@ -12,6 +12,7 @@ import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import java.util.List; import java.util.UUID; @FieldNotNullIfOtherSet(message = "{validation.hashempty}") @@ -44,6 +45,8 @@ public class DescriptionTemplatePersist { @Valid private DefinitionPersist definition = null; + private List users = null; + private String hash; @@ -110,5 +113,13 @@ public class DescriptionTemplatePersist { public void setDefinition(DefinitionPersist definition) { this.definition = definition; } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java new file mode 100644 index 000000000..8ba731b4b --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/persist/NewVersionDescriptionTemplatePersist.java @@ -0,0 +1,123 @@ +package eu.eudat.model.persist; + + +import eu.eudat.commons.enums.DescriptionTemplateStatus; +import eu.eudat.commons.validation.FieldNotNullIfOtherSet; +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.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; + +import java.util.List; +import java.util.UUID; + +@FieldNotNullIfOtherSet(message = "{validation.hashempty}") +public class NewVersionDescriptionTemplatePersist { + @NotNull(message = "{validation.empty}") + @ValidId(message = "{validation.invalidid}") + private UUID id = null; + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + @Size(max = DescriptionTemplateEntity._labelLength, message = "{validation.largerthanmax}") + private String label = null; + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + private String description = null; + + @NotNull(message = "{validation.empty}") + @NotEmpty(message = "{validation.empty}") + private String language = null; + + @NotNull(message = "{validation.empty}") + @ValidId(message = "{validation.invalidid}") + private UUID type = null; + + @ValidEnum(message = "{validation.empty}") + private DescriptionTemplateStatus status; + + @NotNull(message = "{validation.empty}") + @Valid + private DefinitionPersist definition = null; + private List users = null; + + 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 String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public UUID getType() { + return type; + } + + public void setType(UUID type) { + this.type = type; + } + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } + + public DescriptionTemplateStatus getStatus() { + return status; + } + + public void setStatus(DescriptionTemplateStatus status) { + this.status = status; + } + + public DefinitionPersist getDefinition() { + return definition; + } + + public void setDefinition(DefinitionPersist definition) { + this.definition = definition; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } +} + diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java index fa9b59b23..eb67bd54a 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DescriptionTemplateQuery.java @@ -27,6 +27,7 @@ public class DescriptionTemplateQuery extends QueryBase ids; + private Collection groupIds; private Collection isActives; @@ -73,6 +74,21 @@ public class DescriptionTemplateQuery extends QueryBase values) { + this.groupIds = values; + return this; + } + public DescriptionTemplateQuery isActive(IsActive value) { this.isActives = List.of(value); return this; @@ -139,7 +155,7 @@ public class DescriptionTemplateQuery extends QueryBase inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._groupId)); + for (UUID item : this.groupIds) + inClause.value(item); + predicates.add(inClause); + } if (this.like != null && !this.like.isEmpty()) { predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(DescriptionTemplateEntity._description), this.like), queryContext.CriteriaBuilder.like(queryContext.Root.get(DescriptionTemplateEntity._description), this.like) diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateService.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateService.java index 1068742ff..8a76c8688 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateService.java @@ -3,6 +3,7 @@ package eu.eudat.service.descriptiontemplate; import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.persist.DescriptionTemplatePersist; +import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist; import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyForbiddenException; import gr.cite.tools.exception.MyNotFoundException; @@ -18,7 +19,8 @@ import java.util.UUID; public interface DescriptionTemplateService { DescriptionTemplate persist(DescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException; - void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; + DescriptionTemplate buildClone(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException; + DescriptionTemplate createNewVersion(NewVersionDescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java index 11da8e49f..fea42b0af 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplate/DescriptionTemplateServiceImpl.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.XmlHandlingService; +import eu.eudat.commons.enums.DescriptionTemplateStatus; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.UserDescriptionTemplateRole; import eu.eudat.commons.scope.user.UserScope; @@ -12,16 +13,27 @@ import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.UserDescriptionTemplateEntity; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.DescriptionTemplate; import eu.eudat.model.builder.DescriptionTemplateBuilder; import eu.eudat.model.deleter.DescriptionTemplateDeleter; +import eu.eudat.model.deleter.UserDescriptionTemplateDeleter; +import eu.eudat.model.descriptiontemplatedefinition.Definition; +import eu.eudat.model.descriptiontemplatedefinition.Field; +import eu.eudat.model.descriptiontemplatedefinition.Page; +import eu.eudat.model.descriptiontemplatedefinition.Section; import eu.eudat.model.persist.DescriptionTemplatePersist; +import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist; import eu.eudat.model.persist.descriptiontemplatedefinition.*; import eu.eudat.model.persist.descriptiontemplatedefinition.fielddata.BaseFieldDataPersist; +import eu.eudat.query.DescriptionTemplateQuery; +import eu.eudat.query.UserDescriptionTemplateQuery; import eu.eudat.service.fielddatahelper.FieldDataHelperServiceProvider; 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.Ordering; +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; @@ -44,8 +56,10 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerException; import java.time.Instant; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; @Service public class DescriptionTemplateServiceImpl implements DescriptionTemplateService { @@ -64,6 +78,8 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic private final MessageSource messageSource; private final XmlHandlingService xmlHandlingService; private final FieldDataHelperServiceProvider fieldDataHelperServiceProvider; + private final QueryFactory queryFactory; + private final ErrorThesaurusProperties errors; @Autowired public DescriptionTemplateServiceImpl( @@ -74,7 +90,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic ConventionService conventionService, MessageSource messageSource, XmlHandlingService xmlHandlingService, - FieldDataHelperServiceProvider fieldDataHelperServiceProvider) { + FieldDataHelperServiceProvider fieldDataHelperServiceProvider, QueryFactory queryFactory, ErrorThesaurusProperties errors) { this.entityManager = entityManager; this.userScope = userScope; this.authorizationService = authorizationService; @@ -84,10 +100,12 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.messageSource = messageSource; this.xmlHandlingService = xmlHandlingService; this.fieldDataHelperServiceProvider = fieldDataHelperServiceProvider; + this.queryFactory = queryFactory; + this.errors = errors; } public DescriptionTemplate persist(DescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { - logger.debug(new MapLogEntry("persisting data descriptionTemplateType").And("model", model).And("fields", fields)); + logger.debug(new MapLogEntry("persisting data descriptionTemplate").And("model", model).And("fields", fields)); this.authorizationService.authorizeForce(Permission.EditDescriptionTemplate); @@ -97,6 +115,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic if (isUpdate) { data = this.entityManager.find(DescriptionTemplateEntity.class, model.getId()); if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { data = new DescriptionTemplateEntity(); data.setId(UUID.randomUUID()); @@ -118,6 +137,7 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic else this.entityManager.persist(data); + this.persistUsers(data.getId(), model.getUsers()); if (!isUpdate) this.addOwner(data); this.entityManager.flush(); @@ -125,6 +145,30 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); } + private void persistUsers(UUID id, List users) throws InvalidApplicationException { + if (users == null) users = new ArrayList<>(); + List items = this.queryFactory.query(UserDescriptionTemplateQuery.class).isActive(IsActive.Active).descriptionTemplateIds(id).collect(); + for (UUID userId : users) { + UserDescriptionTemplateEntity data = items.stream().filter(x -> x.getUser() == userId).findFirst().orElse(null); + if (data == null){ + data = new UserDescriptionTemplateEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setDescriptionTemplate(id); + data.setUser(userId); + data.setUser(userId); + data.setRole(UserDescriptionTemplateRole.Member); + this.entityManager.persist(data); + } + } + List finalUsers = users; + List toDelete = items.stream().filter(x-> finalUsers.stream().noneMatch(y-> y.equals(x.getUser()))).collect(Collectors.toList()); + + this.deleterFactory.deleter(UserDescriptionTemplateDeleter.class).delete(toDelete); + + } + private void addOwner(DescriptionTemplateEntity descriptionTemplateEntity) throws InvalidApplicationException { UserDescriptionTemplateEntity data = new UserDescriptionTemplateEntity(); data.setId(UUID.randomUUID()); @@ -273,5 +317,116 @@ public class DescriptionTemplateServiceImpl implements DescriptionTemplateServic this.deleterFactory.deleter(DescriptionTemplateDeleter.class).deleteAndSaveByIds(List.of(id)); } + public DescriptionTemplate buildClone(UUID id, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException { + logger.debug(new MapLogEntry("persisting data").And("id", id).And("fields", fields)); + + this.authorizationService.authorizeForce(Permission.CloneDescriptionTemplate); + + DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id); + DescriptionTemplate model = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fields, query.firstAs(fields)); + if (model == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + + model.setLabel(model.getLabel() + " new "); + model.setId(null); + model.setHash(null); + model.setStatus(DescriptionTemplateStatus.Draft); + this.reassignDefinition(model.getDefinition()); + + return model; + } + + private void reassignDefinition(Definition model){ + if (model == null) return; + + if (model.getSections() != null){ + for (Section section : model.getSections()) { + this.reassignSection(section); + } + } + + if (model.getPages() != null){ + for (Page page : model.getPages()) { + this.reassignPage(page); + } + } + } + + private void reassignPage(Page model){ + if (model == null) return; + model.setId(UUID.randomUUID().toString()); + } + + private void reassignSection(Section model){ + if (model == null) return; + model.setId(UUID.randomUUID().toString()); + + if (model.getSections() != null){ + for (Section section : model.getSections()) { + this.reassignSection(section); + } + } + if (model.getFieldSets() != null){ + for (eu.eudat.model.descriptiontemplatedefinition.FieldSet fieldSet : model.getFieldSets()) { + this.reassignFieldSet(fieldSet); + } + } + } + + private void reassignFieldSet(eu.eudat.model.descriptiontemplatedefinition.FieldSet model){ + if (model == null) return; + model.setId(UUID.randomUUID().toString()); + + if (model.getFields() != null){ + for (Field field : model.getFields()) { + this.reassignField(field); + } + } + } + + private void reassignField(Field model){ + if (model == null) return; + model.setId(UUID.randomUUID().toString()); + } + + public DescriptionTemplate createNewVersion(NewVersionDescriptionTemplatePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { + logger.debug(new MapLogEntry("persisting data descriptionTemplateType").And("model", model).And("fields", fields)); + + this.authorizationService.authorizeForce(Permission.CreateNewVersionDescriptionTemplate); + + DescriptionTemplateEntity oldDescriptionTemplateEntity = this.entityManager.find(DescriptionTemplateEntity.class, model.getId()); + if (oldDescriptionTemplateEntity == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplate.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(oldDescriptionTemplateEntity.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); + DescriptionTemplateQuery latestVersionDescriptionTemplateEntityQuery = this.queryFactory.query(DescriptionTemplateQuery.class).groupIds(oldDescriptionTemplateEntity.getGroupId()); + latestVersionDescriptionTemplateEntityQuery.setOrder(new Ordering().addDescending(DescriptionTemplateEntity._version)); + DescriptionTemplateEntity latestVersionDescriptionTemplateEntity = latestVersionDescriptionTemplateEntityQuery.first(); + if (!latestVersionDescriptionTemplateEntity.getVersion().equals(oldDescriptionTemplateEntity.getVersion())){ + throw new MyValidationException(this.errors.getDescriptionTemplateNewVersionConflict().getCode(), this.errors.getDescriptionTemplateNewVersionConflict().getMessage()); + } + + DescriptionTemplateEntity data = new DescriptionTemplateEntity(); + data.setId(UUID.randomUUID()); + data.setIsActive(IsActive.Active); + data.setCreatedAt(Instant.now()); + data.setUpdatedAt(Instant.now()); + data.setGroupId(oldDescriptionTemplateEntity.getGroupId()); + data.setVersion((short)(oldDescriptionTemplateEntity.getVersion() + 1)); + data.setDescription(model.getDescription()); + data.setLabel(model.getLabel()); + data.setType(model.getType()); + data.setLanguage(model.getLanguage()); + data.setStatus(model.getStatus()); + data.setDefinition(this.xmlHandlingService.toXml(this.buildDefinitionEntity(model.getDefinition()))); + + this.entityManager.persist(data); + + this.persistUsers(data.getId(), model.getUsers()); + + //this.addOwner(data); + + this.entityManager.flush(); + + return this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, DescriptionTemplate._id), data); + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java index 4a708c62c..59c7f71b8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/descriptiontemplatetype/DescriptionTemplateTypeServiceImpl.java @@ -58,10 +58,6 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy private final EventBroker eventBroker; - private final QueryFactory queryFactory; - - private final JsonHandlingService jsonHandlingService; - @Autowired public DescriptionTemplateTypeServiceImpl( EntityManager entityManager, @@ -71,9 +67,7 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, - EventBroker eventBroker, - QueryFactory queryFactory, - JsonHandlingService jsonHandlingService) { + EventBroker eventBroker) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -82,8 +76,6 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy this.errors = errors; this.messageSource = messageSource; this.eventBroker = eventBroker; - this.queryFactory = queryFactory; - this.jsonHandlingService = jsonHandlingService; } public DescriptionTemplateType persist(DescriptionTemplateTypePersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException { @@ -96,8 +88,8 @@ public class DescriptionTemplateTypeServiceImpl implements DescriptionTemplateTy DescriptionTemplateTypeEntity data; if (isUpdate) { data = this.entityManager.find(DescriptionTemplateTypeEntity.class, model.getId()); - if (data == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DescriptionTemplateType.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { data = new DescriptionTemplateTypeEntity(); data.setId(UUID.randomUUID()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java index cc1d12ec6..c768b0d96 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmp/DmpServiceImpl.java @@ -58,10 +58,6 @@ public class DmpServiceImpl implements DmpService { private final EventBroker eventBroker; - private final QueryFactory queryFactory; - - private final JsonHandlingService jsonHandlingService; - @Autowired public DmpServiceImpl( EntityManager entityManager, @@ -71,9 +67,7 @@ public class DmpServiceImpl implements DmpService { ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, - EventBroker eventBroker, - QueryFactory queryFactory, - JsonHandlingService jsonHandlingService) { + EventBroker eventBroker) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -82,8 +76,6 @@ public class DmpServiceImpl implements DmpService { 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 { @@ -96,8 +88,8 @@ public class DmpServiceImpl implements DmpService { 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())); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Dmp.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { data = new DmpEntity(); data.setId(UUID.randomUUID()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java index f7a3c50a7..18104f03e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/dmpblueprint/DmpBlueprintServiceImpl.java @@ -9,9 +9,9 @@ import eu.eudat.commons.enums.DmpBlueprintStatus; import eu.eudat.commons.enums.DmpBlueprintSystemFieldType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.types.dmpblueprint.*; -import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpBlueprintEntity; +import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.model.DmpBlueprint; import eu.eudat.model.builder.DmpBlueprintBuilder; import eu.eudat.model.deleter.DmpBlueprintDeleter; @@ -76,6 +76,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { private final QueryFactory queryFactory; private final ResponseUtilsService responseUtilsService; private final XmlHandlingService xmlHandlingService; + private final ErrorThesaurusProperties errors; @Autowired public DmpBlueprintServiceImpl( @@ -85,7 +86,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { BuilderFactory builderFactory, ConventionService conventionService, MessageSource messageSource, QueryFactory queryFactory, - ResponseUtilsService responseUtilsService, XmlHandlingService xmlHandlingService) { + ResponseUtilsService responseUtilsService, XmlHandlingService xmlHandlingService, ErrorThesaurusProperties errors) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -95,6 +96,7 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { this.queryFactory = queryFactory; this.responseUtilsService = responseUtilsService; this.xmlHandlingService = xmlHandlingService; + this.errors = errors; } public DmpBlueprint persist(DmpBlueprintPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, JsonProcessingException, TransformerException, ParserConfigurationException { @@ -107,8 +109,8 @@ public class DmpBlueprintServiceImpl implements DmpBlueprintService { 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())); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), DmpBlueprint.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { data = new DmpBlueprintEntity(); data.setId(UUID.randomUUID()); diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java index b0ad765f3..d17a2f439 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/entitydoi/EntityDoiServiceImpl.java @@ -60,10 +60,6 @@ public class EntityDoiServiceImpl implements EntityDoiService { private final EventBroker eventBroker; - private final QueryFactory queryFactory; - - private final JsonHandlingService jsonHandlingService; - @Autowired public EntityDoiServiceImpl( EntityManager entityManager, @@ -73,9 +69,7 @@ public class EntityDoiServiceImpl implements EntityDoiService { ConventionService conventionService, ErrorThesaurusProperties errors, MessageSource messageSource, - EventBroker eventBroker, - QueryFactory queryFactory, - JsonHandlingService jsonHandlingService) { + EventBroker eventBroker) { this.entityManager = entityManager; this.authorizationService = authorizationService; this.deleterFactory = deleterFactory; @@ -84,8 +78,6 @@ public class EntityDoiServiceImpl implements EntityDoiService { this.errors = errors; this.messageSource = messageSource; this.eventBroker = eventBroker; - this.queryFactory = queryFactory; - this.jsonHandlingService = jsonHandlingService; } public EntityDoi persist(EntityDoiPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException { @@ -98,8 +90,8 @@ public class EntityDoiServiceImpl implements EntityDoiService { EntityDoiEntity data; if (isUpdate) { data = this.entityManager.find(EntityDoiEntity.class, model.getId()); - if (data == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), EntityDoi.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (data == null) throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), EntityDoi.class.getSimpleName()}, LocaleContextHolder.getLocale())); + if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash())) throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage()); } else { data = new EntityDoiEntity(); data.setId(UUID.randomUUID()); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java index f1b69db73..d5a35fbcb 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java @@ -7,8 +7,6 @@ import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.UserDescriptionTemplateEntity; import eu.eudat.data.old.UserInfo; -import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; -import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException; import eu.eudat.logic.managers.AdminManager; import eu.eudat.logic.managers.DatasetProfileManager; import eu.eudat.logic.managers.MetricsManager; @@ -16,10 +14,7 @@ import eu.eudat.logic.managers.UserManager; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.admin.composite.DatasetProfile; -import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; -import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.helpers.responses.ResponseItem; -import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.query.DescriptionTemplateTypeQuery; import eu.eudat.service.descriptiontemplatetype.DescriptionTemplateTypeService; import eu.eudat.types.ApiMessageCode; @@ -68,105 +63,105 @@ public class Admin extends BaseController { this.descriptionTemplateTypeService = descriptionTemplateTypeService; } - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") - public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile) throws Exception { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - //this.getLoggerService().info(principal, "Admin Added Dataset Profile"); - DatasetProfile shortenProfile = profile.toShort(); - DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService); -// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType())); -//TODO: dtziotzios modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType())); - modelDefinition.setGroupId(UUID.randomUUID()); - modelDefinition.setVersion((short) 0); +// @Transactional +// @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") +// public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile) throws Exception { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// //this.getLoggerService().info(principal, "Admin Added Dataset Profile"); +// DatasetProfile shortenProfile = profile.toShort(); +// DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService); +//// modelDefinition.setType(getApiContext().getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType())); +////TODO: dtziotzios modelDefinition.setType(descriptionTemplateTypeService.getEntityByName(profile.getType())); +// modelDefinition.setGroupId(UUID.randomUUID()); +// modelDefinition.setVersion((short) 0); +// +// DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); +// UserDescriptionTemplateEntity userDatasetProfile = new UserDescriptionTemplateEntity(); +// userDatasetProfile.setDescriptionTemplate(descriptionTemplateEntity.getId()); +// UserInfo userInfo = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); +// userDatasetProfile.setUser(userInfo.getId()); +// userDatasetProfile.setRole(UserDescriptionTemplateRole.Owner); +// getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile); +// datasetProfileManager.storeDatasetProfileUsers(descriptionTemplateEntity, profile); +// +// metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(descriptionTemplateEntity.getStatus()) ); +// return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); +// } - DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); - UserDescriptionTemplateEntity userDatasetProfile = new UserDescriptionTemplateEntity(); - userDatasetProfile.setDescriptionTemplate(descriptionTemplateEntity.getId()); - UserInfo userInfo = getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao().find(this.userScope.getUserId()); - userDatasetProfile.setUser(userInfo.getId()); - userDatasetProfile.setRole(UserDescriptionTemplateRole.Owner); - getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile); - datasetProfileManager.storeDatasetProfileUsers(descriptionTemplateEntity, profile); +// @Transactional +// @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") +// public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile) throws Exception { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// DatasetProfile shortenProfile = profile.toShort(); +// DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService); +// DescriptionTemplateEntity datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); +// datasetprofile.setDefinition(modelDefinition.getDefinition()); +// DescriptionTemplateStatus oldStatus = datasetprofile.getStatus(); +// datasetprofile.setStatus(modelDefinition.getStatus()); +// datasetprofile.setLabel(modelDefinition.getLabel()); +// datasetprofile.setDescription(modelDefinition.getDescription()); +// datasetprofile.setLanguage(modelDefinition.getLanguage()); +// DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); +// datasetProfileManager.storeDatasetProfileUsers(descriptionTemplateEntity, profile); +// if (DescriptionTemplateStatus.Finalized.equals(descriptionTemplateEntity.getStatus()) && DescriptionTemplateStatus.Draft.equals(oldStatus)) { +// metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.ACTIVE); +// } +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); +// } - metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(descriptionTemplateEntity.getStatus()) ); - return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); - } +// @Transactional +// @RequestMapping(method = RequestMethod.POST, value = {"/newVersion/{id}"}, produces = "application/json") +// public ResponseEntity newVersionDatasetProfile(@PathVariable String id, @RequestBody DatasetProfile profile) throws Exception { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// try { +// DescriptionTemplateEntity modelDefinition = this.datasetProfileManager.createNewVersionDatasetProfile(id, profile); +// return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); +// } catch (DatasetProfileNewVersionException exception) { +// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); +// } +// } - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile) throws Exception { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - DatasetProfile shortenProfile = profile.toShort(); - DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext(), descriptionTemplateTypeService); - DescriptionTemplateEntity datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); - datasetprofile.setDefinition(modelDefinition.getDefinition()); - DescriptionTemplateStatus oldStatus = datasetprofile.getStatus(); - datasetprofile.setStatus(modelDefinition.getStatus()); - datasetprofile.setLabel(modelDefinition.getLabel()); - datasetprofile.setDescription(modelDefinition.getDescription()); - datasetprofile.setLanguage(modelDefinition.getLanguage()); - DescriptionTemplateEntity descriptionTemplateEntity = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); - datasetProfileManager.storeDatasetProfileUsers(descriptionTemplateEntity, profile); - if (DescriptionTemplateStatus.Finalized.equals(descriptionTemplateEntity.getStatus()) && DescriptionTemplateStatus.Draft.equals(oldStatus)) { - metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.ACTIVE); - } - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); - } +// @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json") +// @Transactional +// public ResponseEntity> get(@PathVariable String id) throws InvalidApplicationException { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id); +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile)); +// } - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/newVersion/{id}"}, produces = "application/json") - public ResponseEntity newVersionDatasetProfile(@PathVariable String id, @RequestBody DatasetProfile profile) throws Exception { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - try { - DescriptionTemplateEntity modelDefinition = this.datasetProfileManager.createNewVersionDatasetProfile(id, profile); - return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); - } catch (DatasetProfileNewVersionException exception) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); - } - } +// @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json") +// public @ResponseBody +// ResponseEntity>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// DataTableData datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem); +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); +// } - @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json") - @Transactional - public ResponseEntity> get(@PathVariable String id) throws InvalidApplicationException { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile)); - } +// @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json") +// public ResponseEntity> getPreview(@RequestBody DatasetProfile profile) throws Exception { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext(), descriptionTemplateTypeService); +// eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition); +// PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); +// pagedDatasetProfile.buildPagedDatasetProfile(datasetProfile); +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile)); +// } - @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json") - public @ResponseBody - ResponseEntity>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - DataTableData datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); - } - - @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> getPreview(@RequestBody DatasetProfile profile) throws Exception { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - DescriptionTemplateEntity modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext(), descriptionTemplateTypeService); - eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition); - PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); - pagedDatasetProfile.buildPagedDatasetProfile(datasetProfile); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile)); - } - - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> clone(@PathVariable String id) throws InvalidApplicationException { - this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - - eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id); - datasetprofile.setLabel(datasetprofile.getLabel() + " new "); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); - } +// @Transactional +// @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") +// public ResponseEntity> clone(@PathVariable String id) throws InvalidApplicationException { +// this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); +// +// eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = this.datasetProfileManager.getDatasetProfile(id); +// datasetprofile.setLabel(datasetprofile.getLabel() + " new "); +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); +// } // @Transactional // @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") @@ -205,8 +200,8 @@ public class Admin extends BaseController { @PathVariable(value = "id", required = false) String id) throws Exception { this.authorizationService.authorizeForce(Permission.AdminRole, Permission.DatasetProfileManagerRole); - eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file); - eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename()); + eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile descriptionTemplateImportXmlModel = this.datasetProfileManager.createDatasetProfileFromXml(file); + eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = descriptionTemplateImportXmlModel.toAdminCompositeModel(file.getOriginalFilename()); DescriptionTemplateEntity modelDefinition; if (id == null) { modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext(), descriptionTemplateTypeService); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java index 09f12b11f..5e6c69f16 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java @@ -52,16 +52,16 @@ public class DatasetProfileController extends BaseController { return ResponseEntity.status(HttpStatus.OK).body(properties); }*/ - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> clone(@PathVariable String id) throws InvalidApplicationException { - this.authorizationService.authorizeForce(Permission.AdminRole); - - DescriptionTemplateEntity profile = this.datasetProfileManager.clone(id); - eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); - datasetprofile.setLabel(profile.getLabel() + " new "); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); - } +// @Transactional +// @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") +// public ResponseEntity> clone(@PathVariable String id) throws InvalidApplicationException { +// this.authorizationService.authorizeForce(Permission.AdminRole); +// +// DescriptionTemplateEntity profile = this.datasetProfileManager.clone(id); +// eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); +// datasetprofile.setLabel(profile.getLabel() + " new "); +// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); +// } @RequestMapping(method = RequestMethod.POST, value = {"/search/autocomplete"}, consumes = "application/json", produces = "application/json") public ResponseEntity getDataForAutocomplete(@RequestBody RequestItem lookupItem) throws XPathExpressionException, InvalidApplicationException { diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java index 46e540048..e668774f8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java @@ -1,47 +1,47 @@ -package eu.eudat.controllers; - -import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest; -import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; -import eu.eudat.logic.managers.DatasetProfileManager; -import eu.eudat.logic.services.ApiContext; -import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem; -import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; -import eu.eudat.models.data.helpers.responses.ResponseItem; -import eu.eudat.types.ApiMessageCode; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import javax.management.InvalidApplicationException; -import java.util.List; - - -@RestController -@CrossOrigin -@RequestMapping(value = {"/api"}) -public class DatasetProfiles extends BaseController { - - private DatasetProfileManager datasetProfileManager; - - @Autowired - public DatasetProfiles(ApiContext apiContext, DatasetProfileManager datasetProfileManager) { - super(apiContext); - this.datasetProfileManager = datasetProfileManager; - } - - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/datasetprofiles/get"}, produces = "application/json") - public @ResponseBody - ResponseEntity>> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws InstantiationException, IllegalAccessException, InvalidApplicationException { - List datasetProfileAutocompleteItems = this.datasetProfileManager.getWithCriteria(datasetProfileAutocompleteRequest); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems)); - } - - @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getAll"}, produces = "application/json") - public @ResponseBody - ResponseEntity>> getAll(@RequestBody DatasetProfileTableRequestItem tableRequestItem) throws InstantiationException, IllegalAccessException, InvalidApplicationException { - List datasetProfileTableData = this.datasetProfileManager.getAll(tableRequestItem); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); - } -} - +//package eu.eudat.controllers; +// +//import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest; +//import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; +//import eu.eudat.logic.managers.DatasetProfileManager; +//import eu.eudat.logic.services.ApiContext; +//import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem; +//import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; +//import eu.eudat.models.data.helpers.responses.ResponseItem; +//import eu.eudat.types.ApiMessageCode; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.http.HttpStatus; +//import org.springframework.http.ResponseEntity; +//import org.springframework.web.bind.annotation.*; +// +//import javax.management.InvalidApplicationException; +//import java.util.List; +// +// +//@RestController +//@CrossOrigin +//@RequestMapping(value = {"/api"}) +//public class DatasetProfiles extends BaseController { +// +// private DatasetProfileManager datasetProfileManager; +// +// @Autowired +// public DatasetProfiles(ApiContext apiContext, DatasetProfileManager datasetProfileManager) { +// super(apiContext); +// this.datasetProfileManager = datasetProfileManager; +// } +// +//// @RequestMapping(method = RequestMethod.POST, value = {"/dmps/datasetprofiles/get"}, produces = "application/json") +//// public @ResponseBody +//// ResponseEntity>> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws InstantiationException, IllegalAccessException, InvalidApplicationException { +//// List datasetProfileAutocompleteItems = this.datasetProfileManager.getWithCriteria(datasetProfileAutocompleteRequest); +//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems)); +//// } +// +//// @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getAll"}, produces = "application/json") +//// public @ResponseBody +//// ResponseEntity>> getAll(@RequestBody DatasetProfileTableRequestItem tableRequestItem) throws InstantiationException, IllegalAccessException, InvalidApplicationException { +//// List datasetProfileTableData = this.datasetProfileManager.getAll(tableRequestItem); +//// return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); +//// } +//} +// diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java index af7739302..c676e712b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/DescriptionTemplateController.java @@ -5,9 +5,12 @@ import eu.eudat.audit.AuditableAction; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.model.DescriptionTemplate; +import eu.eudat.model.DmpBlueprint; import eu.eudat.model.builder.DescriptionTemplateBuilder; import eu.eudat.model.censorship.DescriptionTemplateCensor; +import eu.eudat.model.censorship.DmpBlueprintCensor; import eu.eudat.model.persist.DescriptionTemplatePersist; +import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist; import eu.eudat.model.result.QueryResult; import eu.eudat.query.DescriptionTemplateQuery; import eu.eudat.query.lookup.DescriptionTemplateLookup; @@ -69,7 +72,7 @@ public class DescriptionTemplateController { } @PostMapping("query") - public QueryResult Query(@RequestBody DescriptionTemplateLookup lookup) throws MyApplicationException, MyForbiddenException { + public QueryResult query(@RequestBody DescriptionTemplateLookup lookup) throws MyApplicationException, MyForbiddenException { logger.debug("querying {}", DescriptionTemplate.class.getSimpleName()); this.censorFactory.censor(DescriptionTemplateCensor.class).censor(lookup.getProject(), null); @@ -87,7 +90,7 @@ public class DescriptionTemplateController { } @GetMapping("{id}") - public DescriptionTemplate Get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + public DescriptionTemplate get(@PathVariable("id") UUID id, FieldSet fieldSet, Locale locale) throws MyApplicationException, MyForbiddenException, MyNotFoundException { logger.debug(new MapLogEntry("retrieving" + DescriptionTemplate.class.getSimpleName()).And("id", id).And("fields", fieldSet)); this.censorFactory.censor(DescriptionTemplateCensor.class).censor(fieldSet, null); @@ -108,7 +111,7 @@ public class DescriptionTemplateController { @PostMapping("persist") @Transactional - public DescriptionTemplate Persist(@MyValidate @RequestBody DescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { + public DescriptionTemplate persist(@MyValidate @RequestBody DescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { logger.debug(new MapLogEntry("persisting" + DescriptionTemplate.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); DescriptionTemplate persisted = this.descriptionTemplateTypeService.persist(model, fieldSet); @@ -122,7 +125,7 @@ public class DescriptionTemplateController { @DeleteMapping("{id}") @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" + DescriptionTemplate.class.getSimpleName()).And("id", id)); this.descriptionTemplateTypeService.deleteAndSave(id); @@ -130,4 +133,35 @@ public class DescriptionTemplateController { this.auditService.track(AuditableAction.DescriptionTemplate_Delete, "id", id); //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); } + + @GetMapping("clone/{id}") + public DescriptionTemplate buildClone(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + logger.debug(new MapLogEntry("clone" + DmpBlueprint.class.getSimpleName()).And("id", id).And("fields", fieldSet)); + + this.censorFactory.censor(DmpBlueprintCensor.class).censor(fieldSet, null); + + DescriptionTemplate model = this.descriptionTemplateTypeService.buildClone(id, fieldSet); + + this.auditService.track(AuditableAction.DescriptionTemplate_Clone, Map.ofEntries( + new AbstractMap.SimpleEntry("id", id), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); + //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + + return model; + } + + @PostMapping("new-version") + @Transactional + public DescriptionTemplate createNewVersion(@MyValidate @RequestBody NewVersionDescriptionTemplatePersist model, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { + logger.debug(new MapLogEntry("persisting" + NewVersionDescriptionTemplatePersist.class.getSimpleName()).And("model", model).And("fieldSet", fieldSet)); + DescriptionTemplate persisted = this.descriptionTemplateTypeService.createNewVersion(model, fieldSet); + + this.auditService.track(AuditableAction.DescriptionTemplate_PersistNewVersion, Map.ofEntries( + new AbstractMap.SimpleEntry("model", model), + new AbstractMap.SimpleEntry("fields", fieldSet) + )); + //this.auditService.trackIdentity(AuditableAction.IdentityTracking_Action); + return persisted; + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java index f032c779d..ba6251d2c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/SupportiveMaterialController.java @@ -22,8 +22,6 @@ import java.nio.file.Paths; import java.util.Objects; import java.util.stream.Stream; -import static eu.eudat.types.Authorities.ADMIN; - @RestController @RequestMapping(path = {"/api/material"}) public class SupportiveMaterialController { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java index 5a96b7a77..e9f2f7800 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java @@ -1,17 +1,15 @@ package eu.eudat.logic.managers; -import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.UserDescriptionTemplateRole; import eu.eudat.commons.scope.user.UserScope; import eu.eudat.data.UserDescriptionTemplateEntity; -import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.DescriptionTemplateEntity; +import eu.eudat.data.dao.criteria.DatasetProfileCriteria; import eu.eudat.data.old.UserInfo; import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteRequest; import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.exceptions.datasetprofile.DatasetProfileNewVersionException; -import eu.eudat.logic.builders.model.models.DataTableDataBuilder; import eu.eudat.logic.proxy.config.*; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.entities.GeneralUrls; @@ -23,12 +21,12 @@ import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.ExportXmlBuilderDatasetProfile; import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.ImportXmlBuilderDatasetProfile; import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity; +import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile; import eu.eudat.model.deleter.UserDescriptionTemplateDeleter; import eu.eudat.models.data.datasetprofile.DatasetProfileAutocompleteItem; import eu.eudat.models.data.datasetprofile.DatasetProfileListingModel; import eu.eudat.commons.types.descriptiontemplate.FieldEntity; import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel; -import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.query.DescriptionTemplateQuery; @@ -117,40 +115,40 @@ public class DatasetProfileManager { return datasetprofile; } - public List getWithCriteria(DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException, InvalidApplicationException { - QueryableList items = databaseRepository.getDatasetProfileDao().getWithCriteria(datasetProfileAutocompleteRequest.getCriteria()); - QueryableList pagedItems = datasetProfileAutocompleteRequest.applyPaging(items); - List datasetProfiles = pagedItems.select(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)); - return datasetProfiles; - } +// public List getWithCriteria(DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException, InvalidApplicationException { +// QueryableList items = databaseRepository.getDatasetProfileDao().getWithCriteria(datasetProfileAutocompleteRequest.getCriteria()); +// QueryableList pagedItems = datasetProfileAutocompleteRequest.applyPaging(items); +// List datasetProfiles = pagedItems.select(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)); +// return datasetProfiles; +// } +// +// public DescriptionTemplateEntity clone(String id) throws InvalidApplicationException { +// DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); +// apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile); +// profile.setId(null); +// return profile; +// } - public DescriptionTemplateEntity clone(String id) throws InvalidApplicationException { - DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); - apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile); - profile.setId(null); - return profile; - } +// public DataTableData getPaged(DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { +// QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria()); +// QueryableList authItems = null; +// if (this.authorizationService.authorize(Permission.AdminRole)) { +// authItems = items; +// } else if (this.authorizationService.authorize(Permission.DatasetProfileManagerRole)) { +// List roles = Arrays.asList(0, 1); +// authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getAuthenticated(items, this.userScope.getUserId(), roles); +// } +// QueryableList pagedItems = PaginationManager.applyPaging(authItems, datasetProfileTableRequestItem); +// List datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item)); +// return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build(); +// } - public DataTableData getPaged(DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { - QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria()); - QueryableList authItems = null; - if (this.authorizationService.authorize(Permission.AdminRole)) { - authItems = items; - } else if (this.authorizationService.authorize(Permission.DatasetProfileManagerRole)) { - List roles = Arrays.asList(0, 1); - authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getAuthenticated(items, this.userScope.getUserId(), roles); - } - QueryableList pagedItems = PaginationManager.applyPaging(authItems, datasetProfileTableRequestItem); - List datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item)); - return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build(); - } - - public List getAll(DatasetProfileTableRequestItem tableRequestItem) throws IllegalAccessException, InstantiationException, InvalidApplicationException { - QueryableList items = databaseRepository.getDatasetProfileDao().getWithCriteria(tableRequestItem.getCriteria()); - List datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item)); - - return datasetProfiles; - } +// public List getAll(DatasetProfileTableRequestItem tableRequestItem) throws IllegalAccessException, InstantiationException, InvalidApplicationException { +// QueryableList items = databaseRepository.getDatasetProfileDao().getWithCriteria(tableRequestItem.getCriteria()); +// List datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item)); +// +// return datasetProfiles; +// } public FieldEntity queryForField(String xml, String fieldId) throws XPathExpressionException { FieldEntity fieldEntity = new FieldEntity(); @@ -341,7 +339,7 @@ public class DatasetProfileManager { return fileEnvelope; } - public eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile createDatasetProfileFromXml(MultipartFile multiPartFile) { + public DatasetProfile createDatasetProfileFromXml(MultipartFile multiPartFile) { ImportXmlBuilderDatasetProfile xmlBuilder = new ImportXmlBuilderDatasetProfile(); try { File localFile = convert(multiPartFile); diff --git a/dmp-backend/web/src/main/resources/config/errors.yml b/dmp-backend/web/src/main/resources/config/errors.yml index 42c3b2392..e566b2f1a 100644 --- a/dmp-backend/web/src/main/resources/config/errors.yml +++ b/dmp-backend/web/src/main/resources/config/errors.yml @@ -26,3 +26,6 @@ error-thesaurus: tenant-not-allowed: code: 113 message: tenant not allowed + description-template-new-version-conflict: + code: 114 + message: version to update not the latest diff --git a/dmp-backend/web/src/main/resources/config/permissions.yml b/dmp-backend/web/src/main/resources/config/permissions.yml index 74c116e8b..15e923e43 100644 --- a/dmp-backend/web/src/main/resources/config/permissions.yml +++ b/dmp-backend/web/src/main/resources/config/permissions.yml @@ -131,6 +131,22 @@ permissions: clients: [ ] allowAnonymous: false allowAuthenticated: false + CloneDescriptionTemplate: + roles: + - Admin + - DatasetProfileManager + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false + CreateNewVersionDescriptionTemplate: + roles: + - Admin + - DatasetProfileManager + claims: [ ] + clients: [ ] + allowAnonymous: false + allowAuthenticated: false # Dmp BrowseDmp: roles: