xml serializer changes

This commit is contained in:
Efstratios Giannopoulos 2024-01-30 18:34:22 +02:00
parent 16222fc02c
commit 4d1d712215
22 changed files with 22 additions and 136 deletions

View File

@ -1,11 +1,6 @@
package eu.eudat.commons; package eu.eudat.commons;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import eu.eudat.commons.types.dmpblueprint.DefinitionEntity;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller; import jakarta.xml.bind.Marshaller;
@ -44,13 +39,8 @@ public class XmlHandlingService {
return writer.toString(); return writer.toString();
} }
public String toXml(Object item) throws JsonProcessingException, JAXBException, ParserConfigurationException, InvalidApplicationException, TransformerException { public String toXml(Object item) throws JAXBException {
if (XmlSerializable.class.isAssignableFrom(item.getClass())){
Document document = this.getDocument();
if (document == null) throw new InvalidApplicationException("Can not create document");
document.appendChild(((XmlSerializable)item).toXml(document));
return this.generateXml(document);
}
JAXBContext context = JAXBContext.newInstance(item.getClass()); JAXBContext context = JAXBContext.newInstance(item.getClass());
Marshaller marshaller = context.createMarshaller(); Marshaller marshaller = context.createMarshaller();
@ -69,16 +59,11 @@ public class XmlHandlingService {
} }
public <T> T fromXml(Class<T> type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException { public <T> T fromXml(Class<T> type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException {
if (XmlSerializable.class.isAssignableFrom(type)){
XmlSerializable<T> object = (XmlSerializable<T>)type.newInstance();
return (T) object.fromXml(this.getDocument(xmlString).getDocumentElement());
} else {
JAXBContext jaxbContext = JAXBContext.newInstance(type); JAXBContext jaxbContext = JAXBContext.newInstance(type);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
return (T) jaxbUnmarshaller.unmarshal(new StringReader(xmlString)); return (T) jaxbUnmarshaller.unmarshal(new StringReader(xmlString));
} }
}
public <T> T fromXmlSafe(Class<T> type, String xmlString) { public <T> T fromXmlSafe(Class<T> type, String xmlString) {
if (xmlString == null) return null; if (xmlString == null) return null;

View File

@ -1,15 +1,8 @@
package eu.eudat.commons.types.descriptiontemplate; package eu.eudat.commons.types.descriptiontemplate;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
@XmlRootElement(name = "root") @XmlRootElement(name = "root")

View File

@ -1,16 +1,9 @@
package eu.eudat.commons.types.descriptiontemplate; package eu.eudat.commons.types.descriptiontemplate;
import eu.eudat.commons.types.common.DatabaseViewStyleDefinition; import eu.eudat.commons.types.common.DatabaseViewStyleDefinition;
import eu.eudat.commons.types.xml.XmlSerializable;
import eu.eudat.commons.types.xml.XmlBuilder;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)

View File

@ -1,12 +1,9 @@
package eu.eudat.commons.types.descriptiontemplate; package eu.eudat.commons.types.descriptiontemplate;
import eu.eudat.commons.types.common.DatabaseViewStyleDefinition; import eu.eudat.commons.types.common.DatabaseViewStyleDefinition;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)

View File

@ -1,11 +1,8 @@
package eu.eudat.commons.types.descriptiontemplate; package eu.eudat.commons.types.descriptiontemplate;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class RuleEntity { public class RuleEntity {

View File

@ -1,14 +1,9 @@
package eu.eudat.commons.types.descriptiontemplate.fielddata; package eu.eudat.commons.types.descriptiontemplate.fielddata;
import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Map;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)

View File

@ -1,12 +1,7 @@
package eu.eudat.commons.types.descriptiontemplate.importexport.fielddata; package eu.eudat.commons.types.descriptiontemplate.importexport.fielddata;
import eu.eudat.commons.enums.FieldType; import eu.eudat.commons.enums.FieldType;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.Map;
public abstract class BaseFieldDataImportExport { public abstract class BaseFieldDataImportExport {
@XmlAttribute(name = "label") @XmlAttribute(name = "label")

View File

@ -1,14 +1,7 @@
package eu.eudat.commons.types.dmpblueprint; package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
@XmlRootElement(name = "root") @XmlRootElement(name = "root")

View File

@ -1,11 +1,8 @@
package eu.eudat.commons.types.dmpblueprint; package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.UUID; import java.util.UUID;

View File

@ -1,14 +1,9 @@
package eu.eudat.commons.types.dmpblueprint; package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintExtraFieldDataType;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory; import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlTransient;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.UUID; import java.util.UUID;

View File

@ -1,22 +1,10 @@
package eu.eudat.commons.types.dmpblueprint; package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory; import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.ReferenceTypeSourceType;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceBaseConfigurationEntity;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceExternalApiConfigurationEntity;
import eu.eudat.commons.types.referencetype.ReferenceTypeSourceStaticOptionConfigurationEntity;
import eu.eudat.commons.types.xml.XmlBuilder;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.*; import jakarta.xml.bind.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class SectionEntity { public class SectionEntity {

View File

@ -1,15 +1,9 @@
package eu.eudat.commons.types.dmpblueprint; package eu.eudat.commons.types.dmpblueprint;
import eu.eudat.commons.enums.DmpBlueprintFieldCategory;
import eu.eudat.commons.enums.DmpBlueprintSystemFieldType; import eu.eudat.commons.enums.DmpBlueprintSystemFieldType;
import eu.eudat.commons.types.xml.XmlSerializable;
import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlAttribute;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.util.UUID;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class SystemFieldEntity extends FieldEntity { public class SystemFieldEntity extends FieldEntity {

View File

@ -54,5 +54,5 @@ public class DmpToPublicApiDmpMapper {
return model; return model;
} }
} }

View File

@ -1,20 +1,21 @@
package eu.eudat.model.publicapi.associatedprofile; package eu.eudat.model.publicapi.associatedprofile;
import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.commons.types.xml.XmlSerializable;
import eu.eudat.data.DmpDescriptionTemplateEntity;
import eu.eudat.model.DescriptionTemplate;
import eu.eudat.model.DmpDescriptionTemplate; import eu.eudat.model.DmpDescriptionTemplate;
import org.w3c.dom.Document; import jakarta.xml.bind.annotation.*;
import org.w3c.dom.Element;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedProfilePublicModel> { @XmlRootElement(name = "profile")
@XmlAccessorType(XmlAccessType.FIELD)
public class AssociatedProfilePublicModel {
@XmlAttribute(name="profileId")
private UUID id; private UUID id;
@XmlAttribute(name="descriptionTemplateId")
private UUID descriptionTemplateId; private UUID descriptionTemplateId;
@XmlAttribute(name="label")
private String label; private String label;
@XmlElement(name="data")
private Map<String, Object> data; private Map<String, Object> data;
public UUID getId() { public UUID getId() {
@ -49,36 +50,8 @@ public class AssociatedProfilePublicModel implements XmlSerializable<AssociatedP
this.data = data; this.data = data;
} }
@Override
public Element toXml(Document doc) {
Element profile = doc.createElement("profile");
profile.setAttribute("profileId", this.id.toString());
profile.setAttribute("label", this.label);
return profile;
}
@Override
public AssociatedProfilePublicModel fromXml(Element item) {
this.descriptionTemplateId = UUID.fromString(item.getAttribute("profileId"));
this.label = item.getAttribute("label");
return this;
}
public static AssociatedProfilePublicModel fromDmpDescriptionTemplate(DmpDescriptionTemplate dmpDescriptionTemplate) { public static AssociatedProfilePublicModel fromDmpDescriptionTemplate(DmpDescriptionTemplate dmpDescriptionTemplate) {
AssociatedProfilePublicModel model = new AssociatedProfilePublicModel(); AssociatedProfilePublicModel model = new AssociatedProfilePublicModel();
return model; return model;
} }
public DescriptionTemplateEntity toData() {
DescriptionTemplateEntity profile = new DescriptionTemplateEntity();
profile.setId(this.descriptionTemplateId);
profile.setLabel(this.label);
return profile;
}
public AssociatedProfilePublicModel fromData(DescriptionTemplateEntity entity) {
this.descriptionTemplateId = entity.getId();
this.label = entity.getLabel();
return this;
}
} }

View File

@ -6,7 +6,7 @@ import eu.eudat.commons.XmlHandlingService;
import eu.eudat.commons.enums.*; import eu.eudat.commons.enums.*;
import eu.eudat.commons.scope.user.UserScope; import eu.eudat.commons.scope.user.UserScope;
import eu.eudat.commons.types.dmpblueprint.*; import eu.eudat.commons.types.dmpblueprint.*;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.logic.xml.XmlBuilder;
import eu.eudat.data.*; import eu.eudat.data.*;
import eu.eudat.data.dao.criteria.DataManagementPlanCriteria; import eu.eudat.data.dao.criteria.DataManagementPlanCriteria;
import eu.eudat.data.dao.criteria.DatasetCriteria; import eu.eudat.data.dao.criteria.DatasetCriteria;

View File

@ -2,7 +2,7 @@ package eu.eudat.logic.managers;
import eu.eudat.commons.types.descriptiontemplate.FieldEntity; import eu.eudat.commons.types.descriptiontemplate.FieldEntity;
import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.AutoCompleteDataEntity;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.logic.xml.XmlBuilder;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader; import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
import eu.eudat.service.remotefetcher.config.entities.GeneralUrls; import eu.eudat.service.remotefetcher.config.entities.GeneralUrls;
@ -23,18 +23,9 @@ import org.springframework.http.MediaType;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.management.InvalidApplicationException; import javax.management.InvalidApplicationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.*; import javax.xml.xpath.*;
import java.io.StringWriter;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -2,7 +2,7 @@ package eu.eudat.logic.utilities.documents.xml;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.logic.xml.XmlBuilder;
import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalDatasetDataEntity; import eu.eudat.commons.types.descriptiontemplate.fielddata.ExternalDatasetDataEntity;
import eu.eudat.models.data.user.components.datasetprofile.Field; import eu.eudat.models.data.user.components.datasetprofile.Field;
import eu.eudat.models.data.user.components.datasetprofile.FieldSet; import eu.eudat.models.data.user.components.datasetprofile.FieldSet;

View File

@ -6,7 +6,7 @@ import eu.eudat.models.data.admin.components.datasetprofile.Page;
import eu.eudat.models.data.user.components.datasetprofile.Field; import eu.eudat.models.data.user.components.datasetprofile.Field;
import eu.eudat.models.data.user.components.datasetprofile.FieldSet; import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
import eu.eudat.models.data.user.components.datasetprofile.Section; import eu.eudat.models.data.user.components.datasetprofile.Section;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.logic.xml.XmlBuilder;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.w3c.dom.Document; import org.w3c.dom.Document;

View File

@ -1,4 +1,4 @@
package eu.eudat.commons.types.xml; package eu.eudat.logic.xml;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -1,4 +1,4 @@
package eu.eudat.commons.types.xml; package eu.eudat.logic.xml;
import org.w3c.dom.Document; import org.w3c.dom.Document;

View File

@ -1,7 +1,7 @@
package eu.eudat.models.data.dmp; package eu.eudat.models.data.dmp;
import eu.eudat.data.DescriptionTemplateEntity; import eu.eudat.data.DescriptionTemplateEntity;
import eu.eudat.commons.types.xml.XmlSerializable; import eu.eudat.logic.xml.XmlSerializable;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;

View File

@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import eu.eudat.data.DescriptionEntity; import eu.eudat.data.DescriptionEntity;
import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.logic.xml.XmlBuilder;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;