add DmpExternalReference to DmpBlueprint

This commit is contained in:
amentis 2023-10-25 17:37:37 +03:00
parent 1b66d19bde
commit 032b30ed04
3 changed files with 46 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import eu.eudat.commons.enums.IsActive;
import eu.eudat.model.dmpblueprintdefinition.Definition; import eu.eudat.model.dmpblueprintdefinition.Definition;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class DmpBlueprint { public class DmpBlueprint {
@ -33,6 +34,9 @@ public class DmpBlueprint {
public final static String _hash = "hash"; public final static String _hash = "hash";
private String hash; private String hash;
public static final String _dmpExternalReferences = "dmpExternalReferences";
private List<DmpExternalReference> dmpExternalReferences;
public UUID getId() { public UUID getId() {
return id; return id;
} }
@ -96,6 +100,14 @@ public class DmpBlueprint {
public void setDefinition(Definition definition) { public void setDefinition(Definition definition) {
this.definition = definition; this.definition = definition;
} }
public List<DmpExternalReference> getDmpExternalReferences() {
return dmpExternalReferences;
}
public void setDmpExternalReferences(List<DmpExternalReference> dmpExternalReferences) {
this.dmpExternalReferences = dmpExternalReferences;
}
} }

View File

@ -6,9 +6,14 @@ import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpBlueprintEntity; import eu.eudat.data.DmpBlueprintEntity;
import eu.eudat.model.DmpBlueprint; 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.model.builder.dmpblueprintdefinition.DefinitionBuilder;
import eu.eudat.query.DmpExternalReferenceQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException; import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.fieldset.BaseFieldSet;
import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.fieldset.FieldSet;
import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.DataLogEntry;
import gr.cite.tools.logging.LoggerService; import gr.cite.tools.logging.LoggerService;
@ -19,21 +24,24 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintEntity> { public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintEntity> {
private final BuilderFactory builderFactory; private final BuilderFactory builderFactory;
private final QueryFactory queryFactory;
private final XmlHandlingService xmlHandlingService; private final XmlHandlingService xmlHandlingService;
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None); private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
@Autowired @Autowired
public DmpBlueprintBuilder( public DmpBlueprintBuilder(
ConventionService conventionService, ConventionService conventionService,
BuilderFactory builderFactory, XmlHandlingService xmlHandlingService) { BuilderFactory builderFactory, QueryFactory queryFactory, XmlHandlingService xmlHandlingService) {
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class))); super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBlueprintBuilder.class)));
this.builderFactory = builderFactory; this.builderFactory = builderFactory;
this.queryFactory = queryFactory;
this.xmlHandlingService = xmlHandlingService; this.xmlHandlingService = xmlHandlingService;
} }
@ -49,6 +57,9 @@ public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintE
if (fields == null || data == null || fields.isEmpty()) if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>(); return new ArrayList<>();
FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(DmpBlueprint._definition)); FieldSet definitionFields = fields.extractPrefixed(this.asPrefix(DmpBlueprint._definition));
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asPrefix(ExternalReference._dmpExternalReferences));
Map<UUID, List<DmpExternalReference>> dmpExternalReferenceMap = this.collectDmpExternalReferences(dmpExternalReferencesFields, data);
List<DmpBlueprint> models = new ArrayList<>(); List<DmpBlueprint> models = new ArrayList<>();
for (DmpBlueprintEntity d : data) { for (DmpBlueprintEntity d : data) {
DmpBlueprint m = new DmpBlueprint(); DmpBlueprint m = new DmpBlueprint();
@ -63,9 +74,29 @@ public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintE
DefinitionEntity definition = this.xmlHandlingService.xmlSerializableFromXmlSafe(DefinitionEntity.class, d.getDefinition()); DefinitionEntity definition = this.xmlHandlingService.xmlSerializableFromXmlSafe(DefinitionEntity.class, d.getDefinition());
m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition)); m.setDefinition(this.builderFactory.builder(DefinitionBuilder.class).authorize(this.authorize).build(definitionFields, definition));
} }
if (!dmpExternalReferenceMap.isEmpty() && dmpExternalReferenceMap != null && dmpExternalReferenceMap.containsKey(d.getId())) m.setDmpExternalReferences(dmpExternalReferenceMap.get(d.getId()));
models.add(m);
models.add(m); models.add(m);
} }
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0)); this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
return models; return models;
} }
private Map<UUID, List<DmpExternalReference>> collectDmpExternalReferences(FieldSet fields, List<DmpBlueprintEntity> datas) throws MyApplicationException {
if (fields.isEmpty() || datas.isEmpty()) return null;
this.logger.debug("checking related - {}", DmpExternalReference.class.getSimpleName());
Map<UUID, List<DmpExternalReference>> 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;
}
} }

View File

@ -41,6 +41,8 @@ public class DmpBlueprintCensor extends BaseCensor {
this.authService.authorizeForce(Permission.BrowseDmpBlueprint); this.authService.authorizeForce(Permission.BrowseDmpBlueprint);
FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._definition)); FieldSet definitionFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._definition));
this.censorFactory.censor(DefinitionCensor.class).censor(definitionFields, userId); this.censorFactory.censor(DefinitionCensor.class).censor(definitionFields, userId);
FieldSet dmpExternalReferencesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpBlueprint._dmpExternalReferences));
this.censorFactory.censor(DmpExternalReferenceCensor.class).censor(dmpExternalReferencesFields, userId);
} }
} }