fix associated dmps bugs in DMP table, new/existing DmpDatasetProfile entries were not saved/updated

This commit is contained in:
Bernaldo Mihasi 2023-09-12 15:36:06 +03:00
parent 6f5fcabc79
commit 6154a5fa51
18 changed files with 170 additions and 27 deletions

View File

@ -0,0 +1,9 @@
package eu.eudat.data.dao.entities;
import eu.eudat.data.dao.DatabaseAccessLayer;
import eu.eudat.data.entities.DMPDatasetProfile;
import java.util.UUID;
public interface DmpDatasetProfileDao extends DatabaseAccessLayer<DMPDatasetProfile, UUID> {
}

View File

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

View File

@ -112,7 +112,7 @@ public class DMP implements DataEntity<DMP, UUID> {
/*@Type(type = "eu.eudat.configurations.typedefinition.XMLType") /*@Type(type = "eu.eudat.configurations.typedefinition.XMLType")
@Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true) @Column(name = "\"AssociatedDmps\"", columnDefinition = "xml", nullable = true)
private String associatedDmps;*/ private String associatedDmps;*/
@OneToMany(fetch = FetchType.LAZY) @OneToMany(fetch = FetchType.LAZY, mappedBy = "dmp")
private Set<DMPDatasetProfile> associatedDmps; private Set<DMPDatasetProfile> associatedDmps;

View File

@ -2,7 +2,6 @@ package eu.eudat.data.entities;
import eu.eudat.queryable.queryableentity.DataEntity; import eu.eudat.queryable.queryableentity.DataEntity;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.*; import javax.persistence.*;
import java.util.List; import java.util.List;

View File

@ -1,14 +1,18 @@
package eu.eudat.elastic.entities; package eu.eudat.elastic.entities;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class DatasetTempalate implements ElasticEntity<DatasetTempalate> { public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
private UUID id; private UUID id;
private String name; private String name;
private Map<String, Object> data;
public UUID getId() { public UUID getId() {
return id; return id;
@ -26,11 +30,25 @@ public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
this.name = name; this.name = name;
} }
public Map<String, Object> getData() {
return data;
}
public void setData(Map<String, Object> data) {
this.data = data;
}
@Override @Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException { public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject(); builder.startObject();
builder.field("id", this.id.toString()); builder.field("id", this.id.toString());
builder.field("name", this.name); builder.field("name", this.name);
if(this.data != null) {
builder.field("data", new ObjectMapper().writeValueAsString(this.data));
}
else{
builder.field("data", "");
}
builder.endObject(); builder.endObject();
return builder; return builder;
} }
@ -39,6 +57,12 @@ public class DatasetTempalate implements ElasticEntity<DatasetTempalate> {
public DatasetTempalate fromElasticEntity(Map<String, Object> fields) { public DatasetTempalate fromElasticEntity(Map<String, Object> fields) {
this.id = UUID.fromString((String) fields.get("id")); this.id = UUID.fromString((String) fields.get("id"));
this.name = (String) fields.get("name"); this.name = (String) fields.get("name");
try {
this.data = new ObjectMapper().readValue((String) fields.get("data"), new TypeReference<Map<String, Object>>() {});
}
catch (Exception e){
this.data = new HashMap<>();
}
return this; return this;
} }
} }

View File

@ -447,6 +447,7 @@ public class DataManagementPlanManager {
* Data Management * Data Management
* */ * */
@Transactional
public DMP createOrUpdate(DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception { public DMP createOrUpdate(DataManagementPlanEditorModel dataManagementPlan, Principal principal) throws Exception {
boolean setNotification = false; boolean setNotification = false;
if (dataManagementPlan.getId() != null) { if (dataManagementPlan.getId() != null) {
@ -463,7 +464,7 @@ public class DataManagementPlanManager {
} }
List<Dataset> datasetList = dmp1.getDataset().stream().filter(dataset -> dataset.getStatus() != 99).collect(Collectors.toList()); List<Dataset> datasetList = dmp1.getDataset().stream().filter(dataset -> dataset.getStatus() != 99).collect(Collectors.toList());
for (Dataset dataset : datasetList) { for (Dataset dataset : datasetList) {
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null) if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null)
throw new Exception("Dataset Template for Dataset Description is missing from the DMP."); throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
} }
if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
@ -519,9 +520,19 @@ public class DataManagementPlanManager {
assignFunderUserIfInternal(newDmp, user); assignFunderUserIfInternal(newDmp, user);
assignProjectUserIfInternal(newDmp, user); assignProjectUserIfInternal(newDmp, user);
if(newDmp.getId() != null){
for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){
apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile);
}
}
apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant()); apiContext.getOperationsContext().getDatabaseRepository().getGrantDao().createOrUpdate(newDmp.getGrant());
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
for(DMPDatasetProfile dmpDatasetProfile : newDmp.getAssociatedDmps()){
apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().createOrUpdate(dmpDatasetProfile);
}
if (dataManagementPlan.getUsers() != null && !dataManagementPlan.getUsers().isEmpty()) { if (dataManagementPlan.getUsers() != null && !dataManagementPlan.getUsers().isEmpty()) {
clearUsers(newDmp); clearUsers(newDmp);
for (UserInfoListingModel userListing : dataManagementPlan.getUsers()) { for (UserInfoListingModel userListing : dataManagementPlan.getUsers()) {
@ -597,7 +608,7 @@ public class DataManagementPlanManager {
throw new Exception("Another user have already edit that DMP."); throw new Exception("Another user have already edit that DMP.");
} }
for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) { for (DatasetWizardModel dataset : dataManagementPlan.getDatasets()) {
if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getId())).findAny().orElse(null) == null) if (dataManagementPlan.getProfiles().stream().filter(associatedProfile -> dataset.getProfile().getId().equals(associatedProfile.getDescriptionTemplateId())).findAny().orElse(null) == null)
throw new Exception("Dataset Template for Dataset Description is missing from the DMP."); throw new Exception("Dataset Template for Dataset Description is missing from the DMP.");
} }
if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue())) if (dataManagementPlan.getStatus() == (int) DMP.DMPStatus.FINALISED.getValue() && dmp1.getStatus().equals(DMP.DMPStatus.FINALISED.getValue()))
@ -1997,7 +2008,7 @@ public class DataManagementPlanManager {
try { try {
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile())); dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile()));
} catch (Exception ignored) { } catch (Exception ignored) {
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(associatedProfiles.get(0).getId())); dataset.setProfile(databaseRepository.getDatasetProfileDao().find(associatedProfiles.get(0).getDescriptionTemplateId()));
} }
dataset.setProperties(objectMapper.writeValueAsString(das.getFieldImportModels())); dataset.setProperties(objectMapper.writeValueAsString(das.getFieldImportModels()));
dataset.setStatus((short) 0); dataset.setStatus((short) 0);

View File

@ -40,7 +40,7 @@ public class DatasetWizardManager {
return new LinkedList<>(); return new LinkedList<>();
} }
DatasetProfileCriteria criteria = new DatasetProfileCriteria(); DatasetProfileCriteria criteria = new DatasetProfileCriteria();
criteria.setIds(dataManagementPlan.getProfiles().stream().map(AssociatedProfile::getId).collect(Collectors.toList())); criteria.setIds(dataManagementPlan.getProfiles().stream().map(AssociatedProfile::getDescriptionTemplateId).collect(Collectors.toList()));
List<DescriptionTemplate> descriptionTemplates = profileDao.getWithCriteria(criteria).toList(); List<DescriptionTemplate> descriptionTemplates = profileDao.getWithCriteria(criteria).toList();
criteria.setIds(null); criteria.setIds(null);
criteria.setGroupIds(descriptionTemplates.stream().map(DescriptionTemplate::getGroupId).collect(Collectors.toList())); criteria.setGroupIds(descriptionTemplates.stream().map(DescriptionTemplate::getGroupId).collect(Collectors.toList()));

View File

@ -1,14 +1,26 @@
package eu.eudat.logic.mapper.elastic; package eu.eudat.logic.mapper.elastic;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.entities.DMPDatasetProfile;
import eu.eudat.data.entities.DescriptionTemplate; import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.elastic.entities.DatasetTempalate; import eu.eudat.elastic.entities.DatasetTempalate;
import java.util.HashMap;
import java.util.Map;
public class DatasetTemplateMapper { public class DatasetTemplateMapper {
public static DatasetTempalate toElastic(DescriptionTemplate profile) { public static DatasetTempalate toElastic(DMPDatasetProfile profile) {
DatasetTempalate elastic = new DatasetTempalate(); DatasetTempalate elastic = new DatasetTempalate();
elastic.setId(profile.getId()); elastic.setId(profile.getDatasetprofile().getId());
elastic.setName(profile.getLabel()); elastic.setName(profile.getDatasetprofile().getLabel());
try {
elastic.setData(new ObjectMapper().readValue(profile.getData(), new TypeReference<Map<String, Object>>() {}));
}
catch (Exception e){
elastic.setData(new HashMap<>());
}
return elastic; return elastic;
} }
} }

View File

@ -14,6 +14,8 @@ public interface DatabaseRepository {
DMPDao getDmpDao(); DMPDao getDmpDao();
DmpDatasetProfileDao getDmpDatasetProfileDao();
OrganisationDao getOrganisationDao(); OrganisationDao getOrganisationDao();
GrantDao getGrantDao(); GrantDao getGrantDao();

View File

@ -16,6 +16,7 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
private DatasetDao datasetDao; private DatasetDao datasetDao;
private DatasetProfileDao datasetProfileDao; private DatasetProfileDao datasetProfileDao;
private DMPDao dmpDao; private DMPDao dmpDao;
private DmpDatasetProfileDao dmpDatasetProfileDao;
private OrganisationDao organisationDao; private OrganisationDao organisationDao;
private GrantDao GrantDao; private GrantDao GrantDao;
private RegistryDao registryDao; private RegistryDao registryDao;
@ -64,6 +65,11 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
this.dmpDao = dmpDao; this.dmpDao = dmpDao;
} }
@Autowired
private void setDmpDatasetProfileDao(DmpDatasetProfileDao dmpDatasetProfileDao) {
this.dmpDatasetProfileDao = dmpDatasetProfileDao;
}
@Autowired @Autowired
private void setOrganisationDao(OrganisationDao organisationDao) { private void setOrganisationDao(OrganisationDao organisationDao) {
this.organisationDao = organisationDao; this.organisationDao = organisationDao;
@ -114,6 +120,11 @@ public class DatabaseRepositoryImpl implements DatabaseRepository {
return dmpDao; return dmpDao;
} }
@Override
public DmpDatasetProfileDao getDmpDatasetProfileDao() {
return dmpDatasetProfileDao;
}
@Override @Override
public OrganisationDao getOrganisationDao() { public OrganisationDao getOrganisationDao() {
return organisationDao; return organisationDao;

View File

@ -11,6 +11,7 @@ import java.util.UUID;
public class AssociatedProfile implements XmlSerializable<AssociatedProfile> { public class AssociatedProfile implements XmlSerializable<AssociatedProfile> {
private UUID id; private UUID id;
private UUID descriptionTemplateId;
private String label; private String label;
private Map<String, Object> data; private Map<String, Object> data;
@ -22,6 +23,14 @@ public class AssociatedProfile implements XmlSerializable<AssociatedProfile> {
this.id = id; this.id = id;
} }
public UUID getDescriptionTemplateId() {
return descriptionTemplateId;
}
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId;
}
public String getLabel() { public String getLabel() {
return label; return label;
} }
@ -41,27 +50,27 @@ public class AssociatedProfile implements XmlSerializable<AssociatedProfile> {
@Override @Override
public Element toXml(Document doc) { public Element toXml(Document doc) {
Element profile = doc.createElement("profile"); Element profile = doc.createElement("profile");
profile.setAttribute("profileId", this.id.toString()); profile.setAttribute("profileId", this.descriptionTemplateId.toString());
profile.setAttribute("label", this.label); profile.setAttribute("label", this.label);
return profile; return profile;
} }
@Override @Override
public AssociatedProfile fromXml(Element item) { public AssociatedProfile fromXml(Element item) {
this.id = UUID.fromString(item.getAttribute("profileId")); this.descriptionTemplateId = UUID.fromString(item.getAttribute("profileId"));
this.label = item.getAttribute("label"); this.label = item.getAttribute("label");
return this; return this;
} }
public DescriptionTemplate toData() { public DescriptionTemplate toData() {
DescriptionTemplate profile = new DescriptionTemplate(); DescriptionTemplate profile = new DescriptionTemplate();
profile.setId(this.id); profile.setId(this.descriptionTemplateId);
profile.setLabel(this.label); profile.setLabel(this.label);
return profile; return profile;
} }
public AssociatedProfile fromData(DescriptionTemplate entity) { public AssociatedProfile fromData(DescriptionTemplate entity) {
this.id = entity.getId(); this.descriptionTemplateId = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
return this; return this;
} }

View File

@ -262,6 +262,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.profiles = new LinkedList<>(); this.profiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
associatedProfile.setId(dmpDescriptionProfile.getId());
try { try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {})); associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
} }
@ -331,7 +332,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>(); Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) { for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(UUID.randomUUID()); dmpDatasetProfile.setId(profile.getId());
dmpDatasetProfile.setDmp(dataManagementPlanEntity); dmpDatasetProfile.setDmp(dataManagementPlanEntity);
dmpDatasetProfile.setDatasetprofile(profile.toData()); dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));
@ -380,6 +381,7 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.profiles = new LinkedList<>(); this.profiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile()); AssociatedProfile associatedProfile = new AssociatedProfile().fromData(dmpDescriptionProfile.getDatasetprofile());
associatedProfile.setId(dmpDescriptionProfile.getId());
try { try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {})); associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
} }

View File

@ -369,7 +369,7 @@ public class DataManagementPlanEditorModel implements DataModel<DMP, DataManagem
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>(); Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) { for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(UUID.randomUUID()); dmpDatasetProfile.setId(profile.getId());
dmpDatasetProfile.setDmp(dataManagementPlanEntity); dmpDatasetProfile.setDmp(dataManagementPlanEntity);
dmpDatasetProfile.setDatasetprofile(profile.toData()); dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));

View File

@ -265,7 +265,7 @@ public class DataManagementPlanNewVersionModel implements DataModel<DMP, DataMan
Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>(); Set<DMPDatasetProfile> dmpDatasetProfiles = new HashSet<>();
for (AssociatedProfile profile : this.profiles) { for (AssociatedProfile profile : this.profiles) {
DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile(); DMPDatasetProfile dmpDatasetProfile = new DMPDatasetProfile();
dmpDatasetProfile.setId(UUID.randomUUID()); dmpDatasetProfile.setId(profile.getId());
dmpDatasetProfile.setDmp(entity); dmpDatasetProfile.setDmp(entity);
dmpDatasetProfile.setDatasetprofile(profile.toData()); dmpDatasetProfile.setDatasetprofile(profile.toData());
dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData())); dmpDatasetProfile.setData(new ObjectMapper().writeValueAsString(profile.getData()));

View File

@ -112,7 +112,7 @@ public class DmpQuickWizardModel {
DescriptionTemplate descriptionTemplate = new DescriptionTemplate(); DescriptionTemplate descriptionTemplate = new DescriptionTemplate();
descriptionTemplate.setDefinition(this.datasetProfile.getLabel()); descriptionTemplate.setDefinition(this.datasetProfile.getLabel());
descriptionTemplate.setLabel(this.datasetProfile.getLabel()); descriptionTemplate.setLabel(this.datasetProfile.getLabel());
descriptionTemplate.setId(this.datasetProfile.getId()); descriptionTemplate.setId(this.datasetProfile.getDescriptionTemplateId());
return descriptionTemplate; return descriptionTemplate;
} }

View File

@ -125,16 +125,15 @@ public class DmpRDAMapper {
entity.setDois(new HashSet<>()); entity.setDois(new HashSet<>());
} }
} }
if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty()) { if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty() && entity.getId() != null) {
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).filter(Objects::nonNull).collect(Collectors.toSet())); entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(x -> this.getProfile(x, entity.getId())).filter(Objects::nonNull).collect(Collectors.toSet()));
} }
if (entity.getAssociatedDmps() == null) { if (entity.getAssociatedDmps() == null) {
entity.setAssociatedDmps(new HashSet<>()); entity.setAssociatedDmps(new HashSet<>());
} }
if (profiles != null) { if (profiles != null && entity.getId() != null) {
for (String profile : profiles) { for (String profile : profiles) {
DescriptionTemplate exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(profile)); entity.getAssociatedDmps().add(this.getProfile(profile, entity.getId()));
entity.getAssociatedDmps().add(exProfile);
} }
} }
if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) { if (rda.getContributor() != null && !rda.getContributor().isEmpty() && rda.getContributor().get(0).getContributorId() != null) {
@ -159,7 +158,10 @@ public class DmpRDAMapper {
return entity; return entity;
} }
private DescriptionTemplate getProfile(String id) { private DMPDatasetProfile getProfile(String descriptionTemplateId, UUID dmpId) {
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().asQueryable().where(((builder, root) -> builder.equal(root.get("id"), UUID.fromString(id)))).getSingleOrDefault(); return apiContext.getOperationsContext().getDatabaseRepository().getDmpDatasetProfileDao().asQueryable().where(((builder, root) -> builder.and(
builder.equal(root.get("datasetprofile"), UUID.fromString(descriptionTemplateId)),
builder.equal(root.get("dmp"), dmpId))
)).getSingleOrDefault();
} }
} }

View File

@ -10,6 +10,7 @@ import java.util.UUID;
public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedProfilePublicModel> { public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedProfilePublicModel> {
private UUID id; private UUID id;
private UUID descriptionTemplateId;
private String label; private String label;
private Map<String, Object> data; private Map<String, Object> data;
@ -21,6 +22,14 @@ public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedP
this.id = id; this.id = id;
} }
public UUID getDescriptionTemplateId() {
return descriptionTemplateId;
}
public void setDescriptionTemplateId(UUID descriptionTemplateId) {
this.descriptionTemplateId = descriptionTemplateId;
}
public String getLabel() { public String getLabel() {
return label; return label;
} }
@ -47,20 +56,20 @@ public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedP
@Override @Override
public AssociatedProfilePublicModel fromXml(Element item) { public AssociatedProfilePublicModel fromXml(Element item) {
this.id = UUID.fromString(item.getAttribute("profileId")); this.descriptionTemplateId = UUID.fromString(item.getAttribute("profileId"));
this.label = item.getAttribute("label"); this.label = item.getAttribute("label");
return this; return this;
} }
public DescriptionTemplate toData() { public DescriptionTemplate toData() {
DescriptionTemplate profile = new DescriptionTemplate(); DescriptionTemplate profile = new DescriptionTemplate();
profile.setId(this.id); profile.setId(this.descriptionTemplateId);
profile.setLabel(this.label); profile.setLabel(this.label);
return profile; return profile;
} }
public AssociatedProfilePublicModel fromData(DescriptionTemplate entity) { public AssociatedProfilePublicModel fromData(DescriptionTemplate entity) {
this.id = entity.getId(); this.descriptionTemplateId = entity.getId();
this.label = entity.getLabel(); this.label = entity.getLabel();
return this; return this;
} }

View File

@ -199,6 +199,7 @@ public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagem
this.associatedProfiles = new LinkedList<>(); this.associatedProfiles = new LinkedList<>();
for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) { for (DMPDatasetProfile dmpDescriptionProfile : entity.getAssociatedDmps()) {
AssociatedProfilePublicModel associatedProfile = new AssociatedProfilePublicModel().fromData(dmpDescriptionProfile.getDatasetprofile()); AssociatedProfilePublicModel associatedProfile = new AssociatedProfilePublicModel().fromData(dmpDescriptionProfile.getDatasetprofile());
associatedProfile.setId(dmpDescriptionProfile.getId());
try { try {
associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {})); associatedProfile.setData(new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {}));
} }