diff options
Diffstat (limited to 'model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java')
-rw-r--r-- | model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java | 60 |
1 files changed, 22 insertions, 38 deletions
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); } } |