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 53ca6fa82..f9acb6798 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 @@ -5,6 +5,7 @@ import eu.eudat.commons.enums.IsActive; import eu.eudat.model.dmpblueprintdefinition.Definition; import java.time.Instant; +import java.util.List; import java.util.UUID; public class DmpBlueprint { @@ -33,6 +34,9 @@ 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; } @@ -96,6 +100,14 @@ 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/builder/DmpBlueprintBuilder.java b/dmp-backend/core/src/main/java/eu/eudat/model/builder/DmpBlueprintBuilder.java index 46194e84c..38cb8584f 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,9 +6,14 @@ 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; @@ -19,21 +24,24 @@ 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, XmlHandlingService xmlHandlingService) { + BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) { super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class))); this.builderFactory = builderFactory; + this.queryFactory = queryFactory; this.xmlHandlingService = xmlHandlingService; } @@ -49,6 +57,9 @@ 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(); @@ -63,9 +74,29 @@ 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/censorship/DmpBlueprintCensor.java b/dmp-backend/core/src/main/java/eu/eudat/model/censorship/DmpBlueprintCensor.java index 538c8cd78..c5b1360fd 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,6 +41,8 @@ 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); } }