Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

# Conflicts:
#	dmp-backend/core/src/main/java/eu/eudat/query/DmpUserQuery.java
This commit is contained in:
Efstratios Giannopoulos 2023-11-08 18:45:01 +02:00
commit 7ef668eede
5 changed files with 163 additions and 14 deletions

View File

@ -0,0 +1,71 @@
package eu.eudat.model.persist;
import eu.eudat.commons.validation.FieldNotNullIfOtherSet;
import eu.eudat.commons.validation.ValidId;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.compress.utils.Lists;
import java.util.List;
import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class NewVersionDmpPersist {
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID id = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String label = null;
@NotNull(message = "{validation.empty}")
@NotEmpty(message = "{validation.empty}")
private String description = null;
@NotNull(message = "{validation.empty}")
private List<UUID> descriptionTemplates = Lists.newArrayList();
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 List<UUID> getDescriptionTemplates() {
return descriptionTemplates;
}
public void setDescriptionTemplates(List<UUID> descriptionTemplates) {
this.descriptionTemplates = descriptionTemplates;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -1,6 +1,7 @@
package eu.eudat.query; package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpReferenceEntity; import eu.eudat.data.DmpReferenceEntity;
import eu.eudat.model.DmpReference; import eu.eudat.model.DmpReference;
@ -24,6 +25,8 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
private Collection<UUID> ids; private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<UUID> dmpIds; private Collection<UUID> dmpIds;
private Collection<UUID> referenceIds; private Collection<UUID> referenceIds;
@ -46,6 +49,21 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
return this; return this;
} }
public DmpReferenceQuery isActives(IsActive value) {
this.isActives = List.of(value);
return this;
}
public DmpReferenceQuery isActives(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public DmpReferenceQuery isActives(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public DmpReferenceQuery dmpIds(UUID value) { public DmpReferenceQuery dmpIds(UUID value) {
this.dmpIds = List.of(value); this.dmpIds = List.of(value);
return this; return this;
@ -112,6 +130,12 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._isActive));
for (IsActive item : this.isActives)
inClause.value(item);
predicates.add(inClause);
}
if (this.dmpIds != null) { if (this.dmpIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._dmpId)); CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._dmpId));
for (UUID item : this.dmpIds) for (UUID item : this.dmpIds)

View File

@ -2,21 +2,19 @@ package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.authorization.Permission; import eu.eudat.authorization.Permission;
import eu.eudat.commons.enums.DmpAccessType;
import eu.eudat.commons.enums.DmpUserRole; import eu.eudat.commons.enums.DmpUserRole;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DmpEntity;
import eu.eudat.data.DmpUserEntity; import eu.eudat.data.DmpUserEntity;
import eu.eudat.model.DmpUser; import eu.eudat.model.DmpUser;
import eu.eudat.query.utils.BuildSubQueryInput;
import eu.eudat.query.utils.QueryUtilsService; import eu.eudat.query.utils.QueryUtilsService;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase; import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext; import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple; import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.*; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -30,6 +28,8 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
private Collection<UUID> ids; private Collection<UUID> ids;
private Collection<IsActive> isActives;
private Collection<UUID> dmpIds; private Collection<UUID> dmpIds;
private Collection<UUID> userIds; private Collection<UUID> userIds;
@ -53,6 +53,21 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
return this; return this;
} }
public DmpUserQuery isActives(IsActive value) {
this.isActives = List.of(value);
return this;
}
public DmpUserQuery isActives(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public DmpUserQuery isActives(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public DmpUserQuery dmpIds(UUID value) { public DmpUserQuery dmpIds(UUID value) {
this.dmpIds = List.of(value); this.dmpIds = List.of(value);
return this; return this;
@ -143,7 +158,7 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._user), userId) : queryContext.CriteriaBuilder.or() //Creates a false query userId != null ? queryContext.CriteriaBuilder.equal(queryContext.Root.get(DmpUserEntity._user), userId) : queryContext.CriteriaBuilder.or() //Creates a false query
)); ));
} }
if (predicates.size() > 0) { if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray); return queryContext.CriteriaBuilder.and(predicatesArray);
} else { } else {
@ -160,6 +175,12 @@ public class DmpUserQuery extends QueryBase<DmpUserEntity> {
inClause.value(item); inClause.value(item);
predicates.add(inClause); predicates.add(inClause);
} }
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._isActive));
for (IsActive item : this.isActives)
inClause.value(item);
predicates.add(inClause);
}
if (this.dmpIds != null) { if (this.dmpIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmp)); CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpUserEntity._dmp));
for (UUID item : this.dmpIds) for (UUID item : this.dmpIds)

View File

@ -5,6 +5,7 @@ import eu.eudat.model.DescriptionTemplate;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.persist.DmpPersist; import eu.eudat.model.persist.DmpPersist;
import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist; import eu.eudat.model.persist.NewVersionDescriptionTemplatePersist;
import eu.eudat.model.persist.NewVersionDmpPersist;
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;
@ -23,6 +24,6 @@ public interface DmpService {
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
Dmp createNewVersion(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException; Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException;
} }

View File

@ -21,10 +21,7 @@ import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.deleter.DmpDeleter; import eu.eudat.model.deleter.DmpDeleter;
import eu.eudat.model.deleter.DmpDescriptionTemplateDeleter; import eu.eudat.model.deleter.DmpDescriptionTemplateDeleter;
import eu.eudat.model.deleter.DmpReferenceDeleter; import eu.eudat.model.deleter.DmpReferenceDeleter;
import eu.eudat.model.persist.DmpDescriptionTemplatePersist; import eu.eudat.model.persist.*;
import eu.eudat.model.persist.DmpPersist;
import eu.eudat.model.persist.DmpReferencePersist;
import eu.eudat.model.persist.ReferencePersist;
import eu.eudat.model.persist.referencedefinition.DefinitionPersist; import eu.eudat.model.persist.referencedefinition.DefinitionPersist;
import eu.eudat.model.persist.referencedefinition.FieldPersist; import eu.eudat.model.persist.referencedefinition.FieldPersist;
import eu.eudat.query.*; import eu.eudat.query.*;
@ -141,7 +138,7 @@ public class DmpServiceImpl implements DmpService {
} }
@Override @Override
public Dmp createNewVersion(DmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException { public Dmp createNewVersion(NewVersionDmpPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException, JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
logger.debug(new MapLogEntry("persisting data dmp (new version)").And("model", model).And("fields", fields)); logger.debug(new MapLogEntry("persisting data dmp (new version)").And("model", model).And("fields", fields));
this.authorizationService.authorizeForce(Permission.CreateNewVersionDmp); this.authorizationService.authorizeForce(Permission.CreateNewVersionDmp);
@ -165,9 +162,44 @@ public class DmpServiceImpl implements DmpService {
data.setVersion((short)(oldDmpEntity.getVersion() + 1)); data.setVersion((short)(oldDmpEntity.getVersion() + 1));
data.setDescription(model.getDescription()); data.setDescription(model.getDescription());
data.setLabel(model.getLabel()); data.setLabel(model.getLabel());
data.setLanguage(model.getLanguage()); data.setLanguage(oldDmpEntity.getLanguage());
data.setStatus(model.getStatus()); data.setStatus(oldDmpEntity.getStatus());
data.setProperties(this.jsonHandlingService.toJsonSafe(model.getProperties())); data.setProperties(oldDmpEntity.getProperties());
List<DmpUserEntity> dmpUsers = this.queryFactory.query(DmpUserQuery.class)
.dmpIds(model.getId())
.isActives(IsActive.Active)
.collect();
List<DmpReferenceEntity> dmpReferences = this.queryFactory.query(DmpReferenceQuery.class)
.dmpIds(model.getId())
.isActives(IsActive.Active)
.collect();
for (DmpUserEntity dmpUser : dmpUsers) {
DmpUserEntity newUser = new DmpUserEntity();
newUser.setId(UUID.randomUUID());
newUser.setDmp(data.getId());
newUser.setUser(dmpUser.getUser());
newUser.setRole(dmpUser.getRole());
newUser.setCreatedAt(Instant.now());
newUser.setUpdatedAt(Instant.now());
newUser.setIsActive(IsActive.Active);
this.entityManager.persist(newUser);
}
for (DmpReferenceEntity dmpReference : dmpReferences) {
DmpReferenceEntity newReference = new DmpReferenceEntity();
newReference.setId(UUID.randomUUID());
newReference.setDmpId(data.getId());
newReference.setReferenceId(dmpReference.getReferenceId());
newReference.setData(dmpReference.getData());
newReference.setCreatedAt(Instant.now());
newReference.setUpdatedAt(Instant.now());
newReference.setIsActive(IsActive.Active);
this.entityManager.persist(newReference);
}
this.entityManager.persist(data); this.entityManager.persist(data);