From 59b90519eda3b95b0cfc49b6349a591c7d0c78e2 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 7 Feb 2022 17:56:44 +0000 Subject: Remove JAXB and XML, use GSON for JSON This review converst apex-pdp to use GSON for JSON handling. In order to preserve backward compatibility with the JAXB format of JSON, custom handling of maps was required. Therefore, the policy-common StandardCoder could not be used. There are a lot of small changes, removing annotations from concepts and tweaking of test data. However, this cleans up the code base so it is worth doing. Issue-ID: POLICY-1820 Change-Id: I213fa64f6d7f3f1df8d10f111d9fbedbe80f9fe0 Signed-off-by: liamfallon --- .../contextmodel/concepts/AxContextAlbum.java | 15 -- .../contextmodel/concepts/AxContextAlbums.java | 39 ++---- .../contextmodel/concepts/AxContextModel.java | 14 -- .../contextmodel/concepts/AxContextSchema.java | 15 -- .../contextmodel/concepts/AxContextSchemas.java | 62 +++----- .../handling/ApexContextModelTest.java | 5 - .../src/test/resources/json/ContextModel.json | 156 --------------------- 7 files changed, 29 insertions(+), 277 deletions(-) delete mode 100644 model/context-model/src/test/resources/json/ContextModel.json (limited to 'model/context-model/src') diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java index d7d8a1d96..db64f8847 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.contextmodel.concepts; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -66,11 +61,6 @@ import org.onap.policy.common.utils.validation.Assertions; @ToString @EqualsAndHashCode(callSuper = false) -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexContextAlbum", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxContextAlbum", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "scope", "isWritable", "itemSchema" }) - public class AxContextAlbum extends AxConcept { private static final String SCOPE_STRING = "scope"; @@ -84,17 +74,12 @@ public class AxContextAlbum extends AxConcept { /** The value of scope for a context album for which a scope has not been specified. */ public static final String SCOPE_UNDEFINED = "UNDEFINED"; - @XmlElement(name = "key", required = true) private AxArtifactKey key; - - @XmlElement(name = SCOPE_STRING, required = true) private String scope; - @XmlElement(name = "isWritable", required = true) @Setter private boolean isWritable; - @XmlElement(name = "itemSchema", required = true) private AxArtifactKey itemSchema; /** diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java index 65247ab80..54e3ce44b 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java @@ -28,11 +28,6 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; import lombok.AccessLevel; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -61,18 +56,11 @@ import org.onap.policy.common.utils.validation.Assertions; @Getter @ToString @EqualsAndHashCode(callSuper = false) - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxContextAlbums", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "albums" }) - public final class AxContextAlbums extends AxConcept implements AxConceptGetter { private static final long serialVersionUID = -4844259809024470975L; - @XmlElement(name = "key", required = true) private AxArtifactKey key; - @XmlElement(name = "albums", required = true) @Getter(AccessLevel.NONE) private Map albums; @@ -119,25 +107,6 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter< this.albums.putAll(albums); } - /** - * When a model is unmarshalled from disk or from the database, the context album map is returned as a raw hash map. - * This method is called by JAXB after unmarshaling and is used to convert the hash map to a {@link NavigableMap} so - * that it will work with the {@link AxConceptGetter} interface. - * - * @param unmarsaller the unmarshaler that is unmarshaling the model - * @param parent the parent object of this object in the unmarshaler - */ - public void afterUnmarshal(final Unmarshaller unmarsaller, final Object parent) { - Assertions.argumentNotNull(unmarsaller, "unmarsaller should not be null"); - Assertions.argumentNotNull(parent, "parent should not be null"); - - // The map must be navigable to allow name and version searching, unmarshaling returns a - // hash map - final NavigableMap navigableAlbums = new TreeMap<>(); - navigableAlbums.putAll(albums); - albums = navigableAlbums; - } - /** * {@inheritDoc}. */ @@ -152,6 +121,14 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter< return keyList; } + /** + * {@inheritDoc}. + */ + @Override + public void buildReferences() { + albums.values().stream().forEach(album -> album.buildReferences()); + } + /** * Sets the key of the context album container. * diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java index e17149336..1effe8079 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.contextmodel.concepts; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; @@ -52,19 +47,10 @@ import org.onap.policy.common.utils.validation.Assertions; @Getter @ToString(callSuper = true) @EqualsAndHashCode(callSuper = true) - -@XmlRootElement(name = "apexContextModel", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxContextModel", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = { "schemas", "albums" }) - public class AxContextModel extends AxModel { private static final long serialVersionUID = 8800599637708309945L; - @XmlElement(name = "schemas", required = true) private AxContextSchemas schemas; - - @XmlElement(name = "albums", required = true) private AxContextAlbums albums; /** diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java index a1560c07b..61434ca67 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.contextmodel.concepts; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlType; import lombok.AccessLevel; import lombok.Getter; import lombok.ToString; @@ -59,12 +54,6 @@ import org.onap.policy.common.utils.validation.Assertions; */ @Getter @ToString - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexContextSchema", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxContextSchema", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "schemaFlavour", "schemaDefinition" }) - public class AxContextSchema extends AxConcept { private static final String SCHEMA_FLAVOUR = "schemaFlavour"; private static final String WHITESPACE_REGEXP = "\\s+$"; @@ -80,13 +69,9 @@ public class AxContextSchema extends AxConcept { /** The maximum permissible size of a schema definition. */ public static final int MAX_SCHEMA_SIZE = 32672; // The maximum size supported by Apache Derby - @XmlElement(name = "key", required = true) private AxArtifactKey key; - - @XmlElement(required = true) private String schemaFlavour; - @XmlElement(name = "schemaDefinition", required = true) @Getter(AccessLevel.NONE) private String schemaDefinition; diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java index a5b56f244..5b79a3dcb 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java @@ -28,11 +28,6 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; -import javax.xml.bind.Unmarshaller; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlType; import lombok.AccessLevel; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -60,18 +55,11 @@ import org.onap.policy.common.utils.validation.Assertions; @Getter @ToString @EqualsAndHashCode(callSuper = false) - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxContextSchemas", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "schemas" }) - public class AxContextSchemas extends AxConcept implements AxConceptGetter { private static final long serialVersionUID = -3203734282886453582L; - @XmlElement(name = "key", required = true) private AxArtifactKey key; - @XmlElement(name = "schemas", required = true) @Getter(AccessLevel.NONE) private Map schemas; @@ -105,7 +93,7 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter schemas) { @@ -118,22 +106,6 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter navigableContextSchemas = new TreeMap<>(); - navigableContextSchemas.putAll(schemas); - schemas = navigableContextSchemas; - } - /** * {@inheritDoc}. */ @@ -145,6 +117,14 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter schema.buildReferences()); + } + /** * Sets the key of the context schema container. * @@ -185,30 +165,30 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter contextSchemaEntry : schemas.entrySet()) { if (contextSchemaEntry.getKey().equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on schemas entry " + contextSchemaEntry.getKey() - + " may not be the null key")); + "key on schemas entry " + contextSchemaEntry.getKey() + + " may not be the null key")); } else if (contextSchemaEntry.getValue() == null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on schemas entry " + contextSchemaEntry.getKey() + " may not be null")); + "value on schemas entry " + contextSchemaEntry.getKey() + " may not be null")); } else { if (!contextSchemaEntry.getKey().equals(contextSchemaEntry.getValue().getKey())) { result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on schemas entry " + contextSchemaEntry.getKey() - + " does not equal entry key " - + contextSchemaEntry.getValue().getKey())); + new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "key on schemas entry " + contextSchemaEntry.getKey() + + " does not equal entry key " + + contextSchemaEntry.getValue().getKey())); } result = contextSchemaEntry.getValue().validate(result); @@ -247,7 +227,7 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter newcontextSchemas = new TreeMap<>(); for (final Entry contextSchemasEntry : schemas.entrySet()) { newcontextSchemas.put(new AxArtifactKey(contextSchemasEntry.getKey()), - new AxContextSchema(contextSchemasEntry.getValue())); + new AxContextSchema(contextSchemasEntry.getValue())); } copy.setSchemasMap(newcontextSchemas); @@ -302,7 +282,7 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter((NavigableMap) schemas).get(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } /** @@ -319,6 +299,6 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter getAll(final String conceptKeyName, final String conceptKeyVersion) { return new AxConceptGetterImpl<>((NavigableMap) schemas).getAll(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } } diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java index a18065ed9..998469bac 100644 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java @@ -117,11 +117,6 @@ public class ApexContextModelTest { assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); } - @Test - public void testModelWriteReadXml() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - @Test public void testModelWriteReadJson() throws Exception { testApexModel.testApexModelWriteReadJson(); diff --git a/model/context-model/src/test/resources/json/ContextModel.json b/model/context-model/src/test/resources/json/ContextModel.json deleted file mode 100644 index 2c93ef1c2..000000000 --- a/model/context-model/src/test/resources/json/ContextModel.json +++ /dev/null @@ -1,156 +0,0 @@ -{ - "apexContextModel" : { - "key" : { - "name" : "contextModel", - "version" : "0.0.1" - }, - "keyInformation" : { - "key" : { - "name" : "KeyInfoMapKey", - "version" : "0.0.1" - }, - "keyInfoMap" : { - "keyInfoEntry" : [ { - "key" : { - "name" : "StringType", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000000", - "description" : "axContextType0" - }, { - "key" : { - "name" : "MapType", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000001", - "description" : "axContextType1" - }, { - "key" : { - "name" : "contextMap0", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000002", - "description" : "contextMap0" - }, { - "key" : { - "name" : "contextMap1", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000003", - "description" : "contextMap1" - }, { - "key" : { - "name" : "context", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000004", - "description" : "axContext" - }, { - "key" : { - "name" : "contextModel", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000005", - "description" : "contextModel" - }, { - "key" : { - "name" : "KeyInfoMapKey", - "version" : "0.0.1" - }, - "UUID" : "00000000-0000-0000-0000-000000000006", - "description" : "keyInformation" - } ] - } - }, - "context" : { - "key" : { - "name" : "context", - "version" : "0.0.1" - }, - "contextMaps" : { - "entry" : [ { - "key" : "contextMap0", - "value" : { - "key" : { - "name" : "contextMap0", - "version" : "0.0.1" - }, - "scope" : "APPLICATION", - "mapType" : "BAG", - "contextMap" : { - "contextItem" : [ { - "key" : "axContextItem0_0", - "contextType" : { - "key" : { - "name" : "StringType", - "version" : "0.0.1" - }, - "javaType" : "org.onap.policy.apex.core.contextmodel.concepts.TestContextItem000" - }, - "isWritable" : true, - "valueString" : "" - }, { - "key" : "axContextItem0_1", - "contextType" : { - "key" : { - "name" : "MapType", - "version" : "0.0.1" - }, - "javaType" : "org.onap.policy.apex.core.contextmodel.concepts.TestContextItem00A" - }, - "isWritable" : true, - "valueString" : "" - }, { - "key" : "axContextItem0_2", - "contextType" : { - "key" : { - "name" : "StringType", - "version" : "0.0.1" - }, - "javaType" : "org.onap.policy.apex.core.contextmodel.concepts.TestContextItem000" - }, - "isWritable" : true, - "valueString" : "" - }, { - "key" : "axContextItem0_3", - "contextType" : { - "key" : { - "name" : "MapType", - "version" : "0.0.1" - }, - "javaType" : "org.onap.policy.apex.core.contextmodel.concepts.TestContextItem00A" - }, - "isWritable" : true, - "valueString" : "" - } ] - } - } - }, { - "key" : "contextMap1", - "value" : { - "key" : { - "name" : "contextMap1", - "version" : "0.0.1" - }, - "scope" : "GLOBAL", - "mapType" : "SAMETYPE", - "templateContextItem" : { - "key" : "axTemplateContextItem", - "contextType" : { - "key" : { - "name" : "MapType", - "version" : "0.0.1" - }, - "javaType" : "org.onap.policy.apex.core.contextmodel.concepts.TestContextItem00A" - }, - "isWritable" : true - }, - "contextMap" : { - "contextItem" : [ ] - } - } - } ] - } - } - } -} \ No newline at end of file -- cgit 1.2.3-korg