Adding DescriptionReference lookup and linking on description entity builder
This commit is contained in:
parent
60ca51fe00
commit
8d1c988135
|
@ -4,6 +4,7 @@ import eu.eudat.commons.enums.DescriptionStatus;
|
|||
import eu.eudat.commons.enums.IsActive;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Description {
|
||||
|
@ -72,6 +73,10 @@ public class Description {
|
|||
|
||||
public static final String _hash = "hash";
|
||||
|
||||
private List<DescriptionReference> descriptionReferences;
|
||||
|
||||
public static final String _descriptionReferences = "descriptionReferences";
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -199,4 +204,13 @@ public class Description {
|
|||
public void setHash(String hash) {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
public List<DescriptionReference> getDescriptionReferences() {
|
||||
return descriptionReferences;
|
||||
}
|
||||
|
||||
public void setDescriptionReferences(List<DescriptionReference> descriptionReferences) {
|
||||
this.descriptionReferences = descriptionReferences;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,14 @@ package eu.eudat.model.builder;
|
|||
import eu.eudat.authorization.AuthorizationFlags;
|
||||
import eu.eudat.convention.ConventionService;
|
||||
import eu.eudat.data.DescriptionEntity;
|
||||
import eu.eudat.data.DmpEntity;
|
||||
import eu.eudat.model.Description;
|
||||
import eu.eudat.model.DescriptionReference;
|
||||
import eu.eudat.model.Dmp;
|
||||
import eu.eudat.model.DmpReference;
|
||||
import eu.eudat.query.DescriptionReferenceQuery;
|
||||
import eu.eudat.query.DmpQuery;
|
||||
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 +62,9 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
|
|||
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmp));
|
||||
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
|
||||
|
||||
FieldSet descriptionReferencesFields = fields.extractPrefixed(this.asPrefix(Description._descriptionReferences));
|
||||
Map<UUID, List<DescriptionReference>> descriptionReferencesMap = this.collectDescriptionReferences(descriptionReferencesFields, data);
|
||||
|
||||
List<Description> models = new ArrayList<>();
|
||||
for (DescriptionEntity d : data) {
|
||||
Description m = new Description();
|
||||
|
@ -94,6 +102,9 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
|
|||
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmp()))
|
||||
m.setDmp(dmpItemsMap.get(d.getDmp()));
|
||||
|
||||
if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId()))
|
||||
m.setDescriptionReferences(descriptionReferencesMap.get(d.getId()));
|
||||
|
||||
models.add(m);
|
||||
}
|
||||
|
||||
|
@ -132,4 +143,22 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
|
|||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DescriptionReference>> collectDescriptionReferences(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
|
||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DescriptionReference.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DescriptionReference>> itemMap;
|
||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DescriptionReference._description, Description._id));
|
||||
DescriptionReferenceQuery query = this.queryFactory.query(DescriptionReferenceQuery.class).authorize(this.authorize).descriptionIds(data.stream().map(DescriptionEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DescriptionReferenceBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDescription().getId());
|
||||
|
||||
if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) {
|
||||
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDescription() != null).peek(x -> {
|
||||
x.getDescription().setId(null);
|
||||
});
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,10 +98,13 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
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.setDmpReferences(dmpReferenceMap.get(d.getId()));
|
||||
if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId()))
|
||||
m.setDmpReferences(dmpReferenceMap.get(d.getId()));
|
||||
|
||||
models.add(m);
|
||||
}
|
||||
this.logger.debug("build {} items", Optional.of(models).map(List::size).orElse(0));
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
|
@ -132,15 +135,15 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
|
||||
Map<UUID, List<DmpReference>> 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()));
|
||||
DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(datas.stream().map(DmpEntity::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 -> {
|
||||
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
|
||||
x.getDmp().setId(null);
|
||||
return x;
|
||||
}).collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package eu.eudat.query.lookup;
|
||||
|
||||
import eu.eudat.commons.enums.IsActive;
|
||||
import eu.eudat.query.DescriptionReferenceQuery;
|
||||
import gr.cite.tools.data.query.Lookup;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DescriptionReferenceLookup extends Lookup {
|
||||
|
||||
private Collection<UUID> ids;
|
||||
|
||||
private Collection<UUID> excludedIds;
|
||||
|
||||
private Collection<IsActive> isActives;
|
||||
|
||||
private Collection<UUID> descriptionIds;
|
||||
|
||||
private Collection<UUID> referenceIds;
|
||||
|
||||
public Collection<UUID> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(Collection<UUID> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
public Collection<UUID> getExcludedIds() {
|
||||
return excludedIds;
|
||||
}
|
||||
|
||||
public void setExcludedIds(Collection<UUID> excludedIds) {
|
||||
this.excludedIds = excludedIds;
|
||||
}
|
||||
|
||||
public Collection<IsActive> getIsActives() {
|
||||
return isActives;
|
||||
}
|
||||
|
||||
public void setIsActives(Collection<IsActive> isActives) {
|
||||
this.isActives = isActives;
|
||||
}
|
||||
|
||||
public Collection<UUID> getDescriptionIds() {
|
||||
return descriptionIds;
|
||||
}
|
||||
|
||||
public void setDescriptionIds(Collection<UUID> descriptionIds) {
|
||||
this.descriptionIds = descriptionIds;
|
||||
}
|
||||
|
||||
public Collection<UUID> getReferenceIds() {
|
||||
return referenceIds;
|
||||
}
|
||||
|
||||
public void setReferenceIds(Collection<UUID> referenceIds) {
|
||||
this.referenceIds = referenceIds;
|
||||
}
|
||||
|
||||
public DescriptionReferenceQuery enrich(QueryFactory queryFactory) {
|
||||
DescriptionReferenceQuery query = queryFactory.query(DescriptionReferenceQuery.class);
|
||||
if (this.ids != null) query.ids(this.ids);
|
||||
if (this.excludedIds != null) query.excludedIds(this.excludedIds);
|
||||
if (this.isActives != null) query.isActive(this.isActives);
|
||||
if (this.descriptionIds != null) query.descriptionIds(this.descriptionIds);
|
||||
if (this.referenceIds != null) query.referenceIds(this.referenceIds);
|
||||
|
||||
this.enrichCommon(query);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue