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

(cherry picked from commit 3d10e8ad28)
This commit is contained in:
Bernaldo Mihasi 2023-10-02 10:14:14 +03:00 committed by Diamantis Tziotzios
parent c58de51b33
commit 09dcf5328d
6 changed files with 45 additions and 4 deletions

View File

@ -61,7 +61,7 @@ public class Admin extends BaseController {
@Transactional
@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");
DatasetProfile shortenProfile = profile.toShort();
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
@ -85,7 +85,7 @@ public class Admin extends BaseController {
@Transactional
@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();
DescriptionTemplate modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext());
DescriptionTemplate datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
@ -129,7 +129,7 @@ public class Admin extends BaseController {
}
@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());
eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition);
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
@ -166,6 +166,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<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;
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<DescriptionTemplate> {
private String label;
private DescriptionTemplateType type;
private Set<Dataset> dataset;
private String definition;
@ -41,6 +44,11 @@ public class DatasetProfileBuilder extends Builder<DescriptionTemplate> {
return this;
}
public DatasetProfileBuilder type(DescriptionTemplateType type) {
this.type = type;
return this;
}
public DatasetProfileBuilder dataset(Set<Dataset> dataset) {
this.dataset = dataset;
return this;
@ -88,6 +96,7 @@ public class DatasetProfileBuilder extends Builder<DescriptionTemplate> {
descriptionTemplate.setModified(modified);
descriptionTemplate.setLabel(label);
descriptionTemplate.setLanguage(language);
descriptionTemplate.setType(type);
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.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) {

View File

@ -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();

View File

@ -14,6 +14,7 @@ public class DatasetProfile {
private String description;
private String language;
private String type;
private List<Page> 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<eu.eudat.models.data.admin.components.datasetprofile.Page> pagesDatasetEntity = new LinkedList<>();
List<eu.eudat.models.data.admin.components.datasetprofile.Section> sectionDatasetEntity = new LinkedList<>();
for (Page xmlPage: page) {

View File

@ -12,6 +12,7 @@ import java.util.Map;
public class DatasetProfile implements PropertiesModelBuilder {
private String description;
private String language;
private String type;
private List<Section> sections;
private List<Rule> rules;
private List<Page> 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<Section> getSections() {
return sections;
}