[wip] dmp xml upload changes, including section and extra fields information

This commit is contained in:
Bernaldo Mihasi 2023-10-02 09:34:21 +03:00
parent 6b544e4702
commit d644b1dc91
6 changed files with 184 additions and 47 deletions

View File

@ -1,5 +1,6 @@
package eu.eudat.logic.managers;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration;
import eu.eudat.configurations.dynamicgrant.entities.Property;
@ -1708,9 +1709,9 @@ public class DataManagementPlanManager {
Element dmpProfileId = xmlDoc.createElement("dmpProfileId");
dmpProfileId.setTextContent(dmpProfile.getId().toString());
dmpProfileElement.appendChild(dmpProfileId);
Element values = xmlDoc.createElement("values");
values.setTextContent(dmpProfile.getDefinition());
dmpProfileElement.appendChild(values);
// Element values = xmlDoc.createElement("values");
// values.setTextContent(dmpProfile.getDefinition());
// dmpProfileElement.appendChild(values);
}
dmpElement.appendChild(dmpProfileElement);
@ -1830,8 +1831,33 @@ public class DataManagementPlanManager {
researchersElement.appendChild(researcherElement);
}
dmpElement.appendChild(researchersElement);
Element datasetsElement = xmlDoc.createElement("datasets");
Element extraFields = xmlDoc.createElement("extraFields");
Map<String, Object> dmpProperties = new ObjectMapper().readValue(dmp.getProperties(), new TypeReference<Map<String, Object>>() {});
DataManagementPlanBlueprint blueprint = this.dataManagementProfileManager.getSingleBlueprint(dmp.getProfile().getId().toString(), principal).getDefinition();
blueprint.getSections().forEach(section -> {
section.getFields().forEach(fieldModel -> {
if (fieldModel.getCategory() == FieldCategory.EXTRA) {
Element extraField = xmlDoc.createElement("extraField");
Element extraFieldId = xmlDoc.createElement("id");
extraFieldId.setTextContent(fieldModel.getId().toString());
Element extraFieldLabel = xmlDoc.createElement("label");
extraFieldLabel.setTextContent(fieldModel.getLabel());
Element extraFieldValue = xmlDoc.createElement("value");
Object value = dmpProperties.get(fieldModel.getId().toString());
if (value != null) {
extraFieldValue.setTextContent((String) value);
}
extraField.appendChild(extraFieldId);
extraField.appendChild(extraFieldLabel);
extraField.appendChild(extraFieldValue);
extraFields.appendChild(extraField);
}
});
});
dmpElement.appendChild(extraFields);
Element datasetsElement = xmlDoc.createElement("datasets");
for (Dataset dataset : datasets) {
Element datasetElement = xmlDoc.createElement("dataset");
datasetElement.setAttribute("name", dataset.getLabel());
@ -1840,6 +1866,10 @@ public class DataManagementPlanManager {
datasetElement.appendChild(datasetDescriptionElement);
datasetDescriptionElement.setTextContent(dataset.getDescription());
Element datasetDmpSectionIndex = xmlDoc.createElement("dmpSectionIndex");
datasetElement.appendChild(datasetDmpSectionIndex);
datasetDmpSectionIndex.setTextContent(String.valueOf(dataset.getDmpSectionIndex()));
Element datsetProfileElement = xmlDoc.createElement("profile-id");
datasetElement.appendChild(datsetProfileElement);
datsetProfileElement.setTextContent(dataset.getProfile().getId().toString());
@ -1860,8 +1890,8 @@ public class DataManagementPlanManager {
datasetElement.appendChild(xmlBuilder.createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc));
datasetsElement.appendChild(datasetElement);
}
Element profiles = xmlDoc.createElement("profiles");
Element profiles = xmlDoc.createElement("profiles");
// Get DatasetProfiles from DMP to add to XML.
for (DMPDatasetProfile dmpDescriptionProfile : dmp.getAssociatedDmps()) {
DescriptionTemplate descriptionTemplate = dmpDescriptionProfile.getDatasetprofile();
@ -1878,6 +1908,15 @@ public class DataManagementPlanManager {
Element profileVersion = xmlDoc.createElement("profileVersion");
profileVersion.setTextContent(String.valueOf(descriptionTemplate.getVersion()));
profile.appendChild(profileVersion);
Element profileInSections = xmlDoc.createElement("profileInSections");
Map<String, Object> data = new ObjectMapper().readValue(dmpDescriptionProfile.getData(), new TypeReference<Map<String, Object>>() {});
List<Integer> sections = (List<Integer>) data.get("dmpSectionIndex");
for(int section: sections) {
Element profileInSection = xmlDoc.createElement("section");
profileInSection.setTextContent(String.valueOf(section));
profileInSections.appendChild(profileInSection);
}
profile.appendChild(profileInSections);
profiles.appendChild(profile);
}
dmpElement.appendChild(profiles);
@ -1988,59 +2027,85 @@ public class DataManagementPlanManager {
// Creates new dataManagementPlan to fill it with the data model that was parsed from the xml.
// Creates properties.
DataManagementPlanEditorModel dm = new DataManagementPlanEditorModel();
// DataManagementPlanProfile dmpProfile = new DataManagementPlanProfile();
//
// List<Field> fieldList = new LinkedList<>();
// Field field = new Field();
// field.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());
// field.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
//
// fieldList.add(field);
// dmpProfile.setFields(fieldList);
/*Tuple tuple = new Tuple();
tuple.setId(dataManagementPlans.get(0).getDmpProfile().getDmpProfileId());
tuple.setLabel(dataManagementPlans.get(0).getDmpProfile().getDmpProfileName());*/
eu.eudat.models.data.funder.Funder funder = new eu.eudat.models.data.funder.Funder();
FunderImportModels funderImport = dataManagementPlans.get(0).getFunderImportModels();
funder.setId(funderImport.getId());
funder.setLabel(funderImport.getLabel());
FunderDMPEditorModel funderEditor = new FunderDMPEditorModel();
funderEditor.setExistFunder(funder);
DmpProfileImportModel dmpProfileImportModel = dataManagementPlans.get(0).getDmpProfile();
Tuple<UUID, String> tupleProfile = new Tuple<>();
if (dmpProfileImportModel != null) {
tupleProfile.setId(dmpProfileImportModel.getDmpProfileId());
tupleProfile.setLabel(dmpProfileImportModel.getDmpProfileName());
}
else {
tupleProfile.setId(UUID.fromString("86635178-36a6-484f-9057-a934e4eeecd5"));
tupleProfile.setLabel("Dmp Default Blueprint");
}
dm.setProfile(tupleProfile);
eu.eudat.models.data.grant.Grant grant = new eu.eudat.models.data.grant.Grant();
GrantImportModels grantImport = dataManagementPlans.get(0).getGrantImport();
grant.setId(grantImport.getId());
grant.setLabel(grantImport.getLabel());
grant.setAbbreviation(grantImport.getAbbreviation());
grant.setDescription(grantImport.getDescription());
GrantDMPEditorModel grantEditor = new GrantDMPEditorModel();
grantEditor.setExistGrant(grant);
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImportModels();
project.setId(projectImport.getId());
project.setLabel(projectImport.getLabel());
ProjectDMPEditorModel projectEditor = new ProjectDMPEditorModel();
projectEditor.setExistProject(project);
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
if (profiles != null && profiles.length > 0) {
for (String profile : profiles) {
DescriptionTemplate exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(profile));
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile);
associatedProfiles.add(associatedProfile);
Map<String, Object> dmpPropertiesMap = new HashMap<>();
if (dataManagementPlans.get(0).getExtraFieldsImportModels() != null) {
for (ExtraFieldsImportModels extraField: dataManagementPlans.get(0).getExtraFieldsImportModels()) {
dmpPropertiesMap.put(extraField.getId(), extraField.getValue());
}
}
dm.setProperties(dmpPropertiesMap);
if (this.dataManagementProfileManager.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId().toString(), SystemFieldType.FUNDER, principal)) {
eu.eudat.models.data.funder.Funder funder = new eu.eudat.models.data.funder.Funder();
FunderImportModels funderImport = dataManagementPlans.get(0).getFunderImportModels();
funder.setId(funderImport.getId());
funder.setLabel(funderImport.getLabel());
FunderDMPEditorModel funderEditor = new FunderDMPEditorModel();
funderEditor.setExistFunder(funder);
dm.setFunder(funderEditor);
}
if (this.dataManagementProfileManager.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId().toString(), SystemFieldType.GRANT, principal)) {
eu.eudat.models.data.grant.Grant grant = new eu.eudat.models.data.grant.Grant();
GrantImportModels grantImport = dataManagementPlans.get(0).getGrantImport();
grant.setId(grantImport.getId());
grant.setLabel(grantImport.getLabel());
grant.setAbbreviation(grantImport.getAbbreviation());
grant.setDescription(grantImport.getDescription());
GrantDMPEditorModel grantEditor = new GrantDMPEditorModel();
grantEditor.setExistGrant(grant);
dm.setGrant(grantEditor);
}
if (this.dataManagementProfileManager.fieldInBlueprint(dmpProfileImportModel.getDmpProfileId().toString(), SystemFieldType.PROJECT, principal)) {
eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project();
ProjectImportModels projectImport = dataManagementPlans.get(0).getProjectImportModels();
project.setId(projectImport.getId());
project.setLabel(projectImport.getLabel());
ProjectDMPEditorModel projectEditor = new ProjectDMPEditorModel();
projectEditor.setExistProject(project);
dm.setProject(projectEditor);
}
List<eu.eudat.models.data.dmp.AssociatedProfile> associatedProfiles = new LinkedList<>();
// if (profiles != null && profiles.length > 0) {
// for (String profile : profiles) {
// DescriptionTemplate exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(profile));
// AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile);
// associatedProfiles.add(associatedProfile);
// }
// }
for (AssociatedProfileImportModels a : dataManagementPlans.get(0).getProfilesImportModels()) {
try {
DescriptionTemplate exProfile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(a.getId());
AssociatedProfile associatedProfile = new AssociatedProfile().fromData(exProfile);
Map<String, Object> data = new HashMap<>();
List<Integer> sections = new ArrayList<>(a.getSection());
data.put("dmpSectionIndex", sections);
associatedProfile.setData(data);
associatedProfiles.add(associatedProfile);
} catch (Exception ignored) {
}
}
List<eu.eudat.models.data.dmp.Organisation> organisations = new ArrayList<>();
for (OrganisationImportModel org : dataManagementPlans.get(0).getOrganisationImportModels()) {
eu.eudat.models.data.dmp.Organisation organisation = new eu.eudat.models.data.dmp.Organisation();
@ -2049,6 +2114,7 @@ public class DataManagementPlanManager {
organisation.setKey(organisation.getReference().split(":")[0]);
organisations.add(organisation);
}
List<eu.eudat.models.data.dmp.Researcher> researchers = new LinkedList<>();
for (ResearcherImportModels res : dataManagementPlans.get(0).getResearchersImportModels()) {
eu.eudat.models.data.dmp.Researcher researcher = new eu.eudat.models.data.dmp.Researcher();
@ -2064,9 +2130,6 @@ public class DataManagementPlanManager {
// Sets properties.
dm.setLabel(files[0].getOriginalFilename()); // Sets label.
dm.setGrant(grantEditor); //Sets grant property.
dm.setFunder(funderEditor);
dm.setProject(projectEditor);
dm.setDescription(dataManagementPlans.get(0).getDescriptionImport()); // Sets description property.
dm.setProfiles(associatedProfiles);
dm.setOrganisations(organisations); // Sets organisations property.
@ -2112,6 +2175,7 @@ public class DataManagementPlanManager {
for (DatasetImportModels das: dataManagementPlans.get(0).getDatasetImportModels()) {
eu.eudat.data.entities.Dataset dataset = new eu.eudat.data.entities.Dataset();
dataset.setLabel(das.getName());
dataset.setDmpSectionIndex(das.getDmpSectionIndex());
try {
dataset.setProfile(databaseRepository.getDatasetProfileDao().find(das.getProfile()));
} catch (Exception ignored) {

View File

@ -108,6 +108,11 @@ public class DataManagementProfileManager {
return dataManagementPlanBlueprintListingModel;
}
public boolean fieldInBlueprint(String id, SystemFieldType type, Principal principal) {
DMPProfile dmpProfile = databaseRepository.getDmpProfileDao().find(UUID.fromString(id));
return this.fieldInBlueprint(dmpProfile, type, principal);
}
public boolean fieldInBlueprint(DMPProfile dmpProfile, SystemFieldType type, Principal principal) {
DataManagementPlanBlueprintListingModel dmpBlueprint = new DataManagementPlanBlueprintListingModel();
dmpBlueprint.fromDataModel(dmpProfile);

View File

@ -1,13 +1,16 @@
package eu.eudat.models.data.dmp;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "profile")
public class AssociatedProfileImportModels {
private UUID id;
private String label;
private List<Integer> section;
@XmlElement(name = "profileId")
public UUID getId() { return id; }
@ -16,4 +19,13 @@ public class AssociatedProfileImportModels {
@XmlElement(name = "profilelabel")
public String getLabel() { return label; }
public void setLabel(String label) { this.label = label; }
@XmlElementWrapper(name="profileInSections")
@XmlElement(name = "section")
public List<Integer> getSection() {
return section;
}
public void setSection(List<Integer> section) {
this.section = section;
}
}

View File

@ -17,6 +17,7 @@ public class DatasetImportModels {
private String name;
private UUID profile;
private int dmpSectionIndex;
private HashMap<String, String> fieldImportModels;
@XmlAttribute(name ="name")
@ -27,6 +28,7 @@ public class DatasetImportModels {
this.name = name;
}
@XmlElement(name = "profile-id")
public UUID getProfile() {
return profile;
}
@ -34,6 +36,14 @@ public class DatasetImportModels {
this.profile = profile;
}
@XmlElement(name = "dmpSectionIndex")
public int getDmpSectionIndex() {
return dmpSectionIndex;
}
public void setDmpSectionIndex(int dmpSectionIndex) {
this.dmpSectionIndex = dmpSectionIndex;
}
@XmlJavaTypeAdapter(PageAdapter.class)
@XmlElement(name = "pages")
public HashMap<String, String> getFieldImportModels() {

View File

@ -17,6 +17,7 @@ public class DmpImportModel {
private List<OrganisationImportModel> organisationImportModels;
private List<ResearcherImportModels> researchersImportModels;
private List<UserInfoImportModels> associatedUsersImportModels;
private List<ExtraFieldsImportModels> extraFieldsImportModels;
private List<DynamicFieldWithValueImportModels> dynamicFieldsImportModels;
private List<DatasetImportModels> datasetImportModels;
private String language;
@ -104,6 +105,15 @@ public class DmpImportModel {
this.associatedUsersImportModels = associatedUsersImportModels;
}
@XmlElementWrapper(name="extraFields")
@XmlElement(name = "extraField")
public List<ExtraFieldsImportModels> getExtraFieldsImportModels() {
return extraFieldsImportModels;
}
public void setExtraFieldsImportModels(List<ExtraFieldsImportModels> extraFieldsImportModels) {
this.extraFieldsImportModels = extraFieldsImportModels;
}
@XmlElementWrapper(name="dynamicFieldWithValues")
@XmlElement(name = "dynamicFieldWithValue")
public List<DynamicFieldWithValueImportModels> getDynamicFieldsImportModels() {

View File

@ -0,0 +1,36 @@
package eu.eudat.models.data.dmp;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "extraField")
public class ExtraFieldsImportModels {
private String id;
private String label;
private String value;
@XmlElement(name = "id")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@XmlElement(name = "label")
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@XmlElement(name = "value")
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}