Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Diamantis Tziotzios 2023-11-24 13:56:15 +02:00
commit 9d37900a86
44 changed files with 799 additions and 273 deletions

View File

@ -80,6 +80,12 @@ public class DescriptionEntity implements DataEntity<DescriptionEntity, UUID> {
@Column(name = "dmp", columnDefinition = "uuid", nullable = false)
private UUID dmpId;
@Column(name = "description_template", columnDefinition = "uuid", nullable = false)
private UUID descriptionTemplateId;
public static final String _descriptionTemplateId = "descriptionTemplateId";
public static final String _dmpId = "dmpId";
public UUID getId() {
@ -178,55 +184,17 @@ public class DescriptionEntity implements DataEntity<DescriptionEntity, UUID> {
this.dmpId = dmpId;
}
public UUID getDescriptionTemplateId() {
return descriptionTemplateId;
}
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId;
}
@Override
public void update(DescriptionEntity entity) {
// this.setUri(entity.getUri());
// this.setDescription(entity.getDescription());
// this.setLabel(entity.getLabel());
// this.setProperties(entity.getProperties());
//
// if (entity.getDatasetDataRepositories() == null || entity.getDatasetDataRepositories().size() < 1) {
// if (this.getDatasetDataRepositories() != null) this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
// } else {
// if (this.getDatasetDataRepositories() != null) {
// this.getDatasetDataRepositories().removeAll(this.getDatasetDataRepositories());
// } else {
// this.setDatasetDataRepositories(new HashSet<>());
// }
// this.getDatasetDataRepositories().addAll(entity.getDatasetDataRepositories().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
// }
//
// if (entity.getDatasetExternalDatasets() == null || entity.getDatasetExternalDatasets().size() < 1) {
// if (this.getDatasetExternalDatasets() != null) this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
// } else {
// if (this.getDatasetExternalDatasets() != null) {
// this.getDatasetExternalDatasets().removeAll(this.getDatasetExternalDatasets());
// } else {
// this.setDatasetExternalDatasets(new HashSet<>());
// }
// this.getDatasetExternalDatasets().addAll(entity.getDatasetExternalDatasets().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
// }
//
// if (entity.getServices() == null || entity.getServices().size() < 1) {
// if (this.getServices() != null) this.getServices().removeAll(this.getServices());
// } else {
// if (this.getServices() != null) {
// this.getServices().removeAll(this.getServices());
// } else {
// this.setServices(new HashSet<>());
// }
// this.getServices().addAll(entity.getServices().stream().peek(item -> item.setDataset(this)).collect(Collectors.toList()));
// }
//
// this.setRegistries(entity.getRegistries());
//
// this.setDmp(entity.getDmp());
// this.setDmpSectionIndex(entity.getDmpSectionIndex());
// this.setStatus(entity.getStatus());
// this.setProfile(entity.getProfile());
// this.setModified(new Date());
// if (entity.getStatus().equals(Status.FINALISED.getValue())) this.setFinalizedAt(new Date());
// if (entity.getCreator() != null) this.creator = entity.getCreator();
}
@Override

View File

@ -24,10 +24,10 @@ public class DmpDescriptionTemplateEntity {
public static final String _dmpId = "dmpId";
@Column(name = "description_template", columnDefinition = "uuid", nullable = false)
private UUID descriptionTemplateId;
@Column(name = "description_template_group", columnDefinition = "uuid", nullable = false)
private UUID descriptionTemplateGroupId;
public static final String _descriptionTemplateId = "descriptionTemplateId";
public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId";
@Column(name = "section_id")
private UUID sectionId;
@ -66,12 +66,12 @@ public class DmpDescriptionTemplateEntity {
this.dmpId = dmpId;
}
public UUID getDescriptionTemplateId() {
return descriptionTemplateId;
public UUID getDescriptionTemplateGroupId() {
return descriptionTemplateGroupId;
}
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId;
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
}
public UUID getSectionId() {

View File

@ -127,23 +127,15 @@ public class DescriptionElasticBuilder extends BaseElasticBuilder<DescriptionEla
return itemMap;
}
private Map<UUID, NestedDescriptionTemplateElasticEntity> collectDescriptionTemplates(List<DescriptionEntity> data) throws MyApplicationException {
if (data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(data.stream().map(DescriptionEntity::getDmpDescriptionTemplateId).collect(Collectors.toList())).isActive(IsActive.Active);
List<DmpDescriptionTemplateEntity> associationEntities = associationQuery.collect();
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMap;
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(q, NestedDescriptionTemplateElasticEntity::getId);
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId);
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMap = new HashMap<>();
for (DmpDescriptionTemplateEntity associationEntity : associationEntities){
itemMap.put(associationEntity.getId(), itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null));
}
return itemMap;
}
}

View File

@ -99,13 +99,13 @@ public class DmpElasticBuilder extends BaseElasticBuilder<DmpElasticEntity, DmpE
DmpDescriptionTemplateQuery associationQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(data.stream().map(DmpEntity::getId).collect(Collectors.toList())).isActive(IsActive.Active);
List<DmpDescriptionTemplateEntity> associationEntities = associationQuery.collect();
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).ids(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).isActive(IsActive.Active).groupIds(associationEntities.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()));
Map<UUID, NestedDescriptionTemplateElasticEntity> itemMapById = this.builderFactory.builder(NestedDescriptionTemplateElasticBuilder.class).asForeignKey(query, NestedDescriptionTemplateElasticEntity::getId);
Map<UUID, List<NestedDescriptionTemplateElasticEntity>> itemMap = new HashMap<>();
for (DmpDescriptionTemplateEntity associationEntity : associationEntities){
if (!itemMap.containsKey(associationEntity.getDmpId())) itemMap.put(associationEntity.getDmpId(), new ArrayList<>());
NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateId(), null);
NestedDescriptionTemplateElasticEntity item = itemMapById.getOrDefault(associationEntity.getDescriptionTemplateGroupId(), null);
if (item != null) itemMap.get(associationEntity.getDmpId()).add(item);
}

View File

@ -67,6 +67,10 @@ public class Description {
public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate";
private DescriptionTemplate descriptionTemplate;
public static final String _descriptionTemplate = "descriptionTemplate";
private Dmp dmp;
public static final String _dmp = "dmp";
@ -191,4 +195,12 @@ public class Description {
public void setDmp(Dmp dmp) {
this.dmp = dmp;
}
public DescriptionTemplate getDescriptionTemplate() {
return descriptionTemplate;
}
public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
}
}

View File

@ -17,14 +17,23 @@ public class DmpDescriptionTemplate{
public static final String _dmp = "dmp";
private DescriptionTemplate descriptionTemplate;
private DescriptionTemplate currentDescriptionTemplate;
public static final String _descriptionTemplate = "descriptionTemplate";
public static final String _currentDescriptionTemplate = "currentDescriptionTemplate";
private List<DescriptionTemplate> descriptionTemplates;
public static final String _descriptionTemplates = "descriptionTemplates";
private UUID sectionId;
public static final String _sectionId = "sectionId";
private UUID descriptionTemplateGroupId;
public static final String _descriptionTemplateGroupId = "descriptionTemplateGroupId";
private Instant createdAt;
public static final String _createdAt = "createdAt";
@ -56,12 +65,28 @@ public class DmpDescriptionTemplate{
this.dmp = dmp;
}
public DescriptionTemplate getDescriptionTemplate() {
return descriptionTemplate;
public DescriptionTemplate getCurrentDescriptionTemplate() {
return currentDescriptionTemplate;
}
public void setDescriptionTemplate(DescriptionTemplate descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
public void setCurrentDescriptionTemplate(DescriptionTemplate currentDescriptionTemplate) {
this.currentDescriptionTemplate = currentDescriptionTemplate;
}
public List<DescriptionTemplate> getDescriptionTemplates() {
return descriptionTemplates;
}
public void setDescriptionTemplates(List<DescriptionTemplate> descriptionTemplates) {
this.descriptionTemplates = descriptionTemplates;
}
public UUID getDescriptionTemplateGroupId() {
return descriptionTemplateGroupId;
}
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
}
public UUID getSectionId() {

View File

@ -39,6 +39,11 @@ public class PublicDescription {
public static final String _dmpDescriptionTemplate = "dmpDescriptionTemplate";
private PublicDescriptionTemplate descriptionTemplate;
public static final String _descriptionTemplate = "descriptionTemplate";
public UUID getId() {
return id;
}
@ -104,4 +109,11 @@ public class PublicDescription {
this.dmpDescriptionTemplate = dmpDescriptionTemplate;
}
public PublicDescriptionTemplate getDescriptionTemplate() {
return descriptionTemplate;
}
public void setDescriptionTemplate(PublicDescriptionTemplate descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
}
}

View File

@ -15,10 +15,6 @@ public class PublicDmpDescriptionTemplate {
public static final String _dmp = "dmp";
private PublicDescriptionTemplate descriptionTemplate;
public static final String _descriptionTemplate = "descriptionTemplate";
public UUID getId() {
return id;
}
@ -35,11 +31,4 @@ public class PublicDmpDescriptionTemplate {
this.dmp = dmp;
}
public PublicDescriptionTemplate getDescriptionTemplate() {
return descriptionTemplate;
}
public void setDescriptionTemplate(PublicDescriptionTemplate descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
}
}

View File

@ -62,9 +62,12 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate));
Map<UUID, DmpDescriptionTemplate> dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmpDescriptionTemplate));
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(Description._dmp));
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate));
Map<UUID, DescriptionTemplate> descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data);
FieldSet descriptionReferencesFields = fields.extractPrefixed(this.asPrefix(Description._descriptionReferences));
Map<UUID, List<DescriptionReference>> descriptionReferencesMap = this.collectDescriptionReferences(descriptionReferencesFields, data);
@ -89,6 +92,7 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
if (fields.hasField(this.asIndexer(Description._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
if (!dmpDescriptionTemplateFields.isEmpty() && dmpDescriptionTemplateItemsMap != null && dmpDescriptionTemplateItemsMap.containsKey(d.getDmpDescriptionTemplateId())) m.setDmpDescriptionTemplate(dmpDescriptionTemplateItemsMap.get(d.getDmpDescriptionTemplateId()));
if (!descriptionTemplateFields.isEmpty() && descriptionTemplateItemsMap != null && descriptionTemplateItemsMap.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplateItemsMap.get(d.getDescriptionTemplateId()));
if (!descriptionReferencesFields.isEmpty() && descriptionReferencesMap != null && descriptionReferencesMap.containsKey(d.getId())) m.setDescriptionReferences(descriptionReferencesMap.get(d.getId()));
if (!descriptionTagsFields.isEmpty() && descriptionTagsMap != null && descriptionTagsMap.containsKey(d.getId())) m.setDescriptionTags(descriptionTagsMap.get(d.getId()));
if (!userFields.isEmpty() && userItemsMap != null && userItemsMap.containsKey(d.getCreatedById())) m.setCreatedBy(userItemsMap.get(d.getCreatedById()));
@ -164,6 +168,36 @@ public class DescriptionBuilder extends BaseBuilder<Description, DescriptionEnti
return itemMap;
}
private Map<UUID, DescriptionTemplate> collectDescriptionTemplates(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
Map<UUID, DescriptionTemplate> itemMap;
if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) {
itemMap = this.asEmpty(
data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()),
x -> {
DescriptionTemplate item = new DescriptionTemplate();
item.setId(x);
return item;
},
DescriptionTemplate::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id);
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getId);
}
if (!fields.hasField(DescriptionTemplate._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;

View File

@ -1,11 +1,14 @@
package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.enums.DescriptionTemplateVersionStatus;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.data.DmpEntity;
import eu.eudat.model.*;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpQuery;
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;
@ -53,8 +56,11 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplate));
Map<UUID, DescriptionTemplate> templateItemsMap = this.collectTemplates(templateFields, data);
FieldSet templateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._descriptionTemplates));
Map<UUID, List<DescriptionTemplate>> templateItemsMap = this.collectDescriptionTemplates(templateFields, data);
FieldSet currentDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._currentDescriptionTemplate));
Map<UUID, DescriptionTemplate> currentDescriptionTemplateItemsMap = this.collectCurrentDescriptionTemplates(currentDescriptionTemplateFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(DmpDescriptionTemplate._dmp));
Map<UUID, Dmp> dmpItemsMap = this.collectDmps(dmpFields, data);
@ -67,7 +73,8 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._createdAt))) m.setCreatedAt(d.getCreatedAt());
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(DmpDescriptionTemplate._hash))) m.setHash(this.hashValue(d.getUpdatedAt()));
if (!templateFields.isEmpty() && templateItemsMap != null && templateItemsMap.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(templateItemsMap.get(d.getDescriptionTemplateId()));
if (!templateFields.isEmpty() && templateItemsMap != null && templateItemsMap.containsKey(d.getDescriptionTemplateGroupId())) m.setDescriptionTemplates(templateItemsMap.get(d.getDescriptionTemplateGroupId()));
if (!currentDescriptionTemplateFields.isEmpty() && currentDescriptionTemplateItemsMap != null && currentDescriptionTemplateItemsMap.containsKey(d.getDescriptionTemplateGroupId())) m.setCurrentDescriptionTemplate(currentDescriptionTemplateItemsMap.get(d.getDescriptionTemplateGroupId()));
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
models.add(m);
}
@ -75,32 +82,6 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
return models;
}
private Map<UUID, DescriptionTemplate> collectTemplates(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
Map<UUID, DescriptionTemplate> itemMap;
if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._id))) {
itemMap = this.asEmpty(
data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()),
x -> {
DescriptionTemplate item = new DescriptionTemplate();
item.setId(x);
return item;
},
DescriptionTemplate::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id);
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getId);
}
if (!fields.hasField(DescriptionTemplate._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
private Map<UUID, Dmp> collectDmps(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
@ -129,4 +110,50 @@ public class DmpDescriptionTemplateBuilder extends BaseBuilder<DmpDescriptionTem
return itemMap;
}
private Map<UUID, List<DescriptionTemplate>> collectDescriptionTemplates(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
Map<UUID, List<DescriptionTemplate>> itemMap;
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._groupId);
DescriptionTemplateQuery query = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).groupIds(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asMasterKey(query, clone, DescriptionTemplate::getGroupId);
if (!fields.hasField(DescriptionTemplate._groupId)) {
itemMap.values().stream().flatMap(List::stream).filter(x -> x != null && x.getGroupId() != null).peek(x -> {
x.setGroupId(null);
});
}
return itemMap;
}
private Map<UUID, DescriptionTemplate> collectCurrentDescriptionTemplates(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", DescriptionTemplate.class.getSimpleName());
Map<UUID, DescriptionTemplate> itemMap;
if (!fields.hasOtherField(this.asIndexer(DescriptionTemplate._groupId))) {
itemMap = this.asEmpty(
data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()),
x -> {
DescriptionTemplate item = new DescriptionTemplate();
item.setGroupId(x);
return item;
},
DescriptionTemplate::getGroupId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(DescriptionTemplate._id);
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).versionStatuses(DescriptionTemplateVersionStatus.Current).groupIds(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateGroupId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(DescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DescriptionTemplate::getGroupId);
}
if (!fields.hasField(DescriptionTemplate._groupId)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setGroupId(null)).collect(Collectors.toList());
}
return itemMap;
}
}

View File

@ -3,8 +3,8 @@ package eu.eudat.model.builder;
import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.convention.ConventionService;
import eu.eudat.data.DescriptionEntity;
import eu.eudat.model.PublicDescription;
import eu.eudat.model.PublicDmpDescriptionTemplate;
import eu.eudat.model.*;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery;
import gr.cite.tools.data.builder.BuilderFactory;
import gr.cite.tools.data.query.QueryFactory;
@ -56,6 +56,9 @@ public class PublicDescriptionBuilder extends BaseBuilder<PublicDescription, Des
FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asPrefix(PublicDescription._dmpDescriptionTemplate));
Map<UUID, PublicDmpDescriptionTemplate> dmpDescriptionTemplateItemsMap = this.collectDmpDescriptionTemplates(dmpDescriptionTemplateFields, data);
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asPrefix(Description._descriptionTemplate));
Map<UUID, PublicDescriptionTemplate> descriptionTemplateItemsMap = this.collectDescriptionTemplates(descriptionTemplateFields, data);
List<PublicDescription> models = new ArrayList<>();
for (DescriptionEntity d : data) {
PublicDescription m = new PublicDescription();
@ -67,6 +70,7 @@ public class PublicDescriptionBuilder extends BaseBuilder<PublicDescription, Des
if (fields.hasField(this.asIndexer(PublicDescription._updatedAt))) m.setUpdatedAt(d.getUpdatedAt());
if (fields.hasField(this.asIndexer(PublicDescription._finalizedAt))) m.setFinalizedAt(d.getFinalizedAt());
if (!dmpDescriptionTemplateFields.isEmpty() && dmpDescriptionTemplateItemsMap != null && dmpDescriptionTemplateItemsMap.containsKey(d.getDmpDescriptionTemplateId())) m.setDmpDescriptionTemplate(dmpDescriptionTemplateItemsMap.get(d.getDmpDescriptionTemplateId()));
if (!descriptionTemplateFields.isEmpty() && descriptionTemplateItemsMap != null && descriptionTemplateItemsMap.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(descriptionTemplateItemsMap.get(d.getDescriptionTemplateId()));
models.add(m);
}
@ -105,4 +109,34 @@ public class PublicDescriptionBuilder extends BaseBuilder<PublicDescription, Des
return itemMap;
}
private Map<UUID, PublicDescriptionTemplate> collectDescriptionTemplates(FieldSet fields, List<DescriptionEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", PublicDescriptionTemplate.class.getSimpleName());
Map<UUID, PublicDescriptionTemplate> itemMap;
if (!fields.hasOtherField(this.asIndexer(PublicDescriptionTemplate._id))) {
itemMap = this.asEmpty(
data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()),
x -> {
PublicDescriptionTemplate item = new PublicDescriptionTemplate();
item.setId(x);
return item;
},
PublicDescriptionTemplate::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDescriptionTemplate._id);
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DescriptionEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PublicDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDescriptionTemplate::getId);
}
if (!fields.hasField(PublicDescriptionTemplate._id)) {
itemMap.forEach((id, item) -> {
if (item != null)
item.setId(null);
});
}
return itemMap;
}
}

View File

@ -55,8 +55,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder<PublicDmpDe
if (fields == null || data == null || fields.isEmpty())
return new ArrayList<>();
FieldSet templateFields = fields.extractPrefixed(this.asPrefix(PublicDmpDescriptionTemplate._descriptionTemplate));
Map<UUID, PublicDescriptionTemplate> templateItemsMap = this.collectTemplates(templateFields, data);
FieldSet dmpFields = fields.extractPrefixed(this.asPrefix(PublicDmpDescriptionTemplate._dmp));
Map<UUID, PublicDmp> dmpItemsMap = this.collectDmps(dmpFields, data);
@ -65,7 +63,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder<PublicDmpDe
for (DmpDescriptionTemplateEntity d : data) {
PublicDmpDescriptionTemplate m = new PublicDmpDescriptionTemplate();
if (fields.hasField(this.asIndexer(PublicDmpDescriptionTemplate._id))) m.setId(d.getId());
if (!templateFields.isEmpty() && templateItemsMap != null && templateItemsMap.containsKey(d.getDescriptionTemplateId())) m.setDescriptionTemplate(templateItemsMap.get(d.getDescriptionTemplateId()));
if (!dmpFields.isEmpty() && dmpItemsMap != null && dmpItemsMap.containsKey(d.getDmpId())) m.setDmp(dmpItemsMap.get(d.getDmpId()));
models.add(m);
}
@ -73,33 +70,6 @@ public class PublicDmpDescriptionTemplateBuilder extends BaseBuilder<PublicDmpDe
return models;
}
private Map<UUID, PublicDescriptionTemplate> collectTemplates(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;
this.logger.debug("checking related - {}", PublicDescriptionTemplate.class.getSimpleName());
Map<UUID, PublicDescriptionTemplate> itemMap;
if (!fields.hasOtherField(this.asIndexer(PublicDescriptionTemplate._id))) {
itemMap = this.asEmpty(
data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()),
x -> {
PublicDescriptionTemplate item = new PublicDescriptionTemplate();
item.setId(x);
return item;
},
PublicDescriptionTemplate::getId);
} else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(PublicDescriptionTemplate._id);
DescriptionTemplateQuery q = this.queryFactory.query(DescriptionTemplateQuery.class).authorize(this.authorize).ids(data.stream().map(DmpDescriptionTemplateEntity::getDescriptionTemplateId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(PublicDescriptionTemplateBuilder.class).authorize(this.authorize).asForeignKey(q, clone, PublicDescriptionTemplate::getId);
}
if (!fields.hasField(PublicDescriptionTemplate._id)) {
itemMap.values().stream().filter(Objects::nonNull).peek(x -> x.setId(null)).collect(Collectors.toList());
}
return itemMap;
}
private Map<UUID, PublicDmp> collectDmps(FieldSet fields, List<DmpDescriptionTemplateEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty())
return null;

View File

@ -48,6 +48,9 @@ public class DescriptionCensor extends BaseCensor {
FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmpDescriptionTemplate));
this.censorFactory.censor(DmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields, userId);
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(Description._descriptionTemplate));
this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId);
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(Description._dmp));
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);

View File

@ -42,8 +42,10 @@ public class DmpDescriptionTemplateCensor extends BaseCensor{
this.authService.authorizeForce(Permission.BrowseDescription);
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._dmp));
this.censorFactory.censor(DmpCensor.class).censor(dmpFields, userId);
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplate));
this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplateFields, userId);
FieldSet descriptionTemplatesFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._descriptionTemplates));
this.censorFactory.censor(DescriptionTemplateCensor.class).censor(descriptionTemplatesFields, userId);
FieldSet currentDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(DmpDescriptionTemplate._currentDescriptionTemplate));
this.censorFactory.censor(DescriptionTemplateCensor.class).censor(currentDescriptionTemplateFields, userId);
}
}

View File

@ -2,6 +2,7 @@ package eu.eudat.model.censorship;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.Description;
import eu.eudat.model.PublicDescription;
import eu.eudat.model.censorship.descriptionproperties.PropertyDefinitionCensor;
import gr.cite.commons.web.authz.service.AuthorizationService;
@ -42,6 +43,9 @@ public class PublicDescriptionCensor extends BaseCensor {
FieldSet dmpDescriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDescription._dmpDescriptionTemplate));
this.censorFactory.censor(PublicDmpDescriptionTemplateCensor.class).censor(dmpDescriptionTemplateFields);
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDescription._descriptionTemplate));
this.censorFactory.censor(PublicDescriptionTemplateCensor.class).censor(descriptionTemplateFields);
}
}

View File

@ -43,8 +43,6 @@ public class PublicDmpDescriptionTemplateCensor extends BaseCensor{
this.authService.authorizeForce(Permission.PublicBrowseDescription);
FieldSet dmpFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpDescriptionTemplate._dmp));
this.censorFactory.censor(PublicDmpCensor.class).censor(dmpFields);
FieldSet descriptionTemplateFields = fields.extractPrefixed(this.asIndexerPrefix(PublicDmpDescriptionTemplate._descriptionTemplate));
this.censorFactory.censor(PublicDescriptionTemplateCensor.class).censor(descriptionTemplateFields);
}
}

View File

@ -4,7 +4,6 @@ import eu.eudat.authorization.OwnedResource;
import eu.eudat.authorization.Permission;
import eu.eudat.convention.ConventionService;
import eu.eudat.model.UserAdditionalInfo;
import eu.eudat.model.UserContactInfo;
import gr.cite.commons.web.authz.service.AuthorizationService;
import gr.cite.tools.data.censor.CensorFactory;
import gr.cite.tools.fieldset.FieldSet;
@ -26,10 +25,13 @@ public class UserAdditionalInfoCensor extends BaseCensor {
protected final AuthorizationService authService;
protected final CensorFactory censorFactory;
public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService) {
public UserAdditionalInfoCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) {
super(conventionService);
this.authService = authService;
this.censorFactory = censorFactory;
}
public void censor(FieldSet fields, UUID userId) {
@ -37,6 +39,9 @@ public class UserAdditionalInfoCensor extends BaseCensor {
if (fields == null || fields.isEmpty())
return;
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUser);
FieldSet descriptionReferenceFields = fields.extractPrefixed(this.asIndexerPrefix(UserAdditionalInfo._organization));
this.censorFactory.censor(ReferenceCensor.class).censor(descriptionReferenceFields, userId);
}
}

View File

@ -71,6 +71,7 @@ public class DescriptionTemplateDeleter implements Deleter {
return;
List<UUID> ids = data.stream().map(DescriptionTemplateEntity::getId).distinct().collect(Collectors.toList());
List<UUID> groupIds = data.stream().map(DescriptionTemplateEntity::getGroupId).distinct().collect(Collectors.toList());
{
logger.debug("checking related - {}", UserDescriptionTemplateEntity.class.getSimpleName());
List<UserDescriptionTemplateEntity> items = this.queryFactory.query(UserDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect();
@ -79,7 +80,7 @@ public class DescriptionTemplateDeleter implements Deleter {
}
{
logger.debug("checking related - {}", DmpDescriptionTemplateEntity.class.getSimpleName());
List<DmpDescriptionTemplateEntity> items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(ids).collect();
List<DmpDescriptionTemplateEntity> items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateGroupIds(groupIds).collect();
DmpDescriptionTemplateDeleter deleter = this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class);
deleter.delete(items);
}

View File

@ -74,16 +74,15 @@ public class DmpEntityDepositMapper {
model.setLabel(entity.getLabel());
model.setDescription(entity.getDescription());
model.setProperties(entity.getProperties());
DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDmpDescriptionTemplateId());
DescriptionTemplateEntity descriptionTemplateEntity = getDescriptionTemplate(entity.getDescriptionTemplateId());
model.setProfileDefinition(descriptionTemplateEntity.getDefinition());
model.setFields(fromDefinitionAndProperties(descriptionTemplateEntity.getDefinition(), entity.getProperties()));
return model;
}
private DescriptionTemplateEntity getDescriptionTemplate(UUID dmpDescriptionTemplateId) {
DmpDescriptionTemplateEntity dmpDescriptionTemplate = this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(dmpDescriptionTemplateId).isActive(IsActive.Active).first();
private DescriptionTemplateEntity getDescriptionTemplate(UUID descriptionTemplateId) {
DescriptionTemplateQuery descriptionTemplateQuery = this.queryFactory.query(DescriptionTemplateQuery.class);
return descriptionTemplateQuery.ids(dmpDescriptionTemplate.getDescriptionTemplateId()).isActive(IsActive.Active).first();
return descriptionTemplateQuery.ids(descriptionTemplateId).isActive(IsActive.Active).first();
}
private List<DatasetFieldsDepositModel> fromDefinitionAndProperties(String definition, String properties){

View File

@ -33,6 +33,10 @@ public class DescriptionPersist {
@ValidId(message = "{validation.invalidid}")
private UUID dmpDescriptionTemplateId;
@NotNull(message = "{validation.empty}")
@ValidId(message = "{validation.invalidid}")
private UUID descriptionTemplateId;
@ValidEnum(message = "{validation.empty}")
private DescriptionStatus status;
@ -131,4 +135,12 @@ public class DescriptionPersist {
public void setHash(String hash) {
this.hash = hash;
}
public UUID getDescriptionTemplateId() {
return descriptionTemplateId;
}
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId;
}
}

View File

@ -9,33 +9,20 @@ import java.util.UUID;
@FieldNotNullIfOtherSet(message = "{validation.hashempty}")
public class DmpDescriptionTemplatePersist {
@ValidId(message = "{validation.invalidid}")
private UUID id;
@ValidId(message = "{validation.invalidid}")
@NotNull(message = "{validation.empty}")
private UUID descriptionTemplate;
private UUID descriptionTemplateGroupId;
@ValidId(message = "{validation.invalidid}")
@NotNull(message = "{validation.empty}")
private UUID sectionId;
private String hash;
public UUID getId() {
return id;
public UUID getDescriptionTemplateGroupId() {
return descriptionTemplateGroupId;
}
public void setId(UUID id) {
this.id = id;
}
public UUID getDescriptionTemplate() {
return descriptionTemplate;
}
public void setDescriptionTemplate(UUID descriptionTemplate) {
this.descriptionTemplate = descriptionTemplate;
public void setDescriptionTemplateGroupId(UUID descriptionTemplateGroupId) {
this.descriptionTemplateGroupId = descriptionTemplateGroupId;
}
public UUID getSectionId() {
@ -46,12 +33,4 @@ public class DmpDescriptionTemplatePersist {
this.sectionId = sectionId;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
}

View File

@ -270,6 +270,9 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
else if (item.match(Description._hash)) return DescriptionEntity._updatedAt;
else if (item.match(Description._finalizedAt) || item.match(PublicDescription._finalizedAt)) return DescriptionEntity._finalizedAt;
else if (item.prefix(Description._dmpDescriptionTemplate) || item.prefix(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId;
else if (item.match(Description._dmpDescriptionTemplate) || item.match(PublicDescription._dmpDescriptionTemplate)) return DescriptionEntity._dmpDescriptionTemplateId;
else if (item.prefix(Description._descriptionTemplate) || item.prefix(PublicDescription._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId;
else if (item.match(Description._descriptionTemplate) || item.match(PublicDescription._descriptionTemplate)) return DescriptionEntity._descriptionTemplateId;
else if (item.prefix(Description._dmp)) return DescriptionEntity._dmpId;
else return null;
}
@ -287,6 +290,7 @@ public class DescriptionQuery extends QueryBase<DescriptionEntity> {
item.setIsActive(QueryBase.convertSafe(tuple, columns, DescriptionEntity._isActive, IsActive.class));
item.setFinalizedAt(QueryBase.convertSafe(tuple, columns, DescriptionEntity._finalizedAt, Instant.class));
item.setDmpDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpDescriptionTemplateId, UUID.class));
item.setDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._descriptionTemplateId, UUID.class));
item.setDmpId(QueryBase.convertSafe(tuple, columns, DescriptionEntity._dmpId, UUID.class));
return item;
}

View File

@ -197,12 +197,12 @@ public class DescriptionTemplateQuery extends QueryBase<DescriptionTemplateEntit
if (userId != null || usePublic ) {
Subquery<UUID> dmpDescriptionTemplateSubquery = queryUtilsService.buildSubQuery(new BuildSubQueryInput<>(
new BuildSubQueryInput.Builder<>(DmpDescriptionTemplateEntity.class, UUID.class, queryContext)
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateId))
.keyPathFunc((subQueryRoot) -> subQueryRoot.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId))
.filterFunc((subQueryRoot, cb) ->
cb.in(subQueryRoot.get(DmpDescriptionTemplateEntity._dmpId)).value(queryUtilsService.buildDmpAuthZSubQuery(queryContext.Query, queryContext.CriteriaBuilder, userId, usePublic))
)
));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._id)).value(dmpDescriptionTemplateSubquery));
predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(DescriptionTemplateEntity._groupId)).value(dmpDescriptionTemplateSubquery));
}
if (!predicates.isEmpty()) {
Predicate[] predicatesArray = predicates.toArray(new Predicate[0]);

View File

@ -36,7 +36,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
private Collection<UUID> dmpIds;
private Collection<UUID> descriptionTemplateIds;
private Collection<UUID> descriptionTemplateGroupIds;
private Collection<IsActive> isActives;
@ -105,18 +105,18 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
return this;
}
public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID value) {
this.descriptionTemplateIds = List.of(value);
public DmpDescriptionTemplateQuery descriptionTemplateGroupIds(UUID value) {
this.descriptionTemplateGroupIds = List.of(value);
return this;
}
public DmpDescriptionTemplateQuery descriptionTemplateIds(UUID... value) {
this.descriptionTemplateIds = Arrays.asList(value);
public DmpDescriptionTemplateQuery descriptionTemplateGroupIds(UUID... value) {
this.descriptionTemplateGroupIds = Arrays.asList(value);
return this;
}
public DmpDescriptionTemplateQuery descriptionTemplateIds(Collection<UUID> values) {
this.descriptionTemplateIds = values;
public DmpDescriptionTemplateQuery descriptionTemplateGroupIds(Collection<UUID> values) {
this.descriptionTemplateGroupIds = values;
return this;
}
@ -143,7 +143,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
@Override
protected Boolean isFalseQuery() {
return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.dmpIds) || this.isEmpty(this.descriptionTemplateIds);
return this.isEmpty(this.ids) || this.isEmpty(this.excludedIds) || this.isEmpty(this.isActives) || this.isEmpty(this.dmpIds) || this.isEmpty(this.descriptionTemplateGroupIds);
}
@Override
@ -187,9 +187,9 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
inClause.value(item);
predicates.add(inClause);
}
if (this.descriptionTemplateIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateId));
for (UUID item : this.descriptionTemplateIds)
if (this.descriptionTemplateGroupIds != null) {
CriteriaBuilder.In<UUID> inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(DmpDescriptionTemplateEntity._descriptionTemplateGroupId));
for (UUID item : this.descriptionTemplateGroupIds)
inClause.value(item);
predicates.add(inClause);
}
@ -212,7 +212,7 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
DmpDescriptionTemplateEntity item = new DmpDescriptionTemplateEntity();
item.setId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._id, UUID.class));
item.setDmpId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._dmpId, UUID.class));
item.setDescriptionTemplateId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._descriptionTemplateId, UUID.class));
item.setDescriptionTemplateGroupId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._descriptionTemplateGroupId, UUID.class));
item.setSectionId(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._sectionId, UUID.class));
item.setCreatedAt(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._createdAt, Instant.class));
item.setUpdatedAt(QueryBase.convertSafe(tuple, columns, DmpDescriptionTemplateEntity._updatedAt, Instant.class));
@ -223,8 +223,13 @@ public class DmpDescriptionTemplateQuery extends QueryBase<DmpDescriptionTemplat
protected String fieldNameOf(FieldResolver item) {
if (item.match(DmpDescriptionTemplate._id) || item.match(PublicDmpDescriptionTemplate._id)) return DmpDescriptionTemplateEntity._id;
else if (item.prefix(DmpDescriptionTemplate._dmp) || item.prefix(PublicDmpDescriptionTemplate._dmp)) return DmpDescriptionTemplateEntity._dmpId;
else if (item.prefix(DmpDescriptionTemplate._descriptionTemplate) || item.prefix(PublicDmpDescriptionTemplate._descriptionTemplate)) return DmpDescriptionTemplateEntity._descriptionTemplateId;
else if (item.match(DmpDescriptionTemplate._dmp) || item.prefix(PublicDmpDescriptionTemplate._dmp)) return DmpDescriptionTemplateEntity._dmpId;
else if (item.prefix(DmpDescriptionTemplate._currentDescriptionTemplate)) return DmpDescriptionTemplateEntity._descriptionTemplateGroupId;
else if (item.match(DmpDescriptionTemplate._currentDescriptionTemplate)) return DmpDescriptionTemplateEntity._descriptionTemplateGroupId;
else if (item.prefix(DmpDescriptionTemplate._descriptionTemplates)) return DmpDescriptionTemplateEntity._descriptionTemplateGroupId;
else if (item.match(DmpDescriptionTemplate._descriptionTemplates)) return DmpDescriptionTemplateEntity._descriptionTemplateGroupId;
else if (item.match(DmpDescriptionTemplate._sectionId)) return DmpDescriptionTemplateEntity._sectionId;
else if (item.match(DmpDescriptionTemplate._descriptionTemplateGroupId)) return DmpDescriptionTemplateEntity._descriptionTemplateGroupId;
else if (item.match(DmpDescriptionTemplate._hash)) return DmpDescriptionTemplateEntity._updatedAt;
else if (item.match(DmpDescriptionTemplate._createdAt)) return DmpDescriptionTemplateEntity._createdAt;
else if (item.match(DmpDescriptionTemplate._updatedAt)) return DmpDescriptionTemplateEntity._updatedAt;

View File

@ -140,6 +140,8 @@ public class DescriptionServiceImpl implements DescriptionService {
data.setProperties(this.jsonHandlingService.toJson(this.buildPropertyDefinitionEntity(model.getProperties())));
data.setStatus(model.getStatus());
data.setDescription(model.getDescription());
data.setDescriptionTemplateId(model.getDescriptionTemplateId());
data.setDmpDescriptionTemplateId(model.getDmpDescriptionTemplateId());
data.setUpdatedAt(Instant.now());
if (isUpdate) this.entityManager.merge(data);
else this.entityManager.persist(data);
@ -336,6 +338,7 @@ public class DescriptionServiceImpl implements DescriptionService {
newDescription.setProperties(existing.getProperties());
newDescription.setDmpId(dmpId);
newDescription.setDmpDescriptionTemplateId(existing.getDmpDescriptionTemplateId());
newDescription.setDescriptionTemplateId(existing.getDescriptionTemplateId());
newDescription.setCreatedById(userScope.getUserId());
newDescription.setCreatedAt(Instant.now());
newDescription.setUpdatedAt(Instant.now());

View File

@ -20,10 +20,7 @@ import eu.eudat.event.EventBroker;
import eu.eudat.model.Dmp;
import eu.eudat.model.Reference;
import eu.eudat.model.builder.DmpBuilder;
import eu.eudat.model.deleter.DmpDeleter;
import eu.eudat.model.deleter.DmpDescriptionTemplateDeleter;
import eu.eudat.model.deleter.DmpReferenceDeleter;
import eu.eudat.model.deleter.DmpUserDeleter;
import eu.eudat.model.deleter.*;
import eu.eudat.model.persist.*;
import eu.eudat.model.persist.dmpproperties.DmpBlueprintValuePersist;
import eu.eudat.model.persist.dmpproperties.DmpContactPersist;
@ -130,7 +127,7 @@ public class DmpServiceImpl implements DmpService {
this.patchAndSaveReferences(model.getReferences(), data.getId());
this.patchAndSaveTemplates(model.getDescriptionTemplates(), data.getId());
this.patchAndSaveTemplates(data.getId(), model.getDescriptionTemplates());
this.eventBroker.emit(new DmpTouchedEvent(data.getId()));
@ -218,7 +215,7 @@ public class DmpServiceImpl implements DmpService {
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateId(dmpDescriptionTemplate.getDescriptionTemplateId());
newTemplate.setDescriptionTemplateGroupId(dmpDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(dmpDescriptionTemplate.getSectionId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
@ -306,7 +303,7 @@ public class DmpServiceImpl implements DmpService {
DmpDescriptionTemplateEntity newTemplate = new DmpDescriptionTemplateEntity();
newTemplate.setId(UUID.randomUUID());
newTemplate.setDmpId(newDmp.getId());
newTemplate.setDescriptionTemplateId(dmpDescriptionTemplate.getDescriptionTemplateId());
newTemplate.setDescriptionTemplateGroupId(dmpDescriptionTemplate.getDescriptionTemplateGroupId());
newTemplate.setSectionId(dmpDescriptionTemplate.getSectionId());
newTemplate.setCreatedAt(Instant.now());
newTemplate.setUpdatedAt(Instant.now());
@ -537,39 +534,28 @@ public class DmpServiceImpl implements DmpService {
}
private void patchAndSaveTemplates(List<DmpDescriptionTemplatePersist> models, UUID dmpId) throws InvalidApplicationException {
if (models == null || models.isEmpty())
return;
List<DmpDescriptionTemplateEntity> templates = this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).collect();
Map<UUID, List<DmpDescriptionTemplateEntity>> templatesLookup = this.conventionService.toDictionaryOfList(templates, DmpDescriptionTemplateEntity::getDmpId);
List<DescriptionTemplateEntity> existingTemplates;
if (templatesLookup.containsKey(dmpId))
existingTemplates = this.queryFactory.query(DescriptionTemplateQuery.class).ids(templatesLookup.get(dmpId).stream().map(DmpDescriptionTemplateEntity::getId).toList()).collect();
else existingTemplates = new ArrayList<>();
List<UUID> updatedTemplatesIds = models.stream().map(DmpDescriptionTemplatePersist::getDescriptionTemplate).filter(this.conventionService::isValidGuid).distinct().toList();
List<DescriptionTemplateEntity> toDelete = existingTemplates.stream().filter(x -> !updatedTemplatesIds.contains(x.getId())).toList();
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateRecordsToDelete = this.queryFactory.query(DmpDescriptionTemplateQuery.class).descriptionTemplateIds(toDelete.stream().map(DescriptionTemplateEntity::getId).toList()).collect();
this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class).delete(dmpDescriptionTemplateRecordsToDelete);
private void patchAndSaveTemplates(UUID id, List<DmpDescriptionTemplatePersist> models) throws InvalidApplicationException {
if (models == null) models = new ArrayList<>();
List<DmpDescriptionTemplateEntity> items = this.queryFactory.query(DmpDescriptionTemplateQuery.class).isActive(IsActive.Active).dmpIds(id).collect();
List<UUID> updatedCreatedIds = new ArrayList<>();
for (DmpDescriptionTemplatePersist model : models) {
boolean shouldAdd = existingTemplates.stream().noneMatch(x -> x.getId().equals(model.getDescriptionTemplate()));
if (shouldAdd) {
DmpDescriptionTemplateEntity dmpTemplate = new DmpDescriptionTemplateEntity();
dmpTemplate.setDescriptionTemplateId(model.getDescriptionTemplate());
dmpTemplate.setDmpId(dmpId);
dmpTemplate.setSectionId(model.getSectionId());
dmpTemplate.setCreatedAt(Instant.now());
dmpTemplate.setUpdatedAt(Instant.now());
dmpTemplate.setIsActive(IsActive.Active);
this.entityManager.persist(dmpTemplate);
DmpDescriptionTemplateEntity data = items.stream().filter(x -> x.getDescriptionTemplateGroupId().equals(model.getDescriptionTemplateGroupId()) && x.getSectionId().equals(model.getSectionId())).findFirst().orElse(null);
if (data == null){
data = new DmpDescriptionTemplateEntity();
data.setId(UUID.randomUUID());
data.setIsActive(IsActive.Active);
data.setCreatedAt(Instant.now());
data.setDmpId(id);
data.setSectionId(model.getSectionId());
data.setDescriptionTemplateGroupId(model.getDescriptionTemplateGroupId());
this.entityManager.persist(data);
}
updatedCreatedIds.add(data.getId());
}
this.entityManager.flush();
List<DmpDescriptionTemplateEntity> toDelete = items.stream().filter(x-> updatedCreatedIds.stream().noneMatch(y-> y.equals(x.getId()))).collect(Collectors.toList());
this.deleterFactory.deleter(DmpDescriptionTemplateDeleter.class).delete(toDelete);
}
private @NotNull DefinitionEntity buildDefinitionEntity(DefinitionPersist persist){

View File

@ -485,7 +485,7 @@ public class DataManagementPlanManager {
List<DescriptionEntity> descriptionEntityList = this.databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).toList().stream().filter(dataset -> dataset.getIsActive() != IsActive.Inactive).collect(Collectors.toList());
for (DescriptionEntity descriptionEntity : descriptionEntityList) {
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null)
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> descriptionEntity.getDescriptionTemplateId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null)
throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
}
if (dataManagementPlan.getStatus() == DmpStatus.Finalized.getValue() && dmp1.getStatus().equals(DmpStatus.Finalized.getValue() ))
@ -1639,7 +1639,7 @@ public class DataManagementPlanManager {
//runDatasetTemplate1.setBold(true);
//runDatasetTemplate1.setFontSize(12);
XWPFRun runDatasetTemplate = datasetTemplateParagraph.createRun();
runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel());
runDatasetTemplate.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel());
runDatasetTemplate.setColor("116a78");
//runDatasetTemplate.setBold(true);
//runDatasetTemplate.setFontSize(12);
@ -1685,7 +1685,7 @@ public class DataManagementPlanManager {
runDatasetDescription1.setText("Description: ");
runDatasetDescription1.setColor("000000");
XWPFRun runDatasetDescription = datasetDescParagraph.createRun();
runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(datasetEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel());
runDatasetDescription.setText(this.queryFactory.query(DescriptionTemplateQuery.class).ids(datasetEntity.getDescriptionTemplateId()).first().getLabel());
runDatasetDescription.setColor("116a78");
//wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.HTML, BigInteger.ZERO, 0);
@ -1981,11 +1981,11 @@ public class DataManagementPlanManager {
Element datsetProfileElement = xmlDoc.createElement("profile-id");
datasetElement.appendChild(datsetProfileElement);
datsetProfileElement.setTextContent(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId().toString());
datsetProfileElement.setTextContent(descriptionEntity.getDescriptionTemplateId().toString());
Element datsetProfileLabelElement = xmlDoc.createElement("profile-label");
datasetElement.appendChild(datsetProfileLabelElement);
datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getLabel());
datsetProfileLabelElement.setTextContent(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId()).first().getLabel());
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
Map<String, Object> properties = new HashMap<>();

View File

@ -315,7 +315,7 @@ public class DatasetManager {
// Creates the Criteria to get all version of DescriptionTemplate in question.
DatasetProfileCriteria profileCriteria = new DatasetProfileCriteria();
UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getGroupId();
UUID profileId = this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getGroupId();
List<UUID> uuidList = new LinkedList<>();
uuidList.add(profileId);
profileCriteria.setGroupIds(uuidList);
@ -346,7 +346,7 @@ public class DatasetManager {
DescriptionTemplateEntity profile = profiles.get(0);
// Check if the dataset is on the latest Version.
boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first().getVersion());
boolean latestVersion = profile.getVersion().toString().equals(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first().getVersion());
dataset.setIsProfileLatestVersion(latestVersion);
// eu.eudat.elastic.entities.Dataset datasetElastic; //TODO
@ -409,7 +409,7 @@ public class DatasetManager {
}
public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, DescriptionEntity descriptionEntityEntity) {
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).first());
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(this.queryFactory.query(DescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDescriptionTemplateId()).first());
datasetprofile.setStatus(dataset.getStatus().getValue());
if (descriptionEntityEntity.getProperties() != null) {
JSONObject jObject = new JSONObject(descriptionEntityEntity.getProperties());
@ -616,7 +616,7 @@ public class DatasetManager {
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, descriptionEntityEntity);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
File file = xmlBuilder.build(pagedDatasetProfile, this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntityEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId(), visibilityRuleService, environment);
File file = xmlBuilder.build(pagedDatasetProfile, descriptionEntityEntity.getDescriptionTemplateId(), visibilityRuleService, environment);
FileEnvelope fileEnvelope = new FileEnvelope();
fileEnvelope.setFile(file);
String label = descriptionEntityEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
@ -758,7 +758,7 @@ public class DatasetManager {
public String checkDatasetValidation(DescriptionEntity descriptionEntity) throws Exception {
List<String> datasetProfileValidators = new LinkedList<>();
DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId());
DescriptionTemplateEntity profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(descriptionEntity.getDescriptionTemplateId());
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document xmlDocument = builder.parse(new ByteArrayInputStream(profile.getDefinition().getBytes()));

View File

@ -57,7 +57,7 @@ public class DatasetWizardManager {
public void unlock(ApiContext apiContext, QueryFactory queryFactory, UUID uuid) throws DatasetWizardCannotUnlockException, InvalidApplicationException {
DescriptionEntity descriptionEntity = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().find(uuid);
DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId());
DmpEntity dmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(descriptionEntity.getDescriptionTemplateId());
if(dmp.getStatus().equals(DmpStatus.Finalized)) throw new DatasetWizardCannotUnlockException("To perform this action you will need to revert DMP's finalisation");
descriptionEntity.setStatus(DescriptionStatus.Draft);
apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(descriptionEntity);

View File

@ -414,7 +414,7 @@ public class MetricsManager {
List<DescriptionTemplateEntity> descriptionTemplateEntities = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(criteria).withFields(Collections.singletonList("id")).toList();
DatasetCriteria datasetCriteria = new DatasetCriteria();
datasetCriteria.setDatasetTemplates(descriptionTemplateEntities.stream().map(DescriptionTemplateEntity::getId).collect(Collectors.toList()));
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(root.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()).stream().distinct().count();
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetCriteria).select(root -> root.getDescriptionTemplateId()).stream().distinct().count();
}
}

View File

@ -55,7 +55,7 @@ public class DatasetRDAMapper {
}
rda.setTitle(descriptionEntity.getLabel());
rda.setDescription(descriptionEntity.getDescription());
rda.setAdditionalProperty("template", this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDmpDescriptionTemplateId()).isActive(IsActive.Active).first().getDescriptionTemplateId()); //TODO
rda.setAdditionalProperty("template", this.queryFactory.query(DmpDescriptionTemplateQuery.class).ids(descriptionEntity.getDescriptionTemplateId())); //TODO
try {
JSONObject jObject = new JSONObject(descriptionEntity.getProperties());
Map<String, Object> templateIdsToValues = jObject.toMap();

View File

@ -184,7 +184,7 @@ public class DmpRDAMapper {
return entity;
}
private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException {
return this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).descriptionTemplateIds(UUID.fromString(descriptionTemplateId)).first();
}
// private DmpDescriptionTemplateEntity getProfile(String descriptionTemplateId, UUID dmpId) throws InvalidApplicationException {
// return this.queryFactory.query(DmpDescriptionTemplateQuery.class).dmpIds(dmpId).descriptionTemplateIds(UUID.fromString(descriptionTemplateId)).first();
// }
}

View File

@ -8,16 +8,14 @@ CREATE TABLE IF NOT EXISTS public."DmpDescriptionTemplate"
(
"id" uuid NOT NULL,
"dmp" uuid NOT NULL,
"description_template" uuid NOT NULL,
"description_template_group" uuid NOT NULL,
"section_id" uuid NOT NULL,
"created_at" timestamp without time zone NOT NULL DEFAULT now(),
"updated_at" timestamp without time zone NOT NULL DEFAULT now(),
"is_active" smallint NOT NULL DEFAULT 1,
CONSTRAINT "DmpDescriptionTemplate_pkey" PRIMARY KEY (id),
CONSTRAINT "DmpDescriptionTemplate_dmp_fkey" FOREIGN KEY (dmp)
REFERENCES public."Dmp" (id),
CONSTRAINT "DmpDescriptionTemplate_description_template_fkey" FOREIGN KEY (description_template)
REFERENCES public."DescriptionTemplate" (id)
REFERENCES public."Dmp" (id)
);
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.012', '2023-11-02 12:00:00.000000+02', now(), 'Add Dmp Description Template table (former DMPDatasetProfile).');

View File

@ -14,6 +14,9 @@ BEGIN
ALTER TABLE public."Description" DROP COLUMN dmp_section_index;
ALTER TABLE public."Description" ADD COLUMN description_template uuid NOT NULL;
ALTER TABLE public."Description"
ALTER COLUMN dmp SET NOT NULL;
@ -37,6 +40,13 @@ BEGIN
ON DELETE NO ACTION
NOT VALID;
ALTER TABLE public."Description"
ADD FOREIGN KEY (description_template)
REFERENCES public."DescriptionTemplate" (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.014', '2023-11-20 12:00:00.000000+02', now(), 'Sync table Description.');

View File

@ -0,0 +1,10 @@
package eu.old.eudat.data.dao.entities;
import eu.old.eudat.data.dao.DatabaseAccessLayer;
import eu.old.eudat.data.entities.DatasetDataRepository;
import java.util.UUID;
public interface DatasetDataRepositoryDao extends DatabaseAccessLayer<DatasetDataRepository, UUID> {
}

View File

@ -0,0 +1,51 @@
package eu.old.eudat.data.dao.entities;
import eu.old.eudat.data.dao.DatabaseAccess;
import eu.old.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.old.eudat.data.entities.DatasetDataRepository;
import eu.old.eudat.queryable.QueryableList;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component
public class DatasetDataRepositoryDaoImpl extends DatabaseAccess<DatasetDataRepository> implements DatasetDataRepositoryDao{
public DatasetDataRepositoryDaoImpl(DatabaseService<DatasetDataRepository> databaseService) {
super(databaseService);
}
@Override
public DatasetDataRepository createOrUpdate(DatasetDataRepository item) {
return this.getDatabaseService().createOrUpdate(item,DatasetDataRepository.class);
}
@Override
public CompletableFuture<DatasetDataRepository> createOrUpdateAsync(DatasetDataRepository item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
@Async
public DatasetDataRepository find(UUID id) {
return getDatabaseService().getQueryable(DatasetDataRepository.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DatasetDataRepository find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DatasetDataRepository item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DatasetDataRepository> asQueryable() {
return this.getDatabaseService().getQueryable(DatasetDataRepository.class);
}
}

View File

@ -0,0 +1,10 @@
package eu.old.eudat.data.dao.entities;
import eu.old.eudat.data.dao.DatabaseAccessLayer;
import eu.old.eudat.data.entities.DatasetRegistry;
import java.util.UUID;
public interface DatasetRegistryDao extends DatabaseAccessLayer<DatasetRegistry, UUID> {
}

View File

@ -0,0 +1,51 @@
package eu.old.eudat.data.dao.entities;
import eu.old.eudat.data.dao.DatabaseAccess;
import eu.old.eudat.data.dao.databaselayer.service.DatabaseService;
import eu.old.eudat.data.entities.DatasetRegistry;
import eu.old.eudat.queryable.QueryableList;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Component
public class DatasetRegistryDaoImpl extends DatabaseAccess<DatasetRegistry> implements DatasetRegistryDao {
public DatasetRegistryDaoImpl(DatabaseService<DatasetRegistry> databaseService) {
super(databaseService);
}
@Override
public DatasetRegistry createOrUpdate(DatasetRegistry item) {
return this.getDatabaseService().createOrUpdate(item,DatasetRegistry.class);
}
@Override
public CompletableFuture<DatasetRegistry> createOrUpdateAsync(DatasetRegistry item) {
return CompletableFuture.supplyAsync(() -> this.createOrUpdate(item));
}
@Override
@Async
public DatasetRegistry find(UUID id) {
return getDatabaseService().getQueryable(DatasetRegistry.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
}
@Override
public DatasetRegistry find(UUID id, String hint) {
throw new UnsupportedOperationException();
}
@Override
public void delete(DatasetRegistry item) {
this.getDatabaseService().delete(item);
}
@Override
public QueryableList<DatasetRegistry> asQueryable() {
return this.getDatabaseService().getQueryable(DatasetRegistry.class);
}
}

View File

@ -1,17 +1,19 @@
package eu.old.eudat.data.entities;
import eu.old.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "\"DatasetRegistry\"")
public class DatasetRegistry {
public class DatasetRegistry implements DataEntity<DatasetRegistry, UUID> {
@Id
@GeneratedValue
@ -19,13 +21,13 @@ public class DatasetRegistry {
@Column(name = "\"ID\"", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
//DEPWARN dependency to Hibernate and PostgreSQL
@Column(name = "\"Dataset\"", nullable = false)
private UUID dataset;
@ManyToOne
@JoinColumn(name = "\"Dataset\"", nullable = false)
private Dataset dataset;
//DEPWARN dependency to Hibernate and PostgreSQL
@Column(name = "\"Registry\"", nullable = false)
private UUID registry;
@ManyToOne
@JoinColumn(name = "\"Registry\"", nullable = false)
private Registry registry;
@Column(name = "\"Role\"")
private Integer role;
@ -41,19 +43,19 @@ public class DatasetRegistry {
this.id = id;
}
public UUID getDataset() {
public Dataset getDataset() {
return dataset;
}
public void setDataset(UUID dataset) {
public void setDataset(Dataset dataset) {
this.dataset = dataset;
}
public UUID getRegistry() {
public Registry getRegistry() {
return registry;
}
public void setRegistry(UUID registry) {
public void setRegistry(Registry registry) {
this.registry = registry;
}
@ -72,4 +74,23 @@ public class DatasetRegistry {
public void setData(String data) {
this.data = data;
}
@Override
public void update(DatasetRegistry entity) {
this.dataset = entity.getDataset();
this.registry = entity.getRegistry();
this.role = entity.getRole();
}
@Override
public UUID getKeys() {
return this.id;
}
@Override
public DatasetRegistry buildFromTuple(List<Tuple> tuple, List<String> fields, String base) {
String currentBase = base.isEmpty() ? "" : base + ".";
if(fields.contains(currentBase + "id")) this.id = UUID.fromString((String) tuple.get(0).get(currentBase + "id"));
return this;
}
}

View File

@ -48,8 +48,12 @@ public interface DatabaseRepository {
DatasetExternalDatasetDao getDatasetExternalDatasetDao();
DatasetDataRepositoryDao getDatasetDataRepositoryDao();
DatasetServiceDao getDatasetServiceDao();
DatasetRegistryDao getDatasetRegistryDao();
EmailConfirmationDao getLoginConfirmationEmailDao();
ProjectDao getProjectDao();

View File

@ -33,7 +33,9 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
private ContentDao contentDao;
private DMPProfileDao dmpProfileDao;
private DatasetExternalDatasetDao datasetExternalDatasetDao;
private DatasetDataRepositoryDao datasetDataRepositoryDao;
private DatasetServiceDao datasetServiceDao;
private DatasetRegistryDao datasetRegistryDao;
private EmailConfirmationDao loginConfirmationEmailDao;
private ProjectDao projectDao;
private FunderDao funderDao;
@ -250,6 +252,16 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
this.datasetExternalDatasetDao = datasetExternalDatasetDao;
}
@Override
public DatasetDataRepositoryDao getDatasetDataRepositoryDao() {
return datasetDataRepositoryDao;
}
@Autowired
public void setDatasetDataRepositoryDao(DatasetDataRepositoryDao datasetDataRepositoryDao) {
this.datasetDataRepositoryDao = datasetDataRepositoryDao;
}
@Override
public DatasetServiceDao getDatasetServiceDao() {
return datasetServiceDao;
@ -260,6 +272,16 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
this.datasetServiceDao = datasetServiceDao;
}
@Override
public DatasetRegistryDao getDatasetRegistryDao() {
return datasetRegistryDao;
}
@Autowired
public void setDatasetRegistryDao(DatasetRegistryDao datasetRegistryDao) {
this.datasetRegistryDao = datasetRegistryDao;
}
@Override
public EmailConfirmationDao getLoginConfirmationEmailDao() {
return loginConfirmationEmailDao;

View File

@ -16,12 +16,14 @@ import eu.eudat.data.ReferenceEntity;
import eu.eudat.model.DmpBlueprint;
import eu.eudat.query.DescriptionTemplateQuery;
import eu.eudat.query.DmpBlueprintQuery;
import eu.eudat.query.DmpDescriptionTemplateQuery;
import eu.old.eudat.data.dao.entities.DmpDatasetProfileDao;
import eu.old.eudat.data.dao.entities.ResearcherDao;
import eu.old.eudat.data.entities.DMPDatasetProfile;
import eu.old.eudat.data.entities.Researcher;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import eu.old.eudat.queryable.QueryableList;
import gr.cite.tools.data.query.Paging;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.exception.MyApplicationException;
import gr.cite.tools.logging.LoggerService;
@ -105,7 +107,7 @@ public class DmpDatasetProfileMigrationService {
DmpDescriptionTemplateEntity data = new DmpDescriptionTemplateEntity();
data.setId(UUID.randomUUID());
data.setDescriptionTemplateId(item.getDatasetprofile().getId());
data.setDescriptionTemplateGroupId(item.getDatasetprofile().getId());
data.setDmpId(item.getDmp().getId());
data.setCreatedAt(Instant.now());
data.setUpdatedAt(Instant.now());
@ -120,9 +122,41 @@ public class DmpDatasetProfileMigrationService {
}
} while (items != null && !items.isEmpty() && !TestMode);
removeDuplicates();
}
private void removeDuplicates() {
logger.debug("Checking for duplicates on DmpDescriptionTemplate table after migration");
int page = 0;
//TODO CLEAN Duplicates dmp, DescriptionTemplate, SectionId
DmpDescriptionTemplateQuery dmpDescriptionTemplateQuery = this.queryFactory.query(DmpDescriptionTemplateQuery.class);
long total = dmpDescriptionTemplateQuery.count();
List<DmpDescriptionTemplateEntity> dmpDescriptionTemplateEntities;
do {
logger.debug("Checking " + page * PageSize + " of " + total);
dmpDescriptionTemplateQuery.setPage(new Paging(page * PageSize, PageSize));
dmpDescriptionTemplateEntities = dmpDescriptionTemplateQuery.collect();
DmpDescriptionTemplateEntity previousEntity = null;
for(DmpDescriptionTemplateEntity currentEntity : dmpDescriptionTemplateEntities) {
if (previousEntity == null) {
previousEntity = currentEntity;
continue;
}
if (currentEntity.getDmpId().equals(previousEntity.getDmpId())
&& currentEntity.getDescriptionTemplateGroupId().equals(previousEntity.getDescriptionTemplateGroupId())
&& currentEntity.getSectionId().equals(previousEntity.getSectionId())
) {
logger.warn("Removing found duplicate DmpDescriptionTemplate entity ({}) after DmpDatasetProfiles migration", currentEntity.getId());
this.entityManager.remove(currentEntity);
} else {
previousEntity = currentEntity;
}
}
entityManager.flush();
page++;
} while (!dmpDescriptionTemplateEntities.isEmpty() && !TestMode);
}
@JsonIgnoreProperties({"validationErrorModel"})

View File

@ -0,0 +1,237 @@
package eu.old.eudat.migration;
import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.DescriptionReferenceEntity;
import eu.eudat.data.DmpReferenceEntity;
import eu.old.eudat.data.dao.entities.*;
import eu.old.eudat.data.entities.*;
import eu.old.eudat.logic.services.operations.DatabaseRepository;
import gr.cite.tools.data.query.QueryFactory;
import gr.cite.tools.logging.LoggerService;
import jakarta.persistence.EntityManager;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
@Service
public class ReferenceMigrationService {
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(DmpDatasetProfileMigrationService.class));
private final DatabaseRepository databaseRepository;
private final QueryFactory queryFactory;
private static final int PageSize = 500;
private static final boolean TestMode = false;
private final EntityManager entityManager;
public ReferenceMigrationService(DatabaseRepository databaseRepository, QueryFactory queryFactory, EntityManager entityManager) {
this.databaseRepository = databaseRepository;
this.queryFactory = queryFactory;
this.entityManager = entityManager;
}
public void migrateDmpReferences() {
migrateDmpOrganizations();
migrateDmpResearchers();
}
public void migrateDatasetReferences() {
migrateDatasetDataRepositories();
migrateDatasetExternalDatasets();
migrateDatasetRegistries();
migrateDatasetServices();
}
public void migrateDmpOrganizations() {
OrganisationDao organisationDao = databaseRepository.getOrganisationDao();
long total = organisationDao.asQueryable().count();
logger.debug("Migrate Dmp Organisation (from Organization) Total : " + total);
int page = 0;
List<Organisation> items;
do {
items = organisationDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dmp Organisation " + page * PageSize + " of " + total);
for (Organisation item : items) {
// entityManager.detach(item);
for (DMP dmp : item.getDmps()) {
DmpReferenceEntity data = new DmpReferenceEntity();
data.setId(UUID.randomUUID());
data.setDmpId(dmp.getId());
data.setReferenceId(item.getId());
data.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
public void migrateDmpResearchers() {
ResearcherDao researcherDao = databaseRepository.getResearcherDao();
long total = researcherDao.asQueryable().count();
logger.debug("Migrate Dmp Researcher (from Researcher) Total : " + total);
int page = 0;
List<Researcher> items;
do {
items = researcherDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("created"))).orderBy((builder, root) -> builder.asc(root.get("ID"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dmp Researcher " + page * PageSize + " of " + total);
for (Researcher item : items) {
// entityManager.detach(item);
for (DMP dmp : item.getdMPs()) {
DmpReferenceEntity data = new DmpReferenceEntity();
data.setId(UUID.randomUUID());
data.setDmpId(dmp.getId());
data.setReferenceId(item.getId());
data.setCreatedAt(dmp.getCreated() != null ? dmp.getCreated().toInstant() : Instant.now());
data.setUpdatedAt(dmp.getModified() != null ? dmp.getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
public void migrateDatasetDataRepositories() {
DatasetDataRepositoryDao datasetDataRepositoryDao = databaseRepository.getDatasetDataRepositoryDao();
long total = datasetDataRepositoryDao.asQueryable().count();
logger.debug("Migrate Dataset DataRepository (from DatasetDataRepository) Total : " + total);
int page = 0;
List<DatasetDataRepository> items;
do {
items = datasetDataRepositoryDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dataset DataRepository " + page * PageSize + " of " + total);
for (DatasetDataRepository item : items) {
// entityManager.detach(item);
DescriptionReferenceEntity data = new DescriptionReferenceEntity();
data.setId(UUID.randomUUID());
data.setDescriptionId(item.getDataset().getId());
data.setReferenceId(item.getDataRepository().getId());
data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
public void migrateDatasetExternalDatasets() {
DatasetExternalDatasetDao datasetExternalDatasetDao = databaseRepository.getDatasetExternalDatasetDao();
long total = datasetExternalDatasetDao.asQueryable().count();
logger.debug("Migrate Dataset ExternalDataset (from DatasetExternalDataset) Total : " + total);
int page = 0;
List<DatasetExternalDataset> items;
do {
items = datasetExternalDatasetDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dataset ExternalDataset " + page * PageSize + " of " + total);
for (DatasetExternalDataset item : items) {
// entityManager.detach(item);
DescriptionReferenceEntity data = new DescriptionReferenceEntity();
data.setId(UUID.randomUUID());
data.setDescriptionId(item.getDataset().getId());
data.setReferenceId(item.getExternalDataset().getId());
data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
public void migrateDatasetRegistries() {
DatasetRegistryDao datasetRegistryDao = databaseRepository.getDatasetRegistryDao();
long total = datasetRegistryDao.asQueryable().count();
logger.debug("Migrate Dataset Registry (from DatasetRegistry) Total : " + total);
int page = 0;
List<DatasetRegistry> items;
do {
items = datasetRegistryDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dataset Registry " + page * PageSize + " of " + total);
for (DatasetRegistry item : items) {
// entityManager.detach(item);
DescriptionReferenceEntity data = new DescriptionReferenceEntity();
data.setId(UUID.randomUUID());
data.setDescriptionId(item.getDataset().getId());
data.setReferenceId(item.getRegistry().getId());
data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
public void migrateDatasetServices() {
DatasetServiceDao datasetServiceDao = databaseRepository.getDatasetServiceDao();
long total = datasetServiceDao.asQueryable().count();
logger.debug("Migrate Dataset Service (from DatasetService) Total : " + total);
int page = 0;
List<DatasetService> items;
do {
items = datasetServiceDao.asQueryable().orderBy((builder, root) -> builder.asc(root.get("id"))).skip(page * PageSize).take(PageSize).toList();
if (items != null && !items.isEmpty()) {
logger.debug("Migrate Dataset Service " + page * PageSize + " of " + total);
for (DatasetService item : items) {
// entityManager.detach(item);
DescriptionReferenceEntity data = new DescriptionReferenceEntity();
data.setId(UUID.randomUUID());
data.setDescriptionId(item.getDataset().getId());
data.setReferenceId(item.getService().getId());
data.setCreatedAt(item.getDataset().getCreated() != null ? item.getDataset().getCreated().toInstant() : Instant.now());
data.setUpdatedAt(item.getDataset().getModified() != null ? item.getDataset().getModified().toInstant() : Instant.now());
data.setIsActive(IsActive.Active);
this.entityManager.persist(data);
}
this.entityManager.flush();
page++;
}
} while (items != null && !items.isEmpty());
}
}

View File

@ -32,6 +32,7 @@ public class MigrationController {
private final DatasetMigrationService datasetMigrationService;
private final DmpDatasetProfileMigrationService dmpDatasetProfileMigrationService;
private final OrganizationMigrationService organizationMigrationService;
private final ReferenceMigrationService referenceMigrationService;
public MigrationController(
DmpMigrationService dmpMigrationService,
@ -45,8 +46,8 @@ public class MigrationController {
RegistryMigrationService registryMigrationService,
ResearcherMigrationService researcherMigrationService,
ServiceMigrationService serviceMigrationService,
OrganizationMigrationService organizationMigrationService
) {
OrganizationMigrationService organizationMigrationService,
ReferenceMigrationService referenceMigrationService) {
this.dmpMigrationService = dmpMigrationService;
this.datasetMigrationService = datasetMigrationService;
this.dmpDatasetProfileMigrationService = dmpDatasetProfileMigrationService;
@ -59,6 +60,7 @@ public class MigrationController {
this.researcherMigrationService = researcherMigrationService;
this.serviceMigrationService = serviceMigrationService;
this.organizationMigrationService = organizationMigrationService;
this.referenceMigrationService = referenceMigrationService;
}
@GetMapping("dmps")
@ -79,11 +81,9 @@ public class MigrationController {
@Transactional
public boolean migrateDmpDatasetProfiles() throws IOException, JAXBException, ParserConfigurationException, InstantiationException, IllegalAccessException, SAXException {
this.dmpDatasetProfileMigrationService.migrate();
return true;
return true;
}
@GetMapping("references")
@Transactional
public boolean migrateReferences() {
@ -97,7 +97,21 @@ public class MigrationController {
this.researcherMigrationService.migrate();
this.serviceMigrationService.migrate();
return true;
}
}
@GetMapping("dmp-references")
@Transactional
public boolean migrateDmpReferences() {
this.referenceMigrationService.migrateDmpReferences();
return true;
}
@GetMapping("dataset-references")
@Transactional
public boolean migrateDatasetReferences() {
this.referenceMigrationService.migrateDatasetReferences();
return true;
}
@GetMapping("organizations")
@Transactional