diff --git a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java index bc17a621b..9bb65aee2 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java +++ b/dmp-backend/core/src/main/java/eu/eudat/audit/AuditableAction.java @@ -31,4 +31,9 @@ public class AuditableAction { public static final EventId Dmp_Persist = new EventId(5002, "Dmp_Persist"); public static final EventId Dmp_Delete = new EventId(5003, "Dmp_Delete"); + public static final EventId DescriptionTemplate_Query = new EventId(6000, "DescriptionTemplate_Query"); + public static final EventId DescriptionTemplate_Lookup = new EventId(6001, "DescriptionTemplate_Lookup"); + public static final EventId DescriptionTemplate_Persist = new EventId(6002, "DescriptionTemplate_Persist"); + public static final EventId DescriptionTemplate_Delete = new EventId(6003, "DescriptionTemplate_Delete"); + } diff --git a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java index 5937257bf..0e2c78393 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java +++ b/dmp-backend/core/src/main/java/eu/eudat/authorization/Permission.java @@ -22,6 +22,11 @@ public final class Permission { //Language public static String BrowseStatistics = "BrowseStatistics"; public static String BrowsePublicStatistics = "BrowsePublicStatistics"; + + //DescriptionTemplate + public static String BrowseDescriptionTemplate = "BrowseDescriptionTemplate"; + public static String EditDescriptionTemplate = "EditDescriptionTemplate"; + public static String DeleteDescriptionTemplate = "DeleteDescriptionTemplate"; //DescriptionTemplateType public static String BrowseDescriptionTemplateType = "BrowseDescriptionTemplateType"; diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/XmlHandlingService.java b/dmp-backend/core/src/main/java/eu/eudat/commons/XmlHandlingService.java index a808c9ff7..b87b52851 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/commons/XmlHandlingService.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/XmlHandlingService.java @@ -32,22 +32,6 @@ import java.io.StringWriter; @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) public class XmlHandlingService { - public String xmlSerializableToXml(XmlSerializable item) throws InvalidApplicationException, TransformerException, ParserConfigurationException { - Document document = this.getDocument(); - if (document == null) throw new InvalidApplicationException("Can not create document"); - document.appendChild(item.toXml(document)); - return this.generateXml(document); - } - - public String xmlSerializableToXmlSafe(XmlSerializable item) { - if (item == null) return null; - try { - return this.xmlSerializableToXml(item); - } catch (Exception ex) { - return null; - } - } - public String generateXml(Document doc) throws TransformerException { TransformerFactory tFact = TransformerFactory.newInstance(); Transformer trans = tFact.newTransformer(); @@ -60,7 +44,14 @@ public class XmlHandlingService { return writer.toString(); } - public String toXml(Object item) throws JsonProcessingException, JAXBException { + public String toXml(Object item) throws JsonProcessingException, JAXBException, ParserConfigurationException, InvalidApplicationException, TransformerException { + 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()); Marshaller marshaller = context.createMarshaller(); StringWriter out = new StringWriter(); @@ -77,11 +68,16 @@ public class XmlHandlingService { } } - public T fromXml(Class type, String xmlString) throws JAXBException { - JAXBContext jaxbContext = JAXBContext.newInstance(type); - Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + public T fromXml(Class type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException { + if (XmlSerializable.class.isAssignableFrom(type)){ + XmlSerializable object = (XmlSerializable)type.newInstance(); + return (T) object.fromXml(this.getDocument(xmlString).getDocumentElement()); + } else { + JAXBContext jaxbContext = JAXBContext.newInstance(type); + Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - return (T) jaxbUnmarshaller.unmarshal(new StringReader(xmlString)); + return (T) jaxbUnmarshaller.unmarshal(new StringReader(xmlString)); + } } public T fromXmlSafe(Class type, String xmlString) { @@ -93,19 +89,19 @@ public class XmlHandlingService { } } - public > T xmlSerializableFromXml(Class type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException { - T object = type.newInstance(); - return (T) object.fromXml(this.getDocument(xmlString).getDocumentElement()); - } - - public > T xmlSerializableFromXmlSafe(Class type, String xmlString) { - if (xmlString == null) return null; - try { - return this.xmlSerializableFromXml(type, xmlString); - } catch (Exception ex) { - return null; - } - } +// public > T xmlSerializableFromXml(Class type, String xmlString) throws JAXBException, InstantiationException, IllegalAccessException, ParserConfigurationException, IOException, SAXException { +// T object = type.newInstance(); +// return (T) object.fromXml(this.getDocument(xmlString).getDocumentElement()); +// } +// +// public > T xmlSerializableFromXmlSafe(Class type, String xmlString) { +// if (xmlString == null) return null; +// try { +// return this.xmlSerializableFromXml(type, xmlString); +// } catch (Exception ex) { +// return null; +// } +// } public Document getDocument(String xml) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DescriptionTemplateStatus.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DescriptionTemplateStatus.java new file mode 100644 index 000000000..fbecc1018 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/DescriptionTemplateStatus.java @@ -0,0 +1,30 @@ +package eu.eudat.commons.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.Map; + +public enum DescriptionTemplateStatus implements DatabaseEnum { + + Draft((short) 0), + Finalized((short) 1); + + private final Short value; + + DescriptionTemplateStatus(Short value) { + this.value = value; + } + + @JsonValue + public Short getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(DescriptionTemplateStatus.class); + + public static DescriptionTemplateStatus of(Short i) { + return map.get(i); + } + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataComboBoxType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataComboBoxType.java new file mode 100644 index 000000000..d60621343 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataComboBoxType.java @@ -0,0 +1,27 @@ +package eu.eudat.commons.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.Map; + +public enum FieldDataComboBoxType implements DatabaseEnum { + Autocomplete("autocomplete"), + Wordlist("wordlist"); + private final String value; + + FieldDataComboBoxType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(FieldDataComboBoxType.class); + + public static FieldDataComboBoxType of(String i) { + return map.get(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataExternalDatasetType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataExternalDatasetType.java new file mode 100644 index 000000000..d2b75a913 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataExternalDatasetType.java @@ -0,0 +1,28 @@ +package eu.eudat.commons.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.Map; + +public enum FieldDataExternalDatasetType implements DatabaseEnum { + ReusedDataset("reused_dataset"), + ProducedDataset("produced_dataset"), + Other("other"); + private final String value; + + FieldDataExternalDatasetType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(FieldDataExternalDatasetType.class); + + public static FieldDataExternalDatasetType of(String i) { + return map.get(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataInternalDmpEntryType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataInternalDmpEntryType.java new file mode 100644 index 000000000..2281f0eb6 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldDataInternalDmpEntryType.java @@ -0,0 +1,28 @@ +package eu.eudat.commons.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.Map; + +public enum FieldDataInternalDmpEntryType implements DatabaseEnum { + Researchers("researchers"), + Dmps("dmps"), + Datasets("datasets"); + private final String value; + + FieldDataInternalDmpEntryType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(FieldDataInternalDmpEntryType.class); + + public static FieldDataInternalDmpEntryType of(String i) { + return map.get(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java new file mode 100644 index 000000000..04efa40c0 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldType.java @@ -0,0 +1,50 @@ +package eu.eudat.commons.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.Map; + +public enum FieldType implements DatabaseEnum { + COMBO_BOX("combobox"), + BOOLEAN_DECISION("booleanDecision"), + RADIO_BOX("radiobox"), + INTERNAL_DMP_ENTRIES("internalDmpEntities"), + CHECK_BOX("checkBox"), + FREE_TEXT("freetext"), + TEXT_AREA("textarea"), + RICH_TEXT_AREA("richTextarea"), + UPLOAD("upload"), + DATE_PICKER("datePicker"), + EXTERNAL_DATASETS("externalDatasets"), + DATA_REPOSITORIES("dataRepositories"), + JOURNAL_REPOSITORIES("journalRepositories"), + PUB_REPOSITORIES("pubRepositories"), + LICENSES("licenses"), + TAXONOMIES("taxonomies"), + PUBLICATIONS("publications"), + REGISTRIES("registries"), + SERVICES("services"), + TAGS("tags"), + RESEARCHERS("researchers"), + ORGANIZATIONS("organizations"), + DATASET_IDENTIFIER("datasetIdentifier"), + CURRENCY("currency"), + VALIDATION("validation");; + private final String value; + + FieldType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(FieldType.class); + + public static FieldType of(String i) { + return map.get(i); + } +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldValidationType.java b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldValidationType.java new file mode 100644 index 000000000..fb74fb142 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/enums/FieldValidationType.java @@ -0,0 +1,33 @@ +package eu.eudat.commons.enums; + +import com.fasterxml.jackson.annotation.JsonValue; +import eu.eudat.data.converters.enums.DatabaseEnum; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public enum FieldValidationType implements DatabaseEnum { + + None((short) 0), + Required((short) 1), + Url((short) 2); + + private final Short value; + + FieldValidationType(Short value) { + this.value = value; + } + + @JsonValue + public Short getValue() { + return value; + } + + private static final Map map = EnumUtils.getEnumValueMap(FieldValidationType.class); + + public static FieldValidationType of(Short i) { + return map.get(i); + } + +} \ No newline at end of file diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseDefinition.java new file mode 100644 index 000000000..10d336fd0 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseDefinition.java @@ -0,0 +1,5 @@ +package eu.eudat.commons.types.common; + + +public interface DatabaseDefinition { +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseModelDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseModelDefinition.java new file mode 100644 index 000000000..f8d64308f --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseModelDefinition.java @@ -0,0 +1,7 @@ +package eu.eudat.commons.types.common; + +import eu.eudat.commons.types.common.DatabaseDefinition; + +public interface DatabaseModelDefinition extends DatabaseDefinition { + +} diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseViewStyleDefinition.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseViewStyleDefinition.java new file mode 100644 index 000000000..7aa75c2d8 --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/common/DatabaseViewStyleDefinition.java @@ -0,0 +1,7 @@ +package eu.eudat.commons.types.common; + +import eu.eudat.commons.types.common.DatabaseDefinition; + +public interface DatabaseViewStyleDefinition extends DatabaseDefinition { + +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/ViewStyleModel.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java similarity index 63% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/ViewStyleModel.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java index cc98dbbb2..8d4a8b12f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/ViewStyleModel.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/DefinitionEntity.java @@ -1,4 +1,4 @@ -package eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition; +package eu.eudat.commons.types.descriptiontemplate; import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlSerializable; @@ -10,24 +10,24 @@ import org.w3c.dom.NodeList; import java.util.LinkedList; import java.util.List; -public class ViewStyleModel implements XmlSerializable { - private List
sections; - private List pages; +public class DefinitionEntity implements XmlSerializable { + private List sections; + private List pages; - public List
getSections() { + public List getSections() { return sections; } - public void setSections(List
sections) { + public void setSections(List sections) { this.sections = sections; } - public List getPages() { + public List getPages() { return pages; } - public void setPages(List pages) { - this.pages = pages; + public void setPages(List pageEntities) { + this.pages = pageEntities; } @Override @@ -35,13 +35,13 @@ public class ViewStyleModel implements XmlSerializable { Element root = doc.createElement("root"); Element sections = doc.createElement("sections"); Element pages = doc.createElement("pages"); - for (Section section : this.sections) { - section.setNumbering("" + (this.sections.indexOf(section) + 1)); - sections.appendChild(section.toXml(doc)); + for (SectionEntity sectionEntity : this.sections) { + sectionEntity.setNumbering("" + (this.sections.indexOf(sectionEntity) + 1)); + sections.appendChild(sectionEntity.toXml(doc)); } - for (Page page : this.pages) { - pages.appendChild(page.toXml(doc)); + for (PageEntity pageEntity : this.pages) { + pages.appendChild(pageEntity.toXml(doc)); } root.appendChild(pages); @@ -50,7 +50,7 @@ public class ViewStyleModel implements XmlSerializable { } @Override - public ViewStyleModel fromXml(Element element) { + public DefinitionEntity fromXml(Element element) { this.sections = new LinkedList(); Element sections = (Element) XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "sections"); @@ -59,7 +59,7 @@ public class ViewStyleModel implements XmlSerializable { for (int temp = 0; temp < sectionElements.getLength(); temp++) { Node sectionElement = sectionElements.item(temp); if (sectionElement.getNodeType() == Node.ELEMENT_NODE) { - this.sections.add(new Section().fromXml((Element) sectionElement)); + this.sections.add(new SectionEntity().fromXml((Element) sectionElement)); } } } @@ -70,7 +70,7 @@ public class ViewStyleModel implements XmlSerializable { for (int temp = 0; temp < pagesElements.getLength(); temp++) { Node pageElement = pagesElements.item(temp); if (pageElement.getNodeType() == Node.ELEMENT_NODE) { - this.pages.add(new Page().fromXml((Element) pageElement)); + this.pages.add(new PageEntity().fromXml((Element) pageElement)); } } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldEntity.java similarity index 59% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldEntity.java index 271f78e35..9f3ec2064 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/FieldEntity.java @@ -1,11 +1,11 @@ -package eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition; +package eu.eudat.commons.types.descriptiontemplate; -import eu.eudat.models.data.components.commons.DefaultValue; -import eu.eudat.models.data.components.commons.ViewStyle; -import eu.eudat.models.data.components.commons.Visibility; -import eu.eudat.models.data.components.commons.datafield.FieldData; +import eu.eudat.commons.enums.FieldValidationType; +import eu.eudat.commons.enums.FieldType; +import eu.eudat.commons.types.common.DatabaseViewStyleDefinition; +import eu.eudat.commons.types.descriptiontemplate.fielddata.BaseFieldDataEntity; +import eu.eudat.commons.types.descriptiontemplate.fielddata.FieldDataHelper; import eu.eudat.commons.types.xml.XmlSerializable; -import eu.eudat.logic.utilities.builders.ModelBuilder; import eu.eudat.commons.types.xml.XmlBuilder; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -15,18 +15,17 @@ import org.w3c.dom.NodeList; import java.util.LinkedList; import java.util.List; -public class Field implements DatabaseViewStyleDefinition, XmlSerializable { +public class FieldEntity implements DatabaseViewStyleDefinition, XmlSerializable { private String id; private int ordinal; private List schematics; private String numbering; - private ViewStyle viewStyle; - private DefaultValue defaultValue; - private Visibility visible; - private FieldData data; - private List validations; - - private Boolean export; + private String defaultValue; + private List visibilityRules; + private BaseFieldDataEntity data; + private List validations; + private FieldType fieldType; + private Boolean includeInExport; public String getId() { return id; @@ -49,38 +48,33 @@ public class Field implements DatabaseViewStyleDefinition, XmlSerializable getData() { return data; } - public void setData(FieldData data) { + public void setData(BaseFieldDataEntity data) { this.data = data; } - public DefaultValue getDefaultValue() { + public FieldType getFieldType() { + return fieldType; + } + + public void setFieldType(FieldType fieldType) { + this.fieldType = fieldType; + } + + public String getDefaultValue() { return defaultValue; } - public void setDefaultValue(DefaultValue defaultValue) { + public void setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; } - public Visibility getVisible() { - return visible; - } - public void setVisible(Visibility visible) { - this.visible = visible; - } - public List getValidations() { + public List getValidations() { return validations; } - public void setValidations(List validations) { + public void setValidations(List validations) { this.validations = validations; } @@ -91,12 +85,20 @@ public class Field implements DatabaseViewStyleDefinition, XmlSerializable getVisibilityRules() { + return visibilityRules; + } + + public void setVisibilityRules(List visibilityRules) { + this.visibilityRules = visibilityRules; } @Override @@ -115,17 +117,19 @@ public class Field implements DatabaseViewStyleDefinition, XmlSerializable(); @@ -193,16 +199,16 @@ public class Field implements DatabaseViewStyleDefinition, XmlSerializable { +public class FieldSetEntity implements DatabaseViewStyleDefinition, XmlSerializable { private String id; private int ordinal; - private List fields; + private List fields; private String numbering; private String title; private String description; private String extendedDescription; private String additionalInformation; - private Multiplicity multiplicity; + private MultiplicityEntity multiplicity; private boolean hasCommentField; - private String commentFieldValue; + private String commentFieldValue; //TODO: DescriptionTemplate - public List getFields() { + public List getFields() { return fields; } - public void setFields(List fields) { - this.fields = fields; + public void setFields(List fieldEntities) { + this.fields = fieldEntities; } public String getId() { @@ -66,10 +66,10 @@ public class FieldSet implements DatabaseViewStyleDefinition, XmlSerializable { +public class PageEntity implements DatabaseViewStyleDefinition, XmlSerializable { private String id; private int ordinal; private String title; @@ -44,7 +45,7 @@ public class Page implements DatabaseViewStyleDefinition, XmlSerializable } @Override - public Page fromXml(Element item) { + public PageEntity fromXml(Element item) { this.ordinal = Integer.parseInt(item.getAttribute("ordinal")); this.id = item.getAttribute("id"); this.title = item.getAttribute("title"); diff --git a/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/RuleEntity.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/RuleEntity.java new file mode 100644 index 000000000..6740f18ad --- /dev/null +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/RuleEntity.java @@ -0,0 +1,52 @@ +package eu.eudat.commons.types.descriptiontemplate; + +import eu.eudat.commons.types.xml.XmlSerializable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class RuleEntity implements XmlSerializable { + private String target; + private String value; + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public Element toXml(Document doc) { + Element rule = doc.createElement("rule"); + rule.setAttribute("target", this.target); + + Element value = doc.createElement("value"); + value.setTextContent(this.value); + + rule.appendChild(value); + return rule; + } + + @Override + public RuleEntity fromXml(Element item) { + this.target = item.getAttribute("target"); + + Element value = (Element) item.getElementsByTagName("value").item(0); + if (value != null) { + this.value = value.getTextContent(); + } + + return this; + } + + +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Section.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java similarity index 80% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Section.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java index 6e4b28a9f..a38831b5b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Section.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/SectionEntity.java @@ -1,5 +1,6 @@ -package eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition; +package eu.eudat.commons.types.descriptiontemplate; +import eu.eudat.commons.types.common.DatabaseViewStyleDefinition; import eu.eudat.commons.types.xml.XmlBuilder; import eu.eudat.commons.types.xml.XmlSerializable; import org.w3c.dom.Document; @@ -10,7 +11,7 @@ import org.w3c.dom.NodeList; import java.util.LinkedList; import java.util.List; -public class Section implements DatabaseViewStyleDefinition, XmlSerializable
{ +public class SectionEntity implements DatabaseViewStyleDefinition, XmlSerializable { private String id; private int ordinal; private boolean defaultVisibility; @@ -19,8 +20,8 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable sections; - private List
fieldSets; + private List sections; + private List fieldSets; private Boolean multiplicity; public String getId() { @@ -71,20 +72,20 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable getSections() { + public List getSections() { return sections; } - public void setSections(List
sections) { + public void setSections(List sections) { this.sections = sections; } - public List
getFieldSets() { + public List getFieldSets() { return fieldSets; } - public void setFieldSets(List
fieldSets) { - this.fieldSets = fieldSets; + public void setFieldSets(List fieldSetEntities) { + this.fieldSets = fieldSetEntities; } public String getExtendedDescription() { @@ -134,18 +135,18 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable(); + this.sections = new LinkedList(); Element sections = (Element) XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "sections"); if (sections != null) { NodeList sectionElements = sections.getChildNodes(); for (int temp = 0; temp < sectionElements.getLength(); temp++) { Node sectionElement = sectionElements.item(temp); if (sectionElement.getNodeType() == Node.ELEMENT_NODE) { - this.sections.add(new Section().fromXml((Element) sectionElement)); + this.sections.add(new SectionEntity().fromXml((Element) sectionElement)); } } } - this.fieldSets = new LinkedList
(); + this.fieldSets = new LinkedList(); Element fieldGroups = (Element) XmlBuilder.getNodeFromListByTagName(element.getChildNodes(), "fieldSets"); if (fieldGroups != null) { @@ -199,7 +200,7 @@ public class Section implements DatabaseViewStyleDefinition, XmlSerializable { +public class AutoCompleteDataEntity extends ComboBoxDataEntity { public static class AuthAutoCompleteData { private String url; @@ -59,19 +62,19 @@ public class AutoCompleteData extends ComboBoxData { } } public static class AutoCompleteSingleData { - private int autocompleteType; + private AutocompleteType autocompleteType; private String url; - private ComboBoxData.Option autoCompleteOptions; + private ComboBoxDataEntity.Option autoCompleteOptions; private String optionsRoot; private Boolean hasAuth; private AuthAutoCompleteData auth; private String method; - public int getAutocompleteType() { + public AutocompleteType getAutocompleteType() { return autocompleteType; } - public void setAutocompleteType(int autocompleteType) { + public void setAutocompleteType(AutocompleteType autocompleteType) { this.autocompleteType = autocompleteType; } @@ -105,10 +108,10 @@ public class AutoCompleteData extends ComboBoxData { this.auth = auth; } - public ComboBoxData.Option getAutoCompleteOptions() { + public ComboBoxDataEntity.Option getAutoCompleteOptions() { return autoCompleteOptions; } - public void setAutoCompleteOptions(ComboBoxData.Option autoCompleteOptions) { + public void setAutoCompleteOptions(ComboBoxDataEntity.Option autoCompleteOptions) { this.autoCompleteOptions = autoCompleteOptions; } @@ -144,7 +147,7 @@ public class AutoCompleteData extends ComboBoxData { Element parent = doc.createElement("autocompleteSingle"); parent.setAttribute("url", singleData.url); parent.setAttribute("optionsRoot", singleData.optionsRoot); - parent.setAttribute("autoCompleteType", Integer.toString(singleData.autocompleteType)); + parent.setAttribute("autoCompleteType", Integer.toString(singleData.autocompleteType.getValue())); parent.setAttribute("hasAuth", Boolean.toString(singleData.hasAuth)); parent.setAttribute("method", singleData.method); Element element = doc.createElement("option"); @@ -167,7 +170,7 @@ public class AutoCompleteData extends ComboBoxData { } @Override - public AutoCompleteData fromXml(Element item) { + public AutoCompleteDataEntity fromXml(Element item) { super.fromXml(item); this.autoCompleteSingleDataList = new ArrayList<>(); NodeList items = item.getElementsByTagName("autocompleteSingle"); @@ -190,9 +193,9 @@ public class AutoCompleteData extends ComboBoxData { singleData.optionsRoot = item.getAttribute("optionsRoot"); this.multiAutoComplete = Boolean.parseBoolean(item.getAttribute("multiAutoComplete")); if (item.getAttribute("autoCompleteType") == null || item.getAttribute("autoCompleteType").equals("") ) { - singleData.autocompleteType = AutocompleteType.UNCACHED.getValue(); + singleData.autocompleteType = AutocompleteType.UNCACHED; } else { - singleData.autocompleteType = AutocompleteType.fromValue(Integer.parseInt(item.getAttribute("autoCompleteType"))).getValue(); + singleData.autocompleteType = AutocompleteType.of(Integer.parseInt(item.getAttribute("autoCompleteType"))); } singleData.hasAuth = Boolean.parseBoolean(item.getAttribute("hasAuth")); singleData.method = item.hasAttribute("method") ? item.getAttribute("method") : "GET"; @@ -218,7 +221,7 @@ public class AutoCompleteData extends ComboBoxData { } @Override - public AutoCompleteData fromData(Object data) { + public AutoCompleteDataEntity fromData(Object data) { super.fromData(data); this.autoCompleteSingleDataList = new ArrayList<>(); @@ -244,9 +247,9 @@ public class AutoCompleteData extends ComboBoxData { this.autoCompleteSingleDataList.get(i).method = singleData.containsKey("method") ? (String) singleData.get("method") : "GET"; if (singleData.get("autoCompleteType") == null) { - this.autoCompleteSingleDataList.get(i).autocompleteType = AutocompleteType.UNCACHED.getValue(); + this.autoCompleteSingleDataList.get(i).autocompleteType = AutocompleteType.UNCACHED; } else { - this.autoCompleteSingleDataList.get(i).autocompleteType = AutocompleteType.fromValue((Integer) singleData.get("autoCompleteType")).getValue(); + this.autoCompleteSingleDataList.get(i).autocompleteType = AutocompleteType.of((Integer) singleData.get("autoCompleteType")); } Map options = (Map) singleData.get("autoCompleteOptions"); if (options != null) { @@ -354,26 +357,25 @@ public class AutoCompleteData extends ComboBoxData { return dataMap; } - public enum AutocompleteType { - UNCACHED(0), CACHED(1); + public enum AutocompleteType implements DatabaseEnum { + UNCACHED(0), + CACHED(1); - int value; + private final int value; AutocompleteType(int value) { this.value = value; } - public int getValue() { - return this.value; + @JsonValue + public Integer getValue() { + return value; } - public static AutocompleteType fromValue(int value) { - for (AutocompleteType type: AutocompleteType.values()) { - if (type.getValue() == value) { - return type; - } - } - return UNCACHED; + private static final Map map = EnumUtils.getEnumValueMap(AutocompleteType.class); + + public static AutocompleteType of(int i) { + return map.get(i); } } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/FieldData.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/BaseFieldDataEntity.java similarity index 64% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/FieldData.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/BaseFieldDataEntity.java index eafde3782..e0ead5a54 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/FieldData.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/BaseFieldDataEntity.java @@ -1,4 +1,4 @@ -package eu.eudat.models.data.components.commons.datafield; +package eu.eudat.commons.types.descriptiontemplate.fielddata; import eu.eudat.commons.types.xml.XmlSerializable; import org.w3c.dom.Document; @@ -6,8 +6,9 @@ import org.w3c.dom.Element; import java.util.Map; -public abstract class FieldData implements XmlSerializable { +public abstract class BaseFieldDataEntity implements XmlSerializable { private String label; + private String subType; public String getLabel() { return label; @@ -17,6 +18,14 @@ public abstract class FieldData implements XmlSerializable { this.label = label; } + public String getSubType() { + return subType; + } + + public void setSubType(String subType) { + this.subType = subType; + } + public T fromData(Object data) { return null; } @@ -29,9 +38,5 @@ public abstract class FieldData implements XmlSerializable { return null; } - public T fromXml(Element item) { - return null; - } - public abstract Map toMap(Element item); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/BooleanDecisionData.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/BooleanDecisionDataEntity.java similarity index 75% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/BooleanDecisionData.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/BooleanDecisionDataEntity.java index 1f0f24cf5..ee37fbcd9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/BooleanDecisionData.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/BooleanDecisionDataEntity.java @@ -1,4 +1,4 @@ -package eu.eudat.models.data.components.commons.datafield; +package eu.eudat.commons.types.descriptiontemplate.fielddata; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -6,10 +6,10 @@ import org.w3c.dom.Element; import java.util.HashMap; import java.util.Map; -public class BooleanDecisionData extends FieldData { +public class BooleanDecisionDataEntity extends BaseFieldDataEntity { @Override - public BooleanDecisionData fromData(Object data) { + public BooleanDecisionDataEntity fromData(Object data) { if (data != null) { this.setLabel((String) ((Map) data).get("label")); } @@ -29,7 +29,7 @@ public class BooleanDecisionData extends FieldData { } @Override - public BooleanDecisionData fromXml(Element item) { + public BooleanDecisionDataEntity fromXml(Element item) { this.setLabel(item.getAttribute("label")); return this; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/CheckBoxData.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/CheckBoxDataEntity.java similarity index 78% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/CheckBoxData.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/CheckBoxDataEntity.java index ca00ecf5b..b6cdb3c04 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/CheckBoxData.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/CheckBoxDataEntity.java @@ -1,4 +1,4 @@ -package eu.eudat.models.data.components.commons.datafield; +package eu.eudat.commons.types.descriptiontemplate.fielddata; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -6,7 +6,7 @@ import org.w3c.dom.Element; import java.util.HashMap; import java.util.Map; -public class CheckBoxData extends FieldData { +public class CheckBoxDataEntity extends BaseFieldDataEntity { @Override public Element toXml(Document doc) { @@ -16,13 +16,13 @@ public class CheckBoxData extends FieldData { } @Override - public CheckBoxData fromXml(Element item) { + public CheckBoxDataEntity fromXml(Element item) { this.setLabel(item != null ? item.getAttribute("label") : ""); return this; } @Override - public CheckBoxData fromData(Object data) { + public CheckBoxDataEntity fromData(Object data) { if (data != null) { this.setLabel((String) ((Map) data).get("label")); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/ComboBoxData.java b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/ComboBoxDataEntity.java similarity index 79% rename from dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/ComboBoxData.java rename to dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/ComboBoxDataEntity.java index 4d6e2cb3f..3695a68c9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/components/commons/datafield/ComboBoxData.java +++ b/dmp-backend/core/src/main/java/eu/eudat/commons/types/descriptiontemplate/fielddata/ComboBoxDataEntity.java @@ -1,5 +1,6 @@ -package eu.eudat.models.data.components.commons.datafield; +package eu.eudat.commons.types.descriptiontemplate.fielddata; +import eu.eudat.commons.enums.FieldDataComboBoxType; import eu.eudat.commons.types.xml.XmlSerializable; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -7,7 +8,7 @@ import org.w3c.dom.Element; import java.util.HashMap; import java.util.Map; -public abstract class ComboBoxData extends FieldData { +public abstract class ComboBoxDataEntity extends BaseFieldDataEntity { public static class Option implements XmlSerializable