From 3d10e8ad28124aae28ca009e68e3625b00ec018a Mon Sep 17 00:00:00 2001 From: Aldo Mihasi Date: Mon, 2 Oct 2023 10:14:14 +0300 Subject: [PATCH] add type attribute in xml import/export of a description template --- .../src/main/java/eu/eudat/controllers/Admin.java | 7 ++++--- .../logic/builders/entity/DatasetProfileBuilder.java | 9 +++++++++ .../java/eu/eudat/logic/managers/AdminManager.java | 12 +++++++++++- .../ExportXmlBuilderDatasetProfile.java | 1 + .../datasetProfileModel/DatasetProfile.java | 11 +++++++++++ .../models/data/user/composite/DatasetProfile.java | 9 +++++++++ 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java index b8604c456..c8ad839e0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java @@ -57,7 +57,7 @@ public class Admin extends BaseController { @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") - public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN ,DATASET_PROFILE_MANAGER}) Principal principal) { + public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN ,DATASET_PROFILE_MANAGER}) Principal principal) throws Exception { //this.getLoggerService().info(principal, "Admin Added Dataset Profile"); DatasetProfile shortenProfile = profile.toShort(); DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); @@ -80,7 +80,7 @@ public class Admin extends BaseController { @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) { + public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception { DatasetProfile shortenProfile = profile.toShort(); DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); DescriptionTemplate datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); @@ -124,7 +124,7 @@ public class Admin extends BaseController { } @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) { + public ResponseEntity> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception { DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition); PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); @@ -161,6 +161,7 @@ public class Admin extends BaseController { datasetProfile.setStatus(profile.getStatus()); datasetProfile.setDescription(profile.getDescription()); datasetProfile.setLanguage(profile.getLanguage()); + datasetProfile.setType(profile.getType().getName()); return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel()); } else { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE")); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java index 59194d62f..2300fa6e7 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/builders/entity/DatasetProfileBuilder.java @@ -1,6 +1,7 @@ package eu.eudat.logic.builders.entity; import eu.eudat.data.entities.DescriptionTemplate; +import eu.eudat.data.entities.DescriptionTemplateType; import eu.eudat.logic.builders.Builder; import eu.eudat.data.entities.Dataset; @@ -17,6 +18,8 @@ public class DatasetProfileBuilder extends Builder { private String label; + private DescriptionTemplateType type; + private Set dataset; private String definition; @@ -41,6 +44,11 @@ public class DatasetProfileBuilder extends Builder { return this; } + public DatasetProfileBuilder type(DescriptionTemplateType type) { + this.type = type; + return this; + } + public DatasetProfileBuilder dataset(Set dataset) { this.dataset = dataset; return this; @@ -88,6 +96,7 @@ public class DatasetProfileBuilder extends Builder { descriptionTemplate.setModified(modified); descriptionTemplate.setLabel(label); descriptionTemplate.setLanguage(language); + descriptionTemplate.setType(type); return descriptionTemplate; } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java index a7569ed82..afde380e8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/AdminManager.java @@ -3,6 +3,7 @@ package eu.eudat.logic.managers; import eu.eudat.data.dao.entities.DatasetDao; import eu.eudat.data.dao.entities.DatasetProfileDao; import eu.eudat.data.entities.DescriptionTemplate; +import eu.eudat.data.entities.DescriptionTemplateType; import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption; import eu.eudat.logic.builders.entity.DatasetProfileBuilder; import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel; @@ -18,7 +19,7 @@ import java.util.UUID; public class AdminManager { - public static DescriptionTemplate generateViewStyleDefinition(DatasetProfile profile, ApiContext apiContext) { + public static DescriptionTemplate generateViewStyleDefinition(DatasetProfile profile, ApiContext apiContext) throws Exception { ViewStyleModel viewStyleModel = new ViewStyleModel(); viewStyleModel.setSections(new ModelBuilder().toViewStyleDefinition(profile.getSections(), eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section.class)); viewStyleModel.setPages(new ModelBuilder().toViewStyleDefinition(profile.getPages(), eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Page.class)); @@ -35,8 +36,17 @@ public class AdminManager { profile.setLanguage("en"); } + DescriptionTemplateType type; + try { + type = apiContext.getOperationsContext().getDatabaseRepository().getDescriptionTemplateTypeDao().findFromName(profile.getType()); + } + catch (Exception e) { + throw new Exception("Description template type '" + profile.getType() + "' could not be found."); + } + DescriptionTemplate descriptionTemplate = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel()) .status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage()) + .type(type) .build(); if (descriptionTemplate.getGroupId() == null) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java index 60f2da9e1..a64fd0de5 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/ExportXmlBuilderDatasetProfile.java @@ -36,6 +36,7 @@ public class ExportXmlBuilderDatasetProfile { Element pages = (Element)xmlDoc.getFirstChild(); pages.setAttribute("description", datasetProfile.getDescription()); pages.setAttribute("language", datasetProfile.getLanguage()); + pages.setAttribute("type", datasetProfile.getType()); String xml = XmlBuilder.generateXml(xmlDoc); writer.write(xml); writer.close(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/DatasetProfile.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/DatasetProfile.java index a7d29e30e..e36160e92 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/DatasetProfile.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/datasetProfileXml/datasetProfileModel/DatasetProfile.java @@ -14,6 +14,7 @@ public class DatasetProfile { private String description; private String language; + private String type; private List page; @@ -44,12 +45,22 @@ public class DatasetProfile { this.language = language; } + @XmlAttribute(name = "type") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + public eu.eudat.models.data.admin.composite.DatasetProfile toAdminCompositeModel(String label){ eu.eudat.models.data.admin.composite.DatasetProfile newDatasetEntityProfile = new eu.eudat.models.data.admin.composite.DatasetProfile(); newDatasetEntityProfile.setLabel(label); newDatasetEntityProfile.setStatus(DescriptionTemplate.Status.SAVED.getValue()); newDatasetEntityProfile.setDescription(description); newDatasetEntityProfile.setLanguage(language); + newDatasetEntityProfile.setType(type); List pagesDatasetEntity = new LinkedList<>(); List sectionDatasetEntity = new LinkedList<>(); for (Page xmlPage: page) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/composite/DatasetProfile.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/composite/DatasetProfile.java index 3d6449313..115c8cc7d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/composite/DatasetProfile.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/composite/DatasetProfile.java @@ -12,6 +12,7 @@ import java.util.Map; public class DatasetProfile implements PropertiesModelBuilder { private String description; private String language; + private String type; private List
sections; private List rules; private List pages; @@ -33,6 +34,14 @@ public class DatasetProfile implements PropertiesModelBuilder { this.language = language; } + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + public List
getSections() { return sections; }