Adding dmp-description-template stack
This commit is contained in:
parent
fda8fcef2c
commit
9b9cf0de4d
|
@ -51,6 +51,10 @@ public final class Permission {
|
||||||
public static String ExportDmpBlueprint = "ExportDmpBlueprint";
|
public static String ExportDmpBlueprint = "ExportDmpBlueprint";
|
||||||
public static String ImportDmpBlueprint = "ImportDmpBlueprint";
|
public static String ImportDmpBlueprint = "ImportDmpBlueprint";
|
||||||
|
|
||||||
|
//DmpDescriptionTemplate
|
||||||
|
public static String BrowseDmpDescriptionTemplate = "BrowseDmpDescriptionTemplate";
|
||||||
|
public static String EditDmpDescriptionTemplate = "EditDmpDescriptionTemplate";
|
||||||
|
public static String DeleteDmpDescriptionTemplate = "DeleteDmpDescriptionTemplate";
|
||||||
|
|
||||||
//Description
|
//Description
|
||||||
public static String BrowseDescription = "BrowseDescription";
|
public static String BrowseDescription = "BrowseDescription";
|
||||||
|
@ -82,6 +86,7 @@ public final class Permission {
|
||||||
public static String EditDmpReference = "EditDmpReference";
|
public static String EditDmpReference = "EditDmpReference";
|
||||||
public static String DeleteDmpReference = "DeleteDmpReference";
|
public static String DeleteDmpReference = "DeleteDmpReference";
|
||||||
|
|
||||||
|
//DescriptionReference
|
||||||
public static String BrowseDescriptionReference = "BrowseDescriptionReference";
|
public static String BrowseDescriptionReference = "BrowseDescriptionReference";
|
||||||
public static String EditDescriptionReference = "EditDescriptionReference";
|
public static String EditDescriptionReference = "EditDescriptionReference";
|
||||||
public static String DeleteDescriptionReference = "DeleteDescriptionReference";
|
public static String DeleteDescriptionReference = "DeleteDescriptionReference";
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
package eu.eudat.data;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.data.converters.enums.IsActiveConverter;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Convert;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Table(name = "\"DmpDescriptionTemplate\"")
|
||||||
|
public class DmpDescriptionTemplateEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
public static final String _id = "id";
|
||||||
|
|
||||||
|
@Column(name = "dmp", columnDefinition = "uuid", nullable = false)
|
||||||
|
private UUID dmp;
|
||||||
|
|
||||||
|
public static final String _dmp = "dmp";
|
||||||
|
|
||||||
|
@Column(name = "description_template", columnDefinition = "uuid", nullable = false)
|
||||||
|
private UUID descriptionTemplate;
|
||||||
|
|
||||||
|
public static final String _descriptionTemplate = "descriptionTemplate";
|
||||||
|
|
||||||
|
@Column(name = "section_id")
|
||||||
|
private UUID sectionId;
|
||||||
|
|
||||||
|
public static final String _sectionId = "sectionId";
|
||||||
|
|
||||||
|
@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";
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getDmp() {
|
||||||
|
return dmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDmp(UUID dmp) {
|
||||||
|
this.dmp = dmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getDescriptionTemplate() {
|
||||||
|
return descriptionTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionTemplate(UUID descriptionTemplate) {
|
||||||
|
this.descriptionTemplate = descriptionTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getSectionId() {
|
||||||
|
return sectionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSectionId(UUID sectionId) {
|
||||||
|
this.sectionId = sectionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
package eu.eudat.model;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DmpDescriptionTemplate {
|
||||||
|
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
public static final String _id = "id";
|
||||||
|
|
||||||
|
private Dmp dmp;
|
||||||
|
|
||||||
|
public static final String _dmp = "dmp";
|
||||||
|
|
||||||
|
private DescriptionTemplate descriptionTemplate;
|
||||||
|
|
||||||
|
public static final String _descriptionTemplate = "descriptionTemplate";
|
||||||
|
|
||||||
|
private UUID sectionId;
|
||||||
|
|
||||||
|
public static final String _sectionId = "sectionId";
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dmp getDmp() {
|
||||||
|
return dmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDmp(Dmp dmp) {
|
||||||
|
this.dmp = dmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DescriptionTemplate getDescriptionTemplate() {
|
||||||
|
return descriptionTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) {
|
||||||
|
this.descriptionTemplate = descriptionTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getSectionId() {
|
||||||
|
return sectionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSectionId(UUID sectionId) {
|
||||||
|
this.sectionId = sectionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ public class DescriptionReferenceBuilder extends BaseBuilder<DescriptionReferenc
|
||||||
public DescriptionReferenceBuilder(
|
public DescriptionReferenceBuilder(
|
||||||
ConventionService conventionService,
|
ConventionService conventionService,
|
||||||
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpReferenceBuilder.class)));
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(DescriptionReferenceBuilder.class)));
|
||||||
this.builderFactory = builderFactory;
|
this.builderFactory = builderFactory;
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
package eu.eudat.model.builder;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||||
|
import eu.eudat.data.DmpReferenceEntity;
|
||||||
|
import eu.eudat.model.*;
|
||||||
|
import eu.eudat.query.DescriptionTemplateQuery;
|
||||||
|
import eu.eudat.query.DmpQuery;
|
||||||
|
import eu.eudat.query.ReferenceQuery;
|
||||||
|
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 DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTemplate, DmpDescriptionTemplateEntity> {
|
||||||
|
|
||||||
|
private final BuilderFactory builderFactory;
|
||||||
|
|
||||||
|
private final QueryFactory queryFactory;
|
||||||
|
|
||||||
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DmpDescriptionTemplateBuilder(
|
||||||
|
ConventionService conventionService,
|
||||||
|
BuilderFactory builderFactory, QueryFactory queryFactory) {
|
||||||
|
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpDescriptionTemplateBuilder.class)));
|
||||||
|
this.builderFactory = builderFactory;
|
||||||
|
this.queryFactory = queryFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
|
this.authorize = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DmpDescriptionTemplate> build(FieldSet fields, List<DmpDescriptionTemplateEntity> 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 templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplate));
|
||||||
|
Map<UUID, DescriptionTemplate> templateItemsMap = this.collectTemplates(templateFields, data);
|
||||||
|
|
||||||
|
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._dmp));
|
||||||
|
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
|
||||||
|
|
||||||
|
List<DmpDescriptionTemplate> models = new ArrayList<>();
|
||||||
|
for (DmpDescriptionTemplateEntity d : data) {
|
||||||
|
DmpDescriptionTemplate m = new DmpDescriptionTemplate();
|
||||||
|
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._id)))
|
||||||
|
m.setId(d.getId());
|
||||||
|
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._sectionId)))
|
||||||
|
m.setSectionId(d.getSectionId());
|
||||||
|
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._createdAt)))
|
||||||
|
m.setCreatedAt(d.getCreatedAt());
|
||||||
|
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._updatedAt)))
|
||||||
|
m.setUpdatedAt(d.getUpdatedAt());
|
||||||
|
if (!templateFields.isEmpty() && templateItemsMap != null && templateItemsMap.containsKey(d.getDescriptionTemplate())) {
|
||||||
|
m.setDescriptionTemplate(templateItemsMap.get(d.getDescriptionTemplate()));
|
||||||
|
}
|
||||||
|
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, DescriptionTemplate> collectTemplates(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
|
||||||
|
if (fields.isEmpty() || data.isEmpty())
|
||||||
|
return null;
|
||||||
|
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
|
||||||
|
|
||||||
|
Map<UUID, DescriptionTemplate> itemMap;
|
||||||
|
if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) {
|
||||||
|
itemMap = this.asEmpty(
|
||||||
|
data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplate).distinct().collect(Collectors.toList()),
|
||||||
|
x -> {
|
||||||
|
DescriptionTemplate item = new DescriptionTemplate();
|
||||||
|
item.setId(x);
|
||||||
|
return item;
|
||||||
|
},
|
||||||
|
DescriptionTemplate::getId);
|
||||||
|
} else {
|
||||||
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id);
|
||||||
|
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplate).distinct().collect(Collectors.toList()));
|
||||||
|
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getId);
|
||||||
|
}
|
||||||
|
if (!fields.hasField(DescriptionTemplate._id)) {
|
||||||
|
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpDescriptionTemplateEntity> 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(DmpDescriptionTemplateEntity::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(DmpDescriptionTemplateEntity::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.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,10 +26,12 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceEntity>{
|
public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceEntity> {
|
||||||
|
|
||||||
private final BuilderFactory builderFactory;
|
private final BuilderFactory builderFactory;
|
||||||
|
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
|
|
||||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -52,6 +54,7 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
|
||||||
this.logger.trace(new DataLogEntry("requested fields", fields));
|
this.logger.trace(new DataLogEntry("requested fields", fields));
|
||||||
if (fields == null || data == null || fields.isEmpty())
|
if (fields == null || data == null || fields.isEmpty())
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
||||||
FieldSet referenceFields = fields.extractPrefixed(this.asPrefix(DmpReference._reference));
|
FieldSet referenceFields = fields.extractPrefixed(this.asPrefix(DmpReference._reference));
|
||||||
Map<UUID, Reference> referenceItemsMap = this.collectReferences(referenceFields, data);
|
Map<UUID, Reference> referenceItemsMap = this.collectReferences(referenceFields, data);
|
||||||
|
|
||||||
|
@ -61,14 +64,18 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
|
||||||
List<DmpReference> models = new ArrayList<>();
|
List<DmpReference> models = new ArrayList<>();
|
||||||
for (DmpReferenceEntity d : data) {
|
for (DmpReferenceEntity d : data) {
|
||||||
DmpReference m = new DmpReference();
|
DmpReference m = new DmpReference();
|
||||||
if (fields.hasField(this.asIndexer(DmpReference._id))) m.setId(d.getId());
|
if (fields.hasField(this.asIndexer(DmpReference._id)))
|
||||||
if (fields.hasField(this.asIndexer(DmpReference._data))) m.setData(d.getData());
|
m.setId(d.getId());
|
||||||
if (fields.hasField(this.asIndexer(DmpReference._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
if (fields.hasField(this.asIndexer(DmpReference._data)))
|
||||||
if (fields.hasField(this.asIndexer(DmpReference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
m.setData(d.getData());
|
||||||
if(!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())){
|
if (fields.hasField(this.asIndexer(DmpReference._createdAt)))
|
||||||
|
m.setCreatedAt(d.getCreatedAt());
|
||||||
|
if (fields.hasField(this.asIndexer(DmpReference._updatedAt)))
|
||||||
|
m.setUpdatedAt(d.getUpdatedAt());
|
||||||
|
if (!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())) {
|
||||||
m.setReference(referenceItemsMap.get(d.getReferenceId()));
|
m.setReference(referenceItemsMap.get(d.getReferenceId()));
|
||||||
}
|
}
|
||||||
if(!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())){
|
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) {
|
||||||
m.setDmp(dmpItemsMap.get(d.getDmpId()));
|
m.setDmp(dmpItemsMap.get(d.getDmpId()));
|
||||||
}
|
}
|
||||||
models.add(m);
|
models.add(m);
|
||||||
|
@ -78,13 +85,14 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<UUID, Reference> collectReferences(FieldSet fields, List<DmpReferenceEntity> data) throws MyApplicationException {
|
private Map<UUID, Reference> collectReferences(FieldSet fields, List<DmpReferenceEntity> data) throws MyApplicationException {
|
||||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
if (fields.isEmpty() || data.isEmpty())
|
||||||
|
return null;
|
||||||
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
|
this.logger.debug("checking related - {}", Reference.class.getSimpleName());
|
||||||
|
|
||||||
Map<UUID, Reference> itemMap;
|
Map<UUID, Reference> itemMap;
|
||||||
if (!fields.hasOtherField(this.asIndexer(Reference._id))) {
|
if (!fields.hasOtherField(this.asIndexer(Reference._id))) {
|
||||||
itemMap = this.asEmpty(
|
itemMap = this.asEmpty(
|
||||||
data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()),
|
data.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()),
|
||||||
x -> {
|
x -> {
|
||||||
Reference item = new Reference();
|
Reference item = new Reference();
|
||||||
item.setId(x);
|
item.setId(x);
|
||||||
|
@ -93,7 +101,7 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
|
||||||
Reference::getId);
|
Reference::getId);
|
||||||
} else {
|
} else {
|
||||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id);
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Reference._id);
|
||||||
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()));
|
ReferenceQuery q = this.queryFactory.query(ReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(DmpReferenceEntity::getReferenceId).distinct().collect(Collectors.toList()));
|
||||||
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
|
itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId);
|
||||||
}
|
}
|
||||||
if (!fields.hasField(Reference._id)) {
|
if (!fields.hasField(Reference._id)) {
|
||||||
|
@ -104,13 +112,14 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpReferenceEntity> data) throws MyApplicationException {
|
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpReferenceEntity> data) throws MyApplicationException {
|
||||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
if (fields.isEmpty() || data.isEmpty())
|
||||||
|
return null;
|
||||||
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
|
this.logger.debug("checking related - {}", Dmp.class.getSimpleName());
|
||||||
|
|
||||||
Map<UUID, Dmp> itemMap;
|
Map<UUID, Dmp> itemMap;
|
||||||
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
|
if (!fields.hasOtherField(this.asIndexer(Dmp._id))) {
|
||||||
itemMap = this.asEmpty(
|
itemMap = this.asEmpty(
|
||||||
data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()),
|
data.stream().map(DmpReferenceEntity::getDmpId).distinct().collect(Collectors.toList()),
|
||||||
x -> {
|
x -> {
|
||||||
Dmp item = new Dmp();
|
Dmp item = new Dmp();
|
||||||
item.setId(x);
|
item.setId(x);
|
||||||
|
@ -119,7 +128,7 @@ public class DmpReferenceBuilder extends BaseBuilder<DmpReference, DmpReferenceE
|
||||||
Dmp::getId);
|
Dmp::getId);
|
||||||
} else {
|
} else {
|
||||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
|
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(Dmp._id);
|
||||||
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()));
|
DmpQuery q = this.queryFactory.query(DmpQuery.class).authorize(this.authorize).ids(data.stream().map(DmpReferenceEntity::getDmpId).distinct().collect(Collectors.toList()));
|
||||||
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
|
itemMap = this.builderFactory.builder(DmpBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Dmp::getId);
|
||||||
}
|
}
|
||||||
if (!fields.hasField(Dmp._id)) {
|
if (!fields.hasField(Dmp._id)) {
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package eu.eudat.model.censorship;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.Permission;
|
||||||
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.model.DmpReference;
|
||||||
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
|
import gr.cite.tools.data.censor.CensorFactory;
|
||||||
|
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 DmpDescriptionTemplateCensor extends BaseCensor{
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDescriptionTemplateCensor.class));
|
||||||
|
|
||||||
|
protected final AuthorizationService authService;
|
||||||
|
|
||||||
|
protected final CensorFactory censorFactory;
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateCensor(ConventionService conventionService,
|
||||||
|
AuthorizationService authService,
|
||||||
|
CensorFactory censorFactory) {
|
||||||
|
super(conventionService);
|
||||||
|
this.authService = authService;
|
||||||
|
this.censorFactory = censorFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void censor(FieldSet fields, UUID userId) {
|
||||||
|
logger.debug(new DataLogEntry("censoring fields", fields));
|
||||||
|
if (fields == null || fields.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.authService.authorizeForce(Permission.BrowseDmpReference);
|
||||||
|
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._dmp));
|
||||||
|
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
|
||||||
|
FieldSet referenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._reference));
|
||||||
|
this.censorFactory.censor(ReferenceCensor.class).censor(referenceFields, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package eu.eudat.model.censorship;
|
||||||
|
|
||||||
import eu.eudat.authorization.Permission;
|
import eu.eudat.authorization.Permission;
|
||||||
import eu.eudat.convention.ConventionService;
|
import eu.eudat.convention.ConventionService;
|
||||||
|
import eu.eudat.model.DmpDescriptionTemplate;
|
||||||
import eu.eudat.model.DmpReference;
|
import eu.eudat.model.DmpReference;
|
||||||
import gr.cite.commons.web.authz.service.AuthorizationService;
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
||||||
import gr.cite.tools.data.censor.CensorFactory;
|
import gr.cite.tools.data.censor.CensorFactory;
|
||||||
|
@ -37,11 +38,11 @@ public class DmpReferenceCensor extends BaseCensor {
|
||||||
if (fields == null || fields.isEmpty())
|
if (fields == null || fields.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.authService.authorizeForce(Permission.BrowseDmpReference);
|
this.authService.authorizeForce(Permission.BrowseDmpDescriptionTemplate);
|
||||||
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._dmp));
|
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._dmp));
|
||||||
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
|
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
|
||||||
FieldSet referenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._reference));
|
FieldSet templateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplate));
|
||||||
this.censorFactory.censor(ReferenceCensor.class).censor(referenceFields, userId);
|
this.censorFactory.censor(DescriptionTemplateCensor.class).censor(templateFields, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package eu.eudat.model.deleter;
|
||||||
|
|
||||||
|
import eu.eudat.commons.enums.IsActive;
|
||||||
|
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||||
|
import eu.eudat.data.DmpReferenceEntity;
|
||||||
|
import eu.eudat.query.DmpDescriptionTemplateQuery;
|
||||||
|
import eu.eudat.query.DmpReferenceQuery;
|
||||||
|
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 DmpDescriptionTemplateDeleter implements Deleter {
|
||||||
|
|
||||||
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDescriptionTemplateDeleter.class));
|
||||||
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
|
protected final QueryFactory queryFactory;
|
||||||
|
|
||||||
|
protected final DeleterFactory deleterFactory;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public DmpDescriptionTemplateDeleter(
|
||||||
|
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<DmpDescriptionTemplateEntity> data = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(ids).collect();
|
||||||
|
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
this.deleteAndSave(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAndSave(List<DmpDescriptionTemplateEntity> 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<DmpDescriptionTemplateEntity> data) throws InvalidApplicationException {
|
||||||
|
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||||
|
if (data == null || data.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (DmpDescriptionTemplateEntity item : data) {
|
||||||
|
logger.trace("deleting item {}", item.getId());
|
||||||
|
logger.trace("updating item");
|
||||||
|
item.setUpdatedAt(Instant.now());
|
||||||
|
item.setIsActive(IsActive.Inactive);
|
||||||
|
this.entityManager.merge(item);
|
||||||
|
logger.trace("updated item");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,10 +2,8 @@ package eu.eudat.model.persist;
|
||||||
|
|
||||||
import eu.eudat.commons.enums.DmpStatus;
|
import eu.eudat.commons.enums.DmpStatus;
|
||||||
import eu.eudat.commons.validation.ValidId;
|
import eu.eudat.commons.validation.ValidId;
|
||||||
import eu.eudat.model.Reference;
|
|
||||||
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
import eu.eudat.model.persist.dmpproperties.DmpPropertiesPersist;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -24,7 +22,7 @@ public class DmpPersist {
|
||||||
|
|
||||||
private String language;
|
private String language;
|
||||||
|
|
||||||
private List<ReferencePersist> references;
|
private List<DmpReferencePersist> references;
|
||||||
|
|
||||||
private String hash;
|
private String hash;
|
||||||
|
|
||||||
|
@ -76,11 +74,11 @@ public class DmpPersist {
|
||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReferencePersist> getReferences() {
|
public List<DmpReferencePersist> getReferences() {
|
||||||
return references;
|
return references;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReferences(List<ReferencePersist> references) {
|
public void setReferences(List<DmpReferencePersist> references) {
|
||||||
this.references = references;
|
this.references = references;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
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 java.util.UUID;
|
||||||
|
|
||||||
|
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
|
||||||
|
public class DmpReferencePersist {
|
||||||
|
|
||||||
|
@ValidId(message = "{validation.invalidid}")
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@NotNull(message = "{validation.empty}")
|
||||||
|
@NotEmpty(message = "{validation.empty}")
|
||||||
|
private ReferencePersist reference;
|
||||||
|
|
||||||
|
@NotNull(message = "{validation.empty}")
|
||||||
|
@NotEmpty(message = "{validation.empty}")
|
||||||
|
private String data;
|
||||||
|
|
||||||
|
private String hash;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(UUID id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferencePersist getReference() {
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReference(ReferencePersist reference) {
|
||||||
|
this.reference = reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(String data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHash() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHash(String hash) {
|
||||||
|
this.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,160 @@
|
||||||
|
package eu.eudat.query;
|
||||||
|
|
||||||
|
import eu.eudat.authorization.AuthorizationFlags;
|
||||||
|
import eu.eudat.commons.scope.user.UserScope;
|
||||||
|
import eu.eudat.data.DmpDescriptionTemplateEntity;
|
||||||
|
import eu.eudat.data.DmpReferenceEntity;
|
||||||
|
import eu.eudat.model.DmpDescriptionTemplate;
|
||||||
|
import eu.eudat.model.DmpReference;
|
||||||
|
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 DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplateEntity> {
|
||||||
|
|
||||||
|
private Collection<UUID> ids;
|
||||||
|
|
||||||
|
private Collection<UUID> dmpIds;
|
||||||
|
|
||||||
|
private Collection<UUID> descriptionTemplateIds;
|
||||||
|
|
||||||
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery ids(UUID value) {
|
||||||
|
this.ids = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery ids(UUID... value) {
|
||||||
|
this.ids = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery ids(Collection<UUID> values) {
|
||||||
|
this.ids = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery dmpIds(UUID value) {
|
||||||
|
this.dmpIds = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery dmpIds(UUID... value) {
|
||||||
|
this.dmpIds = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery dmpIds(Collection<UUID> values) {
|
||||||
|
this.dmpIds = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID value) {
|
||||||
|
this.descriptionTemplateIds = List.of(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID... value) {
|
||||||
|
this.descriptionTemplateIds = Arrays.asList(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery descriptionTemplateIds(Collection<UUID> values) {
|
||||||
|
this.descriptionTemplateIds = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery authorize(EnumSet<AuthorizationFlags> values) {
|
||||||
|
this.authorize = values;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final UserScope userScope;
|
||||||
|
|
||||||
|
private final AuthorizationService authService;
|
||||||
|
|
||||||
|
public DmpDescriptionTemplateQuery(
|
||||||
|
UserScope userScope,
|
||||||
|
AuthorizationService authService
|
||||||
|
) {
|
||||||
|
this.userScope = userScope;
|
||||||
|
this.authService = authService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<DmpDescriptionTemplateEntity> entityClass() {
|
||||||
|
return DmpDescriptionTemplateEntity.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean isFalseQuery() {
|
||||||
|
return this.isEmpty(this.ids) || this.isEmpty(this.dmpIds) || this.isEmpty(this.descriptionTemplateIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected <X, Y> Predicate applyFilters(QueryContext<X, Y> queryContext) {
|
||||||
|
List<Predicate> predicates = new ArrayList<>();
|
||||||
|
if (this.ids != null) {
|
||||||
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._id));
|
||||||
|
for (UUID item : this.ids)
|
||||||
|
inClause.value(item);
|
||||||
|
predicates.add(inClause);
|
||||||
|
}
|
||||||
|
if (this.dmpIds != null) {
|
||||||
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._dmp));
|
||||||
|
for (UUID item : this.dmpIds)
|
||||||
|
inClause.value(item);
|
||||||
|
predicates.add(inClause);
|
||||||
|
}
|
||||||
|
if (this.descriptionTemplateIds != null) {
|
||||||
|
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplate));
|
||||||
|
for (UUID item : this.descriptionTemplateIds)
|
||||||
|
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 DmpDescriptionTemplateEntity convert(Tuple tuple, Set<String> columns) {
|
||||||
|
DmpDescriptionTemplateEntity item = new DmpDescriptionTemplateEntity();
|
||||||
|
item.setId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._id, UUID.class));
|
||||||
|
item.setDmp(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._dmp, UUID.class));
|
||||||
|
item.setDescriptionTemplate(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._descriptionTemplate, UUID.class));
|
||||||
|
item.setSectionId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._sectionId, UUID.class));
|
||||||
|
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._createdAt, Instant.class));
|
||||||
|
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._updatedAt, Instant.class));
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String fieldNameOf(FieldResolver item) {
|
||||||
|
if (item.match(DmpDescriptionTemplate._id)) return DmpDescriptionTemplateEntity._id;
|
||||||
|
else if (item.prefix(DmpDescriptionTemplate._dmp)) return DmpDescriptionTemplateEntity._dmp;
|
||||||
|
else if (item.prefix(DmpDescriptionTemplate._descriptionTemplate)) return DmpDescriptionTemplateEntity._descriptionTemplate;
|
||||||
|
else if (item.match(DmpDescriptionTemplate._sectionId)) return DmpDescriptionTemplateEntity._sectionId;
|
||||||
|
else if (item.match(DmpDescriptionTemplate._createdAt)) return DmpDescriptionTemplateEntity._createdAt;
|
||||||
|
else if (item.match(DmpDescriptionTemplate._updatedAt)) return DmpDescriptionTemplateEntity._updatedAt;
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -224,6 +224,7 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
else if (item.match(Dmp._isActive)) return DmpEntity._isActive;
|
else if (item.match(Dmp._isActive)) return DmpEntity._isActive;
|
||||||
else if (item.match(Dmp._finalizedAt)) return DmpEntity._finalizedAt;
|
else if (item.match(Dmp._finalizedAt)) return DmpEntity._finalizedAt;
|
||||||
else if (item.match(Dmp._accessType)) return DmpEntity._accessType;
|
else if (item.match(Dmp._accessType)) return DmpEntity._accessType;
|
||||||
|
else if (item.match(Dmp._creator)) return DmpEntity._creator;
|
||||||
else if (item.match(Dmp._blueprint)) return DmpEntity._blueprint;
|
else if (item.match(Dmp._blueprint)) return DmpEntity._blueprint;
|
||||||
else if (item.match(Dmp._language)) return DmpEntity._language;
|
else if (item.match(Dmp._language)) return DmpEntity._language;
|
||||||
else if (item.match(Dmp._publicAfter)) return DmpEntity._publicAfter;
|
else if (item.match(Dmp._publicAfter)) return DmpEntity._publicAfter;
|
||||||
|
@ -245,6 +246,7 @@ public class DmpQuery extends QueryBase<DmpEntity> {
|
||||||
item.setIsActive(QueryBase.convertSafe(tuple, columns, DmpEntity._isActive, IsActive.class));
|
item.setIsActive(QueryBase.convertSafe(tuple, columns, DmpEntity._isActive, IsActive.class));
|
||||||
item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DmpEntity._finalizedAt, Instant.class));
|
item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DmpEntity._finalizedAt, Instant.class));
|
||||||
item.setAccessType(QueryBase.convertSafe(tuple, columns, DmpEntity._accessType, DmpAccessType.class));
|
item.setAccessType(QueryBase.convertSafe(tuple, columns, DmpEntity._accessType, DmpAccessType.class));
|
||||||
|
item.setCreator(QueryBase.convertSafe(tuple, columns, DmpEntity._creator, UUID.class));
|
||||||
item.setBlueprint(QueryBase.convertSafe(tuple, columns, DmpEntity._blueprint, UUID.class));
|
item.setBlueprint(QueryBase.convertSafe(tuple, columns, DmpEntity._blueprint, UUID.class));
|
||||||
item.setLanguage(QueryBase.convertSafe(tuple, columns, DmpEntity._language, String.class));
|
item.setLanguage(QueryBase.convertSafe(tuple, columns, DmpEntity._language, String.class));
|
||||||
item.setPublicAfter(QueryBase.convertSafe(tuple, columns, DmpEntity._publicAfter, Instant.class));
|
item.setPublicAfter(QueryBase.convertSafe(tuple, columns, DmpEntity._publicAfter, Instant.class));
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class DmpReferenceQuery extends QueryBase<DmpReferenceEntity> {
|
||||||
}
|
}
|
||||||
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.ids)
|
for (UUID item : this.dmpIds)
|
||||||
inClause.value(item);
|
inClause.value(item);
|
||||||
predicates.add(inClause);
|
predicates.add(inClause);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import eu.eudat.model.deleter.DmpDeleter;
|
||||||
import eu.eudat.model.deleter.DmpReferenceDeleter;
|
import eu.eudat.model.deleter.DmpReferenceDeleter;
|
||||||
import eu.eudat.model.deleter.ReferenceDeleter;
|
import eu.eudat.model.deleter.ReferenceDeleter;
|
||||||
import eu.eudat.model.persist.DmpPersist;
|
import eu.eudat.model.persist.DmpPersist;
|
||||||
|
import eu.eudat.model.persist.DmpReferencePersist;
|
||||||
import eu.eudat.model.persist.ReferencePersist;
|
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;
|
||||||
|
@ -201,7 +202,7 @@ public class DmpServiceImpl implements DmpService {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void patchAndSave(List<ReferencePersist> models, UUID dmpId) throws InvalidApplicationException {
|
private void patchAndSave(List<DmpReferencePersist> models, UUID dmpId) throws InvalidApplicationException {
|
||||||
if (models == null || models.isEmpty())
|
if (models == null || models.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -214,25 +215,26 @@ public class DmpServiceImpl implements DmpService {
|
||||||
else
|
else
|
||||||
existingReferences = new ArrayList<>();
|
existingReferences = new ArrayList<>();
|
||||||
|
|
||||||
List<UUID> updatedReferencesIds = models.stream().map(ReferencePersist::getId).filter(this.conventionService::isValidGuid).distinct().toList();
|
List<UUID> updatedReferencesIds = models.stream().map(x -> x.getReference().getId()).filter(this.conventionService::isValidGuid).distinct().toList();
|
||||||
List<ReferenceEntity> toDelete = existingReferences.stream().filter(x -> !updatedReferencesIds.contains(x.getId())).toList();
|
List<ReferenceEntity> toDelete = existingReferences.stream().filter(x -> !updatedReferencesIds.contains(x.getId())).toList();
|
||||||
List<DmpReferenceEntity> dmpReferenceRecordsToDelete = this.queryFactory.query(DmpReferenceQuery.class).referenceIds(toDelete.stream().map(ReferenceEntity::getId).toList()).collect();
|
List<DmpReferenceEntity> dmpReferenceRecordsToDelete = this.queryFactory.query(DmpReferenceQuery.class).referenceIds(toDelete.stream().map(ReferenceEntity::getId).toList()).collect();
|
||||||
this.deleterFactory.deleter(DmpReferenceDeleter.class).delete(dmpReferenceRecordsToDelete);
|
this.deleterFactory.deleter(DmpReferenceDeleter.class).delete(dmpReferenceRecordsToDelete);
|
||||||
this.deleterFactory.deleter(ReferenceDeleter.class).delete(toDelete);
|
|
||||||
|
|
||||||
Map<UUID, ReferenceEntity> existingReferencesLookup = existingReferences.stream().collect(Collectors.toMap(ReferenceEntity::getId, x -> x));
|
Map<UUID, ReferenceEntity> existingReferencesLookup = existingReferences.stream().collect(Collectors.toMap(ReferenceEntity::getId, x -> x));
|
||||||
|
|
||||||
for (ReferencePersist model : models) {
|
for (DmpReferencePersist model : models) {
|
||||||
Boolean isUpdate = this.conventionService.isValidGuid(model.getId());
|
ReferencePersist referenceModel = model.getReference();
|
||||||
|
|
||||||
|
Boolean isUpdate = this.conventionService.isValidGuid(referenceModel.getId());
|
||||||
|
|
||||||
ReferenceEntity data;
|
ReferenceEntity data;
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
if (!existingReferencesLookup.containsKey(model.getId()))
|
if (!existingReferencesLookup.containsKey(referenceModel.getId()))
|
||||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referenceModel.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
data = existingReferencesLookup.get(model.getId());
|
data = existingReferencesLookup.get(referenceModel.getId());
|
||||||
if (data == null)
|
if (data == null)
|
||||||
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{model.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{referenceModel.getId(), Reference.class.getSimpleName()}, LocaleContextHolder.getLocale()));
|
||||||
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(model.getHash()))
|
if (!this.conventionService.hashValue(data.getUpdatedAt()).equals(referenceModel.getHash()))
|
||||||
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
throw new MyValidationException(this.errors.getHashConflict().getCode(), this.errors.getHashConflict().getMessage());
|
||||||
} else {
|
} else {
|
||||||
data = new ReferenceEntity();
|
data = new ReferenceEntity();
|
||||||
|
@ -246,16 +248,16 @@ public class DmpServiceImpl implements DmpService {
|
||||||
dmpReference.setCreatedAt(Instant.now());
|
dmpReference.setCreatedAt(Instant.now());
|
||||||
dmpReference.setUpdatedAt(Instant.now());
|
dmpReference.setUpdatedAt(Instant.now());
|
||||||
dmpReference.setIsActive(IsActive.Active);
|
dmpReference.setIsActive(IsActive.Active);
|
||||||
//TODO: Add data persistence here
|
dmpReference.setData(model.getData());
|
||||||
this.entityManager.persist(dmpReference);
|
this.entityManager.persist(dmpReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(model.getDefinition())));
|
data.setDefinition(this.xmlHandlingService.toXmlSafe(this.buildDefinitionEntity(referenceModel.getDefinition())));
|
||||||
data.setUpdatedAt(Instant.now());
|
data.setUpdatedAt(Instant.now());
|
||||||
data.setReference(model.getReference());
|
data.setReference(referenceModel.getReference());
|
||||||
data.setAbbreviation(model.getAbbreviation());
|
data.setAbbreviation(referenceModel.getAbbreviation());
|
||||||
data.setSource(model.getSource());
|
data.setSource(referenceModel.getSource());
|
||||||
data.setSourceType(model.getSourceType());
|
data.setSourceType(referenceModel.getSourceType());
|
||||||
|
|
||||||
if (isUpdate)
|
if (isUpdate)
|
||||||
this.entityManager.merge(data);
|
this.entityManager.merge(data);
|
||||||
|
|
|
@ -300,6 +300,27 @@ permissions:
|
||||||
allowAnonymous: false
|
allowAnonymous: false
|
||||||
allowAuthenticated: false
|
allowAuthenticated: false
|
||||||
|
|
||||||
|
# DmpDescriptionTemplate Permissions
|
||||||
|
BrowseDmpDescriptionTemplate:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
||||||
|
EditDmpDescriptionTemplate:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
||||||
|
DeleteDmpDescriptionTemplate:
|
||||||
|
roles:
|
||||||
|
- Admin
|
||||||
|
claims: [ ]
|
||||||
|
clients: [ ]
|
||||||
|
allowAnonymous: false
|
||||||
|
allowAuthenticated: false
|
||||||
|
|
||||||
# DescriptionReference Permissions
|
# DescriptionReference Permissions
|
||||||
BrowseDescriptionReference:
|
BrowseDescriptionReference:
|
||||||
roles:
|
roles:
|
||||||
|
|
Loading…
Reference in New Issue