add DmpExternalReference to DmpBlueprint
This commit is contained in:
parent
1b66d19bde
commit
032b30ed04
|
@ -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<DmpExternalReference> dmpExternalReferences;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -96,6 +100,14 @@ public class DmpBlueprint {
|
|||
public void setDefinition(Definition definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
public List<DmpExternalReference> getDmpExternalReferences() {
|
||||
return dmpExternalReferences;
|
||||
}
|
||||
|
||||
public void setDmpExternalReferences(List<DmpExternalReference> dmpExternalReferences) {
|
||||
this.dmpExternalReferences = dmpExternalReferences;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<DmpBlueprint, DmpBlueprintEntity> {
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
private final QueryFactory queryFactory;
|
||||
private final XmlHandlingService xmlHandlingService;
|
||||
private EnumSet<AuthorizationFlags> 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<DmpBlueprint, DmpBlueprintE
|
|||
if (fields == null || data == null || fields.isEmpty())
|
||||
return new ArrayList<>();
|
||||
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<>();
|
||||
for (DmpBlueprintEntity d : data) {
|
||||
DmpBlueprint m = new DmpBlueprint();
|
||||
|
@ -63,9 +74,29 @@ public class DmpBlueprintBuilder extends BaseBuilder<DmpBlueprint, DmpBlueprintE
|
|||
DefinitionEntity definition = this.xmlHandlingService.xmlSerializableFromXmlSafe(DefinitionEntity.class, d.getDefinition());
|
||||
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);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue