Added dmp users on dmp builder

This commit is contained in:
Thomas Georgios Giannos 2023-11-07 16:05:12 +02:00
parent 4a8c3640de
commit 0e6a59ef3d
2 changed files with 49 additions and 9 deletions

View File

@ -90,6 +90,10 @@ public class Dmp {
public static final String _dmpReferences = "dmpReferences";
private List<DmpUser> dmpUsers;
public static final String _dmpUsers = "dmoUsers";
public UUID getId() {
return id;
}
@ -249,4 +253,13 @@ public class Dmp {
public void setDmpReferences(List<DmpReference> dmpReferences) {
this.dmpReferences = dmpReferences;
}
public List<DmpUser> getDmpUsers() {
return dmpUsers;
}
public void setDmpUsers(List<DmpUser> dmpUsers) {
this.dmpUsers = dmpUsers;
}
}

View File

@ -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;
@ -58,8 +59,11 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
FieldSet dmpDescriptionsFields = fields.extractPrefixed(this.asPrefix(Dmp._dmpDescriptions));
Map<UUID, List<Description>> dmpDescriptionsMap = this.collectDmpDescriptions(dmpDescriptionsFields, data);
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();
@ -96,11 +100,14 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
if (fields.hasField(this.asIndexer(Dmp._hash)))
m.setHash(this.hashValue(d.getUpdatedAt()));
if (!dmpDescriptionsFields.isEmpty() && dmpDescriptionsMap != null && dmpDescriptionsMap.containsKey(d.getId()))
if (dmpDescriptionsMap != null && !dmpDescriptionsMap.isEmpty() && 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 (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);
}
@ -130,13 +137,14 @@ public class DmpBuilder extends BaseBuilder<Dmp, DmpEntity> {
return itemMap;
}
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()));
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).authorize(this.authorize).asMasterKey(query, clone, x -> x.getDmp().getId());
if (!fields.hasField(this.asIndexer(DmpReference._dmp, Dmp._id))) {
@ -148,4 +156,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;
}
}