aboutsummaryrefslogtreecommitdiffstats
path: root/model/event-model/src/main/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2022-02-07 17:56:44 +0000
committerliamfallon <liam.fallon@est.tech>2022-02-08 18:39:03 +0000
commit59b90519eda3b95b0cfc49b6349a591c7d0c78e2 (patch)
tree810e07f7d5cf270582264c40245372f597c713a2 /model/event-model/src/main/java
parentdef44b294fa00bb5470e977eef9a05e5087035f0 (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'model/event-model/src/main/java')
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java32
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java13
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java35
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java18
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java8
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java8
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java9
7 files changed, 14 insertions, 109 deletions
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
index 8128b3d9a..a4c0e9db1 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
@@ -23,6 +23,7 @@
package org.onap.policy.apex.model.eventmodel.concepts;
import com.google.common.base.Strings;
+import com.google.gson.annotations.SerializedName;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -31,12 +32,6 @@ import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.TreeSet;
-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.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
import org.apache.commons.lang3.EnumUtils;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
@@ -69,35 +64,22 @@ import org.onap.policy.common.utils.validation.Assertions;
* is checked to ensure it matches the event parameter key on the event. Finally, the parent key of each parameter is
* checked to ensure it matches the event key.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement(name = "apexEvent", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlType(name = "AxEvent", namespace = "http://www.onap.org/policy/apex-pdp", propOrder =
- { "key", "nameSpace", "source", "target", "parameterMap", "toscaPolicyState"})
-
public class AxEvent extends AxConcept {
private static final long serialVersionUID = -1460388382582984269L;
private static final String WHITESPACE_REGEXP = "\\s+$";
/** The key of the event, unique in the Apex system. */
- @XmlElement(name = "key", required = true)
// CHECKSTYLE:OFF: checkstyle:VisibilityMonitor
protected AxArtifactKey key;
// CHECKSTYLE:ON: checkstyle:VisibilityMonitor
- @XmlElement(required = true)
private String nameSpace;
-
- @XmlElement(required = true)
private String source;
-
- @XmlElement(required = true)
private String target;
- @XmlElement(name = "parameter", required = true)
+ @SerializedName("parameter")
private Map<String, AxField> parameterMap;
-
- @XmlElement(required = false)
private String toscaPolicyState;
/**
@@ -189,14 +171,10 @@ public class AxEvent extends AxConcept {
}
/**
- * When an event is unmarshalled from disk or from the database, the parent key in the reference keys in its
- * parameter map are not set. This method is called by JAXB after unmarshaling and is used to set the parent key of
- * the {@link AxField} instances in the parameter map to be the key of the event that contains them.
- *
- * @param unmarshaler the unmarshaler that is unmarshaling the model
- * @param parent the parent object of this object in the unmarshaler
+ * {@inheritDoc}.
*/
- public void afterUnmarshal(final Unmarshaller unmarshaler, final Object parent) {
+ @Override
+ public void buildReferences() {
for (final AxField parameter : parameterMap.values()) {
parameter.getKey().setParentArtifactKey(key);
}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java
index bb4307604..b91712c9d 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java
@@ -23,11 +23,6 @@
package org.onap.policy.apex.model.eventmodel.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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
@@ -46,18 +41,10 @@ import org.onap.policy.common.utils.validation.Assertions;
* <p>Validation runs {@link AxModel} validation on the model. In addition, the {@link AxContextSchemas} and
* {@link AxEvents} validation is run on the context schemas and events in the model.
*/
-
-@XmlRootElement(name = "apexEventModel", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "AxEventModel", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "schemas", "events" })
-
public class AxEventModel extends AxModel {
private static final long serialVersionUID = 8800599637708309945L;
- @XmlElement(name = "schemas", required = true)
private AxContextSchemas schemas;
-
- @XmlElement(name = "events", required = true)
private AxEvents events;
/**
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java
index 26275a157..aac1562de 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java
@@ -27,11 +27,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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter;
@@ -52,17 +47,10 @@ import org.onap.policy.common.utils.validation.Assertions;
* container. Each event entry is checked to ensure that its key and value are not null and that the key matches the key
* in the map value. Each event entry is then validated individually.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "AxEvents", namespace = "http://www.onap.org/policy/apex-pdp", propOrder =
- { "key", "eventMap" })
-
public class AxEvents extends AxConcept implements AxConceptGetter<AxEvent> {
private static final long serialVersionUID = 4290442590545820316L;
- @XmlElement(name = "key", required = true)
private AxArtifactKey key;
-
- @XmlElement(required = true)
private Map<AxArtifactKey, AxEvent> eventMap;
/**
@@ -108,21 +96,6 @@ public class AxEvents extends AxConcept implements AxConceptGetter<AxEvent> {
}
/**
- * When a model is unmarshalled from disk or from the database, the event 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 unmarshaler the unmarshaler that is unmarshaling the model
- * @param parent the parent object of this object in the unmarshaler
- */
- public void afterUnmarshal(final Unmarshaller unmarshaler, final Object parent) {
- // The map must be navigable to allow name and version searching, unmarshaling returns a hash map
- final NavigableMap<AxArtifactKey, AxEvent> navigableEventMap = new TreeMap<>();
- navigableEventMap.putAll(eventMap);
- eventMap = navigableEventMap;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
@@ -145,6 +118,14 @@ public class AxEvents extends AxConcept implements AxConceptGetter<AxEvent> {
}
/**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void buildReferences() {
+ eventMap.values().stream().forEach(event -> event.buildReferences());
+ }
+
+ /**
* Sets the key of the event container.
*
* @param key the event container key
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java
index 9f98a6253..26511c9d1 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java
@@ -23,12 +23,6 @@
package org.onap.policy.apex.model.eventmodel.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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
@@ -37,7 +31,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
-import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
import org.onap.policy.common.utils.validation.Assertions;
/**
@@ -50,11 +43,6 @@ import org.onap.policy.common.utils.validation.Assertions;
*
* <p>Validation checks that the field key and the field schema reference key are not null.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement(name = "apexField", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlType(name = "AxField", namespace = "http://www.onap.org/policy/apex-pdp", propOrder =
- { "key", "fieldSchemaKey", "optional" })
-
public class AxField extends AxConcept {
private static final String KEY_MAY_NOT_BE_NULL = "key may not be null";
private static final String FIELD_SCHEMA_KEY_MAY_NOT_BE_NULL = "fieldSchemaKey may not be null";
@@ -64,14 +52,8 @@ public class AxField extends AxConcept {
private static final int HASH_PRIME_0 = 1231;
private static final int HASH_PRIME_1 = 1237;
- @XmlElement(name = "key", required = true)
- @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
private AxReferenceKey key;
-
- @XmlElement(required = true)
private AxArtifactKey fieldSchemaKey;
-
- @XmlElement(required = false)
private boolean optional;
/**
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java
index 2626e8b25..6155c7186 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java
@@ -21,20 +21,12 @@
package org.onap.policy.apex.model.eventmodel.concepts;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
/**
* This class specializes the {@link AxField} class for use as input fields on events.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement(name = "apexInputField", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlType(name = "AxInputField", namespace = "http://www.onap.org/policy/apex-pdp")
-
public class AxInputField extends AxField {
private static final long serialVersionUID = 2090324845463750391L;
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java
index a3e835202..7f3437617 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java
@@ -21,20 +21,12 @@
package org.onap.policy.apex.model.eventmodel.concepts;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
/**
* This class specializes the {@link AxField} class for use as output fields on events.
*/
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlRootElement(name = "apexOutputField", namespace = "http://www.onap.org/policy/apex-pdp")
-@XmlType(name = "AxOutputField", namespace = "http://www.onap.org/policy/apex-pdp")
-
public class AxOutputField extends AxField {
private static final long serialVersionUID = 2090324845463750391L;
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java
index 7b20b3939..414d22d0e 100644
--- a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java
@@ -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.
@@ -23,12 +24,4 @@
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-
-@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
- xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") })
-
package org.onap.policy.apex.model.eventmodel.concepts;
-
-import javax.xml.bind.annotation.XmlNs;
-import javax.xml.bind.annotation.XmlNsForm;
-import javax.xml.bind.annotation.XmlSchema;