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

# Conflicts:
#	dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java
This commit is contained in:
Efstratios Giannopoulos 2023-10-24 18:01:38 +03:00
commit a68ddd42ce
16 changed files with 1367 additions and 7 deletions

View File

@ -41,6 +41,12 @@ public final class Permission {
public static String ExportDmpBlueprint = "ExportDmpBlueprint"; public static String ExportDmpBlueprint = "ExportDmpBlueprint";
public static String ImportDmpBlueprint = "ImportDmpBlueprint"; public static String ImportDmpBlueprint = "ImportDmpBlueprint";
//Description
public static String BrowseDescription = "BrowseDescription";
public static String EditDescription = "EditDescription";
public static String DeleteDescription = "DeleteDescription";
//DescriptionTemplateType //DescriptionTemplateType
public static String BrowseEntityDoi = "BrowseEntityDoi"; public static String BrowseEntityDoi = "BrowseEntityDoi";
public static String EditEntityDoi = "EditEntityDoi"; public static String EditEntityDoi = "EditEntityDoi";

View File

@ -0,0 +1,31 @@
package eu.eudat.commons.enums;
import com.fasterxml.jackson.annotation.JsonValue;
import eu.eudat.data.converters.enums.DatabaseEnum;
import java.util.Map;
public enum DescriptionStatus implements DatabaseEnum<Short> {
Saved((short) 0),
Finalized((short) 1),
Canceled((short) 2);
private final Short value;
DescriptionStatus(Short value) {
this.value = value;
}
@JsonValue
public Short getValue() {
return value;
}
private static final Map<Short, DescriptionStatus> map = EnumUtils.getEnumValueMap(DescriptionStatus.class);
public static DescriptionStatus of(Short i) {
return map.get(i);
}
}

View File

@ -0,0 +1,219 @@
package eu.eudat.data;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.DescriptionStatusConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Id;
import java.time.Instant;
import java.util.UUID;
//@Entity
//@Table(name = "\"Description\"")
public class DescriptionEntity {
@Id
@Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false)
private UUID id;
public static final String _id = "id";
@Column(name = "label", length = 250, nullable = false)
private String label;
public static final String _label = "label";
@Column(name = "dmp", columnDefinition = "uuid")
private UUID dmp;
public static final String _dmp = "dmp";
@Column(name = "uri", length = 250)
private String uri;
public static final String _uri = "uri";
@Column(name = "properties")
private String properties;
public static final String _properties = "properties";
//TODO: (thgiannos) Previously 'DescriptionTemplate'
@Column(name = "profile", columnDefinition = "uuid")
private UUID profile;
public static final String _profile = "profile";
@Column(name = "reference")
private String reference;
public static final String _reference = "reference";
@Column(name = "status", nullable = false)
@Convert(converter = DescriptionStatusConverter.class)
private DescriptionStatus status;
public static final String _status = "status";
@Column(name = "description")
private String description;
public static final String _description = "description";
@Column(name = "dmp_section_index", nullable = false)
private Integer dmpSectionIndex;
public static final String _dmpSectionIndex = "dmpSectionIndex";
@Column(name = "creator", columnDefinition = "uuid")
private UUID creator;
public static final String _creator = "creator";
@Column(name = "created_at", nullable = false)
private Instant createdAt;
public static final String _createdAt = "createdAt";
@Column(name = "updated_at", nullable = false)
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
@Column(name = "is_active", nullable = false)
@Convert(converter = IsActiveConverter.class)
private IsActive isActive;
public static final String _isActive = "isActive";
@Column(name = "\"finalized_at\"")
@Convert(converter = DateToUTCConverter.class)
private Instant finalizedAt;
public static final String _finalizedAt = "finalizedAt";
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 UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(Integer dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
public UUID getCreator() {
return creator;
}
public void setCreator(UUID creator) {
this.creator = creator;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public Instant getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Instant finalizedAt) {
this.finalizedAt = finalizedAt;
}
}

View File

@ -0,0 +1,11 @@
package eu.eudat.data.converters.enums;
import eu.eudat.commons.enums.DescriptionStatus;
import jakarta.persistence.Converter;
@Converter
public class DescriptionStatusConverter extends DatabaseEnumConverter<DescriptionStatus, Short>{
protected DescriptionStatus of(Short i) {
return DescriptionStatus.of(i);
}
}

View File

@ -0,0 +1,24 @@
package eu.eudat.event;
import java.util.UUID;
public class DescriptionTouchedEvent {
public DescriptionTouchedEvent() {
}
public DescriptionTouchedEvent(UUID id) {
this.id = id;
}
private UUID id;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
}

View File

@ -34,6 +34,10 @@ public class EventBroker {
this.applicationEventPublisher.publishEvent(event); this.applicationEventPublisher.publishEvent(event);
} }
public void emit(DescriptionTouchedEvent event) {
this.applicationEventPublisher.publishEvent(event);
}
public void emit(DescriptionTemplateTypeTouchedEvent event) { public void emit(DescriptionTemplateTypeTouchedEvent event) {
this.applicationEventPublisher.publishEvent(event); this.applicationEventPublisher.publishEvent(event);
} }

View File

@ -0,0 +1,202 @@
package eu.eudat.model;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import java.time.Instant;
import java.util.UUID;
public class Description {
private UUID id;
public static final String _id = "id";
private String label;
public static final String _label = "label";
private Dmp dmp;
public static final String _dmp = "dmp";
private String uri;
public static final String _uri = "uri";
private String properties;
public static final String _properties = "properties";
private UUID profile;
public static final String _profile = "profile";
private String reference;
public static final String _reference = "reference";
private DescriptionStatus status;
public static final String _status = "status";
private String description;
public static final String _description = "description";
private Integer dmpSectionIndex;
public static final String _dmpSectionIndex = "dmpSectionIndex";
private UUID creator;
public static final String _creator = "creator";
private Instant createdAt;
public static final String _createdAt = "createdAt";
private Instant updatedAt;
public static final String _updatedAt = "updatedAt";
private IsActive isActive;
public static final String _isActive = "isActive";
private Instant finalizedAt;
public static final String _finalizedAt = "finalizedAt";
private String hash;
public static final String _hash = "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 Dmp getDmp() {
return dmp;
}
public void setDmp(Dmp dmp) {
this.dmp = dmp;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(Integer dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
public UUID getCreator() {
return creator;
}
public void setCreator(UUID creator) {
this.creator = creator;
}
public Instant getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}
public Instant getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Instant updatedAt) {
this.updatedAt = updatedAt;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
public Instant getFinalizedAt() {
return finalizedAt;
}
public void setFinalizedAt(Instant finalizedAt) {
this.finalizedAt = finalizedAt;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -0,0 +1,133 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.model.Description;
import eu.eudat.model.Dmp;
import eu.eudat.query.DmpQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.stream.Collectors;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEntity> {
private final QueryFactory queryFactory;
private final BuilderFactory builderFactory;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired
public DescriptionBuilder(
ConventionService conventionService,
QueryFactory queryFactory,
BuilderFactory builderFactory) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionBuilder.class)));
this.queryFactory = queryFactory;
this.builderFactory = builderFactory;
}
public DescriptionBuilder authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
public List<Description> build(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
this.logger.debug("building for {} items requesting {} fields", Optional.ofNullable(data).map(List::size).orElse(0), Optional.ofNullable(fields).map(FieldSet::getFields).map(Set::size).orElse(0));
this.logger.trace(new DataLogEntry("requested fields", fields));
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmp));
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
List<Description> models = new ArrayList<>();
for (DescriptionEntity d : data) {
Description m = new Description();
if (fields.hasField(this.asIndexer(Description._id)))
m.setId(d.getId());
if (fields.hasField(this.asIndexer(Description._label)))
m.setLabel(d.getLabel());
if (fields.hasField(this.asIndexer(Description._uri)))
m.setUri(d.getUri());
if (fields.hasField(this.asIndexer(Description._properties)))
m.setProperties(d.getProperties());
if (fields.hasField(this.asIndexer(Description._profile)))
m.setProfile(d.getProfile());
if (fields.hasField(this.asIndexer(Description._reference)))
m.setReference(d.getReference());
if (fields.hasField(this.asIndexer(Description._status)))
m.setStatus(d.getStatus());
if (fields.hasField(this.asIndexer(Description._description)))
m.setDescription(d.getDescription());
if (fields.hasField(this.asIndexer(Description._creator)))
m.setCreator(d.getCreator());
if (fields.hasField(this.asIndexer(Description._dmpSectionIndex)))
m.setDmpSectionIndex(d.getDmpSectionIndex());
if (fields.hasField(this.asIndexer(Description._createdAt)))
m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(Description._updatedAt)))
m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(Description._isActive)))
m.setIsActive(d.getIsActive());
if (fields.hasField(this.asIndexer(Description._finalizedAt)))
m.setFinalizedAt(d.getFinalizedAt());
if (fields.hasField(this.asIndexer(Description._hash)))
m.setHash(this.hashValue(d.getUpdatedAt()));
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp()))
m.setDmp(dmpItemsMap.get(d.getDmp()));
models.add(m);
}
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models;
}
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
Map<UUID, Dmp> itemMap;
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
itemMap = this.asEmpty(
data.stream().map(DescriptionEntity::getDmp).distinct().collect(Collectors.toList()),
x -> {
Dmp item = new Dmp();
item.setId(x);
return item;
},
Dmp::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDmp).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
}
if (!fields.hasField(Dmp._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -0,0 +1,37 @@
package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionCensor extends BaseCensor {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionCensor.class));
protected final AuthorizationService authService;
public DescriptionCensor(ConventionService conventionService, AuthorizationService authService) {
super(conventionService);
this.authService = authService;
}
public void censor(FieldSet fields, UUID userId) {
logger.debug(new DataLogEntry("censoring fields", fields));
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeForce(Permission.BrowseDescription);
}
}

View File

@ -0,0 +1,79 @@
package eu.eudat.model.deleter;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.query.DescriptionQuery;
import gr.cite.tools.data.deleter.Deleter;
import gr.cite.tools.data.deleter.DeleterFactory;
import gr.cite.tools.data.query.QueryFactory;
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.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.management.InvalidApplicationException;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionDeleter implements Deleter {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionDeleter.class));
private final EntityManager entityManager;
protected final QueryFactory queryFactory;
protected final DeleterFactory deleterFactory;
@Autowired
public DescriptionDeleter(
EntityManager entityManager,
QueryFactory queryFactory,
DeleterFactory deleterFactory
) {
this.entityManager = entityManager;
this.queryFactory = queryFactory;
this.deleterFactory = deleterFactory;
}
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
List<DescriptionEntity> data = this.queryFactory.query(DescriptionQuery.class).ids(ids).collect();
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.deleteAndSave(data);
}
public void deleteAndSave(List<DescriptionEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
this.delete(data);
logger.trace("saving changes");
this.entityManager.flush();
logger.trace("changes saved");
}
public void delete(List<DescriptionEntity> data) throws InvalidApplicationException {
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
if (data == null || data.isEmpty())
return;
Instant now = Instant.now();
for (DescriptionEntity item : data) {
logger.trace("deleting item {}", item.getId());
item.setIsActive(IsActive.Inactive);
item.setUpdatedAt(now);
logger.trace("updating item");
this.entityManager.merge(item);
logger.trace("updated item");
}
}
}

View File

@ -0,0 +1,121 @@
package eu.eudat.model.persist;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.validation.ValidId;
import java.util.UUID;
public class DescriptionPersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
private String label;
private UUID dmp;
private String uri;
private String properties;
private UUID profile;
private String reference;
private DescriptionStatus status;
private String description;
private Integer dmpSectionIndex;
private IsActive isActive;
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 UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getProperties() {
return properties;
}
public void setProperties(String properties) {
this.properties = properties;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public DescriptionStatus getStatus() {
return status;
}
public void setStatus(DescriptionStatus status) {
this.status = status;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(Integer dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
public IsActive getIsActive() {
return isActive;
}
public void setIsActive(IsActive isActive) {
this.isActive = isActive;
}
}

View File

@ -0,0 +1,253 @@
package eu.eudat.query;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.DescriptionStatus;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.model.Description;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.query.FieldResolver;
import gr.cite.tools.data.query.QueryBase;
import gr.cite.tools.data.query.QueryContext;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.*;
@Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DescriptionQuery extends QueryBase<DescriptionEntity> {
private String like;
private Collection<UUID> ids;
private Collection<UUID> excludedIds;
private Collection<IsActive> isActives;
private Collection<DescriptionStatus> statuses;
private Collection<UUID> dmpIds;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
private final UserScope userScope;
private final AuthorizationService authService;
public DescriptionQuery(UserScope userScope, AuthorizationService authService) {
this.userScope = userScope;
this.authService = authService;
}
public DescriptionQuery like(String value) {
this.like = value;
return this;
}
public DescriptionQuery ids(UUID value) {
this.ids = List.of(value);
return this;
}
public DescriptionQuery ids(UUID... value) {
this.ids = Arrays.asList(value);
return this;
}
public DescriptionQuery ids(Collection<UUID> values) {
this.ids = values;
return this;
}
public DescriptionQuery excludedIds(Collection<UUID> values) {
this.excludedIds = values;
return this;
}
public DescriptionQuery excludedIds(UUID value) {
this.excludedIds = List.of(value);
return this;
}
public DescriptionQuery excludedIds(UUID... value) {
this.excludedIds = Arrays.asList(value);
return this;
}
public DescriptionQuery isActive(IsActive value) {
this.isActives = List.of(value);
return this;
}
public DescriptionQuery isActive(IsActive... value) {
this.isActives = Arrays.asList(value);
return this;
}
public DescriptionQuery isActive(Collection<IsActive> values) {
this.isActives = values;
return this;
}
public DescriptionQuery statuses(DescriptionStatus value) {
this.statuses = List.of(value);
return this;
}
public DescriptionQuery statuses(DescriptionStatus... value) {
this.statuses = Arrays.asList(value);
return this;
}
public DescriptionQuery statuses(Collection<DescriptionStatus> values) {
this.statuses = values;
return this;
}
public DescriptionQuery dmpIds(UUID value) {
this.dmpIds = List.of(value);
return this;
}
public DescriptionQuery dmpIds(UUID... value) {
this.dmpIds = Arrays.asList(value);
return this;
}
public DescriptionQuery dmpIds(Collection<UUID> values) {
this.dmpIds = values;
return this;
}
public DescriptionQuery authorize(EnumSet<AuthorizationFlags> values) {
this.authorize = values;
return this;
}
@Override
protected Boolean isFalseQuery() {
return
this.isEmpty(this.ids) ||
this.isEmpty(this.isActives) ||
this.isEmpty(this.excludedIds) ||
this.isEmpty(this.statuses) ||
this.isEmpty(this.dmpIds);
}
@Override
protected Class<DescriptionEntity> entityClass() {
return DescriptionEntity.class;
}
@Override
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
List<Predicate> predicates = new ArrayList<>();
if (this.like != null && !this.like.isEmpty()) {
predicates.add(queryContext.CriteriaBuilder.like(queryContext.Root.get(DescriptionEntity._label), this.like));
}
if (this.ids != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id));
for (UUID item : this.ids)
inClause.value(item);
predicates.add(inClause);
}
if (this.excludedIds != null) {
CriteriaBuilder.In<UUID> notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._id));
for (UUID item : this.excludedIds)
notInClause.value(item);
predicates.add(notInClause.not());
}
if (this.isActives != null) {
CriteriaBuilder.In<IsActive> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._isActive));
for (IsActive item : this.isActives)
inClause.value(item);
predicates.add(inClause);
}
if (this.statuses != null) {
CriteriaBuilder.In<DescriptionStatus> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._status));
for (DescriptionStatus item : this.statuses)
inClause.value(item);
predicates.add(inClause);
}
if (this.dmpIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionEntity._dmp));
for (UUID item : this.dmpIds)
inClause.value(item);
predicates.add(inClause);
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);
return queryContext.CriteriaBuilder.and(predicatesArray);
} else {
return null;
}
}
@Override
protected String fieldNameOf(FieldResolver item) {
if (item.match(Description._id))
return DescriptionEntity._id;
else if (item.match(Description._label))
return DescriptionEntity._label;
else if (item.prefix(Description._dmp))
return DescriptionEntity._dmp;
else if (item.match(Description._dmp))
return DescriptionEntity._dmp;
else if (item.match(Description._uri))
return DescriptionEntity._uri;
else if (item.match(Description._properties))
return DescriptionEntity._properties;
else if (item.match(Description._profile))
return DescriptionEntity._profile;
else if (item.match(Description._reference))
return DescriptionEntity._reference;
else if (item.match(Description._status))
return DescriptionEntity._status;
else if (item.match(Description._description))
return DescriptionEntity._description;
else if (item.match(Description._dmpSectionIndex))
return DescriptionEntity._dmpSectionIndex;
else if (item.match(Description._creator))
return DescriptionEntity._creator;
else if (item.match(Description._createdAt))
return DescriptionEntity._createdAt;
else if (item.match(Description._updatedAt))
return DescriptionEntity._updatedAt;
else if (item.match(Description._isActive))
return DescriptionEntity._isActive;
else if (item.match(Description._finalizedAt))
return DescriptionEntity._finalizedAt;
else
return null;
}
@Override
protected DescriptionEntity convert(Tuple tuple, Set<String> columns) {
DescriptionEntity item = new DescriptionEntity();
item.setId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._id, UUID.class));
item.setLabel(QueryBase.convertSafe(tuple, columns, DescriptionEntity._label, String.class));
item.setDmp(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmp, UUID.class));
item.setUri(QueryBase.convertSafe(tuple, columns, DescriptionEntity._uri, String.class));
item.setProperties(QueryBase.convertSafe(tuple, columns, DescriptionEntity._properties, String.class));
item.setProfile(QueryBase.convertSafe(tuple, columns, DescriptionEntity._profile, UUID.class));
item.setReference(QueryBase.convertSafe(tuple, columns, DescriptionEntity._reference, String.class));
item.setStatus(QueryBase.convertSafe(tuple, columns, DescriptionEntity._status, DescriptionStatus.class));
item.setDescription(QueryBase.convertSafe(tuple, columns, DescriptionEntity._description, String.class));
item.setDmpSectionIndex(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpSectionIndex, Integer.class));
item.setCreator(QueryBase.convertSafe(tuple, columns, DescriptionEntity._creator, UUID.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._updatedAt, Instant.class));
item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionEntity._isActive, IsActive.class));
item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._finalizedAt, Instant.class));
return item;
}
}

View File

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

View File

@ -0,0 +1,20 @@
package eu.eudat.service.description;
import eu.eudat.model.Description;
import eu.eudat.model.persist.DescriptionPersist;
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 DescriptionService {
Description persist(DescriptionPersist model, FieldSet fields) throws MyForbiddenException, MyValidationException, MyApplicationException, MyNotFoundException, InvalidApplicationException;
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
}

View File

@ -0,0 +1,138 @@
package eu.eudat.service.description;
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.DescriptionEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.event.DescriptionTouchedEvent;
import eu.eudat.event.EventBroker;
import eu.eudat.model.Description;
import eu.eudat.model.builder.DescriptionBuilder;
import eu.eudat.model.deleter.DescriptionDeleter;
import eu.eudat.model.persist.DescriptionPersist;
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 DescriptionServiceImpl implements DescriptionService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DescriptionServiceImpl.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 DescriptionServiceImpl(
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;
}
@Override
public Description persist(DescriptionPersist 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.EditDescription);
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
DescriptionEntity data;
if (isUpdate) {
data = this.entityManager.find(DescriptionEntity.class, model.getId());
if (data == null)
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Description.class.getSimpleName()}, LocaleContextHolder.getLocale()));
} else {
data = new DescriptionEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
}
data.setLabel(model.getLabel());
data.setDmp(model.getDmp());
data.setUri(model.getUri());
data.setProperties(model.getProperties());
data.setProfile(model.getProfile());
data.setReference(model.getReference());
data.setStatus(model.getStatus());
data.setDescription(model.getDescription());
data.setDmpSectionIndex(model.getDmpSectionIndex());
data.setUpdatedAt(Instant.now());
if (isUpdate)
this.entityManager.merge(data);
else
this.entityManager.persist(data);
this.entityManager.flush();
this.eventBroker.emit(new DescriptionTouchedEvent(data.getId()));
return this.builderFactory.builder(DescriptionBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(BaseFieldSet.build(fields, Description._id), data);
}
@Override
public void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException {
logger.debug("deleting description: {}", id);
this.authorizationService.authorizeForce(Permission.DeleteDescription);
this.deleterFactory.deleter(DescriptionDeleter.class).deleteAndSaveByIds(List.of(id));
}
}

View File

@ -5,21 +5,14 @@ import eu.eudat.authorization.Permission;
import eu.eudat.commons.JsonHandlingService; import eu.eudat.commons.JsonHandlingService;
import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.IsActive;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionTemplateTypeEntity;
import eu.eudat.data.DmpEntity; import eu.eudat.data.DmpEntity;
import eu.eudat.errorcode.ErrorThesaurusProperties; import eu.eudat.errorcode.ErrorThesaurusProperties;
import eu.eudat.event.DescriptionTemplateTypeTouchedEvent;
import eu.eudat.event.DmpTouchedEvent; import eu.eudat.event.DmpTouchedEvent;
import eu.eudat.event.EventBroker; import eu.eudat.event.EventBroker;
import eu.eudat.model.DescriptionTemplateType;
import eu.eudat.model.Dmp; import eu.eudat.model.Dmp;
import eu.eudat.model.builder.DescriptionTemplateTypeBuilder;
import eu.eudat.model.builder.DmpBuilder; import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.deleter.DescriptionTemplateTypeDeleter;
import eu.eudat.model.deleter.DmpDeleter; import eu.eudat.model.deleter.DmpDeleter;
import eu.eudat.model.persist.DescriptionTemplateTypePersist;
import eu.eudat.model.persist.DmpPersist; import eu.eudat.model.persist.DmpPersist;
import eu.eudat.service.descriptiontemplatetype.DescriptionTemplateTypeServiceImpl;
import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.deleter.DeleterFactory;