summaryrefslogtreecommitdiffstats
path: root/model/context-model
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2022-02-09 19:04:25 +0000
committerGerrit Code Review <gerrit@onap.org>2022-02-09 19:04:25 +0000
commitc9da04cc4ff4b133edd68ceee77f5bb5128d6574 (patch)
tree701523daabcb77f4ded20bd3dfe4c3660bb1fb90 /model/context-model
parent143d9c2e74ebe962640810140aa028637af88a6c (diff)
parent59b90519eda3b95b0cfc49b6349a591c7d0c78e2 (diff)
Merge "Remove JAXB and XML, use GSON for JSON"
Diffstat (limited to 'model/context-model')
-rw-r--r--model/context-model/pom.xml27
-rw-r--r--model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java15
-rw-r--r--model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java39
-rw-r--r--model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java14
-rw-r--r--model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java15
-rw-r--r--model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java62
-rw-r--r--model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java5
-rw-r--r--model/context-model/src/test/resources/json/ContextModel.json156
8 files changed, 30 insertions, 303 deletions
diff --git a/model/context-model/pom.xml b/model/context-model/pom.xml
index f38067cfa..f20808186 100644
--- a/model/context-model/pom.xml
+++ b/model/context-model/pom.xml
@@ -1,6 +1,7 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ Modifications Copyright (C) 2022 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -36,30 +37,4 @@
<version>${project.version}</version>
</dependency>
</dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-xml-schema</id>
- <phase>process-classes</phase>
- <goals>
- <goal>java</goal>
- </goals>
- <configuration>
- <mainClass>org.onap.policy.apex.model.basicmodel.handling.ApexSchemaGenerator</mainClass>
- <classpathScope>compile</classpathScope>
- <arguments>
- <argument>org.onap.policy.apex.model.contextmodel.concepts.AxContextModel</argument>
- <argument>${project.build.directory}/model/xml/apex-context-model.xsd</argument>
- </arguments>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
</project>
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<AxContextAlbum> {
private static final long serialVersionUID = -4844259809024470975L;
- @XmlElement(name = "key", required = true)
private AxArtifactKey key;
- @XmlElement(name = "albums", required = true)
@Getter(AccessLevel.NONE)
private Map<AxArtifactKey, AxContextAlbum> albums;
@@ -120,25 +108,6 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter<
}
/**
- * 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<AxArtifactKey, AxContextAlbum> navigableAlbums = new TreeMap<>();
- navigableAlbums.putAll(albums);
- albums = navigableAlbums;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
@@ -153,6 +122,14 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter<
}
/**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void buildReferences() {
+ albums.values().stream().forEach(album -> album.buildReferences());
+ }
+
+ /**
* Sets the key of the context album container.
*
* @param key the context album container key
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<AxContextSchema> {
private static final long serialVersionUID = -3203734282886453582L;
- @XmlElement(name = "key", required = true)
private AxArtifactKey key;
- @XmlElement(name = "schemas", required = true)
@Getter(AccessLevel.NONE)
private Map<AxArtifactKey, AxContextSchema> schemas;
@@ -105,7 +93,7 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
/**
* This Constructor creates a {@link AxContextSchemas} object with all its fields defined.
*
- * @param key the key of the context schema container
+ * @param key the key of the context schema container
* @param schemas a map of the schemas to insert in the context schema container
*/
public AxContextSchemas(final AxArtifactKey key, final Map<AxArtifactKey, AxContextSchema> schemas) {
@@ -119,22 +107,6 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
}
/**
- * When a model is unmarshalled from disk or from the database, the context schema 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 unmarshaller the unmarshaler that is unmarshaling the model
- * @param parent the parent object of this object in the unmarshaler
- */
- public void afterUnmarshal(final Unmarshaller unmarshaller, final Object parent) {
- // The map must be navigable to allow name and version searching, unmarshaling returns a
- // hash map
- final NavigableMap<AxArtifactKey, AxContextSchema> navigableContextSchemas = new TreeMap<>();
- navigableContextSchemas.putAll(schemas);
- schemas = navigableContextSchemas;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
@@ -146,6 +118,14 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
}
/**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void buildReferences() {
+ schemas.values().stream().forEach(schema -> schema.buildReferences());
+ }
+
+ /**
* Sets the key of the context schema container.
*
* @param key the key of the container
@@ -185,30 +165,30 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
if (key.equals(AxArtifactKey.getNullKey())) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "key is a null key"));
+ "key is a null key"));
}
result = key.validate(result);
if (schemas.size() == 0) {
result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "contextSchemas may not be empty"));
+ "contextSchemas may not be empty"));
} else {
for (final Entry<AxArtifactKey, AxContextSchema> 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<AxCon
final Map<AxArtifactKey, AxContextSchema> newcontextSchemas = new TreeMap<>();
for (final Entry<AxArtifactKey, AxContextSchema> 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<AxCon
@Override
public AxContextSchema get(final String conceptKeyName, final String conceptKeyVersion) {
return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxContextSchema>) schemas).get(conceptKeyName,
- conceptKeyVersion);
+ conceptKeyVersion);
}
/**
@@ -319,6 +299,6 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
@Override
public Set<AxContextSchema> getAll(final String conceptKeyName, final String conceptKeyVersion) {
return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxContextSchema>) 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
@@ -118,11 +118,6 @@ public class ApexContextModelTest {
}
@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