add type attribute in xml import/export of a description template

This commit is contained in:
Bernaldo Mihasi 2023-10-02 10:14:14 +03:00
parent 53b61853e1
commit 3d10e8ad28
6 changed files with 45 additions and 4 deletions

View File

@ -57,7 +57,7 @@ public class Admin extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN ,DATASET_PROFILE_MANAGER}) Principal principal) { public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN ,DATASET_PROFILE_MANAGER}) Principal principal) throws Exception {
//this.getLoggerService().info(principal, "Admin Added Dataset Profile"); //this.getLoggerService().info(principal, "Admin Added Dataset Profile");
DatasetProfile shortenProfile = profile.toShort(); DatasetProfile shortenProfile = profile.toShort();
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
@ -80,7 +80,7 @@ public class Admin extends BaseController {
@Transactional @Transactional
@RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) { public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception {
DatasetProfile shortenProfile = profile.toShort(); DatasetProfile shortenProfile = profile.toShort();
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
DescriptionTemplate datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); 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") @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) { public ResponseEntity<ResponseItem<PagedDatasetProfile>> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN, DATASET_PROFILE_MANAGER}) Principal principal) throws Exception {
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition); eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition);
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
@ -161,6 +161,7 @@ public class Admin extends BaseController {
datasetProfile.setStatus(profile.getStatus()); datasetProfile.setStatus(profile.getStatus());
datasetProfile.setDescription(profile.getDescription()); datasetProfile.setDescription(profile.getDescription());
datasetProfile.setLanguage(profile.getLanguage()); datasetProfile.setLanguage(profile.getLanguage());
datasetProfile.setType(profile.getType().getName());
return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel()); return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel());
} else { } else {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE")); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE"));

View File

@ -1,6 +1,7 @@
package eu.eudat.logic.builders.entity; package eu.eudat.logic.builders.entity;
import eu.eudat.data.entities.DescriptionTemplate; import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.logic.builders.Builder; import eu.eudat.logic.builders.Builder;
import eu.eudat.data.entities.Dataset; import eu.eudat.data.entities.Dataset;
@ -17,6 +18,8 @@ public class DatasetProfileBuilder extends Builder<DescriptionTemplate> {
private String label; private String label;
private DescriptionTemplateType type;
private Set<Dataset> dataset; private Set<Dataset> dataset;
private String definition; private String definition;
@ -41,6 +44,11 @@ public class DatasetProfileBuilder extends Builder<DescriptionTemplate> {
return this; return this;
} }
public DatasetProfileBuilder type(DescriptionTemplateType type) {
this.type = type;
return this;
}
public DatasetProfileBuilder dataset(Set<Dataset> dataset) { public DatasetProfileBuilder dataset(Set<Dataset> dataset) {
this.dataset = dataset; this.dataset = dataset;
return this; return this;
@ -88,6 +96,7 @@ public class DatasetProfileBuilder extends Builder<DescriptionTemplate> {
descriptionTemplate.setModified(modified); descriptionTemplate.setModified(modified);
descriptionTemplate.setLabel(label); descriptionTemplate.setLabel(label);
descriptionTemplate.setLanguage(language); descriptionTemplate.setLanguage(language);
descriptionTemplate.setType(type);
return descriptionTemplate; return descriptionTemplate;
} }
} }

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import eu.eudat.data.dao.entities.DatasetDao; import eu.eudat.data.dao.entities.DatasetDao;
import eu.eudat.data.dao.entities.DatasetProfileDao; import eu.eudat.data.dao.entities.DatasetProfileDao;
import eu.eudat.data.entities.DescriptionTemplate; import eu.eudat.data.entities.DescriptionTemplate;
import eu.eudat.data.entities.DescriptionTemplateType;
import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption; import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;
import eu.eudat.logic.builders.entity.DatasetProfileBuilder; import eu.eudat.logic.builders.entity.DatasetProfileBuilder;
import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel; import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel;
@ -18,7 +19,7 @@ import java.util.UUID;
public class AdminManager { 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 viewStyleModel = new ViewStyleModel();
viewStyleModel.setSections(new ModelBuilder().toViewStyleDefinition(profile.getSections(), eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Section.class)); 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)); 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"); 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()) 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()) .status(profile.getStatus()).created(new Date()).description(profile.getDescription()).language(profile.getLanguage())
.type(type)
.build(); .build();
if (descriptionTemplate.getGroupId() == null) { if (descriptionTemplate.getGroupId() == null) {

View File

@ -36,6 +36,7 @@ public class ExportXmlBuilderDatasetProfile {
Element pages = (Element)xmlDoc.getFirstChild(); Element pages = (Element)xmlDoc.getFirstChild();
pages.setAttribute("description", datasetProfile.getDescription()); pages.setAttribute("description", datasetProfile.getDescription());
pages.setAttribute("language", datasetProfile.getLanguage()); pages.setAttribute("language", datasetProfile.getLanguage());
pages.setAttribute("type", datasetProfile.getType());
String xml = XmlBuilder.generateXml(xmlDoc); String xml = XmlBuilder.generateXml(xmlDoc);
writer.write(xml); writer.write(xml);
writer.close(); writer.close();

View File

@ -14,6 +14,7 @@ public class DatasetProfile {
private String description; private String description;
private String language; private String language;
private String type;
private List<Page> page; private List<Page> page;
@ -44,12 +45,22 @@ public class DatasetProfile {
this.language = language; 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){ 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(); eu.eudat.models.data.admin.composite.DatasetProfile newDatasetEntityProfile = new eu.eudat.models.data.admin.composite.DatasetProfile();
newDatasetEntityProfile.setLabel(label); newDatasetEntityProfile.setLabel(label);
newDatasetEntityProfile.setStatus(DescriptionTemplate.Status.SAVED.getValue()); newDatasetEntityProfile.setStatus(DescriptionTemplate.Status.SAVED.getValue());
newDatasetEntityProfile.setDescription(description); newDatasetEntityProfile.setDescription(description);
newDatasetEntityProfile.setLanguage(language); newDatasetEntityProfile.setLanguage(language);
newDatasetEntityProfile.setType(type);
List<eu.eudat.models.data.admin.components.datasetprofile.Page> pagesDatasetEntity = new LinkedList<>(); List<eu.eudat.models.data.admin.components.datasetprofile.Page> pagesDatasetEntity = new LinkedList<>();
List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionDatasetEntity = new LinkedList<>(); List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionDatasetEntity = new LinkedList<>();
for (Page xmlPage: page) { for (Page xmlPage: page) {

View File

@ -12,6 +12,7 @@ import java.util.Map;
public class DatasetProfile implements PropertiesModelBuilder { public class DatasetProfile implements PropertiesModelBuilder {
private String description; private String description;
private String language; private String language;
private String type;
private List<Section> sections; private List<Section> sections;
private List<Rule> rules; private List<Rule> rules;
private List<Page> pages; private List<Page> pages;
@ -33,6 +34,14 @@ public class DatasetProfile implements PropertiesModelBuilder {
this.language = language; this.language = language;
} }
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<Section> getSections() { public List<Section> getSections() {
return sections; return sections;
} }