diff options
Diffstat (limited to 'model/policy-model/src/main')
16 files changed, 177 insertions, 462 deletions
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java index a7cb97a46..0564d5854 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java @@ -22,19 +22,12 @@ package org.onap.policy.apex.model.policymodel.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.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; 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; /** @@ -49,12 +42,6 @@ import org.onap.policy.common.utils.validation.Assertions; * <p>Validation checks that the logic key is valid, that the logic flavour is defined and is valid when checked against * the {@code LOGIC_FLAVOUR_REGEXP} regular expression, and that the specified logic string is not null or blank. */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexLogic", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxLogic", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "logicFlavour", "logic" }) - public class AxLogic extends AxConcept { private static final long serialVersionUID = -4260562004005697328L; @@ -74,14 +61,8 @@ public class AxLogic extends AxConcept { /** The maximum permissible size of a logic definition. */ public static final int MAX_LOGIC_SIZE = 32672; // The maximum size supported by Apache Derby - @XmlElement(name = "key", required = true) - @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class) private AxReferenceKey key; - - @XmlElement(required = true) private String logicFlavour; - - @XmlElement(required = true) private String logic; /** diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java index 4073046ab..bb30f46cf 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.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 policy 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 policy entry is then validated individually. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxPolicies", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "policyMap" }) - public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { private static final long serialVersionUID = 4290442590545820316L; - @XmlElement(name = "key", required = true) private AxArtifactKey key; - - @XmlElement(required = true) private Map<AxArtifactKey, AxPolicy> policyMap; /** @@ -95,7 +83,7 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { /** * This Constructor creates a policy container with all of its fields defined. * - * @param key the policy container key + * @param key the policy container key * @param policyMap the policies to be stored in the policy container */ public AxPolicies(final AxArtifactKey key, final Map<AxArtifactKey, AxPolicy> policyMap) { @@ -109,22 +97,6 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { } /** - * When a model is unmarshalled from disk or from the database, the policy 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, AxPolicy> navigablePolicyMap = new TreeMap<>(); - navigablePolicyMap.putAll(policyMap); - policyMap = navigablePolicyMap; - } - - /** * {@inheritDoc}. */ @Override @@ -147,6 +119,18 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { } /** + * {@inheritDoc}. + */ + @Override + public void buildReferences() { + policyMap.entrySet().stream().forEach(policyEntry -> { + policyEntry.getValue().setKey(policyEntry.getKey()); + policyEntry.getValue().buildReferences(); + } + ); + } + + /** * Sets the key of the policy container. * * @param key the policy container key @@ -185,23 +169,23 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { 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 (policyMap.size() == 0) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "policyMap may not be empty")); + "policyMap may not be empty")); } else { for (final Entry<AxArtifactKey, AxPolicy> policyEntry : policyMap.entrySet()) { final AxArtifactKey entryKey = policyEntry.getKey(); if (entryKey.equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on policy entry " + entryKey + " may not be the null key")); + "key on policy entry " + entryKey + " may not be the null key")); } else if (policyEntry.getValue() == null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on policy entry " + entryKey + " may not be null")); + "value on policy entry " + entryKey + " may not be null")); } else { validate(result, policyEntry, entryKey); result = policyEntry.getValue().validate(result); @@ -213,11 +197,11 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { } private void validate(final AxValidationResult result, final Entry<AxArtifactKey, AxPolicy> policyEntry, - final AxArtifactKey entryKey) { + final AxArtifactKey entryKey) { if (!entryKey.equals(policyEntry.getValue().getKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on policy entry key " + entryKey + " does not equal policy value key " - + policyEntry.getValue().getKey())); + "key on policy entry key " + entryKey + " does not equal policy value key " + + policyEntry.getValue().getKey())); } } @@ -354,7 +338,7 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { @Override public AxPolicy get(final String conceptKeyName, final String conceptKeyVersion) { return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } /** @@ -371,6 +355,6 @@ public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { @Override public Set<AxPolicy> getAll(final String conceptKeyName, final String conceptKeyVersion) { return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).getAll(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } } diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java index 64785daef..a47afe4d6 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java @@ -21,17 +21,13 @@ package org.onap.policy.apex.model.policymodel.concepts; +import com.google.gson.annotations.SerializedName; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -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; @@ -60,38 +56,42 @@ import org.slf4j.ext.XLoggerFactory; * <p>The template of a policy is a string that can be used by policy editors to store meta information on the policy * that can be used at design time. The policy template string is not used during policy execution. * - * <p>During validation of a policy, the validation checks listed below are executed: <ol> <li>The policy key must not - * be a null key <li>The policy key must be valid <li>If the policy template is not set, an observation is issued <li>At - * least one state must be defined <li>Keys and values must all be defined, that is not null <li>The key on each entry - * in the state map must match the key in the entry's value <li>The parent key of each state in the state map of a - * policy must be the key of that policy <li>Each state must itself be valid, see validation in {@link AxState} <li>The - * next state of the state output of each state must be defined as a state in the policy <li>The first state of a policy - * must be set <li>The first state of a policy must be defined in the policy <li>If a state is defined but is not used - * in a policy,a warning is issued <li>The state tree of the policy must be valid, see validation in {@link AxStateTree} + * <p>During validation of a policy, the validation checks listed below are executed: + * <ol> + * <li>The policy key must not + * be a null key + * <li>The policy key must be valid + * <li>If the policy template is not set, an observation is issued + * <li>At + * least one state must be defined + * <li>Keys and values must all be defined, that is not null + * <li>The key on each entry + * in the state map must match the key in the entry's value + * <li>The parent key of each state in the state map of a + * policy must be the key of that policy + * <li>Each state must itself be valid, see validation in {@link AxState} + * <li>The + * next state of the state output of each state must be defined as a state in the policy + * <li>The first state of a policy + * must be set + * <li>The first state of a policy must be defined in the policy + * <li>If a state is defined but is not used + * in a policy,a warning is issued + * <li>The state tree of the policy must be valid, see validation in {@link AxStateTree} * </ol> */ - -@XmlRootElement(name = "apexPolicy", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxPolicy", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "template", "stateMap", "firstState" }) - public class AxPolicy extends AxConcept { private static final long serialVersionUID = -1775614096390365941L; // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(AxPolicy.class); - @XmlElement(name = "policyKey", required = true) + @SerializedName("policyKey") private AxArtifactKey key; - - @XmlElement(required = true) private String template; - @XmlElement(name = "state", required = true) + @SerializedName("state") private Map<String, AxState> stateMap; - - @XmlElement(required = true) private String firstState; /** @@ -116,15 +116,18 @@ public class AxPolicy extends AxConcept { * @param key the key of the policy */ public AxPolicy(final AxArtifactKey key) { - this(key, "", new TreeMap<>(), ""); + this(key, + "", + new TreeMap<>(), + ""); } /** * This Constructor creates a policy with the given key and all its fields defined. * - * @param key the key of the policy - * @param template the policy template for policy editor metadata - * @param stateMap the state map containing the states of the policy + * @param key the key of the policy + * @param template the policy template for policy editor metadata + * @param stateMap the state map containing the states of the policy * @param firstState the first state that will execute on this policy */ public AxPolicy(final AxArtifactKey key, final String template, final Map<String, AxState> stateMap, @@ -172,6 +175,20 @@ public class AxPolicy extends AxConcept { } /** + * {@inheritDoc}. + */ + @Override + public void buildReferences() { + stateMap.entrySet().stream().forEach(stateEntry -> { + if (!stateEntry.getValue().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { + stateEntry.getValue().getKey().setParentArtifactKey(key); + } + stateEntry.getValue().buildReferences(); + } + ); + } + + /** * Sets the key of the policy. * * @param key the key of the policy @@ -246,20 +263,21 @@ public class AxPolicy extends AxConcept { AxValidationResult result = resultIn; if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key is a null key")); + result.addValidationMessage( + new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); } result = key.validate(result); if (template.trim().length() == 0) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION, - "a policy template has not been specified")); + "a policy template has not been specified")); } if (stateMap.size() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "stateMap may not be empty")); + result.addValidationMessage( + new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "stateMap may not be empty")); } else { for (final Entry<String, AxState> stateEntry : stateMap.entrySet()) { result = validateStateEntry(stateEntry, result); @@ -275,11 +293,11 @@ public class AxPolicy extends AxConcept { // We only check the unused states on models validated this far if (firstState.trim().length() == 0) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "no first state specified, first state may not be blank")); + "no first state specified, first state may not be blank")); } else { if (!stateMap.containsKey(firstState)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "first state not found in stateMap")); + "first state not found in stateMap")); } else { validateStateTree(result); } @@ -292,43 +310,42 @@ public class AxPolicy extends AxConcept { * Validate a state entry. * * @param stateEntry the state entry to validate - * @param result The validation result to append to + * @param result The validation result to append to * @return The result of the validation */ - private AxValidationResult validateStateEntry(final Entry<String, AxState> stateEntry, AxValidationResult result) { + private AxValidationResult validateStateEntry(final Entry<String, AxState> stateEntry, AxValidationResult + result) { if (stateEntry.getKey() == null || stateEntry.getKey().equals(AxKey.NULL_KEY_NAME)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on state entry key " + stateEntry.getKey() + " may not be the null key")); + "key on state entry key " + stateEntry.getKey() + " may not be the null key")); return result; } if (stateEntry.getValue() == null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on state entry value " + stateEntry.getKey() + " may not be null")); + "value on state entry value " + stateEntry.getKey() + " may not be null")); return result; } if (!stateEntry.getKey().equals(stateEntry.getValue().getKey().getLocalName())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on state entry key " + stateEntry.getKey() - + " does not equal state entry value local name " - + stateEntry.getValue().getKey().getLocalName())); + "key on state entry key " + stateEntry.getKey() + " does not equal state entry value local name " + + stateEntry.getValue().getKey().getLocalName())); } if (!stateEntry.getValue().getKey().getParentArtifactKey().equals(key)) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent key on state entry key " + stateEntry.getValue().getKey() - + " does not equal policy key")); + "parent key on state entry key " + stateEntry.getValue().getKey() + " does not equal policy key")); } result = stateEntry.getValue().validate(result); for (final AxStateOutput stateOutput : stateEntry.getValue().getStateOutputs().values()) { if (!stateOutput.getNextState().equals(AxReferenceKey.getNullKey()) - && !stateMap.containsKey(stateOutput.getNextState().getLocalName())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - " nextState of state " + stateEntry.getKey() + " not found in StateMap: " - + stateOutput.getNextState().getId())); + && !stateMap.containsKey(stateOutput.getNextState().getLocalName())) { + result.addValidationMessage( + new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, " nextState of state " + + stateEntry.getKey() + " not found in StateMap: " + stateOutput.getNextState().getId())); } } @@ -353,12 +370,11 @@ public class AxPolicy extends AxConcept { for (final AxState unreferencedState : unreferencedStateSet) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING, - "state " + unreferencedState.getKey() - + " is not referenced in the policy execution tree")); + "state " + unreferencedState.getKey() + " is not referenced in the policy execution tree")); } } catch (PolicyRuntimeException pre) { AxValidationMessage validationMessage = new AxValidationMessage(key, this.getClass(), - ValidationResult.WARNING, "state tree in policy is invalid"); + ValidationResult.WARNING, "state tree in policy is invalid"); LOGGER.trace(validationMessage.getMessage(), pre); result.addValidationMessage(validationMessage); } diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java index 38c08ed94..e119536fb 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java @@ -25,14 +25,6 @@ package org.onap.policy.apex.model.policymodel.concepts; import java.util.List; import java.util.Map.Entry; -import javax.xml.bind.Marshaller; -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 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; @@ -41,7 +33,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxModel; 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.handling.KeyInfoMarshalFilter; import org.onap.policy.apex.model.basicmodel.service.ModelService; import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; @@ -50,7 +41,6 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; import org.onap.policy.apex.model.eventmodel.concepts.AxEvents; import org.onap.policy.apex.model.eventmodel.concepts.AxField; -import org.onap.policy.apex.model.policymodel.handling.EmptyAlbumsAdapter; import org.onap.policy.common.utils.validation.Assertions; /** @@ -98,30 +88,23 @@ import org.onap.policy.common.utils.validation.Assertions; * <li>All events referred to on direct state outputs must exist * </ol> */ -@XmlRootElement(name = "apexPolicyModel", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxPolicyModel", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"policies", "tasks", "events", "albums", "schemas"}) - public class AxPolicyModel extends AxModel { + // @formatter:off + private static final String SCHEMAS_TOKEN = "_Schemas"; + private static final String KEY_INFO_TOKEN = "_KeyInfo"; + private static final String EVENTS_TOKEN = "_Events"; + private static final String ALBUMS_TOKEN = "_Albums"; + private static final String TASKS_TOKEN = "_Tasks"; + private static final String POLICIESS_TOKEN = "_Policies"; + private static final String DOES_NOT_EXIST = " does not exist"; private static final long serialVersionUID = 8800599637708309945L; - @XmlElement(name = "policies", required = true) private AxPolicies policies; - - @XmlElement(name = "tasks", required = true) private AxTasks tasks; - - @XmlElement(name = "events", required = true) private AxEvents events; - - @XmlElement(name = "albums", required = false) - @XmlJavaTypeAdapter(EmptyAlbumsAdapter.class) private AxContextAlbums albums; - - @XmlElement(name = "schemas", required = true) private AxContextSchemas schemas; /** @@ -148,12 +131,13 @@ public class AxPolicyModel extends AxModel { * @param key the key */ public AxPolicyModel(final AxArtifactKey key) { - this(key, new AxContextSchemas(new AxArtifactKey(key.getName() + "_Schemas", key.getVersion())), - new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion())), - new AxEvents(new AxArtifactKey(key.getName() + "_Events", key.getVersion())), - new AxContextAlbums(new AxArtifactKey(key.getName() + "_Albums", key.getVersion())), - new AxTasks(new AxArtifactKey(key.getName() + "_Tasks", key.getVersion())), - new AxPolicies(new AxArtifactKey(key.getName() + "_Policies", key.getVersion()))); + this(key, + new AxContextSchemas(new AxArtifactKey(key.getName() + SCHEMAS_TOKEN, key.getVersion())), + new AxKeyInformation(new AxArtifactKey(key.getName() + KEY_INFO_TOKEN, key.getVersion())), + new AxEvents(new AxArtifactKey(key.getName() + EVENTS_TOKEN, key.getVersion())), + new AxContextAlbums(new AxArtifactKey(key.getName() + ALBUMS_TOKEN, key.getVersion())), + new AxTasks(new AxArtifactKey(key.getName() + TASKS_TOKEN, key.getVersion())), + new AxPolicies(new AxArtifactKey(key.getName() + POLICIESS_TOKEN, key.getVersion()))); } /** @@ -168,7 +152,7 @@ public class AxPolicyModel extends AxModel { * @param policies the policy container for the policy model */ public AxPolicyModel(final AxArtifactKey key, final AxContextSchemas schemas, final AxKeyInformation keyInformation, - final AxEvents events, final AxContextAlbums albums, final AxTasks tasks, final AxPolicies policies) { + final AxEvents events, final AxContextAlbums albums, final AxTasks tasks, final AxPolicies policies) { super(key, keyInformation); Assertions.argumentNotNull(schemas, "schemas may not be null"); Assertions.argumentNotNull(events, "events may not be null"); @@ -334,7 +318,7 @@ public class AxPolicyModel extends AxModel { validateEventKeys(result); validateContextAlbumKeys(result); - result = validateAllTaskKeys(result); + validateAllTaskKeys(result); validatePolicyKeys(result); return result; @@ -384,7 +368,7 @@ public class AxPolicyModel extends AxModel { */ private AxValidationResult validateAllTaskKeys(AxValidationResult result) { for (final AxTask task : tasks.getAll(null)) { - result = validateTaskKeys(task, result); + validateTaskKeys(task, result); } return result; } @@ -496,7 +480,7 @@ public class AxPolicyModel extends AxModel { * @param result the validation result to append to */ private void validateEventTaskFieldCompatibilityOnStateOutput(final AxState state, final AxTask task, - final AxStateOutput stateOutput, AxValidationResult result) { + final AxStateOutput stateOutput, AxValidationResult result) { if (stateOutput == null) { result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(), ValidationResult.INVALID, "state output on task reference for task " + task.getId() + " is null")); @@ -512,38 +496,26 @@ public class AxPolicyModel extends AxModel { } /** - * When a model is unmarshalled from disk or from the database, if the albums field was missing a blank - * with a null key was added. This method is called by JAXB after unmarshalling and is + * When a model is deserialized, if the albums field was missing a blank + * with a null key was added. This method is called by JAXB after deserializing and is * used to insert an appropriate key - * - * @param unmarshaller the unmarshaller that is unmarshalling the model - * @param parent the parent object of this object in the unmarshaller */ - public void afterUnmarshal(final Unmarshaller unmarshaller, final Object parent) { - new EmptyAlbumsAdapter().doAfterUnmarshal(this); - } - - /** - * When a model is marshalled from disk or database, if the albums field is empty/null, then the albums field - * is not emitted. If the (empty) albums field is not emitted then it's keyinfo should also be suppressed - * This method is called by JAXB before marshaling and is used to insert the appropriate filters - * - * @param marshaller the marshaller that is marshaller the model - * @throws Exception if there is a problem with the marshalling - */ - public void beforeMarshal(final Marshaller marshaller) throws Exception { - EmptyAlbumsAdapter albumsfilter = new EmptyAlbumsAdapter(); - marshaller.setAdapter(EmptyAlbumsAdapter.class, albumsfilter); - //get/create the keyinfofilter - KeyInfoMarshalFilter keyinfoFilter = marshaller.getAdapter(KeyInfoMarshalFilter.class); - if (keyinfoFilter == null) { - keyinfoFilter = new KeyInfoMarshalFilter(); - } - //if the albumsfilter would filter out this model's albums add the album's key to the keyinfofilter - if (albumsfilter.marshal(this.albums) == null && this.albums != null) { - keyinfoFilter.addFilterKey(this.albums.getKey()); + @Override + public void buildReferences() { + getSchemas().buildReferences(); + getEvents().buildReferences(); + getAlbums().buildReferences(); + getTasks().buildReferences(); + getPolicies().buildReferences(); + getKeyInformation().buildReferences(); + + AxArtifactKey nullAlbumskey = new AxArtifactKey(AxKey.NULL_KEY_NAME + ALBUMS_TOKEN, AxKey.NULL_KEY_VERSION); + + if (AxArtifactKey.getNullKey().equals(getAlbums().getKey()) + || nullAlbumskey.equals(getAlbums().getKey())) { + getAlbums().setKey(new AxArtifactKey(getKey().getName() + ALBUMS_TOKEN, getKey().getVersion())); + getKeyInformation().generateKeyInfo(getAlbums()); } - marshaller.setAdapter(keyinfoFilter); } /** diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java index df07b0ea3..ae8efbff4 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java @@ -23,18 +23,13 @@ package org.onap.policy.apex.model.policymodel.concepts; +import com.google.gson.annotations.SerializedName; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; 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.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; @@ -106,40 +101,27 @@ import org.onap.policy.common.utils.validation.Assertions; * <li>Each State Finalizer logic instance in a state must be valid, see validation in {@link AxStateFinalizerLogic} * </ol> */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexState", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxState", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = - { "key", "trigger", "stateOutputs", "contextAlbumReferenceSet", "taskSelectionLogic", "stateFinalizerLogicMap", - "defaultTask", "taskReferenceMap" }) - public class AxState extends AxConcept { private static final String DOES_NOT_EQUAL_STATE_KEY = " does not equal state key"; private static final long serialVersionUID = 8041771382337655535L; - @XmlElement(name = "stateKey", required = true) + + + @SerializedName("stateKey") private AxReferenceKey key; - @XmlElement(required = true) private AxArtifactKey trigger; - - @XmlElement(name = "stateOutputs", required = true) private Map<String, AxStateOutput> stateOutputs; - @XmlElement(name = "contextAlbumReference") + @SerializedName("contextAlbumReference") private Set<AxArtifactKey> contextAlbumReferenceSet; - @XmlElement(required = true) private AxTaskSelectionLogic taskSelectionLogic; - - @XmlElement(name = "stateFinalizerLogicMap", required = true) private Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap; - - @XmlElement(required = true) private AxArtifactKey defaultTask; - @XmlElement(name = "taskReferences", required = true) + @SerializedName("taskReferences") private Map<AxArtifactKey, AxStateTaskReference> taskReferenceMap; /** @@ -210,29 +192,19 @@ public class AxState extends AxConcept { // CHECKSTYLE:ON: checkstyle:parameterNumber /** - * When a state is unmarshalled from disk or from the database, the parent of contained objects is not defined. This - * method is called by JAXB after unmarshaling and is used to set the parent keys of all + * When a state is deserialized from disk or from the database, the parent of contained objects is not defined. This + * method is called by JAXB after deserialized and is used to set the parent keys of all * {@link AxTaskSelectionLogic}, {@link AxStateOutput}, and {@link AxStateFinalizerLogic} instance in the state. - * - * @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) { + @Override + public void buildReferences() { if (!taskSelectionLogic.getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { taskSelectionLogic.getKey().setParentReferenceKey(key); } - for (final Entry<String, AxStateOutput> soEntry : stateOutputs.entrySet()) { - soEntry.getValue().getKey().setParentReferenceKey(key); - } - - for (final Entry<String, AxStateFinalizerLogic> sflEntry : stateFinalizerLogicMap.entrySet()) { - sflEntry.getValue().getKey().setParentReferenceKey(key); - } - - for (final Entry<AxArtifactKey, AxStateTaskReference> trEntry : taskReferenceMap.entrySet()) { - trEntry.getValue().getKey().setParentReferenceKey(key); - } + stateOutputs.values().stream().forEach(output -> output.getKey().setParentReferenceKey(key)); + stateFinalizerLogicMap.values().stream().forEach(output -> output.getKey().setParentReferenceKey(key)); + taskReferenceMap.values().stream().forEach(output -> output.getKey().setParentReferenceKey(key)); } /** diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java index 51ec51a8f..31ffedea8 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java @@ -21,10 +21,6 @@ package org.onap.policy.apex.model.policymodel.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.AxReferenceKey; /** @@ -39,10 +35,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; * * <p>Validation uses standard Apex Logic validation, see validation in {@link AxLogic}. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexStateFinalizerLogic", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxStateFinalizerLogic", namespace = "http://www.onap.org/policy/apex-pdp") - public class AxStateFinalizerLogic extends AxLogic { private static final long serialVersionUID = 2090324845463750391L; diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java index b90f2c84d..7d4695290 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java @@ -23,13 +23,9 @@ package org.onap.policy.apex.model.policymodel.concepts; +import com.google.gson.annotations.SerializedName; import java.util.List; import java.util.Set; -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.Getter; import lombok.NonNull; import lombok.Setter; @@ -60,28 +56,20 @@ import org.onap.policy.common.utils.validation.Assertions; * <li>The next state key must be valid, see validation in {@link AxReferenceKey} * </ol> */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexStateOutput", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxStateOutput", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"key", "outgoingEvent", "outgoingEventSet", "nextState"}) @Getter @Setter public class AxStateOutput extends AxConcept { private static final long serialVersionUID = 8041771382337655535L; - @XmlElement(name = "key", required = true) @NonNull private AxReferenceKey key; - @XmlElement(required = true) @NonNull private AxArtifactKey outgoingEvent; - @XmlElement(name = "outgoingEventReference", required = false) + @SerializedName("outgoingEventReference") private Set<AxArtifactKey> outgoingEventSet; - @XmlElement(required = true) @NonNull private AxReferenceKey nextState; // @formatter:on diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java index 741eb8833..171747c0c 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java @@ -1,37 +1,31 @@ /*- * ============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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ package org.onap.policy.apex.model.policymodel.concepts; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlType; - /** * This enumeration defines the type of state output selection that is defined for a task in a * state. The {@link AxStateTaskReference} instance for each task uses this enumeration to decide * what type of output selection to use when a task has completed execution. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxStateTaskOutputType", namespace = "http://www.onap.org/policy/apex-pdp") - public enum AxStateTaskOutputType { /** The state output selection for the task has not been defined. */ UNDEFINED, diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java index 711e1842b..748eca92d 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.policymodel.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; @@ -61,22 +56,11 @@ import org.onap.policy.common.utils.validation.Assertions; * {@link AxReferenceKey} * </ol> */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexStateTaskReference", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxStateTaskReference", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"key", "outputType", "output"}) - public class AxStateTaskReference extends AxConcept { private static final long serialVersionUID = 8041771382337655535L; - @XmlElement(name = "key", required = true) private AxReferenceKey key; - - @XmlElement(required = true) private AxStateTaskOutputType outputType; - - @XmlElement(required = true) private AxReferenceKey output; /** diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java index 3911a1f97..c8b6baf4b 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java @@ -22,18 +22,13 @@ package org.onap.policy.apex.model.policymodel.concepts; +import com.google.gson.annotations.SerializedName; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; 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 lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -71,14 +66,6 @@ import org.onap.policy.common.utils.validation.Assertions; * <li>The task logic must be valid, see validation in {@link AxTaskLogic} * </ol> */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexTask", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType( - name = "AxTask", - namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"key", "inputEvent", "outputEvents", "taskParameters", - "contextAlbumReferenceSet", "taskLogic"}) @Getter @Setter public class AxTask extends AxConcept { @@ -86,24 +73,17 @@ public class AxTask extends AxConcept { private static final long serialVersionUID = 5374237330697362762L; - @XmlElement(name = "key", required = true) @NonNull private AxArtifactKey key; - @XmlElement(name = "inputEvent", required = false) private AxEvent inputEvent; - - @XmlElement(name = "outputEvents", required = false) private Map<String, AxEvent> outputEvents; - - @XmlElement(name = "taskParameters", required = true) private Map<String, AxTaskParameter> taskParameters; - @XmlElement(name = "contextAlbumReference") + @SerializedName("contextAlbumReference") @NonNull private Set<AxArtifactKey> contextAlbumReferenceSet; - @XmlElement(required = true) @NonNull private AxTaskLogic taskLogic; @@ -163,18 +143,17 @@ public class AxTask extends AxConcept { } /** - * When a task is unmarshalled from disk or from the database, the parent of contained objects - * is not defined. This method is called by JAXB after unmarshaling and is used to set the + * When a task is deserialized from disk or from the database, the parent of contained objects + * is not defined. This method is called by JAXB after deserialization and is used to set the * parent keys of all {@link AxTaskParameter} instance in the task. - * - * @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) { - taskLogic.getKey().setParentArtifactKey(key); - for (final AxTaskParameter parameter : taskParameters.values()) { - parameter.getKey().setParentArtifactKey(key); + @Override + public void buildReferences() { + if (!taskLogic.getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { + taskLogic.getKey().setParentArtifactKey(key); } + + taskParameters.values().stream().forEach(parameter -> parameter.getKey().setParentArtifactKey(key)); } /** diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java index 38c0d6daf..8665d9e3e 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java @@ -21,10 +21,6 @@ package org.onap.policy.apex.model.policymodel.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; @@ -38,10 +34,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; * * <p>Validation uses standard Apex Logic validation, see validation in {@link AxLogic}. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexLogic", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxTaskLogic", namespace = "http://www.onap.org/policy/apex-pdp") - public class AxTaskLogic extends AxLogic { private static final long serialVersionUID = 2090324845463750391L; diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java index 7cb052a7f..a468ec499 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java @@ -22,11 +22,6 @@ package org.onap.policy.apex.model.policymodel.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.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; @@ -42,19 +37,10 @@ import org.onap.policy.common.utils.validation.Assertions; * a default value. If the task parameter is not set in a configuration file, the task uses its * default value. */ - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"key", "defaultValue"}) - public class AxTaskParameter extends AxConcept { private static final long serialVersionUID = 7351688156934099977L; - @XmlElement(name = "key", required = true) private AxReferenceKey key; - - @XmlElement private String defaultValue; /** diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java index 43b8f11a6..b9cfd802d 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java @@ -21,10 +21,6 @@ package org.onap.policy.apex.model.policymodel.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.AxReferenceKey; /** @@ -37,10 +33,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; * * <p>Validation uses standard Apex Logic validation, see validation in {@link AxLogic}. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlRootElement(name = "apexTaskSelectionLogic", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxTaskSelectionLogic", namespace = "http://www.onap.org/policy/apex-pdp") - public class AxTaskSelectionLogic extends AxLogic { private static final long serialVersionUID = 2090324845463750391L; diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.java index bae50e061..f9ccafd54 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.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,15 +47,10 @@ import org.onap.policy.common.utils.validation.Assertions; * in the container. Each task 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 task entry is then validated individually. */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "AxTasks", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = {"key", "taskMap"}) public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { private static final long serialVersionUID = 4290442590545820316L; - @XmlElement(name = "key", required = true) private AxArtifactKey key; - - @XmlElement(required = true) private Map<AxArtifactKey, AxTask> taskMap; /** @@ -93,7 +83,7 @@ public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { /** * This Constructor creates a task container with all of its fields defined. * - * @param key the task container key + * @param key the task container key * @param taskMap the tasks to be stored in the task container */ public AxTasks(final AxArtifactKey key, final Map<AxArtifactKey, AxTask> taskMap) { @@ -107,23 +97,6 @@ public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { } /** - * When a model is unmarshalled from disk or from the database, the task 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, AxTask> navigableTaskMap = new TreeMap<>(); - navigableTaskMap.putAll(taskMap); - taskMap = navigableTaskMap; - } - - /** * {@inheritDoc}. */ @Override @@ -146,6 +119,14 @@ public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { } /** + * {@inheritDoc}. + */ + @Override + public void buildReferences() { + taskMap.values().stream().forEach(task -> task.buildReferences()); + } + + /** * Sets the task container key. * * @param key the task container key @@ -184,27 +165,27 @@ public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { if (key.equals(AxArtifactKey.getNullKey())) { result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); + new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); } result = key.validate(result); if (taskMap.size() == 0) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "taskMap may not be empty")); + "taskMap may not be empty")); } else { for (final Entry<AxArtifactKey, AxTask> taskEntry : taskMap.entrySet()) { if (taskEntry.getKey().equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on task entry " + taskEntry.getKey() + " may not be the null key")); + "key on task entry " + taskEntry.getKey() + " may not be the null key")); } else if (taskEntry.getValue() == null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on task entry " + taskEntry.getKey() + " may not be null")); + "value on task entry " + taskEntry.getKey() + " may not be null")); } else { if (!taskEntry.getKey().equals(taskEntry.getValue().getKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), - ValidationResult.INVALID, "key on task entry key " + taskEntry.getKey() - + " does not equal task value key " + taskEntry.getValue().getKey())); + ValidationResult.INVALID, "key on task entry key " + taskEntry.getKey() + + " does not equal task value key " + taskEntry.getValue().getKey())); } result = taskEntry.getValue().validate(result); @@ -348,7 +329,7 @@ public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { @Override public AxTask get(final String conceptKeyName, final String conceptKeyVersion) { return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } /** @@ -365,6 +346,6 @@ public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { @Override public Set<AxTask> getAll(final String conceptKeyName, final String conceptKeyVersion) { return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).getAll(conceptKeyName, - conceptKeyVersion); + conceptKeyVersion); } } diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java index cc15a6af5..acf0e8221 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java @@ -1,19 +1,20 @@ /*- * ============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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -21,15 +22,7 @@ /** * Contains the concepts required to specify policies and tasks in APEX. It defines the main Apex * concepts of policies and tasks. - * + * * @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.policymodel.concepts; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlNsForm; -import javax.xml.bind.annotation.XmlSchema; diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/EmptyAlbumsAdapter.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/EmptyAlbumsAdapter.java deleted file mode 100644 index aa19edf0b..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/EmptyAlbumsAdapter.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.policymodel.handling; - -import javax.xml.bind.annotation.adapters.XmlAdapter; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -/** - * This class makes the albums field optional in marshaled Policy Models. - * Empty albums are not marshaled to JSON/XML. - * When unmarshaled, if no albums value is present then a new empty albums entry is created. - * - * @author John Keeney (john.keeney@ericsson.com) - */ -public class EmptyAlbumsAdapter extends XmlAdapter<AxContextAlbums, AxContextAlbums> { - - - /** - * Decide whether to marshall a context albums entry. Non-empty context albums are always marshalled. - * Empty albums are filtered. - * - * @param albums the albums entry - * @return the albums entry, or null if empty - * @throws Exception if there is a problem with the marshalling - * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(Object) - */ - @Override - public AxContextAlbums marshal(AxContextAlbums albums) throws Exception { - if ((albums == null) || (albums.getAlbumsMap() == null) || (albums.getAlbumsMap().isEmpty())) { - return null; - } else { - return albums; - } - } - - /** - * Decide whether to unmarshall a context albums entry - Always. - * - * @param val the albums entry - * @return the albums entry - * @throws Exception if there is a problem with the unmarshalling - * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(Object) - */ - @Override - public AxContextAlbums unmarshal(AxContextAlbums val) throws Exception { - return val; - } - - /** - * After unmarshalling has completed the model's context albums entry may be null/empty or default. - * If so the key for the albums entry should updated to a sensible value and additional keyinfo - * information should then be added for that key - * - * @param policyModel the policy model containing the possibly empty context albums entry - * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(Object) - */ - public void doAfterUnmarshal(AxPolicyModel policyModel) { - AxArtifactKey nullkey = new AxArtifactKey(); - AxArtifactKey blanknullalbumskey = - new AxArtifactKey(nullkey.getKey().getName() + "_Albums", nullkey.getKey().getVersion()); - AxArtifactKey thisalbumskey = policyModel.getAlbums().getKey(); - AxArtifactKey thismodelkey = policyModel.getKey(); - AxContextAlbums thismodelalbums = policyModel.getAlbums(); - - if (nullkey.equals(thisalbumskey) || blanknullalbumskey.equals(thisalbumskey)) { - thismodelalbums.setKey(new AxArtifactKey(thismodelkey.getName() + "_Albums", thismodelkey.getVersion())); - policyModel.getKeyInformation().generateKeyInfo(thismodelalbums); - } - } - -} |