Added dmp users on dmp builder
This commit is contained in:
parent
4e99fb08e9
commit
3e15749b56
|
@ -6,6 +6,7 @@ import eu.eudat.data.DmpEntity;
|
|||
import eu.eudat.model.*;
|
||||
import eu.eudat.query.DescriptionQuery;
|
||||
import eu.eudat.query.DmpReferenceQuery;
|
||||
import eu.eudat.query.DmpUserQuery;
|
||||
import gr.cite.tools.data.builder.BuilderFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.exception.MyApplicationException;
|
||||
|
@ -55,8 +56,11 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
|
||||
List<Dmp> models = new ArrayList<>();
|
||||
|
||||
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Reference._dmpReferences));
|
||||
Map<UUID, List<DmpReference>> dmpReferenceMap = this.collectDmpReferences(dmpReferencesFields, data);
|
||||
FieldSet dmpReferencesFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpReferences));
|
||||
Map<UUID, List<DmpReference>> dmpReferencesMap = this.collectDmpReferences(dmpReferencesFields, data);
|
||||
|
||||
FieldSet dmpUsersFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpUsers));
|
||||
Map<UUID, List<DmpUser>> dmpUsersMap = this.collectDmpUsers(dmpUsersFields, data);
|
||||
|
||||
for (DmpEntity d : data) {
|
||||
Dmp m = new Dmp();
|
||||
|
@ -93,8 +97,11 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
if (fields.hasField(this.asIndexer(Dmp._hash)))
|
||||
m.setHash(this.hashValue(d.getUpdatedAt()));
|
||||
|
||||
if (dmpReferenceMap != null && !dmpReferenceMap.isEmpty() && dmpReferenceMap.containsKey(d.getId()))
|
||||
m.setDmpReferences(dmpReferenceMap.get(d.getId()));
|
||||
if (dmpReferencesMap != null && !dmpReferencesMap.isEmpty() && dmpReferencesMap.containsKey(d.getId()))
|
||||
m.setDmpReferences(dmpReferencesMap.get(d.getId()));
|
||||
|
||||
if (dmpUsersMap != null && !dmpUsersMap.isEmpty() && dmpUsersMap.containsKey(d.getId()))
|
||||
m.setDmpUsers(dmpUsersMap.get(d.getId()));
|
||||
|
||||
models.add(m);
|
||||
}
|
||||
|
@ -103,14 +110,14 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
return models;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DmpReference>> collectDmpReferences(FieldSet fields, List<DmpEntity> datas) throws MyApplicationException {
|
||||
if (fields.isEmpty() || datas.isEmpty()) return null;
|
||||
private Map<UUID, List<DmpReference>> collectDmpReferences(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
|
||||
if (fields.isEmpty() || data.isEmpty()) return null;
|
||||
this.logger.debug("checking related - {}", DmpReference.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DmpReference>> itemMap = null;
|
||||
Map<UUID, List<DmpReference>> itemMap;
|
||||
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(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());
|
||||
DmpReferenceQuery query = this.queryFactory.query(DmpReferenceQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DmpReferenceBuilder.class).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).peek(x -> {
|
||||
|
@ -121,4 +128,23 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
|
|||
return itemMap;
|
||||
}
|
||||
|
||||
private Map<UUID, List<DmpUser>> collectDmpUsers(FieldSet fields, List<DmpEntity> data) throws MyApplicationException {
|
||||
if (fields.isEmpty() || data.isEmpty())
|
||||
return null;
|
||||
this.logger.debug("checking related - {}", DmpUser.class.getSimpleName());
|
||||
|
||||
Map<UUID, List<DmpUser>> itemMap;
|
||||
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(this.asIndexer(DmpUser._dmp, Dmp._id));
|
||||
DmpUserQuery query = this.queryFactory.query(DmpUserQuery.class).authorize(this.authorize).dmpIds(data.stream().map(DmpEntity::getId).distinct().collect(Collectors.toList()));
|
||||
itemMap = this.builderFactory.builder(DmpUserBuilder.class).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
|
||||
|
||||
if (!fields.hasField(this.asIndexer(DmpUser._dmp, Dmp._id))) {
|
||||
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getDmp() != null).peek(x -> {
|
||||
x.getDmp().setId(null);
|
||||
});
|
||||
}
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue