From c12fd1f1beddd0044f1b22d49a20f665b5006955 Mon Sep 17 00:00:00 2001 From: annabakouli Date: Thu, 30 Nov 2017 18:29:44 +0200 Subject: [PATCH] serialization - deserialization between model and definition for Rules and Multiplicity --- dmp-admin/src/app/testModel/testModel.ts | 76 +++- .../xmlmodels/modeldefinition/FieldSet.java | 18 + .../xmlmodels/viewstyledefinition/Field.java | 15 + .../viewstyledefinition/FieldSet.java | 16 + .../java/models/components/commons/Rule.java | 76 ++++ .../models/components/commons/Visibility.java | 58 +++ .../components/datasetprofile/Field.java | 13 +- .../components/datasetprofile/FieldSet.java | 17 +- .../dynamic-form-field.component.html | 2 +- dmp-frontend/src/app/testModel/testmodel.ts | 408 +++++++++++++----- 10 files changed, 577 insertions(+), 122 deletions(-) create mode 100644 dmp-backend/src/main/java/models/components/commons/Rule.java create mode 100644 dmp-backend/src/main/java/models/components/commons/Visibility.java diff --git a/dmp-admin/src/app/testModel/testModel.ts b/dmp-admin/src/app/testModel/testModel.ts index 69cf0566c..2b33d7343 100644 --- a/dmp-admin/src/app/testModel/testModel.ts +++ b/dmp-admin/src/app/testModel/testModel.ts @@ -31,7 +31,29 @@ export const TestModel = { "description": "", "extendedDescription": "", "viewStyle": "checkBox", - "rule":[], + "rules":[ + { + "ruleType":"fieldValue", + "target":"metadataStandarsA211", + "ruleStyle":"boolean", + "value":"true", + "valueType":"boolean" + }, + { + "ruleType":"fieldValue", + "target":"freeOfChargeGroupCommentA213", + "ruleStyle":"boolean", + "value":"true", + "valueType":"boolean" + }, + { + "ruleType":"fieldValue", + "target":"standardisedVocabulariesA212", + "ruleStyle":"boolean", + "value":"true", + "valueType":"boolean" + } + ], "multiplicity":{ "min":0, "max":1 @@ -76,7 +98,15 @@ export const TestModel = { "description": "User can select from a list of metadata standards. If they cannot find the standard in the list provided then they should choose \"not listed\". Selecting this will result in a field in which the user can insert the URL to the description of the metadata scheme used. A \"comments\" box should exist to allow users to add comments. They may select more than one metadata standard. They may specify more than one URL when selecting \"not listed\". They are also presented with a field in which to specify the location of the metadata service. Users can select the \"no metadata\" button to specify no metadata will be used to describe the data.", "extendedDescription": "FieldGroup Description", "viewStyle": "booleanDesicion", - "rule":[], + "rules":[ + { + "ruleType":"fieldValue", + "target":"noMetadata", + "ruleStyle":"boolean", + "value":"true", + "valueType":"boolean" + } + ], "multiplicity":{ "min":0, "max":1 @@ -94,7 +124,7 @@ export const TestModel = { "description": "The data will be described by metadata that follows the metadata standards described in , , ? The data will be described by metadata that follows the metadata schema described in , . The metadata will be stored in the service located at ", "extendedDescription": "", "viewStyle": "combobox", - "rule":[], + "rules":[], "multiplicity":{ "min":0, "max":1 @@ -111,7 +141,15 @@ export const TestModel = { "description": "", "extendedDescription": "", "viewStyle": "checkBox", - "rule":[], + "rules":[ + { + "ruleType":"fieldValue", + "target":"", + "ruleStyle":"boolean", + "value":"", + "valueType":"boolean" + } + ], "multiplicity":{ "min":0, "max":1 @@ -128,7 +166,15 @@ export const TestModel = { "description": "URL to the description of the metadata scheme used", "extendedDescription": "", "viewStyle": "freetext", - "rule":[], + "rules":[ + { + "ruleType":"fieldValue", + "target":"", + "ruleStyle":"boolean", + "value":"", + "valueType":"boolean" + } + ], "multiplicity":{ "min":0, "max":1 @@ -145,7 +191,15 @@ export const TestModel = { "description": "", "extendedDescription": "", "viewStyle": "freetext", - "rule":[], + "rules":[ + { + "ruleType":"fieldValue", + "target":"", + "ruleStyle":"boolean", + "value":"", + "valueType":"boolean" + } + ], "multiplicity":{ "min":0, "max":1 @@ -162,7 +216,15 @@ export const TestModel = { "description": "", "extendedDescription": "", "viewStyle": "checkBox", - "rule":[], + "rules":[ + { + "ruleType":"fieldValue", + "target":"", + "ruleStyle":"boolean", + "value":"", + "valueType":"boolean" + } + ], "multiplicity":{ "min":0, "max":1 diff --git a/dmp-backend/src/main/java/entities/xmlmodels/modeldefinition/FieldSet.java b/dmp-backend/src/main/java/entities/xmlmodels/modeldefinition/FieldSet.java index 04fd12ec2..fbdd3101e 100644 --- a/dmp-backend/src/main/java/entities/xmlmodels/modeldefinition/FieldSet.java +++ b/dmp-backend/src/main/java/entities/xmlmodels/modeldefinition/FieldSet.java @@ -11,6 +11,7 @@ import org.w3c.dom.NodeList; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import models.components.commons.Multiplicity; import utilities.XmlSerializable; import utilities.builders.XmlBuilder; @@ -19,6 +20,7 @@ public class FieldSet implements DatabaseModelDefinition,XmlSerializable fields; @@ -41,6 +43,12 @@ public class FieldSet implements DatabaseModelDefinition,XmlSerializable private String description; private String extendedDescription; private ViewStyle viewStyle; + private Visibility visible; private FieldData data; public String getId() { return id; @@ -67,6 +69,13 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable public void setData(FieldData data) { this.data = data; } + + public Visibility getVisible() { + return visible; + } + public void setVisible(Visibility visible) { + this.visible = visible; + } @Override public Element toXml(Document doc) { Element rootElement = doc.createElement("field"); @@ -84,6 +93,9 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable viewStyle.setAttribute("renderstyle", this.viewStyle.getRenderStyle()); viewStyle.setAttribute("cssClass", this.viewStyle.getCssClass()); + Element visibility = this.visible.toXml(doc); + + rootElement.appendChild(visibility); rootElement.appendChild(extendedDescription); rootElement.appendChild(viewStyle); rootElement.appendChild(description); @@ -107,6 +119,9 @@ public class Field implements DatabaseViewStyleDefinition,XmlSerializable this.viewStyle.setRenderStyle(viewStyle.getAttribute("renderstyle")); this.viewStyle.setCssClass(viewStyle.getAttribute("cssClass")); + Element visibility = (Element)element.getElementsByTagName("visible").item(0); + this.visible = new Visibility().fromXml(visibility); + Element dataElement = (Element)element.getElementsByTagName("data").item(0); this.data = new ModelBuilder().toFieldData(null, this.viewStyle.getRenderStyle()); if(this.data!=null)this.data.fromXml(dataElement); diff --git a/dmp-backend/src/main/java/entities/xmlmodels/viewstyledefinition/FieldSet.java b/dmp-backend/src/main/java/entities/xmlmodels/viewstyledefinition/FieldSet.java index db3ef0ef8..b35291c83 100644 --- a/dmp-backend/src/main/java/entities/xmlmodels/viewstyledefinition/FieldSet.java +++ b/dmp-backend/src/main/java/entities/xmlmodels/viewstyledefinition/FieldSet.java @@ -22,6 +22,22 @@ public class FieldSet implements DatabaseViewStyleDefinition,XmlSerializable fields) { this.fields = fields; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getOrdinal() { + return ordinal; + } + + public void setOrdinal(int ordinal) { + this.ordinal = ordinal; } @Override diff --git a/dmp-backend/src/main/java/models/components/commons/Rule.java b/dmp-backend/src/main/java/models/components/commons/Rule.java new file mode 100644 index 000000000..6e297d0e5 --- /dev/null +++ b/dmp-backend/src/main/java/models/components/commons/Rule.java @@ -0,0 +1,76 @@ +package models.components.commons; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import utilities.XmlSerializable; + +public class Rule implements XmlSerializable{ + private String ruleType; + private String target; + private String ruleStyle; + private String value; + private String valueType; + public String getRuleType() { + return ruleType; + } + public void setRuleType(String ruleType) { + this.ruleType = ruleType; + } + public String getTarget() { + return target; + } + public void setTarget(String target) { + this.target = target; + } + public String getRuleStyle() { + return ruleStyle; + } + public void setRuleStyle(String ruleStyle) { + this.ruleStyle = ruleStyle; + } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + public String getValueType() { + return valueType; + } + public void setValueType(String valueType) { + this.valueType = valueType; + } + + @Override + public Element toXml(Document doc) { + Element rule = doc.createElement("rule"); + rule.setAttribute("type",this.ruleType); + rule.setAttribute("target", this.target); + rule.setAttribute("ruleStyle", this.ruleStyle); + + Element value = doc.createElement("value"); + value.setAttribute("type", this.valueType); + value.setTextContent(this.value); + + rule.appendChild(value); + return rule; + } + @Override + public Rule fromXml(Element item) { + this.ruleType = item.getAttribute("type"); + this.target = item.getAttribute("target"); + this.ruleStyle = item.getAttribute("ruleStyle"); + + Element value = (Element)item.getElementsByTagName("value").item(0); + if(value!=null){ + this.valueType = value.getAttribute("type"); + this.value = value.getTextContent(); + } + + return this; + } + + + +} diff --git a/dmp-backend/src/main/java/models/components/commons/Visibility.java b/dmp-backend/src/main/java/models/components/commons/Visibility.java new file mode 100644 index 000000000..6e8914344 --- /dev/null +++ b/dmp-backend/src/main/java/models/components/commons/Visibility.java @@ -0,0 +1,58 @@ +package models.components.commons; + +import java.util.LinkedList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import entities.xmlmodels.viewstyledefinition.Field; +import utilities.XmlSerializable; + +public class Visibility implements XmlSerializable{ + private List rules; + private String style; + public List getRules() { + return rules; + } + + public void setRules(List rules) { + this.rules = rules; + } + + public String getStyle() { + return style; + } + + public void setStyle(String style) { + this.style = style; + } + + @Override + public Element toXml(Document doc) { + Element root = doc.createElement("visible"); + root.setAttribute("style", this.style); + if(rules!=null&&!rules.isEmpty()){ + for(Rule rule:rules){ + root.appendChild(rule.toXml(doc)); + } + } + return root; + } + + @Override + public Visibility fromXml(Element item) { + this.style = item.getAttribute("style"); + this.rules = new LinkedList(); + NodeList rulesElements = item.getChildNodes(); + for (int temp = 0; temp < rulesElements.getLength(); temp++) { + Node ruleElement = rulesElements.item(temp); + if (ruleElement .getNodeType() == Node.ELEMENT_NODE) { + this.rules.add(new Rule().fromXml((Element)ruleElement)); + } + } + return this; + } +} diff --git a/dmp-backend/src/main/java/models/components/datasetprofile/Field.java b/dmp-backend/src/main/java/models/components/datasetprofile/Field.java index 271358c40..49af20a28 100644 --- a/dmp-backend/src/main/java/models/components/datasetprofile/Field.java +++ b/dmp-backend/src/main/java/models/components/datasetprofile/Field.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; import models.components.commons.DefaultValue; import models.components.commons.Multiplicity; import models.components.commons.ViewStyle; +import models.components.commons.Visibility; import utilities.ModelDefinition; import utilities.ViewStyleDefinition; import utilities.builders.ModelBuilder; @@ -26,7 +27,7 @@ public class Field implements ModelDefinition,ViewStyleDefinition{ private String id; private int ordinal; - + private Multiplicity multiplicity; private List fields; public List getFields() { @@ -39,12 +40,21 @@ public class FieldSet implements ModelDefinition modelfields = new ModelBuilder().toModelDefinition(this.fields, entities.xmlmodels.modeldefinition.Field.class); fieldSet.setFields(modelfields); + fieldSet.setMultiplicity(this.multiplicity); return fieldSet; } @@ -52,18 +62,23 @@ public class FieldSet implements ModelDefinition viewStylefields = new ModelBuilder().toViewStyleDefinition(this.fields, entities.xmlmodels.viewstyledefinition.Field.class); item.setFields(viewStylefields); + item.setId(this.id); + item.setOrdinal(this.ordinal); return item; } @Override public void fromDatabaseDefinition(entities.xmlmodels.viewstyledefinition.FieldSet item) { this.fields = new ModelBuilder().fromViewStyleDefinition(item.getFields(), Field.class); + this.id = item.getId(); + this.ordinal = item.getOrdinal(); } diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html b/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html index 4ca6e9c2e..d57eafe53 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html @@ -26,7 +26,7 @@ --> -
+
diff --git a/dmp-frontend/src/app/testModel/testmodel.ts b/dmp-frontend/src/app/testModel/testmodel.ts index 65692431a..bd311badb 100644 --- a/dmp-frontend/src/app/testModel/testmodel.ts +++ b/dmp-frontend/src/app/testModel/testmodel.ts @@ -94,13 +94,38 @@ export const TestModel = { "renderStyle": "checkBox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [ + { + "ruleType": "fieldValue", + "target": "metadataStandarsA211", + "ruleStyle": "boolean", + "value": "true", + "valueType": "boolean" + }, + { + "ruleType": "fieldValue", + "target": "freeOfChargeGroupCommentA213", + "ruleStyle": "boolean", + "value": "true", + "valueType": "boolean" + }, + { + "ruleType": "fieldValue", + "target": "standardisedVocabulariesA212", + "ruleStyle": "boolean", + "value": "true", + "valueType": "boolean" + } + ] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { @@ -116,13 +141,16 @@ export const TestModel = { "renderStyle": "radiobox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "defaultValue": { + "type": "any", + "value": "" }, - "multiplicity":{ - "min":"1", - "max":"1" + "visible": { + "rules": [] + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { "options": [ @@ -132,7 +160,12 @@ export const TestModel = { ] } } - ] + ],"multiplicity": { + "min": "1", + "max": "1" + }, + "id":"useMetadataQ211fs", + "ordinal":1 } ] } @@ -176,19 +209,36 @@ export const TestModel = { "renderStyle": "booleanDecision", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [ + { + "ruleType": "fieldValue", + "target": "noMetadata", + "ruleStyle": "boolean", + "value": "true", + "valueType": "boolean" + } + ] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } } - ] + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"useMetadataQ211fs", + "ordinal":1 }, { "fields": @@ -203,19 +253,29 @@ export const TestModel = { "renderStyle": "combobox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "defaultValue": { + "type": "any", + "value": "" }, - "multiplicity":{ - "min":"1", - "max":"1" + "visible": { + "rules": [] + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { "type": "autocomplete", "url": "http://dionysus.di.uoa.gr:8080/dmp-backend/rest/external/datarepos?query=gree" } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"metadataStandarsA211fs", + "ordinal":1 }, { "fields": @@ -230,19 +290,36 @@ export const TestModel = { "renderStyle": "checkBox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [ + { + "ruleType": "fieldValue", + "target": "", + "ruleStyle": "boolean", + "value": "", + "valueType": "boolean" + } + ] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } } - ] + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"notlistedA211fs", + "ordinal":1 }, { "fields": @@ -257,18 +334,28 @@ export const TestModel = { "renderStyle": "freetext", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"notlistedUrlA211fs", + "ordinal":1 }, { "fields": @@ -283,18 +370,28 @@ export const TestModel = { "renderStyle": "freetext", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "defaultValue": { + "type": "any", + "value": "" }, - "multiplicity":{ - "min":"1", - "max":"1" + "visible": { + "rules": [] + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"notlistedCommentA211fs", + "ordinal":1 }, { "fields": @@ -309,19 +406,28 @@ export const TestModel = { "renderStyle": "checkBox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } } - ] + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"noMetadatafs", + "ordinal":1 } ] }, @@ -346,18 +452,28 @@ export const TestModel = { "renderStyle": "booleanDesicion", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"nuseVocabulariesQ212fs", + "ordinal":1 }, { "fields": [ @@ -371,13 +487,16 @@ export const TestModel = { "renderStyle": "combobox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { "type": "wordlist", @@ -387,7 +506,14 @@ export const TestModel = { { "label": "Panagiotis", "value": "mpotis" } ] } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"standardisedVocabulariesA212fs", + "ordinal":1 }, { "fields": [ @@ -401,18 +527,28 @@ export const TestModel = { "renderStyle": "checkBox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"notlistedVocabularyA212fs", + "ordinal":1 }, { "fields": [ @@ -426,18 +562,28 @@ export const TestModel = { "renderStyle": "freetext", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"notlistedVocUrlA212fs", + "ordinal":1 }, { "fields": [ @@ -451,18 +597,28 @@ export const TestModel = { "renderStyle": "freetext", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "defaultValue": { + "type": "any", + "value": "" }, - "multiplicity":{ - "min":"1", - "max":"1" + "visible": { + "rules": [] + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"notlistedVocCommentA212fs", + "ordinal":1 }, { "fields": [ @@ -472,23 +628,32 @@ export const TestModel = { "title": "The metadata will not make use of any vocabulary", "description": "", "extendedDescription": "", - "viewStyle": { + "viewStyle": { "renderStyle": "checkBox", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "defaultValue": { + "type": "any", + "value": "" }, - "multiplicity":{ - "min":"1", - "max":"1" + "visible": { + "rules": [] + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } } - ] + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"noMetadataVocabularyA212fs", + "ordinal":1 } ] }, @@ -513,18 +678,28 @@ export const TestModel = { "renderStyle": "booleanDesicion", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } - }] + } + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"freeOfChargeGroupQ213fs", + "ordinal":1 }, { "fields": [ @@ -538,19 +713,28 @@ export const TestModel = { "renderStyle": "freetext", "cssClass": "" }, - "defaultValue":{ - "type":"any", - "value":"" + "visible": { + "rules": [] }, - "multiplicity":{ - "min":"1", - "max":"1" + "defaultValue": { + "type": "any", + "value": "" + }, + "multiplicity": { + "min": "1", + "max": "1" }, "data": { } } - ] + ], + "multiplicity": { + "min": "1", + "max": "1" + }, + "id":"freeOfChargeGroupCommentA213fs", + "ordinal":1 } ] }