diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/DmpReferenceEntity.java similarity index 94% rename from dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java rename to dmp-backend/core/src/main/java/eu/eudat/data/DmpReferenceEntity.java index 072024af8..aa0f98e06 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/DmpExternalReferenceEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/DmpReferenceEntity.java @@ -8,8 +8,8 @@ import jakarta.persistence.Table; import java.util.UUID; @Entity -@Table(name = "\"DmpExternalReference\"") -public class DmpExternalReferenceEntity { +@Table(name = "\"DmpReference\"") +public class DmpReferenceEntity { @Id @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java similarity index 98% rename from dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java rename to dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java index 8cb605ae1..bb3b1db63 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/data/ExternalReferenceEntity.java +++ b/dmp-backend/core/src/main/java/eu/eudat/data/ReferenceEntity.java @@ -12,8 +12,8 @@ import java.time.Instant; import java.util.UUID; @Entity -@Table(name = "\"ExternalReference\"") -public class ExternalReferenceEntity { +@Table(name = "\"Reference\"") +public class ReferenceEntity { @Id @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java b/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java index c57b5d5fc..c02eb147e 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Dmp.java @@ -93,6 +93,9 @@ public class Dmp { public static final String _dmpDescriptions = "dmpDescriptions"; + public static final String _dmpExternalReferences = "dmpExternalReferences"; + private List dmpReferences; + public UUID getId() { return id; } @@ -260,4 +263,12 @@ public class Dmp { public void setDmpDescriptions(List dmpDescriptions) { this.dmpDescriptions = dmpDescriptions; } + + public List getDmpExternalReferences() { + return dmpReferences; + } + + public void setDmpExternalReferences(List dmpReferences) { + this.dmpReferences = dmpReferences; + } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/DmpBlueprint.java b/dmp-backend/core/src/main/java/eu/eudat/model/DmpBlueprint.java index f9acb6798..89f67ad50 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/DmpBlueprint.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/DmpBlueprint.java @@ -34,9 +34,6 @@ public class DmpBlueprint { public final static String _hash = "hash"; private String hash; - public static final String _dmpExternalReferences = "dmpExternalReferences"; - private List dmpExternalReferences; - public UUID getId() { return id; } @@ -100,14 +97,6 @@ public class DmpBlueprint { public void setDefinition(Definition definition) { this.definition = definition; } - - public List getDmpExternalReferences() { - return dmpExternalReferences; - } - - public void setDmpExternalReferences(List dmpExternalReferences) { - this.dmpExternalReferences = dmpExternalReferences; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java b/dmp-backend/core/src/main/java/eu/eudat/model/DmpReference.java similarity index 60% rename from dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java rename to dmp-backend/core/src/main/java/eu/eudat/model/DmpReference.java index 67deac0a8..77b3ff6b4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/DmpExternalReference.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/DmpReference.java @@ -2,15 +2,15 @@ package eu.eudat.model; import java.util.UUID; -public class DmpExternalReference { +public class DmpReference { private UUID id; public static final String _id = "id"; - private DmpBlueprint dmp; + private Dmp dmp; public static final String _dmp = "dmp"; - private ExternalReference externalReference; + private Reference reference; public static final String _externalReference = "externalReference"; private String data; @@ -24,20 +24,20 @@ public class DmpExternalReference { this.id = id; } - public DmpBlueprint getDmp() { + public Dmp getDmp() { return dmp; } - public void setDmp(DmpBlueprint dmp) { + public void setDmp(Dmp dmp) { this.dmp = dmp; } - public ExternalReference getExternalReference() { - return externalReference; + public Reference getExternalReference() { + return reference; } - public void setExternalReference(ExternalReference externalReference) { - this.externalReference = externalReference; + public void setExternalReference(Reference reference) { + this.reference = reference; } public String getData() { diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java b/dmp-backend/core/src/main/java/eu/eudat/model/Reference.java similarity index 90% rename from dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java rename to dmp-backend/core/src/main/java/eu/eudat/model/Reference.java index d8d279c05..9343e8158 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/ExternalReference.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/Reference.java @@ -8,7 +8,7 @@ import java.time.Instant; import java.util.List; import java.util.UUID; -public class ExternalReference { +public class Reference { private UUID id; public static final String _id = "id"; @@ -49,7 +49,7 @@ public class ExternalReference { //private UserInfo createdBy; ToDo //public static final String _createdBy = "createdBy"; - private List dmpExternalReferences; + private List dmpReferences; public static final String _dmpExternalReferences = "dmpExternalReferences"; public UUID getId() { @@ -148,11 +148,11 @@ public class ExternalReference { this.updatedAt = updatedAt; } - public List getDmpExternalReferences() { - return dmpExternalReferences; + public List getDmpExternalReferences() { + return dmpReferences; } - public void setDmpExternalReferences(List dmpExternalReferences) { - this.dmpExternalReferences = dmpExternalReferences; + public void setDmpExternalReferences(List dmpReferences) { + this.dmpReferences = dmpReferences; } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBlueprintBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBlueprintBuilder.java index 9bdd92024..46194e84c 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBlueprintBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBlueprintBuilder.java @@ -6,14 +6,9 @@ import eu.eudat.commons.types.dmpblueprint.DefinitionEntity; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.model.DmpBlueprint; -import eu.eudat.model.DmpExternalReference; -import eu.eudat.model.ExternalReference; import eu.eudat.model.builder.dmpblueprintdefinition.DefinitionBuilder; -import eu.eudat.query.DmpExternalReferenceQuery; 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; @@ -24,24 +19,21 @@ 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 DmpBlueprintBuilder extends BaseBuilder { private final BuilderFactory builderFactory; - private final QueryFactory queryFactory; private final XmlHandlingService xmlHandlingService; private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); @Autowired public DmpBlueprintBuilder( ConventionService conventionService, - BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) { + BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class))); this.builderFactory = builderFactory; - this.queryFactory = queryFactory; this.xmlHandlingService = xmlHandlingService; } @@ -57,9 +49,6 @@ public class DmpBlueprintBuilder extends BaseBuilder(); FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(DmpBlueprint._definition)); - FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asPrefix(ExternalReference._dmpExternalReferences)); - Map> dmpExternalReferenceMap = this.collectDmpExternalReferences(dmpExternalReferencesFields, data); - List models = new ArrayList<>(); for (DmpBlueprintEntity d : data) { DmpBlueprint m = new DmpBlueprint(); @@ -74,29 +63,9 @@ public class DmpBlueprintBuilder extends BaseBuilder> collectDmpExternalReferences(FieldSet fields, List datas) throws MyApplicationException { - if (fields.isEmpty() || datas.isEmpty()) return null; - this.logger.debug("checking related - {}", DmpExternalReference.class.getSimpleName()); - - Map> itemMap = null; - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpExternalReference._dmp, DmpBlueprint._id)); - DmpExternalReferenceQuery query = this.queryFactory.query(DmpExternalReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DmpExternalReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); - - if (!fields.hasField(this.asIndexer(DmpExternalReference._dmp, DmpBlueprint._id))) { - itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).map(x -> { - x.getDmp().setId(null); - return x; - }).collect(Collectors.toList()); - } - return itemMap; - } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java index 12573d759..3eff0fdd2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBuilder.java @@ -3,9 +3,9 @@ package eu.eudat.model.builder; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.convention.ConventionService; import eu.eudat.data.DmpEntity; -import eu.eudat.model.Description; -import eu.eudat.model.Dmp; +import eu.eudat.model.*; import eu.eudat.query.DescriptionQuery; +import eu.eudat.query.DmpReferenceQuery; import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.query.QueryFactory; import gr.cite.tools.exception.MyApplicationException; @@ -57,6 +57,8 @@ public class DmpBuilder extends BaseBuilder { FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptions)); Map> dmpDescriptionsMap = this.collectDmpDescriptions(dmpDescriptionsFields, data); + FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpExternalReferences)); + Map> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data); for (DmpEntity d : data) { Dmp m = new Dmp(); @@ -96,6 +98,7 @@ public class DmpBuilder extends BaseBuilder { if (!dmpDescriptionsFields.isEmpty() && dmpDescriptionsMap != null && dmpDescriptionsMap.containsKey(d.getId())) m.setDmpDescriptions(dmpDescriptionsMap.get(d.getId())); + if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpReferenceMap.get(d.getId())); models.add(m); } this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); @@ -123,4 +126,22 @@ public class DmpBuilder extends BaseBuilder { return itemMap; } + private Map> collectDmpReferences(FieldSet fields, List datas) throws MyApplicationException { + if (fields.isEmpty() || datas.isEmpty()) return null; + this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); + + Map> itemMap = null; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpReference._dmp, Dmp._id)); + DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId()); + + if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).map(x -> { + x.getDmp().setId(null); + return x; + }).collect(Collectors.toList()); + } + return itemMap; + } + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java deleted file mode 100644 index 25c7400ab..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpExternalReferenceBuilder.java +++ /dev/null @@ -1,130 +0,0 @@ -package eu.eudat.model.builder; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.DmpExternalReferenceEntity; -import eu.eudat.model.DmpBlueprint; -import eu.eudat.model.DmpExternalReference; -import eu.eudat.model.ExternalReference; -import eu.eudat.query.DmpBlueprintQuery; -import eu.eudat.query.ExternalReferenceQuery; -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 DmpExternalReferenceBuilder extends BaseBuilder{ - - private final BuilderFactory builderFactory; - private final QueryFactory queryFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public DmpExternalReferenceBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, QueryFactory queryFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceBuilder.class))); - this.builderFactory = builderFactory; - this.queryFactory = queryFactory; - } - - public DmpExternalReferenceBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List 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 externalReferenceFields = fields.extractPrefixed(this.asPrefix(DmpExternalReference._externalReference)); - Map externalReferenceItemsMap = this.collectExternalReferences(externalReferenceFields, data); - - FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpExternalReference._dmp)); - Map dmpBlueprintItemsMap = this.collectDmps(dmpFields, data); - - List models = new ArrayList<>(); - for (DmpExternalReferenceEntity d : data) { - DmpExternalReference m = new DmpExternalReference(); - if (fields.hasField(this.asIndexer(DmpExternalReference._id))) m.setId(d.getId()); - if (fields.hasField(this.asIndexer(DmpExternalReference._data))) m.setData(d.getData()); - if(!externalReferenceFields.isEmpty() && externalReferenceItemsMap != null && externalReferenceItemsMap.containsKey(d.getReferenceId())){ - m.setExternalReference(externalReferenceItemsMap.get(d.getReferenceId())); - } - if(!dmpFields.isEmpty() && dmpBlueprintItemsMap != null && dmpBlueprintItemsMap.containsKey(d.getDmpId())){ - m.setDmp(dmpBlueprintItemsMap.get(d.getDmpId())); - } - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } - - private Map collectExternalReferences(FieldSet fields, List data) throws MyApplicationException { - if (fields.isEmpty() || data.isEmpty()) return null; - this.logger.debug("checking related - {}", ExternalReference.class.getSimpleName()); - - Map itemMap; - if (!fields.hasOtherField(this.asIndexer(ExternalReference._id))) { - itemMap = this.asEmpty( - data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()), - x -> { - ExternalReference item = new ExternalReference(); - item.setId(x); - return item; - }, - ExternalReference::getId); - } else { - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(ExternalReference._id); - ExternalReferenceQuery q = this.queryFactory.query(ExternalReferenceQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, ExternalReference::getId); - } - if (!fields.hasField(ExternalReference._id)) { - itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); - } - - return itemMap; - } - - private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { - if (fields.isEmpty() || data.isEmpty()) return null; - this.logger.debug("checking related - {}", DmpBlueprint.class.getSimpleName()); - - Map itemMap; - if (!fields.hasOtherField(this.asIndexer(DmpBlueprint._id))) { - itemMap = this.asEmpty( - data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList()), - x -> { - DmpBlueprint item = new DmpBlueprint(); - item.setId(x); - return item; - }, - DmpBlueprint::getId); - } else { - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DmpBlueprint._id); - DmpBlueprintQuery q = this.queryFactory.query(DmpBlueprintQuery.class).authorize(this.authorize).ids(data.stream().map(x -> x.getDmpId()).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DmpBlueprintBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DmpBlueprint::getId); - } - if (!fields.hasField(DmpBlueprint._id)) { - itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); - } - - return itemMap; - } - -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpReferenceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpReferenceBuilder.java new file mode 100644 index 000000000..cbd3a58fd --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpReferenceBuilder.java @@ -0,0 +1,130 @@ +package eu.eudat.model.builder; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.DmpReferenceEntity; +import eu.eudat.model.Dmp; +import eu.eudat.model.DmpReference; +import eu.eudat.model.Reference; +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 DmpReferenceBuilder extends BaseBuilder{ + + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public DmpReferenceBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpReferenceBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public DmpReferenceBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List 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 referenceFields = fields.extractPrefixed(this.asPrefix(DmpReference._externalReference)); + Map referenceItemsMap = this.collectReferences(referenceFields, data); + + FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpReference._dmp)); + Map dmpItemsMap = this.collectDmps(dmpFields, data); + + List models = new ArrayList<>(); + for (DmpReferenceEntity d : data) { + DmpReference m = new DmpReference(); + if (fields.hasField(this.asIndexer(DmpReference._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(DmpReference._data))) m.setData(d.getData()); + if(!referenceFields.isEmpty() && referenceItemsMap != null && referenceItemsMap.containsKey(d.getReferenceId())){ + m.setExternalReference(referenceItemsMap.get(d.getReferenceId())); + } + if(!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())){ + m.setDmp(dmpItemsMap.get(d.getDmpId())); + } + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + private Map collectReferences(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) return null; + this.logger.debug("checking related - {}", Reference.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(Reference._id))) { + itemMap = this.asEmpty( + data.stream().map(x -> x.getReferenceId()).distinct().collect(Collectors.toList()), + x -> { + Reference item = new Reference(); + item.setId(x); + return item; + }, + Reference::getId); + } else { + 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())); + itemMap = this.builderFactory.builder(ReferenceBuilder.class).authorize(this.authorize).asForeignKey(q, clone, Reference::getId); + } + if (!fields.hasField(Reference._id)) { + itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList()); + } + + return itemMap; + } + + private Map collectDmps(FieldSet fields, List data) throws MyApplicationException { + if (fields.isEmpty() || data.isEmpty()) return null; + this.logger.debug("checking related - {}", Dmp.class.getSimpleName()); + + Map itemMap; + if (!fields.hasOtherField(this.asIndexer(Dmp._id))) { + itemMap = this.asEmpty( + data.stream().map(x -> x.getDmpId()).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(x -> x.getDmpId()).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; + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java deleted file mode 100644 index d2280800f..000000000 --- a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ExternalReferenceBuilder.java +++ /dev/null @@ -1,101 +0,0 @@ -package eu.eudat.model.builder; - -import eu.eudat.authorization.AuthorizationFlags; -import eu.eudat.convention.ConventionService; -import eu.eudat.data.ExternalReferenceEntity; -import eu.eudat.model.DmpExternalReference; -import eu.eudat.model.ExternalReference; -import eu.eudat.query.DmpExternalReferenceQuery; -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 ExternalReferenceBuilder extends BaseBuilder{ - - private final BuilderFactory builderFactory; - private final QueryFactory queryFactory; - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - @Autowired - public ExternalReferenceBuilder( - ConventionService conventionService, - BuilderFactory builderFactory, QueryFactory queryFactory) { - super(conventionService, new LoggerService(LoggerFactory.getLogger(ExternalReferenceBuilder.class))); - this.builderFactory = builderFactory; - this.queryFactory = queryFactory; - } - - public ExternalReferenceBuilder authorize(EnumSet values) { - this.authorize = values; - return this; - } - - @Override - public List build(FieldSet fields, List 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 userInfoFields = fields.extractPrefixed(this.asPrefix(ExternalReference._createdBy)); - - FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asPrefix(ExternalReference._dmpExternalReferences)); - Map> dmpExternalReferenceMap = this.collectDmpExternalReferences(dmpExternalReferencesFields, data); - - List models = new ArrayList<>(); - for (ExternalReferenceEntity d : data) { - ExternalReference m = new ExternalReference(); - if (fields.hasField(this.asIndexer(ExternalReference._id))) m.setId(d.getId()); - if (fields.hasField(this.asIndexer(ExternalReference._label))) m.setLabel(d.getLabel()); - if (fields.hasField(this.asIndexer(ExternalReference._createdAt))) m.setCreatedAt(d.getCreatedAt()); - if (fields.hasField(this.asIndexer(ExternalReference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); - if (fields.hasField(this.asIndexer(ExternalReference._isActive))) m.setIsActive(d.getIsActive()); - if (fields.hasField(this.asIndexer(ExternalReference._definition))) m.setReference(d.getDefinition()); - if (fields.hasField(this.asIndexer(ExternalReference._reference))) m.setReference(d.getReference()); - if (fields.hasField(this.asIndexer(ExternalReference._abbreviation))) m.setAbbreviation(d.getAbbreviation()); - if (fields.hasField(this.asIndexer(ExternalReference._description))) m.setDescription(d.getDescription()); - if (fields.hasField(this.asIndexer(ExternalReference._source))) m.setSource(d.getSource()); - if (fields.hasField(this.asIndexer(ExternalReference._sourceType))) m.setSourceType(d.getSourceType()); - if (fields.hasField(this.asIndexer(ExternalReference._type))) m.setType(d.getType()); -// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){ -// //ToDo -// } - if (!dmpExternalReferenceMap.isEmpty() && dmpExternalReferenceMap != null && dmpExternalReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpExternalReferenceMap.get(d.getId())); - models.add(m); - } - this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); - return models; - } - - private Map> collectDmpExternalReferences(FieldSet fields, List datas) throws MyApplicationException { - if (fields.isEmpty() || datas.isEmpty()) return null; - this.logger.debug("checking related - {}", DmpExternalReference.class.getSimpleName()); - - Map> itemMap = null; - FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpExternalReference._externalReference, ExternalReference._id)); - DmpExternalReferenceQuery query = this.queryFactory.query(DmpExternalReferenceQuery.class).authorize(this.authorize).referenceIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList())); - itemMap = this.builderFactory.builder(DmpExternalReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getExternalReference().getId()); - - if (!fields.hasField(this.asIndexer(DmpExternalReference._externalReference, ExternalReference._id))) { - itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getExternalReference() != null).map(x -> { - x.getExternalReference().setId(null); - return x; - }).collect(Collectors.toList()); - } - return itemMap; - } -} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceBuilder.java new file mode 100644 index 000000000..8bfb99753 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/model/builder/ReferenceBuilder.java @@ -0,0 +1,101 @@ +package eu.eudat.model.builder; + +import eu.eudat.authorization.AuthorizationFlags; +import eu.eudat.convention.ConventionService; +import eu.eudat.data.ReferenceEntity; +import eu.eudat.model.DmpReference; +import eu.eudat.model.Reference; +import eu.eudat.query.DmpReferenceQuery; +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 ReferenceBuilder extends BaseBuilder{ + + private final BuilderFactory builderFactory; + private final QueryFactory queryFactory; + private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); + + @Autowired + public ReferenceBuilder( + ConventionService conventionService, + BuilderFactory builderFactory, QueryFactory queryFactory) { + super(conventionService, new LoggerService(LoggerFactory.getLogger(ReferenceBuilder.class))); + this.builderFactory = builderFactory; + this.queryFactory = queryFactory; + } + + public ReferenceBuilder authorize(EnumSet values) { + this.authorize = values; + return this; + } + + @Override + public List build(FieldSet fields, List 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 userInfoFields = fields.extractPrefixed(this.asPrefix(ExternalReference._createdBy)); + + FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpExternalReferences)); + Map> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data); + + List models = new ArrayList<>(); + for (ReferenceEntity d : data) { + Reference m = new Reference(); + if (fields.hasField(this.asIndexer(Reference._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(Reference._label))) m.setLabel(d.getLabel()); + if (fields.hasField(this.asIndexer(Reference._createdAt))) m.setCreatedAt(d.getCreatedAt()); + if (fields.hasField(this.asIndexer(Reference._updatedAt))) m.setUpdatedAt(d.getUpdatedAt()); + if (fields.hasField(this.asIndexer(Reference._isActive))) m.setIsActive(d.getIsActive()); + if (fields.hasField(this.asIndexer(Reference._definition))) m.setReference(d.getDefinition()); + if (fields.hasField(this.asIndexer(Reference._reference))) m.setReference(d.getReference()); + if (fields.hasField(this.asIndexer(Reference._abbreviation))) m.setAbbreviation(d.getAbbreviation()); + if (fields.hasField(this.asIndexer(Reference._description))) m.setDescription(d.getDescription()); + if (fields.hasField(this.asIndexer(Reference._source))) m.setSource(d.getSource()); + if (fields.hasField(this.asIndexer(Reference._sourceType))) m.setSourceType(d.getSourceType()); + if (fields.hasField(this.asIndexer(Reference._type))) m.setType(d.getType()); +// if (!userInfoFields.isEmpty() && d.getCreatedBy() != null){ +// //ToDo +// } + if (!dmpReferenceMap.isEmpty() && dmpReferenceMap != null && dmpReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpReferenceMap.get(d.getId())); + models.add(m); + } + this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); + return models; + } + + private Map> collectDmpReferences(FieldSet fields, List datas) throws MyApplicationException { + if (fields.isEmpty() || datas.isEmpty()) return null; + this.logger.debug("checking related - {}", DmpReference.class.getSimpleName()); + + Map> itemMap = null; + FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpReference._externalReference, Reference._id)); + DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).referenceIds(datas.stream().map(x -> x.getId()).distinct().collect(Collectors.toList())); + itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).authorize(this.authorize).authorize(this.authorize).asMasterKey(query, clone, x -> x.getExternalReference().getId()); + + if (!fields.hasField(this.asIndexer(DmpReference._externalReference, Reference._id))) { + itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getExternalReference() != null).map(x -> { + x.getExternalReference().setId(null); + return x; + }).collect(Collectors.toList()); + } + return itemMap; + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpBlueprintCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpBlueprintCensor.java index c5b1360fd..538c8cd78 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpBlueprintCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpBlueprintCensor.java @@ -41,8 +41,6 @@ public class DmpBlueprintCensor extends BaseCensor { this.authService.authorizeForce(Permission.BrowseDmpBlueprint); FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._definition)); this.censorFactory.censor(DefinitionCensor.class).censor(definitionFields, userId); - FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._dmpExternalReferences)); - this.censorFactory.censor(DmpExternalReferenceCensor.class).censor(dmpExternalReferencesFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java index 216572666..e99138cb1 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpCensor.java @@ -42,6 +42,8 @@ public class DmpCensor extends BaseCensor { FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpDescriptions)); this.censorFactory.censor(DescriptionCensor.class).censor(dmpDescriptionsFields, userId); + FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Dmp._dmpExternalReferences)); + this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpExternalReferencesFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java similarity index 66% rename from dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java rename to dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java index bd372a41e..97364c931 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpExternalReferenceCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpReferenceCensor.java @@ -2,7 +2,7 @@ package eu.eudat.model.censorship; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; -import eu.eudat.model.DmpExternalReference; +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; @@ -17,16 +17,16 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpExternalReferenceCensor extends BaseCensor { +public class DmpReferenceCensor extends BaseCensor { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceCensor.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpReferenceCensor.class)); protected final AuthorizationService authService; protected final CensorFactory censorFactory; - public DmpExternalReferenceCensor(ConventionService conventionService, - AuthorizationService authService, - CensorFactory censorFactory) { + public DmpReferenceCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { super(conventionService); this.authService = authService; this.censorFactory = censorFactory; @@ -38,10 +38,10 @@ public class DmpExternalReferenceCensor extends BaseCensor { return; this.authService.authorizeForce(Permission.BrowseDmpExternalReference); - FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpExternalReference._dmp)); - this.censorFactory.censor(DmpBlueprintCensor.class).censor(dmpFields, userId); - FieldSet externalReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpExternalReference._externalReference)); - this.censorFactory.censor(ExternalReferenceCensor.class).censor(externalReferenceFields, userId); + FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._dmp)); + this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId); + FieldSet externalReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(DmpReference._externalReference)); + this.censorFactory.censor(ReferenceCensor.class).censor(externalReferenceFields, userId); } } diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceCensor.java similarity index 73% rename from dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java rename to dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceCensor.java index 07f09d5e5..5b9ce98be 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ExternalReferenceCensor.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/ReferenceCensor.java @@ -2,7 +2,7 @@ package eu.eudat.model.censorship; import eu.eudat.authorization.Permission; import eu.eudat.convention.ConventionService; -import eu.eudat.model.ExternalReference; +import eu.eudat.model.Reference; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; @@ -17,16 +17,16 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ExternalReferenceCensor extends BaseCensor { +public class ReferenceCensor extends BaseCensor { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceCensor.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceCensor.class)); protected final AuthorizationService authService; protected final CensorFactory censorFactory; - public ExternalReferenceCensor(ConventionService conventionService, - AuthorizationService authService, - CensorFactory censorFactory) { + public ReferenceCensor(ConventionService conventionService, + AuthorizationService authService, + CensorFactory censorFactory) { super(conventionService); this.authService = authService; this.censorFactory = censorFactory; @@ -38,8 +38,8 @@ public class ExternalReferenceCensor extends BaseCensor { return; this.authService.authorizeForce(Permission.BrowseExternalReference); - FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._dmpExternalReferences)); - this.censorFactory.censor(DmpExternalReferenceCensor.class).censor(dmpExternalReferencesFields, userId); + FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(Reference._dmpExternalReferences)); + this.censorFactory.censor(DmpReferenceCensor.class).censor(dmpExternalReferencesFields, userId); //ToDo //FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(ExternalReference._createdBy)); //this.censorFactory.censor(UserInfo.class).censor(definitionFields, userId); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpReferenceDeleter.java similarity index 77% rename from dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java rename to dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpReferenceDeleter.java index 41f063322..5953ed6e3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpExternalReferenceDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/DmpReferenceDeleter.java @@ -1,7 +1,7 @@ package eu.eudat.model.deleter; -import eu.eudat.data.DmpExternalReferenceEntity; -import eu.eudat.query.DmpExternalReferenceQuery; +import eu.eudat.data.DmpReferenceEntity; +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; @@ -21,9 +21,9 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpExternalReferenceDeleter implements Deleter { +public class DmpReferenceDeleter implements Deleter { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpExternalReferenceDeleter.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpReferenceDeleter.class)); private final EntityManager entityManager; protected final QueryFactory queryFactory; @@ -31,7 +31,7 @@ public class DmpExternalReferenceDeleter implements Deleter { protected final DeleterFactory deleterFactory; @Autowired - public DmpExternalReferenceDeleter( + public DmpReferenceDeleter( EntityManager entityManager, QueryFactory queryFactory, DeleterFactory deleterFactory @@ -43,12 +43,12 @@ public class DmpExternalReferenceDeleter implements Deleter { public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids)); - List data = this.queryFactory.query(DmpExternalReferenceQuery.class).ids(ids).collect(); + List data = this.queryFactory.query(DmpReferenceQuery.class).ids(ids).collect(); logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0)); this.deleteAndSave(data); } - public void deleteAndSave(List data) throws InvalidApplicationException { + public void deleteAndSave(List data) throws InvalidApplicationException { logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); this.delete(data); logger.trace("saving changes"); @@ -56,12 +56,12 @@ public class DmpExternalReferenceDeleter implements Deleter { logger.trace("changes saved"); } - public void delete(List data) throws InvalidApplicationException { + public void delete(List data) throws InvalidApplicationException { logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); if (data == null || data.isEmpty()) return; - for (DmpExternalReferenceEntity item : data) { + for (DmpReferenceEntity item : data) { logger.trace("deleting item {}", item.getId()); logger.trace("updating item"); this.entityManager.merge(item); diff --git a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java similarity index 79% rename from dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java rename to dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java index 4711da890..f2bb69945 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ExternalReferenceDeleter.java +++ b/dmp-backend/core/src/main/java/eu/eudat/model/deleter/ReferenceDeleter.java @@ -1,8 +1,8 @@ package eu.eudat.model.deleter; import eu.eudat.commons.enums.IsActive; -import eu.eudat.data.ExternalReferenceEntity; -import eu.eudat.query.ExternalReferenceQuery; +import eu.eudat.data.ReferenceEntity; +import eu.eudat.query.ReferenceQuery; import gr.cite.tools.data.deleter.Deleter; import gr.cite.tools.data.deleter.DeleterFactory; import gr.cite.tools.data.query.QueryFactory; @@ -23,9 +23,9 @@ import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ExternalReferenceDeleter implements Deleter { +public class ReferenceDeleter implements Deleter { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceDeleter.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceDeleter.class)); private final EntityManager entityManager; protected final QueryFactory queryFactory; @@ -33,7 +33,7 @@ public class ExternalReferenceDeleter implements Deleter { protected final DeleterFactory deleterFactory; @Autowired - public ExternalReferenceDeleter( + public ReferenceDeleter( EntityManager entityManager, QueryFactory queryFactory, DeleterFactory deleterFactory @@ -45,12 +45,12 @@ public class ExternalReferenceDeleter implements Deleter { public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids)); - List data = this.queryFactory.query(ExternalReferenceQuery.class).ids(ids).collect(); + List data = this.queryFactory.query(ReferenceQuery.class).ids(ids).collect(); logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0)); this.deleteAndSave(data); } - public void deleteAndSave(List data) throws InvalidApplicationException { + public void deleteAndSave(List data) throws InvalidApplicationException { logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); this.delete(data); logger.trace("saving changes"); @@ -58,14 +58,14 @@ public class ExternalReferenceDeleter implements Deleter { logger.trace("changes saved"); } - public void delete(List data) throws InvalidApplicationException { + public void delete(List 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 (ExternalReferenceEntity item : data) { + for (ReferenceEntity item : data) { logger.trace("deleting item {}", item.getId()); item.setIsActive(IsActive.Inactive); item.setUpdatedAt(now); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java similarity index 61% rename from dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java rename to dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java index a2a8ba61c..8177067e4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/DmpExternalReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/DmpReferenceQuery.java @@ -2,7 +2,7 @@ package eu.eudat.query; import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.data.DmpExternalReferenceEntity; +import eu.eudat.data.DmpReferenceEntity; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; @@ -18,7 +18,7 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class DmpExternalReferenceQuery extends QueryBase { +public class DmpReferenceQuery extends QueryBase { private Collection ids; @@ -29,52 +29,52 @@ public class DmpExternalReferenceQuery extends QueryBase authorize = EnumSet.of(AuthorizationFlags.None); - public DmpExternalReferenceQuery ids(UUID value) { + public DmpReferenceQuery ids(UUID value) { this.ids = List.of(value); return this; } - public DmpExternalReferenceQuery ids(UUID... value) { + public DmpReferenceQuery ids(UUID... value) { this.ids = Arrays.asList(value); return this; } - public DmpExternalReferenceQuery ids(Collection values) { + public DmpReferenceQuery ids(Collection values) { this.ids = values; return this; } - public DmpExternalReferenceQuery dmpIds(UUID value) { + public DmpReferenceQuery dmpIds(UUID value) { this.dmpIds = List.of(value); return this; } - public DmpExternalReferenceQuery dmpIds(UUID... value) { + public DmpReferenceQuery dmpIds(UUID... value) { this.dmpIds = Arrays.asList(value); return this; } - public DmpExternalReferenceQuery dmpIds(Collection values) { + public DmpReferenceQuery dmpIds(Collection values) { this.dmpIds = values; return this; } - public DmpExternalReferenceQuery referenceIds(UUID value) { + public DmpReferenceQuery referenceIds(UUID value) { this.referenceIds = List.of(value); return this; } - public DmpExternalReferenceQuery referenceIds(UUID... value) { + public DmpReferenceQuery referenceIds(UUID... value) { this.referenceIds = Arrays.asList(value); return this; } - public DmpExternalReferenceQuery referenceIds(Collection values) { + public DmpReferenceQuery referenceIds(Collection values) { this.referenceIds = values; return this; } - public DmpExternalReferenceQuery authorize(EnumSet values) { + public DmpReferenceQuery authorize(EnumSet values) { this.authorize = values; return this; } @@ -83,7 +83,7 @@ public class DmpExternalReferenceQuery extends QueryBase entityClass() { - return DmpExternalReferenceEntity.class; + protected Class entityClass() { + return DmpReferenceEntity.class; } @Override @@ -105,19 +105,19 @@ public class DmpExternalReferenceQuery extends QueryBase Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); if (this.ids != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._id)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._id)); for (UUID item : this.ids) inClause.value(item); predicates.add(inClause); } if (this.dmpIds != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._dmpId)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._dmpId)); for (UUID item : this.ids) inClause.value(item); predicates.add(inClause); } if (this.referenceIds != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpExternalReferenceEntity._referenceId)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpReferenceEntity._referenceId)); for (UUID item : this.ids) inClause.value(item); predicates.add(inClause); @@ -131,21 +131,21 @@ public class DmpExternalReferenceQuery extends QueryBase columns) { - DmpExternalReferenceEntity item = new DmpExternalReferenceEntity(); - item.setId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._id, UUID.class)); - item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._dmpId, UUID.class)); - item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._referenceId, UUID.class)); - item.setData(QueryBase.convertSafe(tuple, columns, DmpExternalReferenceEntity._data, String.class)); + protected DmpReferenceEntity convert(Tuple tuple, Set columns) { + DmpReferenceEntity item = new DmpReferenceEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._id, UUID.class)); + item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._dmpId, UUID.class)); + item.setReferenceId(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._referenceId, UUID.class)); + item.setData(QueryBase.convertSafe(tuple, columns, DmpReferenceEntity._data, String.class)); return item; } @Override protected String fieldNameOf(FieldResolver item) { - if (item.match(DmpExternalReferenceEntity._id)) return DmpExternalReferenceEntity._id; - else if (item.prefix(DmpExternalReferenceEntity._dmpId)) return DmpExternalReferenceEntity._dmpId; - else if (item.prefix(DmpExternalReferenceEntity._referenceId)) return DmpExternalReferenceEntity._referenceId; - else if (item.match(DmpExternalReferenceEntity._data)) return DmpExternalReferenceEntity._data; + if (item.match(DmpReferenceEntity._id)) return DmpReferenceEntity._id; + else if (item.prefix(DmpReferenceEntity._dmpId)) return DmpReferenceEntity._dmpId; + else if (item.prefix(DmpReferenceEntity._referenceId)) return DmpReferenceEntity._referenceId; + else if (item.match(DmpReferenceEntity._data)) return DmpReferenceEntity._data; else return null; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java similarity index 55% rename from dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java rename to dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java index 747221a31..6ffddfec3 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/ExternalReferenceQuery.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/ReferenceQuery.java @@ -5,8 +5,7 @@ import eu.eudat.commons.enums.ExternalReferencesType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.SourceType; import eu.eudat.commons.scope.user.UserScope; -import eu.eudat.data.DmpBlueprintEntity; -import eu.eudat.data.ExternalReferenceEntity; +import eu.eudat.data.ReferenceEntity; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.query.FieldResolver; import gr.cite.tools.data.query.QueryBase; @@ -23,7 +22,7 @@ import java.util.*; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ExternalReferenceQuery extends QueryBase { +public class ReferenceQuery extends QueryBase { private String like; @@ -39,87 +38,87 @@ public class ExternalReferenceQuery extends QueryBase { private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - public ExternalReferenceQuery like(String value) { + public ReferenceQuery like(String value) { this.like = value; return this; } - public ExternalReferenceQuery ids(UUID value) { + public ReferenceQuery ids(UUID value) { this.ids = List.of(value); return this; } - public ExternalReferenceQuery ids(UUID... value) { + public ReferenceQuery ids(UUID... value) { this.ids = Arrays.asList(value); return this; } - public ExternalReferenceQuery ids(Collection values) { + public ReferenceQuery ids(Collection values) { this.ids = values; return this; } - public ExternalReferenceQuery isActive(IsActive value) { + public ReferenceQuery isActive(IsActive value) { this.isActives = List.of(value); return this; } - public ExternalReferenceQuery isActive(IsActive... value) { + public ReferenceQuery isActive(IsActive... value) { this.isActives = Arrays.asList(value); return this; } - public ExternalReferenceQuery isActive(Collection values) { + public ReferenceQuery isActive(Collection values) { this.isActives = values; return this; } - public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType value) { + public ReferenceQuery externalReferenceTypes(ExternalReferencesType value) { this.externalReferenceTypes = List.of(value); return this; } - public ExternalReferenceQuery externalReferenceTypes(ExternalReferencesType... value) { + public ReferenceQuery externalReferenceTypes(ExternalReferencesType... value) { this.externalReferenceTypes = Arrays.asList(value); return this; } - public ExternalReferenceQuery externalReferenceTypes(Collection values) { + public ReferenceQuery externalReferenceTypes(Collection values) { this.externalReferenceTypes = values; return this; } - public ExternalReferenceQuery excludedIds(Collection values) { + public ReferenceQuery excludedIds(Collection values) { this.excludedIds = values; return this; } - public ExternalReferenceQuery excludedIds(UUID value) { + public ReferenceQuery excludedIds(UUID value) { this.excludedIds = List.of(value); return this; } - public ExternalReferenceQuery excludedIds(UUID... value) { + public ReferenceQuery excludedIds(UUID... value) { this.excludedIds = Arrays.asList(value); return this; } - public ExternalReferenceQuery sourceTypes(SourceType value) { + public ReferenceQuery sourceTypes(SourceType value) { this.sourceTypes = List.of(value); return this; } - public ExternalReferenceQuery sourceTypes(SourceType... value) { + public ReferenceQuery sourceTypes(SourceType... value) { this.sourceTypes = Arrays.asList(value); return this; } - public ExternalReferenceQuery sourceTypes(Collection values) { + public ReferenceQuery sourceTypes(Collection values) { this.sourceTypes = values; return this; } - public ExternalReferenceQuery authorize(EnumSet values) { + public ReferenceQuery authorize(EnumSet values) { this.authorize = values; return this; } @@ -128,7 +127,7 @@ public class ExternalReferenceQuery extends QueryBase { private final AuthorizationService authService; - public ExternalReferenceQuery( + public ReferenceQuery( UserScope userScope, AuthorizationService authService ) { @@ -137,8 +136,8 @@ public class ExternalReferenceQuery extends QueryBase { } @Override - protected Class entityClass() { - return ExternalReferenceEntity.class; + protected Class entityClass() { + return ReferenceEntity.class; } @Override @@ -150,36 +149,36 @@ public class ExternalReferenceQuery extends QueryBase { protected Predicate applyFilters(QueryContext queryContext) { List predicates = new ArrayList<>(); if (this.ids != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._id)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)); for (UUID item : this.ids) inClause.value(item); predicates.add(inClause); } if (this.like != null && !this.like.isEmpty()) { - predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._label), this.like), - queryContext.CriteriaBuilder.like(queryContext.Root.get(ExternalReferenceEntity._description), this.like) + predicates.add(queryContext.CriteriaBuilder.or(queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._label), this.like), + queryContext.CriteriaBuilder.like(queryContext.Root.get(ReferenceEntity._description), this.like) )); } if (this.isActives != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._isActive)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._isActive)); for (IsActive item : this.isActives) inClause.value(item); predicates.add(inClause); } if (this.sourceTypes != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._sourceType)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._sourceType)); for (SourceType item : this.sourceTypes) inClause.value(item); predicates.add(inClause); } if (this.externalReferenceTypes != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._type)); + CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._type)); for (ExternalReferencesType item : this.externalReferenceTypes) inClause.value(item); predicates.add(inClause); } if (this.excludedIds != null) { - CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ExternalReferenceEntity._id)); + CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(ReferenceEntity._id)); for (UUID item : this.excludedIds) notInClause.value(item); predicates.add(notInClause.not()); @@ -193,38 +192,38 @@ public class ExternalReferenceQuery extends QueryBase { } @Override - protected ExternalReferenceEntity convert(Tuple tuple, Set columns) { - ExternalReferenceEntity item = new ExternalReferenceEntity(); - item.setId(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._id, UUID.class)); - item.setLabel(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._label, String.class)); - item.setDescription(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._description, String.class)); - item.setCreatedAt(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdAt, Instant.class)); - item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._updatedAt, Instant.class)); - item.setIsActive(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._isActive, IsActive.class)); - item.setDefinition(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._definition, String.class)); - item.setAbbreviation(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._abbreviation, String.class)); - item.setReference(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._reference, String.class)); - item.setSource(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._source, String.class)); - item.setSourceType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._sourceType, SourceType.class)); - item.setType(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._type, ExternalReferencesType.class)); - item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ExternalReferenceEntity._createdBy, UUID.class)); + protected ReferenceEntity convert(Tuple tuple, Set columns) { + ReferenceEntity item = new ReferenceEntity(); + item.setId(QueryBase.convertSafe(tuple, columns, ReferenceEntity._id, UUID.class)); + item.setLabel(QueryBase.convertSafe(tuple, columns, ReferenceEntity._label, String.class)); + item.setDescription(QueryBase.convertSafe(tuple, columns, ReferenceEntity._description, String.class)); + item.setCreatedAt(QueryBase.convertSafe(tuple, columns, ReferenceEntity._createdAt, Instant.class)); + item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, ReferenceEntity._updatedAt, Instant.class)); + item.setIsActive(QueryBase.convertSafe(tuple, columns, ReferenceEntity._isActive, IsActive.class)); + item.setDefinition(QueryBase.convertSafe(tuple, columns, ReferenceEntity._definition, String.class)); + item.setAbbreviation(QueryBase.convertSafe(tuple, columns, ReferenceEntity._abbreviation, String.class)); + item.setReference(QueryBase.convertSafe(tuple, columns, ReferenceEntity._reference, String.class)); + item.setSource(QueryBase.convertSafe(tuple, columns, ReferenceEntity._source, String.class)); + item.setSourceType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._sourceType, SourceType.class)); + item.setType(QueryBase.convertSafe(tuple, columns, ReferenceEntity._type, ExternalReferencesType.class)); + item.setCreatedBy(QueryBase.convertSafe(tuple, columns, ReferenceEntity._createdBy, UUID.class)); return item; } @Override protected String fieldNameOf(FieldResolver item) { - if (item.match(ExternalReferenceEntity._id)) return ExternalReferenceEntity._id; - else if (item.match(ExternalReferenceEntity._label)) return ExternalReferenceEntity._label; - else if (item.match(ExternalReferenceEntity._description)) return ExternalReferenceEntity._description; - else if (item.match(ExternalReferenceEntity._createdAt)) return ExternalReferenceEntity._createdAt; - else if (item.match(ExternalReferenceEntity._updatedAt)) return ExternalReferenceEntity._updatedAt; - else if (item.match(ExternalReferenceEntity._isActive)) return ExternalReferenceEntity._isActive; - else if (item.match(ExternalReferenceEntity._definition)) return ExternalReferenceEntity._definition; - else if (item.match(ExternalReferenceEntity._abbreviation)) return ExternalReferenceEntity._abbreviation; - else if (item.match(ExternalReferenceEntity._reference)) return ExternalReferenceEntity._reference; - else if (item.match(ExternalReferenceEntity._source)) return ExternalReferenceEntity._source; - else if (item.match(ExternalReferenceEntity._sourceType)) return ExternalReferenceEntity._sourceType; - else if (item.match(ExternalReferenceEntity._type)) return ExternalReferenceEntity._type; + if (item.match(ReferenceEntity._id)) return ReferenceEntity._id; + else if (item.match(ReferenceEntity._label)) return ReferenceEntity._label; + else if (item.match(ReferenceEntity._description)) return ReferenceEntity._description; + else if (item.match(ReferenceEntity._createdAt)) return ReferenceEntity._createdAt; + else if (item.match(ReferenceEntity._updatedAt)) return ReferenceEntity._updatedAt; + else if (item.match(ReferenceEntity._isActive)) return ReferenceEntity._isActive; + else if (item.match(ReferenceEntity._definition)) return ReferenceEntity._definition; + else if (item.match(ReferenceEntity._abbreviation)) return ReferenceEntity._abbreviation; + else if (item.match(ReferenceEntity._reference)) return ReferenceEntity._reference; + else if (item.match(ReferenceEntity._source)) return ReferenceEntity._source; + else if (item.match(ReferenceEntity._sourceType)) return ReferenceEntity._sourceType; + else if (item.match(ReferenceEntity._type)) return ReferenceEntity._type; //else if (item.prefix(ExternalReferenceEntity._createdBy)) return ExternalReferenceEntity._createdBy; else return null; } diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpReferenceLookup.java similarity index 66% rename from dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java rename to dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpReferenceLookup.java index affe22396..706cd5ac8 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpExternalReferenceLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/DmpReferenceLookup.java @@ -1,13 +1,13 @@ package eu.eudat.query.lookup; -import eu.eudat.query.DmpExternalReferenceQuery; +import eu.eudat.query.DmpReferenceQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; import java.util.Collection; import java.util.UUID; -public class DmpExternalReferenceLookup extends Lookup { +public class DmpReferenceLookup extends Lookup { private Collection ids; @@ -16,8 +16,8 @@ public class DmpExternalReferenceLookup extends Lookup { private Collection referenceIds; - public DmpExternalReferenceQuery enrich(QueryFactory queryFactory) { - DmpExternalReferenceQuery query = queryFactory.query(DmpExternalReferenceQuery.class); + public DmpReferenceQuery enrich(QueryFactory queryFactory) { + DmpReferenceQuery query = queryFactory.query(DmpReferenceQuery.class); if (this.ids != null) query.ids(this.ids); if (this.dmpIds != null) query.dmpIds(this.dmpIds); if (this.referenceIds != null) query.referenceIds(this.referenceIds); diff --git a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ReferenceLookup.java similarity index 89% rename from dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java rename to dmp-backend/core/src/main/java/eu/eudat/query/lookup/ReferenceLookup.java index 3e991f483..d307d67b6 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ExternalReferenceLookup.java +++ b/dmp-backend/core/src/main/java/eu/eudat/query/lookup/ReferenceLookup.java @@ -3,7 +3,7 @@ package eu.eudat.query.lookup; import eu.eudat.commons.enums.ExternalReferencesType; import eu.eudat.commons.enums.IsActive; import eu.eudat.commons.enums.SourceType; -import eu.eudat.query.ExternalReferenceQuery; +import eu.eudat.query.ReferenceQuery; import gr.cite.tools.data.query.Lookup; import gr.cite.tools.data.query.QueryFactory; @@ -11,7 +11,7 @@ import java.util.Collection; import java.util.List; import java.util.UUID; -public class ExternalReferenceLookup extends Lookup { +public class ReferenceLookup extends Lookup { private String like; @@ -73,8 +73,8 @@ public class ExternalReferenceLookup extends Lookup { this.externalReferenceTypes = externalReferenceTypes; } - public ExternalReferenceQuery enrich(QueryFactory queryFactory) { - ExternalReferenceQuery query = queryFactory.query(ExternalReferenceQuery.class); + public ReferenceQuery enrich(QueryFactory queryFactory) { + ReferenceQuery query = queryFactory.query(ReferenceQuery.class); if (this.like != null) query.like(this.like); if (this.isActive != null) query.isActive(this.isActive); if (this.externalReferenceTypes != null) query.externalReferenceTypes(this.externalReferenceTypes); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ExternalReferenceController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java similarity index 73% rename from dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ExternalReferenceController.java rename to dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java index 38bc97775..49cfcd7ed 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ExternalReferenceController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/v2/ReferenceController.java @@ -5,19 +5,19 @@ import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.ExternalReferencesType; import eu.eudat.controllers.BaseController; -import eu.eudat.data.ExternalReferenceEntity; +import eu.eudat.data.ReferenceEntity; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.services.ApiContext; -import eu.eudat.logic.services.externalreferences.ExternalReferenceService; -import eu.eudat.model.ExternalReference; -import eu.eudat.model.builder.ExternalReferenceBuilder; -import eu.eudat.model.censorship.ExternalReferenceCensor; +import eu.eudat.logic.services.references.ReferenceService; +import eu.eudat.model.Reference; +import eu.eudat.model.builder.ReferenceBuilder; +import eu.eudat.model.censorship.ReferenceCensor; import eu.eudat.model.result.QueryResult; import eu.eudat.models.data.FetcherExternalReference; import eu.eudat.models.data.helpers.responses.ResponseItem; -import eu.eudat.query.ExternalReferenceQuery; -import eu.eudat.query.lookup.ExternalReferenceLookup; +import eu.eudat.query.ReferenceQuery; +import eu.eudat.query.lookup.ReferenceLookup; import eu.eudat.types.ApiMessageCode; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.auditing.AuditService; @@ -47,29 +47,29 @@ import java.util.UUID; @RestController @RequestMapping(path = {"api/external-references"}) -public class ExternalReferenceController extends BaseController { +public class ReferenceController extends BaseController { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceController.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceController.class)); private final BuilderFactory builderFactory; private final AuditService auditService; - private final ExternalReferenceService externalReferenceService; + private final ReferenceService referenceService; private final CensorFactory censorFactory; private final QueryFactory queryFactory; private final MessageSource messageSource; private final AuthorizationService authorizationService; @Autowired - public ExternalReferenceController( + public ReferenceController( ApiContext apiContext, BuilderFactory builderFactory, - ExternalReferenceService externalReferenceService, + ReferenceService referenceService, AuditService auditService, CensorFactory censorFactory, QueryFactory queryFactory, MessageSource messageSource, AuthorizationService authorizationService) { super(apiContext); this.builderFactory = builderFactory; - this.externalReferenceService = externalReferenceService; + this.referenceService = referenceService; this.auditService = auditService; this.censorFactory = censorFactory; this.queryFactory = queryFactory; @@ -78,14 +78,14 @@ public class ExternalReferenceController extends BaseController { } @PostMapping("query") - public QueryResult query(@RequestBody ExternalReferenceLookup lookup) throws MyApplicationException, MyForbiddenException { - logger.debug("querying {}", ExternalReference.class.getSimpleName()); + public QueryResult query(@RequestBody ReferenceLookup lookup) throws MyApplicationException, MyForbiddenException { + logger.debug("querying {}", Reference.class.getSimpleName()); - this.censorFactory.censor(ExternalReferenceCensor.class).censor(lookup.getProject(), null); + this.censorFactory.censor(ReferenceCensor.class).censor(lookup.getProject(), null); - ExternalReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); - List datas = query.collectAs(lookup.getProject()); - List models = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas); + ReferenceQuery query = lookup.enrich(this.queryFactory).authorize(AuthorizationFlags.OwnerOrPermission); + List datas = query.collectAs(lookup.getProject()); + List models = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(lookup.getProject(), datas); long count = (lookup.getMetadata() != null && lookup.getMetadata().getCountAll()) ? query.count() : models.size(); this.auditService.track(AuditableAction.External_Reference_Query, "lookup", lookup); @@ -94,15 +94,15 @@ public class ExternalReferenceController extends BaseController { } @GetMapping("{id}") - public ExternalReference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { - logger.debug(new MapLogEntry("retrieving" + eu.eudat.model.ExternalReference.class.getSimpleName()).And("id", id).And("fields", fieldSet)); + public Reference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { + logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id).And("fields", fieldSet)); - this.censorFactory.censor(ExternalReferenceCensor.class).censor(fieldSet, null); + this.censorFactory.censor(ReferenceCensor.class).censor(fieldSet, null); - ExternalReferenceQuery query = this.queryFactory.query(ExternalReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id); - ExternalReference model = this.builderFactory.builder(ExternalReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); + ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).authorize(AuthorizationFlags.OwnerOrPermission).ids(id); + Reference model = this.builderFactory.builder(ReferenceBuilder.class).authorize(AuthorizationFlags.OwnerOrPermission).build(fieldSet, query.firstAs(fieldSet)); if (model == null) - throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, eu.eudat.model.ExternalReference.class.getSimpleName()}, LocaleContextHolder.getLocale())); + throw new MyNotFoundException(messageSource.getMessage("General_ItemNotFound", new Object[]{id, Reference.class.getSimpleName()}, LocaleContextHolder.getLocale())); this.auditService.track(AuditableAction.External_Reference_Lookup, Map.ofEntries( new AbstractMap.SimpleEntry("id", id), @@ -120,16 +120,16 @@ public class ExternalReferenceController extends BaseController { this.authorizationService.authorizeForce(Permission.AuthenticatedRole); ExternalReferencesType externalReferencesType = ExternalReferencesType.of((short) externalType); - List fetcherExternalReferences = this.externalReferenceService.searchExternalReference(externalReferencesType, query, type); + List fetcherExternalReferences = this.referenceService.searchExternalReference(externalReferencesType, query, type); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(fetcherExternalReferences)); } @DeleteMapping("{id}") @Transactional public void delete(@PathVariable("id") UUID id) throws MyForbiddenException, InvalidApplicationException { - logger.debug(new MapLogEntry("retrieving" + ExternalReference.class.getSimpleName()).And("id", id)); + logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id)); - this.externalReferenceService.deleteAndSave(id); + this.referenceService.deleteAndSave(id); this.auditService.track(AuditableAction.External_Reference_Delete, "id", id); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferencesCacheOptions.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ExternalReferencesCacheOptions.java similarity index 86% rename from dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferencesCacheOptions.java rename to dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ExternalReferencesCacheOptions.java index 08fa2b99a..a7a800a11 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferencesCacheOptions.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ExternalReferencesCacheOptions.java @@ -1,4 +1,4 @@ -package eu.eudat.logic.services.externalreferences; +package eu.eudat.logic.services.references; import gr.cite.tools.cache.CacheOptions; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferencesCacheService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ExternalReferencesCacheService.java similarity index 97% rename from dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferencesCacheService.java rename to dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ExternalReferencesCacheService.java index d27effce5..f569f6631 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferencesCacheService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ExternalReferencesCacheService.java @@ -1,4 +1,4 @@ -package eu.eudat.logic.services.externalreferences; +package eu.eudat.logic.services.references; import eu.eudat.logic.proxy.config.ExternalUrlCriteria; import gr.cite.tools.cache.CacheService; diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferenceService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java similarity index 87% rename from dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferenceService.java rename to dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java index 21032c347..9f61dd346 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/externalreferences/ExternalReferenceService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/references/ReferenceService.java @@ -1,4 +1,4 @@ -package eu.eudat.logic.services.externalreferences; +package eu.eudat.logic.services.references; import eu.eudat.authorization.Permission; import eu.eudat.commons.enums.ExternalReferencesType; @@ -18,7 +18,7 @@ import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.logic.services.ApiContext; -import eu.eudat.model.deleter.ExternalReferenceDeleter; +import eu.eudat.model.deleter.ReferenceDeleter; import eu.eudat.models.data.FetcherExternalReference; import eu.eudat.queryable.QueryableList; import gr.cite.commons.web.authz.service.AuthorizationService; @@ -36,9 +36,9 @@ import java.util.*; import java.util.stream.Collectors; @org.springframework.stereotype.Service -public class ExternalReferenceService { +public class ReferenceService { - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ExternalReferenceService.class)); + private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(ReferenceService.class)); private final ApiContext apiContext; private final UserScope userScope; private final RemoteFetcher remoteFetcher; @@ -50,16 +50,16 @@ public class ExternalReferenceService { private final MessageSource messageSource; private final QueryFactory queryFactory; - public ExternalReferenceService(ApiContext apiContext, - UserScope userScope, - RemoteFetcher remoteFetcher, - EntityManager entityManager, - AuthorizationService authorizationService, - DeleterFactory deleterFactory, - BuilderFactory builderFactory, - ConventionService conventionService, - MessageSource messageSource, - QueryFactory queryFactory) { + public ReferenceService(ApiContext apiContext, + UserScope userScope, + RemoteFetcher remoteFetcher, + EntityManager entityManager, + AuthorizationService authorizationService, + DeleterFactory deleterFactory, + BuilderFactory builderFactory, + ConventionService conventionService, + MessageSource messageSource, + QueryFactory queryFactory) { this.apiContext = apiContext; this.userScope = userScope; this.remoteFetcher = remoteFetcher; @@ -77,7 +77,7 @@ public class ExternalReferenceService { this.authorizationService.authorizeForce(Permission.DeleteExternalReference); - this.deleterFactory.deleter(ExternalReferenceDeleter.class).deleteAndSaveByIds(List.of(id)); + this.deleterFactory.deleter(ReferenceDeleter.class).deleteAndSaveByIds(List.of(id)); } // external references: