From 30c669cb8ca5fa3db804aae40c7489c1bdbea053 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Fri, 14 Jan 2022 18:17:32 +0200 Subject: [PATCH] Update Depedencies --- dmp-backend/pom.xml | 53 +- .../controllers/DatasetProfileController.java | 4 - .../controllers/UserInvitationController.java | 1 - .../managers/DataManagementPlanManager.java | 30 +- .../eudat/logic/managers/DatasetManager.java | 62 +-- .../eu/eudat/logic/managers/UserManager.java | 3 +- .../PrefillingConfigMapAdapter.java | 1 - .../B2Access/B2AccessCustomProviderImpl.java | 2 +- .../google/GoogleTokenValidator.java | 4 +- .../eu/eudat/logic/services/ApiContext.java | 3 + .../eudat/logic/services/ApiContextImpl.java | 7 + .../AbstractAuthenticationService.java | 44 +- .../VerifiedUserAuthenticationService.java | 12 +- .../documents/xml/ExportXmlBuilder.java | 3 - .../models/data/dmp/DataManagementPlan.java | 222 ++++---- .../dmp/DataManagementPlanEditorModel.java | 98 ++-- .../data/rda/ContactRDAExportModel.java | 44 -- .../DatasetDistributionRDAExportModel.java | 93 ---- .../rda/DatasetMetadataRDAExportModel.java | 47 -- .../data/rda/DatasetRDAExportModel.java | 474 ------------------ ...tasetSecurityAndPrivacyRDAExportModel.java | 29 -- ...atasetTechnicalResourceRDAExportModel.java | 28 -- .../rda/DmpContributorRDAExportModel.java | 52 -- .../data/rda/DmpCostRDAExportModel.java | 36 -- .../models/data/rda/DmpRDAExportModel.java | 164 ------ .../data/rda/FundingRDAExportModel.java | 43 -- .../models/data/rda/HostRDAExportModel.java | 86 ---- .../models/data/rda/IdRDAExportModel.java | 25 - .../data/rda/LicenseRDAExportModel.java | 20 - .../data/rda/ProjectRDAExportModel.java | 54 -- .../eudat/models/data/rda/RDAExportModel.java | 25 - .../eu/eudat/models/data/rda/RdaField.java | 36 -- .../user/components/datasetprofile/Field.java | 5 +- .../models/rda/mapper/CostRDAMapper.java | 19 +- .../models/rda/mapper/DatasetRDAMapper.java | 4 +- .../eudat/models/rda/mapper/DmpRDAMapper.java | 22 +- 36 files changed, 312 insertions(+), 1543 deletions(-) delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ContactRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetDistributionRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpContributorRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpCostRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/FundingRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/HostRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/IdRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/LicenseRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ProjectRDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java delete mode 100644 dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 16f74c1c1..32dc92fa8 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -27,7 +27,7 @@ 1.8 0.0.1-SNAPSHOT - 5.3.8 + 5.3.14 5.3.10.RELEASE @@ -36,27 +36,27 @@ --> - 5.5.3.Final + 5.6.3.Final 1.9 4.11 1.2.17 - 2.15.0 + 2.17.0 1.7.12 - 1.2.3 + 1.2.10 - + org.springframework spring-context-support @@ -91,19 +91,18 @@ org.apache.httpcomponents httpclient - 4.5.12 org.apache.httpcomponents httpcore-nio - 4.4.13 + 4.4.15 org.apache.httpcomponents httpcore - 4.4.13 + 4.4.15 @@ -127,13 +126,13 @@ com.google.api-client google-api-client - 1.23.0 + 1.33.0 com.jayway.jsonpath json-path - 2.4.0 + 2.6.0 @@ -141,7 +140,7 @@ com.fasterxml.jackson.dataformat jackson-dataformat-xml - 2.12.3 + 2.13.1 @@ -149,13 +148,13 @@ com.fasterxml.jackson.core jackson-core - 2.12.3 + 2.13.1 com.fasterxml.jackson.core jackson-databind - 2.12.3 + 2.13.1 @@ -167,26 +166,25 @@ org.apache.commons commons-lang3 - 3.5 org.apache.poi poi-ooxml - 4.0.0 + 5.0.0 org.apache.poi poi - 4.0.0 + 5.0.0 org.apache.xmlgraphics fop - 2.3 + 2.6 @@ -210,13 +208,13 @@ fr.opensagres.xdocreport fr.opensagres.xdocreport.itext.extension - 2.0.1 + 2.0.2 commons-io commons-io - 2.1 + 2.11.0 org.glassfish.jaxb jaxb-runtime - 2.3.1 + 3.0.1 @@ -262,7 +260,6 @@ javax.annotation javax.annotation-api - 1.3.1 @@ -277,32 +274,32 @@ io.prometheus simpleclient - 0.11.0 + 0.14.1 io.prometheus simpleclient_hotspot - 0.11.0 + 0.14.1 io.prometheus simpleclient_httpserver - 0.11.0 + 0.14.1 io.prometheus simpleclient_pushgateway - 0.11.0 + 0.14.1 io.micrometer micrometer-registry-prometheus - 1.7.1 + 1.8.1 org.springframework.boot diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java index 5f16cb390..a7e059ffc 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java @@ -9,9 +9,7 @@ import eu.eudat.models.data.components.commons.datafield.AutoCompleteData; import eu.eudat.models.data.externaldataset.ExternalAutocompleteFieldModel; import eu.eudat.models.data.helpers.common.AutoCompleteLookupItem; import eu.eudat.models.data.helpers.responses.ResponseItem; -import eu.eudat.models.data.properties.PropertiesModel; import eu.eudat.models.data.security.Principal; -import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -19,9 +17,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.xml.xpath.XPathExpressionException; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.UUID; import static eu.eudat.types.Authorities.ADMIN; diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java index d9633d312..3838fee4a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java @@ -52,7 +52,6 @@ public class UserInvitationController extends BaseController { public @ResponseBody // ResponseEntity>> getUsers(Principal principal) throws IllegalAccessException, InstantiationException { ResponseEntity>> getUsers(Principal principal, @RequestBody UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException { - System.out.println(userInfoRequestItem.getCriteria().getLike()); // List users = invitationsManager.getUsers(principal); List users = invitationsManager.getUsersWithCriteria(principal, userInfoRequestItem); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index b8c4ccf0d..56cb7fe42 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -1,7 +1,6 @@ package eu.eudat.logic.managers; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.configurations.dynamicgrant.DynamicGrantConfiguration; import eu.eudat.configurations.dynamicgrant.entities.Property; @@ -64,7 +63,6 @@ import eu.eudat.types.MetricNames; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -299,15 +297,21 @@ public class DataManagementPlanManager { .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED) && !dataset.getStatus().equals(Dataset.Status.CANCELED)) .forEach(dataset -> { dataManagementPlan.getDatasets().stream().filter(datasetWizardModel -> datasetWizardModel.getId().equals(dataset.getId())).forEach(datasetWizardModel -> { - DatasetWizardModel wizardModel = datasetManager.getSingle(datasetWizardModel.getId().toString(), principal); - datasetWizardModel.setDatasetProfileDefinition(wizardModel.getDatasetProfileDefinition()); - datasetWizardModel.setTags(wizardModel.getTags()); + DatasetWizardModel wizardModel; + try { + wizardModel = datasetManager.getSingle(datasetWizardModel.getId().toString(), principal); + datasetWizardModel.setDatasetProfileDefinition(wizardModel.getDatasetProfileDefinition()); + datasetWizardModel.setTags(wizardModel.getTags()); + } catch (JsonProcessingException e) { + logger.error(e.getLocalizedMessage(), e); + } + }); }); if (isPublic) { dataManagementPlan.setDatasets(dataManagementPlan.getDatasets().stream().filter(dataset -> dataset.getStatus() == Dataset.Status.FINALISED.getValue()).collect(Collectors.toList())); } - Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? new org.json.JSONObject(dataManagementPlanEntity.getDmpProperties()).toMap() : null; + Map dmpProperties = dataManagementPlanEntity.getDmpProperties() != null ? apiContext.getObjectMapper().readValue(dataManagementPlanEntity.getDmpProperties(), HashMap.class) : null; if (dmpProperties != null && dataManagementPlan.getDynamicFields() != null) dataManagementPlan.getDynamicFields().forEach(item -> { @@ -1305,10 +1309,11 @@ public class DataManagementPlanManager { datasetDescriptionRun.setBold(true); datasetDescriptionRun.setFontSize(12); - PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity); - visibilityRuleService.setProperties(properties); - visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); + PagedDatasetProfile pagedDatasetProfile = null; try { + pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity); + visibilityRuleService.setProperties(properties); + visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); } catch (IOException e) { logger.error(e.getMessage(), e); @@ -1456,8 +1461,7 @@ public class DataManagementPlanManager { DatasetWizardModel datasetWizardModel = new DatasetWizardModel(); Map properties = new HashMap<>(); if (dataset.getProperties() != null) { - JSONObject jobject = new JSONObject(dataset.getProperties()); - properties = jobject.toMap(); + properties = apiContext.getObjectMapper().readValue(dataset.getProperties(), HashMap.class); } PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(datasetWizardModel, dataset); visibilityRuleService.setProperties(properties); @@ -2017,7 +2021,7 @@ public class DataManagementPlanManager { headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_JSON); String createData = null; - Map extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>(); + Map extraProperties = dmp.getExtraProperties() != null ? apiContext.getObjectMapper().readValue(dmp.getExtraProperties(), HashMap.class) : new HashMap<>(); StringBuilder dataBuilder = new StringBuilder(); dataBuilder.append("{\n \"metadata\": {\n"); dataBuilder.append( " \"title\": \"").append(dmp.getLabel()).append("\",\n"); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 4cb98b59b..c578db0e5 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -1,5 +1,6 @@ package eu.eudat.logic.managers; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.data.dao.criteria.*; @@ -49,22 +50,19 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.queryable.QueryableList; import eu.eudat.types.Authorities; import eu.eudat.types.MetricNames; -import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; -import org.json.JSONArray; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; -import org.springframework.core.io.FileSystemResource; -import org.springframework.http.*; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -91,8 +89,6 @@ import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; @Component public class DatasetManager { @@ -279,7 +275,7 @@ public class DatasetManager { return dataTable; } - public DatasetWizardModel getSingle(String id, Principal principal) { + public DatasetWizardModel getSingle(String id, Principal principal) throws JsonProcessingException { DatasetWizardModel dataset = new DatasetWizardModel(); eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); if (datasetEntity.getDmp().getUsers() @@ -380,12 +376,11 @@ public class DatasetManager { return databaseRepository.getDatasetDao().find(id); } - public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) { + public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) throws JsonProcessingException { eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile()); datasetprofile.setStatus(dataset.getStatus()); if (datasetEntity.getProperties() != null) { - JSONObject jObject = new JSONObject(datasetEntity.getProperties()); - Map properties = jObject.toMap(); + Map properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class); datasetprofile.fromJsonObject(properties); } PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); @@ -451,8 +446,7 @@ public class DatasetManager { Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { - JSONObject jObject = new JSONObject(datasetEntity.getProperties()); - properties = jObject.toMap(); + properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class); } wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO); @@ -484,8 +478,7 @@ public class DatasetManager { Map properties = new HashMap<>(); if (dataset.getDatasetProfileDefinition() != null) { - JSONObject jObject = new JSONObject(propertiesModelToString(dataset.getDatasetProfileDefinition())); - properties = jObject.toMap(); + properties = apiContext.getObjectMapper().readValue(propertiesModelToString(dataset.getDatasetProfileDefinition()), HashMap.class); } wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER2, BigInteger.ZERO); @@ -542,8 +535,7 @@ public class DatasetManager { throw new UnauthorisedException(); Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { - JSONObject jobject = new JSONObject(datasetEntity.getProperties()); - properties = jobject.toMap(); + properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class); } PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity); visibilityRuleService.setProperties(properties); @@ -656,9 +648,9 @@ public class DatasetManager { nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); - JSONObject obj = new JSONObject(dataset.getProperties()); + Map obj = apiContext.getObjectMapper().readValue(dataset.getProperties(), HashMap.class); VisibilityRuleService visibilityRuleService = this.apiContext.getUtilitiesService().getVisibilityRuleService(); - visibilityRuleService.setProperties(obj.toMap()); + visibilityRuleService.setProperties(obj); dataset.setProfile(profile); PagedDatasetProfile pagedDatasetProfile = this.getPagedProfile(new DatasetWizardModel(), dataset); @@ -666,7 +658,7 @@ public class DatasetManager { for (String validator : datasetProfileValidators) { - if ((obj.has(validator) && (obj.getString(validator) == null || obj.getString(validator).trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) { + if ((obj.containsKey(validator) && (obj.get(validator) == null || obj.get(validator).toString().trim().isEmpty())) && isElementVisible(nodeList, validator, visibilityRuleService)) { throw new Exception("Field value of " + validator + " must be filled."); } } @@ -695,11 +687,10 @@ public class DatasetManager { } } - private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) { + private String propertiesModelToString(PagedDatasetProfile pagedDatasetProfile) throws JsonProcessingException { Map values = new LinkedHashMap<>(); pagedDatasetProfile.toMap(values); - JSONObject jobject = new JSONObject(values); - return jobject.toString(); + return apiContext.getObjectMapper().writeValueAsString(values); } public void updateTags(Dataset datasetEntity, List tags) throws Exception { @@ -908,12 +899,9 @@ public class DatasetManager { ))))) .collect(Collectors.toMap(DatasetImportField::getId, DatasetImportField::getValue)); - // Transforms map into json file. - JSONObject jsonDatasetProperties = new JSONObject(importMap); - // Creates the entity data set to save. eu.eudat.data.entities.Dataset entity = new Dataset(); - entity.setProperties(jsonDatasetProperties.toString()); + entity.setProperties(apiContext.getObjectMapper().writeValueAsString(importMap)); entity.setLabel(importFile.getOriginalFilename()); DMP dmp = new DMP(); dmp.setId(UUID.fromString(dmpId)); @@ -942,7 +930,7 @@ public class DatasetManager { // TODO: When tags functionality return. } - public DatasetWizardModel datasetUpdateProfile(String id) { + public DatasetWizardModel datasetUpdateProfile(String id) throws JsonProcessingException { DatasetWizardModel dataset = new DatasetWizardModel(); eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); eu.eudat.elastic.entities.Dataset datasetElastic; @@ -982,12 +970,11 @@ public class DatasetManager { return dataset; } - public PagedDatasetProfile getLatestDatasetProfile(Dataset datasetEntity, DatasetProfile profile) { + public PagedDatasetProfile getLatestDatasetProfile(Dataset datasetEntity, DatasetProfile profile) throws JsonProcessingException { eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(profile); datasetprofile.setStatus(datasetEntity.getStatus()); if (datasetEntity.getProperties() != null) { - JSONObject jobject = new JSONObject(datasetEntity.getProperties()); - Map properties = jobject.toMap(); + Map properties = apiContext.getObjectMapper().readValue(datasetEntity.getProperties(), HashMap.class); datasetprofile.fromJsonObject(properties); } PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); @@ -1053,10 +1040,15 @@ public class DatasetManager { JsonNode value = node.get("value"); if (!value.toString().equals("\"\"")) { String stringValue = value.toString().replaceAll("=", ":"); - JSONArray values = new JSONArray(stringValue); + List> values = null; + try { + values = apiContext.getObjectMapper().readValue(stringValue, LinkedList.class); + } catch (JsonProcessingException e) { + logger.error(e.getLocalizedMessage(), e); + } if (values != null) { values.iterator().forEachRemaining(element -> { - Map data = ((JSONObject) element).toMap(); + Map data = element; this.addTag(tags, wizardModel.getTags(), data.get("id").toString(), data.get("name").toString()); }); } else { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java index e7b00d0e6..40e5cc6c6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java @@ -33,7 +33,6 @@ import eu.eudat.models.data.userinfo.UserProfile; import eu.eudat.queryable.QueryableList; import eu.eudat.types.Authorities; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -133,7 +132,7 @@ public class UserManager { userInfo.setName(settings.entrySet().stream().filter(entry -> entry.getKey().equals("name")).filter(Objects::nonNull).map(entry -> entry.getValue().toString()).findFirst().orElse(userInfo.getName())); settings.remove("name"); result.putAll(settings); - userInfo.setAdditionalinfo(new JSONObject(result).toString()); + userInfo.setAdditionalinfo(new ObjectMapper().writeValueAsString(result)); apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao() .createOrUpdate(userInfo); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/prefilling/PrefillingConfigMapAdapter.java b/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/prefilling/PrefillingConfigMapAdapter.java index 927587d18..6aa9a096b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/prefilling/PrefillingConfigMapAdapter.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/proxy/config/prefilling/PrefillingConfigMapAdapter.java @@ -23,7 +23,6 @@ public class PrefillingConfigMapAdapter extends XmlAdapter additionalInfo = userInfo.getAdditionalinfo() != null ? - new JSONObject(userInfo.getAdditionalinfo()).toMap() : new HashMap<>(); - if (profile.getAvatarUrl() != null && !profile.getAvatarUrl().isEmpty() && !profile.getAvatarUrl().equals("null")) { - additionalInfo.put("avatarUrl", profile.getAvatarUrl()); + Map additionalInfo = null; + try { + additionalInfo = userInfo.getAdditionalinfo() != null ? + apiContext.getObjectMapper().readValue(userInfo.getAdditionalinfo(), HashMap.class) : new HashMap<>(); + if (profile.getAvatarUrl() != null && !profile.getAvatarUrl().isEmpty() && !profile.getAvatarUrl().equals("null")) { + additionalInfo.put("avatarUrl", profile.getAvatarUrl()); + } + if (profile.getZenodoId() != null && !profile.getZenodoId().isEmpty() && !profile.getZenodoId().equals("null")) { + additionalInfo.put("zenodoToken", profile.getZenodoId()); + } + if (profile.getZenodoExpire() != null) { + additionalInfo.put("expirationDate", Instant.now().plusSeconds(profile.getZenodoExpire()).toEpochMilli()); + } + if (profile.getZenodoRefresh() != null) { + additionalInfo.put("zenodoRefresh", profile.getZenodoRefresh()); + } + if (profile.getProvider() == TokenValidatorFactoryImpl.LoginProvider.ZENODO) { + additionalInfo.put("zenodoEmail", profile.getEmail()); + } + userInfo.setLastloggedin(new Date()); + userInfo.setAdditionalinfo(apiContext.getObjectMapper().writeValueAsString(additionalInfo)); + } catch (JsonProcessingException e) { + logger.error(e.getLocalizedMessage(), e); } - if (profile.getZenodoId() != null && !profile.getZenodoId().isEmpty() && !profile.getZenodoId().equals("null")) { - additionalInfo.put("zenodoToken", profile.getZenodoId()); - } - if (profile.getZenodoExpire() != null) { - additionalInfo.put("expirationDate", Instant.now().plusSeconds(profile.getZenodoExpire()).toEpochMilli()); - } - if (profile.getZenodoRefresh() != null) { - additionalInfo.put("zenodoRefresh", profile.getZenodoRefresh()); - } - if (profile.getProvider() == TokenValidatorFactoryImpl.LoginProvider.ZENODO) { - additionalInfo.put("zenodoEmail", profile.getEmail()); - } - userInfo.setLastloggedin(new Date()); - userInfo.setAdditionalinfo(new JSONObject(additionalInfo).toString()); + Set credentials = userInfo.getCredentials(); if (credentials.contains(credential)) { Credential oldCredential = credentials.stream().filter(item -> credential.getProvider().equals(item.getProvider())).findFirst().get(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/authentication/VerifiedUserAuthenticationService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/authentication/VerifiedUserAuthenticationService.java index dfaca0d7a..88ca0dc20 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/authentication/VerifiedUserAuthenticationService.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/operations/authentication/VerifiedUserAuthenticationService.java @@ -1,27 +1,21 @@ package eu.eudat.logic.services.operations.authentication; import com.fasterxml.jackson.databind.ObjectMapper; -import eu.eudat.data.entities.Credential; import eu.eudat.data.entities.UserInfo; import eu.eudat.data.entities.UserRole; import eu.eudat.data.entities.UserToken; import eu.eudat.exceptions.security.NullEmailException; -import eu.eudat.logic.builders.entity.CredentialBuilder; -import eu.eudat.logic.builders.entity.UserInfoBuilder; -import eu.eudat.logic.builders.entity.UserTokenBuilder; import eu.eudat.logic.builders.model.models.PrincipalBuilder; -import eu.eudat.logic.security.validators.TokenValidatorFactoryImpl; import eu.eudat.logic.services.ApiContext; -import eu.eudat.models.data.login.Credentials; -import eu.eudat.models.data.loginprovider.LoginProviderUser; import eu.eudat.models.data.security.Principal; import eu.eudat.types.Authorities; -import org.json.JSONObject; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import java.time.Instant; -import java.util.*; +import java.util.Date; +import java.util.HashSet; +import java.util.List; @Service("verifiedUserAuthenticationService") diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java index 9c8a591b4..a435b62d2 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java @@ -1,7 +1,6 @@ package eu.eudat.logic.utilities.documents.xml; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.exc.MismatchedInputException; import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.models.data.components.commons.datafield.ExternalDatasetsData; @@ -10,8 +9,6 @@ import eu.eudat.models.data.user.components.datasetprofile.FieldSet; import eu.eudat.models.data.user.components.datasetprofile.Section; import eu.eudat.models.data.user.composite.DatasetProfilePage; import eu.eudat.models.data.user.composite.PagedDatasetProfile; -import org.json.JSONArray; -import org.json.JSONException; import org.springframework.core.env.Environment; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java index cc2dcd4fb..ca5bdcba6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlan.java @@ -1,5 +1,7 @@ package eu.eudat.models.data.dmp; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.data.entities.*; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.models.DataModel; @@ -7,18 +9,20 @@ import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue; import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile; import eu.eudat.models.data.funder.Funder; -import eu.eudat.models.data.helpermodels.Tuple; -import eu.eudat.models.data.listingmodels.DatasetListingModel; -import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.grant.Grant; +import eu.eudat.models.data.helpermodels.Tuple; +import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.project.Project; import eu.eudat.models.data.userinfo.UserListingModel; import net.minidev.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; import java.util.stream.Collectors; public class DataManagementPlan implements DataModel { + private static final Logger logger = LoggerFactory.getLogger(DataManagementPlan.class); private UUID id; private String label; private UUID groupId; @@ -233,67 +237,72 @@ public class DataManagementPlan implements DataModel { @Override public DataManagementPlan fromDataModel(DMP entity) { - this.id = entity.getId(); - this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; - this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); - this.version = entity.getVersion(); - this.groupId = this.groupId == null ? null : entity.getGroupId(); - this.label = entity.getLabel(); - this.grant = new Grant(); - this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; - this.grant.fromDataModel(entity.getGrant()); - this.creator = new eu.eudat.models.data.userinfo.UserInfo(); - this.groupId = entity.getGroupId(); - this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); - this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement()); - if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) { - this.definition.getFields().forEach(item -> { - Optional> fieldOptional = ((List>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst(); - if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value")); - }); - } - if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) - this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.profiles = new LinkedList<>(); - for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); - this.profiles.add(associatedProfile); + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.id = entity.getId(); + this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; + this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); + this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); + this.version = entity.getVersion(); + this.groupId = this.groupId == null ? null : entity.getGroupId(); + this.label = entity.getLabel(); + this.grant = new Grant(); + this.properties = entity.getProperties() != null ? objectMapper.readValue(entity.getProperties(), HashMap.class) : null; + this.grant.fromDataModel(entity.getGrant()); + this.creator = new eu.eudat.models.data.userinfo.UserInfo(); + this.groupId = entity.getGroupId(); + this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); + this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement()); + if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) { + this.definition.getFields().forEach(item -> { + Optional> fieldOptional = ((List>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst(); + if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value")); + }); } - } - if (entity.getDataset() != null) { - if (entity.isPublic()) { - this.datasets = entity.getDataset().stream() - .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()) && !dataset.getStatus().equals(Dataset.Status.SAVED.getValue())) - .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); - } else { - this.datasets = entity.getDataset().stream() - .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())) - .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); + if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) + this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); + + if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { + this.profiles = new LinkedList<>(); + for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { + AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); + this.profiles.add(associatedProfile); + } } - } - this.modified = entity.getModified(); - this.created = entity.getCreated(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); - this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.doi = entity.getDoi(); + if (entity.getDataset() != null) { + if (entity.isPublic()) { + this.datasets = entity.getDataset().stream() + .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue()) && !dataset.getStatus().equals(Dataset.Status.SAVED.getValue())) + .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); + } else { + this.datasets = entity.getDataset().stream() + .filter(dataset -> !dataset.getStatus().equals(Dataset.Status.DELETED.getValue()) && !dataset.getStatus().equals(Dataset.Status.CANCELED.getValue())) + .map(x -> new DatasetWizardModel().fromDataModelNoDmp(x)).collect(Collectors.toList()); + } + } + this.modified = entity.getModified(); + this.created = entity.getCreated(); + this.description = entity.getDescription(); + this.status = entity.getStatus(); + this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); + this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); + this.doi = entity.getDoi(); - if (entity.getProject() != null) { - this.project = new Project(); - this.project = new Project().fromDataModel(entity.getProject()); - } + if (entity.getProject() != null) { + this.project = new Project(); + this.project = new Project().fromDataModel(entity.getProject()); + } - if (entity.getGrant().getFunder() != null) { - this.funder = new Funder(); - this.funder.fromDataModel(entity.getGrant().getFunder()); - } - this.isPublic = entity.isPublic(); + if (entity.getGrant().getFunder() != null) { + this.funder = new Funder(); + this.funder.fromDataModel(entity.getGrant().getFunder()); + } + this.isPublic = entity.isPublic(); - this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; + this.extraProperties = entity.getExtraProperties() != null ? objectMapper.readValue(entity.getExtraProperties(), HashMap.class) : null; + } catch (JsonProcessingException e) { + logger.error(e.getMessage(), e); + } return this; } @@ -342,54 +351,59 @@ public class DataManagementPlan implements DataModel { } public DataManagementPlan fromDataModelNoDatasets(DMP entity) { - this.id = entity.getId(); - this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; - this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.version = entity.getVersion(); - this.label = entity.getLabel(); - this.grant = new Grant(); - this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; - this.creator = new eu.eudat.models.data.userinfo.UserInfo(); - this.groupId = entity.getGroupId(); - this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); - this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement()); - if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) { - this.definition.getFields().forEach(item -> { - Optional> fieldOptional = ((List>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst(); - fieldOptional.ifPresent(stringObjectMap -> item.setValue(stringObjectMap.get("value"))); - }); - } - if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) - this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.profiles = new LinkedList<>(); - for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); - this.profiles.add(associatedProfile); + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.id = entity.getId(); + this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; + this.organisations = entity.getOrganisations() != null ? entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); + this.researchers = entity.getResearchers() != null ? entity.getResearchers().stream().filter(Objects::nonNull).map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); + this.version = entity.getVersion(); + this.label = entity.getLabel(); + this.grant = new Grant(); + this.properties = entity.getProperties() != null ? objectMapper.readValue(entity.getProperties(), HashMap.class) : null; + this.creator = new eu.eudat.models.data.userinfo.UserInfo(); + this.groupId = entity.getGroupId(); + this.lockable = entity.getDataset() != null && entity.getDataset().stream().findAny().isPresent(); + this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement()); + if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) { + this.definition.getFields().forEach(item -> { + Optional> fieldOptional = ((List>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst(); + fieldOptional.ifPresent(stringObjectMap -> item.setValue(stringObjectMap.get("value"))); + }); } - } - this.modified = entity.getModified(); - this.created = entity.getCreated(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); - this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); - this.doi = entity.getDoi(); - this.grant.fromDataModel(entity.getGrant()); + if (entity.getUsers() != null && entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) + this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - if (entity.getProject() != null) { - this.project = new Project(); - this.project = new Project().fromDataModel(entity.getProject()); - } - if (entity.getGrant().getFunder() != null) { - this.funder = new Funder(); - this.funder.fromDataModel(entity.getGrant().getFunder()); - } - this.isPublic = entity.isPublic(); + if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { + this.profiles = new LinkedList<>(); + for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { + AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); + this.profiles.add(associatedProfile); + } + } + this.modified = entity.getModified(); + this.created = entity.getCreated(); + this.description = entity.getDescription(); + this.status = entity.getStatus(); + this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); + this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); + this.doi = entity.getDoi(); + this.grant.fromDataModel(entity.getGrant()); - this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; + if (entity.getProject() != null) { + this.project = new Project(); + this.project = new Project().fromDataModel(entity.getProject()); + } + if (entity.getGrant().getFunder() != null) { + this.funder = new Funder(); + this.funder.fromDataModel(entity.getGrant().getFunder()); + } + this.isPublic = entity.isPublic(); + + this.extraProperties = entity.getExtraProperties() != null ? objectMapper.readValue(entity.getExtraProperties(), HashMap.class) : null; + } catch (JsonProcessingException e) { + logger.error(e.getMessage(), e); + } return this; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java index 1eca8b81c..a3781c1b1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DataManagementPlanEditorModel.java @@ -1,5 +1,7 @@ package eu.eudat.models.data.dmp; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.data.entities.*; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.models.DataModel; @@ -7,18 +9,20 @@ import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue; import eu.eudat.models.data.entities.xmlmodels.dmpprofiledefinition.DataManagementPlanProfile; import eu.eudat.models.data.funder.FunderDMPEditorModel; -import eu.eudat.models.data.helpermodels.Tuple; -import eu.eudat.models.data.listingmodels.DatasetListingModel; -import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.grant.GrantDMPEditorModel; +import eu.eudat.models.data.helpermodels.Tuple; +import eu.eudat.models.data.listingmodels.UserInfoListingModel; import eu.eudat.models.data.project.ProjectDMPEditorModel; import eu.eudat.models.data.userinfo.UserListingModel; import net.minidev.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; import java.util.stream.Collectors; public class DataManagementPlanEditorModel implements DataModel { + private static final Logger logger = LoggerFactory.getLogger(DataManagementPlan.class); private UUID id; private String label; private UUID groupId; @@ -224,50 +228,54 @@ public class DataManagementPlanEditorModel implements DataModel(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; - this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); - this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); - this.version = entity.getVersion(); - this.groupId = this.groupId == null ? null : entity.getGroupId(); - this.label = entity.getLabel(); - this.grant = new GrantDMPEditorModel(); - this.properties = entity.getProperties() != null ? new org.json.JSONObject(entity.getProperties()).toMap() : null; - this.grant.getExistGrant().fromDataModel(entity.getGrant()); - this.grant.getExistGrant().setSource(""); - this.creator = new eu.eudat.models.data.userinfo.UserInfo(); - this.groupId = entity.getGroupId(); - this.lockable = entity.getDataset().stream().findAny().isPresent(); - this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement()); - if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) { - this.definition.getFields().forEach(item -> { - Optional> fieldOptional = ((List>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst(); - if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value")); - }); - } - if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) - this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - - if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { - this.profiles = new LinkedList<>(); - for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { - AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); - this.profiles.add(associatedProfile); + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.id = entity.getId(); + this.profile = entity.getProfile() != null ? new Tuple(entity.getProfile().getId(), entity.getProfile().getLabel()) : null; + this.organisations = entity.getOrganisations().stream().map(item -> new Organisation().fromDataModel(item)).collect(Collectors.toList()); + this.researchers = entity.getResearchers().stream().map(item -> new Researcher().fromDataModel(item)).collect(Collectors.toList()); + this.version = entity.getVersion(); + this.groupId = this.groupId == null ? null : entity.getGroupId(); + this.label = entity.getLabel(); + this.grant = new GrantDMPEditorModel(); + this.properties = entity.getProperties() != null ? objectMapper.readValue(entity.getProperties(), HashMap.class) : null; + this.grant.getExistGrant().fromDataModel(entity.getGrant()); + this.grant.getExistGrant().setSource(""); + this.creator = new eu.eudat.models.data.userinfo.UserInfo(); + this.groupId = entity.getGroupId(); + this.lockable = entity.getDataset().stream().findAny().isPresent(); + this.definition = entity.getProfile() == null ? null : new DataManagementPlanProfile().fromXml(XmlBuilder.fromXml(entity.getProfile().getDefinition()).getDocumentElement()); + if (this.definition != null && this.definition.getFields() != null && !this.definition.getFields().isEmpty() && this.properties != null) { + this.definition.getFields().forEach(item -> { + Optional> fieldOptional = ((List>) this.properties.get("fields")).stream().filter(field -> field.get("id").equals(item.getId().toString())).findFirst(); + if (fieldOptional.isPresent()) item.setValue(fieldOptional.get().get("value")); + }); } - } - this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList()); - this.modified = entity.getModified(); - this.created = entity.getCreated(); - this.description = entity.getDescription(); - this.status = entity.getStatus(); - this.project = new ProjectDMPEditorModel(); - this.project.getExistProject().fromDataModel(entity.getProject()); - this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()); - this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()); - this.funder = new FunderDMPEditorModel(); - this.funder.getExistFunder().fromDataModel(entity.getGrant().getFunder()); - this.extraProperties = entity.getExtraProperties() != null ? new org.json.JSONObject(entity.getExtraProperties()).toMap() : null; + if (entity.getUsers().stream().anyMatch(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue()))) + this.creator.fromDataModel(entity.getUsers().stream().filter(user -> user.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); + if (entity.getAssociatedDmps() != null && !entity.getAssociatedDmps().isEmpty()) { + this.profiles = new LinkedList<>(); + for (DatasetProfile datasetProfile: entity.getAssociatedDmps()) { + AssociatedProfile associatedProfile = new AssociatedProfile().fromData(datasetProfile); + this.profiles.add(associatedProfile); + } + } + this.datasets = entity.getDataset().stream().map(item -> new DatasetWizardModel().fromDataModelNoDmp(item)).collect(Collectors.toList()); + this.modified = entity.getModified(); + this.created = entity.getCreated(); + this.description = entity.getDescription(); + this.status = entity.getStatus(); + this.project = new ProjectDMPEditorModel(); + this.project.getExistProject().fromDataModel(entity.getProject()); + this.associatedUsers = entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()); + this.users = entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()); + this.funder = new FunderDMPEditorModel(); + this.funder.getExistFunder().fromDataModel(entity.getGrant().getFunder()); + this.extraProperties = entity.getExtraProperties() != null ? objectMapper.readValue(entity.getExtraProperties(), HashMap.class) : null; + } catch (JsonProcessingException e) { + logger.error(e.getMessage(), e); + } return this; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ContactRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ContactRDAExportModel.java deleted file mode 100644 index 6f03ac9f7..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ContactRDAExportModel.java +++ /dev/null @@ -1,44 +0,0 @@ -package eu.eudat.models.data.rda; - -import eu.eudat.data.entities.UserInfo; - -public class ContactRDAExportModel { - private String mbox; - private String name; - private IdRDAExportModel contact_id; - - public String getMbox() { - return mbox; - } - public void setMbox(String mbox) { - this.mbox = mbox; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - public IdRDAExportModel getContact_id() { - return contact_id; - } - public void setContact_id(IdRDAExportModel contact_id) { - this.contact_id = contact_id; - } - - public ContactRDAExportModel fromDataModel(UserInfo entity) { - ContactRDAExportModel contact = new ContactRDAExportModel(); - contact.mbox = entity.getEmail(); - contact.name = entity.getName(); - // TODO: we should use a contact_id and not our UUID. - if (!entity.getId().toString().isEmpty()) { - contact.contact_id = new IdRDAExportModel(entity.getId().toString(), "other"); - } - else { - contact.contact_id = null; - } - return contact; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetDistributionRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetDistributionRDAExportModel.java deleted file mode 100644 index 0711822cb..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetDistributionRDAExportModel.java +++ /dev/null @@ -1,93 +0,0 @@ -package eu.eudat.models.data.rda; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -import java.util.List; - -public class DatasetDistributionRDAExportModel { - private String access_url; - private String available_till; - private String byte_size; - private String data_access; // Allowed values: open / shared / closed - private String description; - private String download_url; - private List format; // Format according to: https://www.iana.org/assignments/media-types/media-types.xhtml if appropriate, otherwise use the common name for this format - private HostRDAExportModel host; - private List license; - private String title; - - public String getAccess_url() { - return access_url; - } - public void setAccess_url(String access_url) { - this.access_url = access_url; - } - - public String getAvailable_till() { - return available_till; - } - public void setAvailable_till(String available_till) { - this.available_till = available_till; - } - - public String getByte_size() { - return byte_size; - } - public void setByte_size(String byte_size) { - this.byte_size = byte_size; - } - - public String getData_access() { - return data_access; - } - public void setData_access(String data_access) { - this.data_access = data_access; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public String getDownload_url() { - return download_url; - } - public void setDownload_url(String download_url) { - this.download_url = download_url; - } - - public List getFormat() { - return format; - } - public void setFormat(List format) { - this.format = format; - } - - public HostRDAExportModel getHost() { - return host; - } - public void setHost(HostRDAExportModel host) { - this.host = host; - } - - public List getLicense() { - return license; - } - public void setLicense(List license) { - this.license = license; - } - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - - @JsonIgnore - public boolean isValid() { - return title != null || data_access != null; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java deleted file mode 100644 index 2b5da6abd..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetMetadataRDAExportModel.java +++ /dev/null @@ -1,47 +0,0 @@ -package eu.eudat.models.data.rda; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -public class DatasetMetadataRDAExportModel { - private String description; // Not mandatory. - private String language; - private IdRDAExportModel metadata_standard_id; - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public String getLanguage() { - return language; - } - public void setLanguage(String language) { - this.language = language; - } - - public IdRDAExportModel getMetadata_standard_id() { - return metadata_standard_id; - } - public void setMetadata_standard_id(IdRDAExportModel metadata_standard_id) { - this.metadata_standard_id = metadata_standard_id; - } - - public DatasetMetadataRDAExportModel fromDataModel(String key, Object value) { - DatasetMetadataRDAExportModel metadataRDAExportModel = new DatasetMetadataRDAExportModel(); - if (key.contains("metadata_standard_id")) - metadataRDAExportModel.setMetadata_standard_id(new IdRDAExportModel(value.toString(), "other")); - else if (key.contains("language")) - metadataRDAExportModel.setLanguage(value.toString()); - else if (key.contains("description")) - metadataRDAExportModel.setDescription(value.toString()); - - return metadataRDAExportModel; - } - - @JsonIgnore - public boolean isValid() { - return description != null || language != null || metadata_standard_id != null; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java deleted file mode 100644 index ccd79971f..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetRDAExportModel.java +++ /dev/null @@ -1,474 +0,0 @@ -package eu.eudat.models.data.rda; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.jayway.jsonpath.JsonPath; -import eu.eudat.data.entities.Dataset; -import eu.eudat.logic.managers.DatasetManager; -import eu.eudat.logic.utilities.builders.XmlBuilder; -import eu.eudat.models.data.security.Principal; -import org.json.JSONArray; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import javax.xml.xpath.*; -import java.text.DateFormat; -import java.util.*; - -import static java.util.stream.Collectors.groupingBy; - -public class DatasetRDAExportModel { - private static final Logger logger = LoggerFactory.getLogger(DatasetRDAExportModel.class); - - private static final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - private Map multiplicityIdToFieldSetId = new HashMap<>(); - - private List data_quality_assurance; - private IdRDAExportModel dataset_id; - private String description; - private List distribution; - private String issued; // Created Date, could also use finalized one. - private List keyword; - private String language; - private List metadata; - private String personal_data; // Allowed Values: yes no unknown. - private String preservation_statement; - private List security_and_privacy; - private String sensitive_data; // Allowed Values: yes no unknown. - private List technical_resource; - private String title; - private String type; // Type according to: http://vocabularies.coar-repositories.org/pubby/resource_type.html - - public List getData_quality_assurance() { - return data_quality_assurance; - } - public void setData_quality_assurance(List data_quality_assurance) { - this.data_quality_assurance = data_quality_assurance; - } - - public IdRDAExportModel getDataset_id() { - return dataset_id; - } - public void setDataset_id(IdRDAExportModel dataset_id) { - this.dataset_id = dataset_id; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public List getDistribution() { - return distribution; - } - public void setDistribution(List distribution) { - this.distribution = distribution; - } - - public String getIssued() { - return issued; - } - public void setIssued(String issued) { - this.issued = issued; - } - - public List getKeyword() { - return keyword; - } - public void setKeyword(List keyword) { - this.keyword = keyword; - } - - public String getLanguage() { - return language; - } - public void setLanguage(String language) { - this.language = language; - } - - public List getMetadata() { - return metadata; - } - public void setMetadata(List metadata) { - this.metadata = metadata; - } - - public String getPersonal_data() { - return personal_data; - } - public void setPersonal_data(String personal_data) { - this.personal_data = personal_data; - } - - public String getPreservation_statement() { - return preservation_statement; - } - public void setPreservation_statement(String preservation_statement) { - this.preservation_statement = preservation_statement; - } - - public List getSecurity_and_privacy() { - return security_and_privacy; - } - public void setSecurity_and_privacy(List security_and_privacy) { - this.security_and_privacy = security_and_privacy; - } - - public String getSensitive_data() { - return sensitive_data; - } - public void setSensitive_data(String sensitive_data) { - this.sensitive_data = sensitive_data; - } - - public List getTechnical_resource() { - return technical_resource; - } - public void setTechnical_resource(List technical_resource) { - this.technical_resource = technical_resource; - } - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - - - public DatasetRDAExportModel fromDataModel(Dataset dataset, DatasetManager datasetManager, Principal principal) { - // Map of template Ids to rda values. - JSONObject jObject = new JSONObject(dataset.getProperties()); - Map templateIdsToValues = jObject.toMap(); - - /*--------- Building dataset rda export model ---------*/ - DatasetRDAExportModel datasetRDAExportModel = new DatasetRDAExportModel(); - datasetRDAExportModel.setDataset_id(new IdRDAExportModel(dataset.getId().toString(), "other")); - if (dataset.getDescription() != null) datasetRDAExportModel.setDescription(dataset.getDescription().replace("\n", " ")); - datasetRDAExportModel.setIssued(DateFormat.getDateInstance(DateFormat.SHORT).format(dataset.getCreated())); - datasetRDAExportModel.setLanguage("en"); // mock data - datasetRDAExportModel.setTitle(dataset.getLabel()); - - // Transform the answered dataset description to json so we can parse it and fill the rda model. - JSONObject datasetDescriptionJson = null; - try { - String jsonResult = mapper.writeValueAsString(datasetManager.getSingle(dataset.getId().toString(), principal).getDatasetProfileDefinition()); - datasetDescriptionJson = new JSONObject(jsonResult); - } catch (JsonProcessingException e) { - logger.error(e.getMessage(), e); - } - setMultiplicityIdToFieldSetId(datasetDescriptionJson); - - /*--------- Building personal data. ---------*/ - String personalData = buildSingleProperties("dataset.personal_data", datasetDescriptionJson, templateIdsToValues); - if (personalData != null) { - datasetRDAExportModel.setPersonal_data(personalData); - } else { - datasetRDAExportModel.setPersonal_data("unknown"); - } - - /*--------- Building preservation statement. ---------*/ - datasetRDAExportModel.setPreservation_statement(buildSingleProperties("dataset.preservation_statement", datasetDescriptionJson, templateIdsToValues)); - - /*--------- Building sensitive data. ---------*/ - String sensitiveData = buildSingleProperties("dataset.sensitive_data", datasetDescriptionJson, templateIdsToValues); - if (personalData != null) { - datasetRDAExportModel.setSensitive_data(sensitiveData); - } else { - datasetRDAExportModel.setSensitive_data("unknown"); - } - - /*--------- Building type. ---------*/ - datasetRDAExportModel.setType(buildSingleProperties("dataset.type", datasetDescriptionJson, templateIdsToValues)); - - /*--------- Building data_quality_assurance. ---------*/ - datasetRDAExportModel.setData_quality_assurance(buildDataQualityAssurance(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building distribution. ---------*/ - datasetRDAExportModel.setDistribution(buildDistribution(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building keywords. ---------*/ - datasetRDAExportModel.setKeyword(buildKeywords(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building metadata items. ---------*/ - datasetRDAExportModel.setMetadata(buildMetadata(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building security and privacy items. ---------*/ - datasetRDAExportModel.setSecurity_and_privacy(buildSecurityAndPrivacy(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - /*--------- Building technical_resource. ---------*/ - datasetRDAExportModel.setTechnical_resource(buildTechnicalResource(datasetDescriptionJson, templateIdsToValues, dataset.getProfile().getDefinition())); - - return datasetRDAExportModel; - } - - private String buildSingleProperties(String rdaKey, JSONObject datasetDescriptionJson, Map templateIdsToValues) { - String expression = "$..fields[*][?(@.rdaProperty == \"" + rdaKey + "\" )].id"; - List list = jsonValueListFromExpression(datasetDescriptionJson, expression); - if (!list.isEmpty()) { - return templateIdsToValues.get(list.get(0)).toString(); - } else { - return null; - } - } - - private List buildDataQualityAssurance(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { - List dataQualityFields = getRDAFieldsFromJson(datasetDescriptionJson, new String[]{"dataset.data_quality_assurance"}, datasetProfileDefinition); - for (RdaField rdaField : dataQualityFields) { - rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); - } - List dataQualityAssuranceList = new LinkedList<>(); - for (RdaField rdaField : dataQualityFields) { - dataQualityAssuranceList.add(rdaField.getRdaValue()); - } - - return dataQualityAssuranceList; - } - - private List buildDistribution(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { - DatasetDistributionRDAExportModel distributionModel = new DatasetDistributionRDAExportModel(); - distributionModel.setAccess_url(buildSingleProperties("dataset.distribution.access_url", datasetDescriptionJson, templateIdsToValues)); - distributionModel.setAvailable_till(buildSingleProperties("dataset.distribution.available_till", datasetDescriptionJson, templateIdsToValues)); - distributionModel.setByte_size(buildSingleProperties("dataset.distribution.byte_size", datasetDescriptionJson, templateIdsToValues)); - distributionModel.setData_access(buildSingleProperties("dataset.distribution.data_access", datasetDescriptionJson, templateIdsToValues)); - distributionModel.setDescription(buildSingleProperties("dataset.distribution.description", datasetDescriptionJson, templateIdsToValues)); - distributionModel.setDownload_url(buildSingleProperties("dataset.distribution.download_url", datasetDescriptionJson, templateIdsToValues)); - distributionModel.setTitle(buildSingleProperties("dataset.distribution.title", datasetDescriptionJson, templateIdsToValues)); - - /*--------- Building format. ---------*/ - - - // We currently support the return of only one distribution. - List distributionList = new LinkedList<>(); - if (distributionModel.isValid()) { - distributionList.add(distributionModel); - } else { - DatasetDistributionRDAExportModel model = new DatasetDistributionRDAExportModel(); - model.setDescription("Distribution data was not valid"); - distributionList.add(model); - } - - return distributionList; - } - - private List buildKeywords(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { - List keywordFields = getRDAFieldsFromJson(datasetDescriptionJson, new String[]{"dataset.keyword"}, datasetProfileDefinition); - for (RdaField rdaField : keywordFields) { - rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); - } - List keywordsList = new LinkedList<>(); - for (RdaField rdaField : keywordFields) { - keywordsList.add(rdaField.getRdaValue()); - } - - return keywordsList; - } - - private List buildMetadata(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { - List metadataFields = getRDAFieldsFromJson(datasetDescriptionJson, - new String[]{"dataset.metadata.metadata_standard_id.type", "dataset.metadata.metadata_standard_id.identifier", "dataset.metadata.description", "dataset.metadata.language", "dataset.metadata.metadata_standard_id"}, - datasetProfileDefinition); - - // Adding rdaValue and FieldSetIds on metadataFields. - for (RdaField rdaField : metadataFields) { - rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); - } - // Group metadataFields based on their field set id. - Map> groupedMetadataFields = metadataFields.stream().collect(groupingBy(RdaField::getFieldSetId)); - - // Creating the metadata. - List metadataRDAExportModelList = new LinkedList<>(); - for (String fieldSetId : groupedMetadataFields.keySet()) { - DatasetMetadataRDAExportModel metadataRda = new DatasetMetadataRDAExportModel(); - for (RdaField rdaField : groupedMetadataFields.get(fieldSetId)) { - if (rdaField.getRdaProperty().equals("dataset.metadata.metadata_standard_id.identifier")) { - if (metadataRda.getMetadata_standard_id() != null) { - metadataRda.getMetadata_standard_id().setIdentifier(rdaField.getRdaValue()); - } else { - metadataRda.setMetadata_standard_id(new IdRDAExportModel(rdaField.getRdaValue(), "other")); - } - } - if (rdaField.getRdaProperty().equals("dataset.metadata.metadata_standard_id.type")) { - if (metadataRda.getMetadata_standard_id() != null) { - metadataRda.getMetadata_standard_id().setType(rdaField.getRdaValue()); - } else { - metadataRda.setMetadata_standard_id(new IdRDAExportModel("", rdaField.getRdaValue())); - } - } - if (rdaField.getRdaProperty().equals("dataset.metadata.description")) { - metadataRda.setDescription(rdaField.getRdaValue()); - } - if (rdaField.getRdaProperty().equals("dataset.metadata.language")) { - metadataRda.setLanguage(rdaField.getRdaValue()); - } - if (rdaField.getRdaProperty().equals("dataset.metadata.metadata_standard_id") && !rdaField.getRdaValue().isEmpty()) { - JSONArray jsonArray = new JSONArray(rdaField.getRdaValue()); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - Map jsonObjectMap = jsonObject.toMap(); - DatasetMetadataRDAExportModel metadataRda1 = new DatasetMetadataRDAExportModel(); -// metadataRda1.setMetadata_standard_id(new IdRDAExportModel(jsonObjectMap.get("label").toString(), jsonObjectMap.get("source").toString())); - metadataRda1.setMetadata_standard_id(new IdRDAExportModel(jsonObjectMap.get("uri").toString(), "url")); - metadataRDAExportModelList.add(metadataRda1); - } - } - } - if (metadataRda.isValid()) { - metadataRDAExportModelList.add(metadataRda); - } - } - - return new LinkedList<>(metadataRDAExportModelList); - } - - private List buildSecurityAndPrivacy(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { - List secAndPrFields = getRDAFieldsFromJson( - datasetDescriptionJson, - new String[]{"dataset.security_and_privacy.description", "dataset.security_and_privacy.title", "dataset.security_and_privacy"}, - datasetProfileDefinition); - for (RdaField rdaField : secAndPrFields) { - rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); - } - Map> groupedSecurityAndPrivacyFields = secAndPrFields.stream().collect(groupingBy(RdaField::getFieldSetId)); - - List securityAndPrivacyRDAExportModelList = new LinkedList<>(); - for (String fieldSetId : groupedSecurityAndPrivacyFields.keySet()) { - DatasetSecurityAndPrivacyRDAExportModel securityAndPrivacyModel = new DatasetSecurityAndPrivacyRDAExportModel(); - for (RdaField rdaField : groupedSecurityAndPrivacyFields.get(fieldSetId)) { - if (rdaField.getRdaProperty().equals("dataset.security_and_privacy.description")) { - securityAndPrivacyModel.setDescription(rdaField.getRdaValue()); - } - if (rdaField.getRdaProperty().equals("dataset.security_and_privacy.title")) { - securityAndPrivacyModel.setTitle(rdaField.getRdaValue()); - } - if (rdaField.getRdaProperty().equals("dataset.security_and_privacy")) { - JSONArray jsonArray = new JSONArray(rdaField.getRdaValue()); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - Map jsonObjectMap = jsonObject.toMap(); - DatasetSecurityAndPrivacyRDAExportModel secAndPrivacy = new DatasetSecurityAndPrivacyRDAExportModel(jsonObjectMap.get("label").toString(), jsonObjectMap.get("source").toString()); - securityAndPrivacyRDAExportModelList.add(secAndPrivacy); - } - } - } - securityAndPrivacyRDAExportModelList.add(securityAndPrivacyModel); - } - - return securityAndPrivacyRDAExportModelList; - } - - private List buildTechnicalResource(JSONObject datasetDescriptionJson, Map templateIdsToValues, String datasetProfileDefinition) { - List dataQualityFields = getRDAFieldsFromJson(datasetDescriptionJson, - new String[]{"dataset.technical_resource.technical_resource", "dataset.technical_resource.technical_resource.description", "dataset.technical_resource.technical_resource.name"}, - datasetProfileDefinition); - for (RdaField rdaField : dataQualityFields) { - rdaField.setRdaValue(templateIdsToValues.get(rdaField.getFieldId()).toString()); - } - List technicalResourceList = new LinkedList<>(); - Map> groupedDataQualityFields = dataQualityFields.stream().collect(groupingBy(RdaField::getFieldSetId)); - for (String fieldSetId : groupedDataQualityFields.keySet()) { - DatasetTechnicalResourceRDAExportModel technicalResourceModel = new DatasetTechnicalResourceRDAExportModel(); - for (RdaField rdaField : groupedDataQualityFields.get(fieldSetId)) { - if (rdaField.getRdaProperty().equals("dataset.technical_resource.technical_resource.description")) { - technicalResourceModel.setDescription(rdaField.getRdaValue()); - } - if (rdaField.getRdaProperty().equals("dataset.technical_resource.technical_resource.name")) { - technicalResourceModel.setName(rdaField.getRdaValue()); - } - if (rdaField.getRdaProperty().equals("dataset.security_and_privacy")) { - JSONArray jsonArray = new JSONArray(rdaField.getRdaValue()); - for (int i = 0; i < jsonArray.length(); i++) { - JSONObject jsonObject = jsonArray.getJSONObject(i); - Map jsonObjectMap = jsonObject.toMap(); - DatasetTechnicalResourceRDAExportModel technicalResource = new DatasetTechnicalResourceRDAExportModel(jsonObjectMap.get("label").toString(), jsonObjectMap.get("label").toString()); - technicalResourceList.add(technicalResource); - } - } - } - technicalResourceList.add(technicalResourceModel); - } - - return technicalResourceList; - } - - private void setMultiplicityIdToFieldSetId(JSONObject json) { - String multiplicityItemsFieldSetIdExp = "$..multiplicityItems[*].id"; - List multiplicityItemsFieldSetIdList = jsonValueListFromExpression(json, multiplicityItemsFieldSetIdExp); - for (String fieldSetId : multiplicityItemsFieldSetIdList) { - String fieldsFromFieldSetIdExp = "$..multiplicityItems[*][?(@.id == \""+ fieldSetId +"\")].fields[*].id"; - List fieldsIdList = jsonValueListFromExpression(json, fieldsFromFieldSetIdExp); - for (String fieldId : fieldsIdList) { - this.multiplicityIdToFieldSetId.put(fieldId, fieldSetId); - } - } - } - - private List getRDAFieldsFromJson(JSONObject json, String[] rdaKey, String datasetProfileDefinition) { - List rdaFields = new LinkedList<>(); - for (String key : rdaKey) { - String fieldIdExpression = "$..fields[*][?(@.rdaProperty == \"" + key + "\" )].id"; - List listFromExpression = jsonValueListFromExpression(json, fieldIdExpression); - for (String fieldId : listFromExpression) { - RdaField rdaField = new RdaField(); - rdaField.setRdaProperty(key); - rdaField.setFieldId(fieldId); - if (fieldId.startsWith("multiple_")) { - rdaField.setFieldSetId(this.multiplicityIdToFieldSetId.get(fieldId)); - } else { - rdaField.setFieldSetId(getFieldSetIdForFieldFromXML(datasetProfileDefinition, fieldId)); - } - rdaFields.add(rdaField); - } - } - return rdaFields; - } - - private List jsonValueListFromExpression(JSONObject json, String expression) { - net.minidev.json.JSONArray jsonArray = JsonPath.parse(json.toString()).read(expression); - List valueList = new LinkedList<>(); - for (Object o : jsonArray) { - valueList.add(o.toString()); - } - return valueList; - } - - private String getFieldSetIdForFieldFromXML(String datasetProfileDefinition, String fieldId) { - String fieldSetIdExpression = "//field[@id ='" + fieldId + "']/ancestor::fieldSet/@id"; - List listFromExpression = xmlValueListFromExpression(datasetProfileDefinition, fieldSetIdExpression); - if (listFromExpression.size() == 1) return listFromExpression.get(0); - return null; - } - - private List xmlValueListFromExpression(String xml, String expression) { - List valuesList = new LinkedList<>(); - Document document = XmlBuilder.fromXml(xml); - XPathFactory xpathFactory = XPathFactory.newInstance(); - XPath xpath = xpathFactory.newXPath(); - try { - XPathExpression expr = xpath.compile(expression); - NodeList nodeList = (NodeList) expr.evaluate(document, XPathConstants.NODESET); - for (int i = 0; i < nodeList.getLength(); i++) { - Node node = nodeList.item(i); - valuesList.add(node.getNodeValue()); - } - } catch (XPathExpressionException e) { - logger.error(e.getMessage(), e); - } - - return valuesList; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java deleted file mode 100644 index a2d2a5581..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetSecurityAndPrivacyRDAExportModel.java +++ /dev/null @@ -1,29 +0,0 @@ -package eu.eudat.models.data.rda; - -public class DatasetSecurityAndPrivacyRDAExportModel { - private String description; - private String title; - - public DatasetSecurityAndPrivacyRDAExportModel() { - - } - - public DatasetSecurityAndPrivacyRDAExportModel(String description, String title) { - this.description = description; - this.title = title; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java deleted file mode 100644 index 6c47ea98e..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DatasetTechnicalResourceRDAExportModel.java +++ /dev/null @@ -1,28 +0,0 @@ -package eu.eudat.models.data.rda; - -public class DatasetTechnicalResourceRDAExportModel { - private String description; - private String name; - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - public DatasetTechnicalResourceRDAExportModel(String description, String name) { - this.description = description; - this.name = name; - } - - public DatasetTechnicalResourceRDAExportModel() { - } -} \ No newline at end of file diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpContributorRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpContributorRDAExportModel.java deleted file mode 100644 index 47079023f..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpContributorRDAExportModel.java +++ /dev/null @@ -1,52 +0,0 @@ -package eu.eudat.models.data.rda; - -import eu.eudat.data.entities.UserInfo; - -import java.util.LinkedList; -import java.util.List; - -public class DmpContributorRDAExportModel { - private IdRDAExportModel contributor_id; - private String mbox; - private String name; - private List role; - - public IdRDAExportModel getContributor_id() { - return contributor_id; - } - public void setContributor_id(IdRDAExportModel contributor_id) { - this.contributor_id = contributor_id; - } - - public String getMbox() { - return mbox; - } - public void setMbox(String mbox) { - this.mbox = mbox; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - public List getRole() { - return role; - } - public void setRole(List role) { - this.role = role; - } - - public DmpContributorRDAExportModel fromDataModel(UserInfo user, String role) { - DmpContributorRDAExportModel contributor = new DmpContributorRDAExportModel(); - contributor.contributor_id = new IdRDAExportModel(user.getId().toString(), "other"); - contributor.mbox = user.getEmail(); - contributor.name = user.getName(); - contributor.role = new LinkedList<>(); - contributor.role.add(role); - - return contributor; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpCostRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpCostRDAExportModel.java deleted file mode 100644 index 98abbadd8..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpCostRDAExportModel.java +++ /dev/null @@ -1,36 +0,0 @@ -package eu.eudat.models.data.rda; - -public class DmpCostRDAExportModel { - private String currency_code; //Allowed values defined by ISO 4217. - private String description; - private String title; - private String value; - - public String getCurrency_code() { - return currency_code; - } - public void setCurrency_code(String currency_code) { - this.currency_code = currency_code; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - - public String getValue() { - return value; - } - public void setValue(String value) { - this.value = value; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java deleted file mode 100644 index 47147fc4e..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/DmpRDAExportModel.java +++ /dev/null @@ -1,164 +0,0 @@ -package eu.eudat.models.data.rda; - -import eu.eudat.data.entities.DMP; -import eu.eudat.data.entities.Dataset; -import eu.eudat.data.entities.UserDMP; -import eu.eudat.data.entities.UserInfo; -import eu.eudat.logic.managers.DatasetManager; -import eu.eudat.models.data.security.Principal; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Collectors; - -public class DmpRDAExportModel { - private ContactRDAExportModel contact; - private List contributor; - private List cost; - private String created; - private List dataset; - private String description; - private IdRDAExportModel dmp_id; - private String ethical_issues_description; - private String ethical_issues_exist; // Allowed Values: yes no unknown. - private String ethical_issues_report; - private String language; - private String modified; - private ProjectRDAExportModel project; - private String title; - - public ContactRDAExportModel getContact() { - return contact; - } - public void setContact(ContactRDAExportModel contact) { - this.contact = contact; - } - - public List getContributor() { - return contributor; - } - public void setContributor(List contributor) { - this.contributor = contributor; - } - - public List getCost() { - return cost; - } - public void setCost(List cost) { - this.cost = cost; - } - - public String getCreated() { - return created; - } - public void setCreated(String created) { - this.created = created; - } - - public List getDataset() { - return dataset; - } - public void setDataset(List dataset) { - this.dataset = dataset; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public IdRDAExportModel getDmp_id() { - return dmp_id; - } - public void setDmp_id(IdRDAExportModel dmp_id) { - this.dmp_id = dmp_id; - } - - public String getEthical_issues_description() { - return ethical_issues_description; - } - public void setEthical_issues_description(String ethical_issues_description) { - this.ethical_issues_description = ethical_issues_description; - } - - public String getEthical_issues_exist() { - return ethical_issues_exist; - } - public void setEthical_issues_exist(String ethical_issues_exist) { - this.ethical_issues_exist = ethical_issues_exist; - } - - public String getEthical_issues_report() { - return ethical_issues_report; - } - public void setEthical_issues_report(String ethical_issues_report) { - this.ethical_issues_report = ethical_issues_report; - } - - public String getLanguage() { - return language; - } - public void setLanguage(String language) { - this.language = language; - } - - public String getModified() { - return modified; - } - public void setModified(String modified) { - this.modified = modified; - } - - public ProjectRDAExportModel getProject() { - return project; - } - public void setProject(ProjectRDAExportModel project) { - this.project = project; - } - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - - public DmpRDAExportModel fromDataModel(DMP entity, DatasetManager datasetManager, Principal principal) { - DmpRDAExportModel dmpRda = new DmpRDAExportModel(); - dmpRda.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); - if (entity.getUsers().stream().anyMatch(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue()))) { - dmpRda.contributor = new LinkedList<>(); - for (UserDMP userdmp : entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.USER.getValue())).collect(Collectors.toList())) { - dmpRda.contributor.add(new DmpContributorRDAExportModel().fromDataModel(userdmp.getUser(), UserDMP.UserDMPRoles.fromInteger(userdmp.getRole()).toString())); - } - } - dmpRda.cost = null; - SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); - dmpRda.created = formatter.format(entity.getCreated()); - dmpRda.dataset = new LinkedList<>(); - for (Dataset dataset : entity.getDataset()) { - if (dataset.getStatus() != Dataset.Status.DELETED.getValue() && dataset.getStatus() != Dataset.Status.CANCELED.getValue()) - dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset, datasetManager, principal)); - } - dmpRda.description = entity.getDescription().replace("\n", " "); - if (entity.getDoi() != null) { - dmpRda.dmp_id = new IdRDAExportModel(entity.getDoi(), "zenodo"); - } - else { - dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); - } - // Mock up data on "language" and "ethical_issues_*" for now. - dmpRda.ethical_issues_exist = "unknown"; - dmpRda.language = "en"; - dmpRda.modified = formatter.format(new Date()); - dmpRda.project = new ProjectRDAExportModel().fromDataModel(entity.getGrant()); - dmpRda.title = entity.getLabel(); - - return dmpRda; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/FundingRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/FundingRDAExportModel.java deleted file mode 100644 index 5691cae2c..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/FundingRDAExportModel.java +++ /dev/null @@ -1,43 +0,0 @@ -package eu.eudat.models.data.rda; - -import eu.eudat.data.entities.Funder; -import eu.eudat.data.entities.Grant; - -public class FundingRDAExportModel { - private IdRDAExportModel funder_id; - private IdRDAExportModel grant_id; - private String funding_status; - - public IdRDAExportModel getFunder_id() { - return funder_id; - } - public void setFunder_id(IdRDAExportModel funder_id) { - this.funder_id = funder_id; - } - - public IdRDAExportModel getGrant_id() { - return grant_id; - } - public void setGrant_id(IdRDAExportModel grant_id) { - this.grant_id = grant_id; - } - - public String getFunding_status() { - return funding_status; - } - public void setFunding_status(String funding_status) { - this.funding_status = funding_status; - } - - public FundingRDAExportModel fromDataModel(Funder funder, Grant grant) { - FundingRDAExportModel funding = new FundingRDAExportModel(); - funding.funding_status = "planned"; // mock data - if (funder != null) { - funding.funder_id = new IdRDAExportModel(funder.getReference(), "other"); - } - if (grant != null) { - funding.grant_id = new IdRDAExportModel(grant.getReference(), "other"); - } - return funding; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/HostRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/HostRDAExportModel.java deleted file mode 100644 index bac169259..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/HostRDAExportModel.java +++ /dev/null @@ -1,86 +0,0 @@ -package eu.eudat.models.data.rda; - -import java.util.List; - -public class HostRDAExportModel { - private String availability; - private String backup__frequency; - private String backup_type; - private String certified_with; // Repository certified with one the following standards: DIN31644 / DINI-Zertifikat / DSA / ISO16363 / ISO16919 /TRAC / WDS / CoreTrustSeal - private String description; - private String geo_location; // Physical location of the data expressed using ISO 3166-1 country code. - private List pid_system; // PID System: ark arxiv bibcode doi ean13 eissn handle igsn isbn issn istc lissn lsid pmid purl upc url urn other - private String storage_type; - private String support_versioning; // Allowed values: yes / no / unknown - private String title; - - public String getAvailability() { - return availability; - } - public void setAvailability(String availability) { - this.availability = availability; - } - - public String getBackup__frequency() { - return backup__frequency; - } - public void setBackup__frequency(String backup__frequency) { - this.backup__frequency = backup__frequency; - } - - public String getBackup_type() { - return backup_type; - } - public void setBackup_type(String backup_type) { - this.backup_type = backup_type; - } - - public String getCertified_with() { - return certified_with; - } - public void setCertified_with(String certified_with) { - this.certified_with = certified_with; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public String getGeo_location() { - return geo_location; - } - public void setGeo_location(String geo_location) { - this.geo_location = geo_location; - } - - public List getPid_system() { - return pid_system; - } - public void setPid_system(List pid_system) { - this.pid_system = pid_system; - } - - public String getStorage_type() { - return storage_type; - } - public void setStorage_type(String storage_type) { - this.storage_type = storage_type; - } - - public String getSupport_versioning() { - return support_versioning; - } - public void setSupport_versioning(String support_versioning) { - this.support_versioning = support_versioning; - } - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/IdRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/IdRDAExportModel.java deleted file mode 100644 index 2aef46e5b..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/IdRDAExportModel.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.eudat.models.data.rda; - -public class IdRDAExportModel { - private String identifier; - private String type; - - public String getIdentifier() { - return identifier; - } - public void setIdentifier(String identifier) { - this.identifier = identifier; - } - - public String getType() { - return type; - } - public void setType(String type) { - this.type = type; - } - - IdRDAExportModel(String identifier, String type) { - this.identifier = identifier; - this.type = type; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/LicenseRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/LicenseRDAExportModel.java deleted file mode 100644 index dec57a467..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/LicenseRDAExportModel.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.eudat.models.data.rda; - -public class LicenseRDAExportModel { - private String license_ref; - private String start_date; // If date is set in the future, it indicates embargo period. - - public String getLicense_ref() { - return license_ref; - } - public void setLicense_ref(String license_ref) { - this.license_ref = license_ref; - } - - public String getStart_date() { - return start_date; - } - public void setStart_date(String start_date) { - this.start_date = start_date; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ProjectRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ProjectRDAExportModel.java deleted file mode 100644 index 2d5b1912a..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/ProjectRDAExportModel.java +++ /dev/null @@ -1,54 +0,0 @@ -package eu.eudat.models.data.rda; - -import eu.eudat.data.entities.Grant; - -import java.util.Date; - -public class ProjectRDAExportModel { - private String title; - private String description; - private Date project_start; - private Date project_end; - private FundingRDAExportModel funding; - - public String getTitle() { - return title; - } - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - public Date getProject_start() { - return project_start; - } - public void setProject_start(Date project_start) { - this.project_start = project_start; - } - - public Date getProject_end() { - return project_end; - } - public void setProject_end(Date project_end) { - this.project_end = project_end; - } - - public FundingRDAExportModel getFunding() { - return funding; - } - public void setFunding(FundingRDAExportModel funding) { - this.funding = funding; - } - - - public ProjectRDAExportModel fromDataModel(Grant grant) { - this.funding = new FundingRDAExportModel().fromDataModel(grant.getFunder(), grant); - return this; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java deleted file mode 100644 index 98bb5627d..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RDAExportModel.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.eudat.models.data.rda; - -import eu.eudat.data.entities.DMP; -import eu.eudat.data.entities.Dataset; -import eu.eudat.logic.managers.DatasetManager; -import eu.eudat.models.data.security.Principal; - -import java.util.LinkedList; -import java.util.List; - -public class RDAExportModel { - private DmpRDAExportModel dmp; - - public DmpRDAExportModel getDmp() { - return dmp; - } - public void setDmp(DmpRDAExportModel dmp) { - this.dmp = dmp; - } - - public RDAExportModel fromDataModel(DMP dmp, DatasetManager datasetManager, Principal principal) { - this.dmp = new DmpRDAExportModel().fromDataModel(dmp, datasetManager, principal); - return this; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java deleted file mode 100644 index 31acd5c51..000000000 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/rda/RdaField.java +++ /dev/null @@ -1,36 +0,0 @@ -package eu.eudat.models.data.rda; - -public class RdaField { - private String rdaProperty; - private String rdaValue; - private String fieldId; - private String fieldSetId; - - public String getRdaProperty() { - return rdaProperty; - } - public void setRdaProperty(String rdaProperty) { - this.rdaProperty = rdaProperty; - } - - public String getRdaValue() { - return rdaValue; - } - public void setRdaValue(String rdaValue) { - this.rdaValue = rdaValue; - } - - public String getFieldId() { - return fieldId; - } - public void setFieldId(String fieldId) { - this.fieldId = fieldId; - } - - public String getFieldSetId() { - return fieldSetId; - } - public void setFieldSetId(String fieldSetId) { - this.fieldSetId = fieldSetId; - } -} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java index 6fe3c7741..aebed5646 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java @@ -11,9 +11,6 @@ import eu.eudat.models.data.user.composite.PropertiesModelBuilder; import eu.eudat.logic.utilities.interfaces.ViewStyleDefinition; import eu.eudat.logic.utilities.builders.ModelBuilder; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -205,7 +202,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin ObjectMapper mapper = new ObjectMapper(); List stringList = mapper.readValue(properties.get(this.id).toString(), LinkedList.class); this.value = stringList; - } catch (JSONException | NullPointerException | IOException e) { + } catch ( NullPointerException | IOException e) { this.value = (String) properties.get(this.id); } this.multiplicityItems = new LinkedList<>(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/CostRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/CostRDAMapper.java index 942f48d4a..45c9e300f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/CostRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/CostRDAMapper.java @@ -1,24 +1,31 @@ package eu.eudat.models.rda.mapper; -import java.util.*; -import java.util.stream.Collectors; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.logic.utilities.json.JavaToJson; import eu.eudat.models.rda.Cost; -import eu.eudat.models.rda.PidSystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + public class CostRDAMapper { private static final Logger logger = LoggerFactory.getLogger(DatasetRDAMapper.class); public static Cost toRDA(Map cost) { Cost rda = new Cost(); - Map code = new org.json.JSONObject((String) cost.get("code")).toMap(); - rda.setCurrencyCode(Cost.CurrencyCode.fromValue((String) code.get("value"))); + Map code; + try { + code = new ObjectMapper().readValue((String) cost.get("code"), HashMap.class); + rda.setCurrencyCode(Cost.CurrencyCode.fromValue((String) code.get("value"))); + } catch (JsonProcessingException e) { + logger.error(e.getLocalizedMessage(), e); + } rda.setDescription((String) cost.get("description")); if (cost.get("title") == null) { throw new IllegalArgumentException("Cost Title is missing"); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java index 11644f0a4..ad0775c44 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DatasetRDAMapper.java @@ -10,7 +10,6 @@ import eu.eudat.logic.utilities.json.JsonSearcher; import eu.eudat.models.data.datasetprofile.DatasetProfileOverviewModel; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; import eu.eudat.models.rda.*; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -51,8 +50,7 @@ public class DatasetRDAMapper { rda.setDescription(dataset.getDescription()); rda.setAdditionalProperty("template", dataset.getProfile().getId()); try { - JSONObject jObject = new JSONObject(dataset.getProperties()); - Map templateIdsToValues = jObject.toMap(); + Map templateIdsToValues = apiContext.getObjectMapper().readValue(dataset.getProperties(), HashMap.class); DatasetWizardModel datasetWizardModel = new DatasetWizardModel().fromDataModel(dataset); datasetWizardModel.setDatasetProfileDefinition(datasetManager.getPagedProfile(datasetWizardModel, dataset)); ObjectMapper mapper = new ObjectMapper(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java index 539367e10..4919f7d72 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/rda/mapper/DmpRDAMapper.java @@ -1,12 +1,14 @@ package eu.eudat.models.rda.mapper; +import com.fasterxml.jackson.core.JsonProcessingException; import eu.eudat.data.entities.*; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.utilities.helpers.StreamDistinctBy; -import eu.eudat.models.rda.Cost; import eu.eudat.models.rda.Dmp; import eu.eudat.models.rda.DmpId; import net.minidev.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -17,6 +19,7 @@ import java.util.stream.Collectors; @Component public class DmpRDAMapper { + private static final Logger logger = LoggerFactory.getLogger(DmpRDAMapper.class); private DatasetRDAMapper datasetRDAMapper; private ApiContext apiContext; @@ -34,17 +37,22 @@ public class DmpRDAMapper { if (dmp.getDataset() == null || dmp.getDataset().isEmpty()) { throw new IllegalArgumentException("DMP has no Datasets"); } - Map extraProperties; + Map extraProperties = null; if (dmp.getExtraProperties() == null) { throw new IllegalArgumentException("DMP is missing language and contact properties"); } else { - extraProperties = new org.json.JSONObject(dmp.getExtraProperties()).toMap(); - /*if (extraProperties.get("language") == null) { + try { + extraProperties = apiContext.getObjectMapper().readValue(dmp.getExtraProperties(), HashMap.class); + /*if (extraProperties.get("language") == null) { throw new IllegalArgumentException("DMP must have it's language property defined"); }*/ - if (extraProperties.get("contact") == null) { - throw new IllegalArgumentException("DMP must have it's contact property defined"); + if (extraProperties.get("contact") == null) { + throw new IllegalArgumentException("DMP must have it's contact property defined"); + } + } catch (JsonProcessingException e) { + logger.error(e.getLocalizedMessage(), e); } + } Dmp rda = new Dmp(); if (dmp.getDoi() != null && !dmp.getDoi().isEmpty()) { @@ -66,7 +74,7 @@ public class DmpRDAMapper { rda.setModified(dmp.getModified()); rda.setTitle(dmp.getLabel()); - if (!extraProperties.isEmpty()) { + if (extraProperties != null && !extraProperties.isEmpty()) { if (extraProperties.get("ethicalIssues") != null) { rda.setEthicalIssuesExist(Dmp.EthicalIssuesExist.fromValue(extraProperties.get("ethicalIssues").toString())); } else {