Updated the dmp builder to be able to populate the associated descriptions on the dmps
This commit is contained in:
parent
bf8edfad92
commit
7ab1313b83
|
@ -4,6 +4,7 @@ import eu.eudat.commons.enums.DmpStatus;
|
|||
import eu.eudat.commons.enums.IsActive;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Dmp {
|
||||
|
@ -88,6 +89,10 @@ public class Dmp {
|
|||
|
||||
public static final String _hash = "hash";
|
||||
|
||||
private List<Description> dmpDescriptions;
|
||||
|
||||
public static final String _dmpDescriptions = "dmpDescriptions";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -248,4 +253,11 @@ public class Dmp {
|
|||
this.hash = hash;
|
||||
}
|
||||
|
||||
public List<Description> getDmpDescriptions() {
|
||||
return dmpDescriptions;
|
||||
}
|
||||
|
||||
public void setDmpDescriptions(List<Description> dmpDescriptions) {
|
||||
this.dmpDescriptions = dmpDescriptions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,13 @@ 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.query.DescriptionQuery;
|
||||
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;
|
||||
|
@ -15,16 +20,25 @@ 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 DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
private final BuilderFactory builderFactory;
|
||||
|
||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||
|
||||
@Autowired
|
||||
public DmpBuilder(ConventionService conventionService) {
|
||||
public DmpBuilder(ConventionService conventionService,
|
||||
QueryFactory queryFactory,
|
||||
BuilderFactory builderFactory) {
|
||||
super(conventionService, new LoggerService(LoggerFactory.getLogger(DmpBuilder.class)));
|
||||
this.queryFactory = queryFactory;
|
||||
this.builderFactory = builderFactory;
|
||||
}
|
||||
|
||||
public DmpBuilder authorize(EnumSet<AuthorizationFlags> values) {
|
||||
|
@ -38,29 +52,75 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
this.logger.trace(new DataLogEntry("requested fields", fields));
|
||||
if (fields == null || data == null || fields.isEmpty())
|
||||
return new ArrayList<>();
|
||||
|
||||
List<Dmp> models = new ArrayList<>();
|
||||
|
||||
FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptions));
|
||||
Map<UUID, List<Description>> dmpDescriptionsMap = this.collectDmpDescriptions(dmpDescriptionsFields, data);
|
||||
|
||||
for (DmpEntity d : data) {
|
||||
Dmp m = new Dmp();
|
||||
if (fields.hasField(this.asIndexer(Dmp._id))) m.setId(d.getId());
|
||||
if (fields.hasField(this.asIndexer(Dmp._label))) m.setLabel(d.getLabel());
|
||||
if (fields.hasField(this.asIndexer(Dmp._version))) m.setVersion(d.getVersion());
|
||||
if (fields.hasField(this.asIndexer(Dmp._status))) m.setStatus(d.getStatus());
|
||||
if (fields.hasField(this.asIndexer(Dmp._properties))) m.setProperties(d.getProperties());
|
||||
if (fields.hasField(this.asIndexer(Dmp._dmpProperties))) m.setDmpProperties(d.getDmpProperties());
|
||||
if (fields.hasField(this.asIndexer(Dmp._groupId))) m.setGroupId(d.getGroupId());
|
||||
if (fields.hasField(this.asIndexer(Dmp._description))) m.setDescription(d.getDescription());
|
||||
if (fields.hasField(this.asIndexer(Dmp._isPublic))) m.setIsPublic(d.getIsPublic());
|
||||
if (fields.hasField(this.asIndexer(Dmp._extraProperties))) m.setExtraProperties(d.getExtraProperties());
|
||||
if (fields.hasField(this.asIndexer(Dmp._createdAt))) m.setCreatedAt(d.getCreatedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._isActive))) m.setIsActive(d.getIsActive());
|
||||
if (fields.hasField(this.asIndexer(Dmp._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._publishedAt))) m.setPublishedAt(d.getPublishedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
|
||||
if (fields.hasField(this.asIndexer(Dmp._id)))
|
||||
m.setId(d.getId());
|
||||
if (fields.hasField(this.asIndexer(Dmp._label)))
|
||||
m.setLabel(d.getLabel());
|
||||
if (fields.hasField(this.asIndexer(Dmp._version)))
|
||||
m.setVersion(d.getVersion());
|
||||
if (fields.hasField(this.asIndexer(Dmp._status)))
|
||||
m.setStatus(d.getStatus());
|
||||
if (fields.hasField(this.asIndexer(Dmp._properties)))
|
||||
m.setProperties(d.getProperties());
|
||||
if (fields.hasField(this.asIndexer(Dmp._dmpProperties)))
|
||||
m.setDmpProperties(d.getDmpProperties());
|
||||
if (fields.hasField(this.asIndexer(Dmp._groupId)))
|
||||
m.setGroupId(d.getGroupId());
|
||||
if (fields.hasField(this.asIndexer(Dmp._description)))
|
||||
m.setDescription(d.getDescription());
|
||||
if (fields.hasField(this.asIndexer(Dmp._isPublic)))
|
||||
m.setIsPublic(d.getIsPublic());
|
||||
if (fields.hasField(this.asIndexer(Dmp._extraProperties)))
|
||||
m.setExtraProperties(d.getExtraProperties());
|
||||
if (fields.hasField(this.asIndexer(Dmp._createdAt)))
|
||||
m.setCreatedAt(d.getCreatedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._updatedAt)))
|
||||
m.setUpdatedAt(d.getUpdatedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._isActive)))
|
||||
m.setIsActive(d.getIsActive());
|
||||
if (fields.hasField(this.asIndexer(Dmp._finalizedAt)))
|
||||
m.setFinalizedAt(d.getFinalizedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._publishedAt)))
|
||||
m.setPublishedAt(d.getPublishedAt());
|
||||
if (fields.hasField(this.asIndexer(Dmp._hash)))
|
||||
m.setHash(this.hashValue(d.getUpdatedAt()));
|
||||
|
||||
if (!dmpDescriptionsFields.isEmpty() && dmpDescriptionsMap != null && dmpDescriptionsMap.containsKey(d.getId()))
|
||||
m.setDmpDescriptions(dmpDescriptionsMap.get(d.getId()));
|
||||
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<Description>> collectDmpDescriptions(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
|
||||
if (fields.isEmpty() || data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", Description.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<Description>> itemMap;
|
||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(Description._dmp, Dmp._id));
|
||||
DescriptionQuery query = this.queryFactory.query(DescriptionQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DescriptionBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
|
||||
|
||||
if (!fields.hasField(this.asIndexer(Description._dmp, Dmp._id))) {
|
||||
itemMap.forEach((id, dmps) -> {
|
||||
dmps.forEach(description -> {
|
||||
if (description != null && description.getDmp() != null)
|
||||
description.getDmp().setId(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue