diff options
Diffstat (limited to 'model/event-model')
2 files changed, 92 insertions, 24 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 156b733ef..e3663e702 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,8 @@ package org.onap.policy.apex.model.eventmodel.concepts; +import com.google.common.base.Strings; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -40,9 +43,11 @@ 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; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus; 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; @@ -50,7 +55,7 @@ import org.onap.policy.common.utils.validation.Assertions; /** * This class defines an Apex event. An {@link AxEvent} is used to kick off execution of policies in Apex and is emitted - * by policies when they completer execution. In addition, Apex uses {@link AxEvent} instances internally to pass + * by policies when they complete execution. In addition, Apex uses {@link AxEvent} instances internally to pass * control from one Apex state to the next during execution. * * <p>The {@link AxArtifactKey} of an event uniquely identifies it in an Apex system and the name field in the key is @@ -76,7 +81,7 @@ import org.onap.policy.common.utils.validation.Assertions; @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" }) + { "key", "nameSpace", "source", "target", "parameterMap", "toscaPolicyState"}) public class AxEvent extends AxConcept { private static final long serialVersionUID = -1460388382582984269L; @@ -106,6 +111,10 @@ public class AxEvent extends AxConcept { @XmlElement(name = "parameter", required = true) private Map<String, AxField> parameterMap; + @Column(name = "toscaPolicyState") + @XmlElement(required = false) + private String toscaPolicyState; + /** * The default constructor creates an event with a null artifact key. The event name space, source, and target are * all defined as empty strings and the parameter map is initialized as an empty map. @@ -130,7 +139,7 @@ public class AxEvent extends AxConcept { * @param key the key of the event */ public AxEvent(final AxArtifactKey key) { - this(key, "", "", "", new TreeMap<>()); + this(key, "", "", "", new TreeMap<>(), ""); } /** @@ -141,7 +150,7 @@ public class AxEvent extends AxConcept { * @param nameSpace the name space of the event */ public AxEvent(final AxArtifactKey key, final String nameSpace) { - this(key, nameSpace, "", "", new TreeMap<>()); + this(key, nameSpace, "", "", new TreeMap<>(), ""); } /** @@ -154,7 +163,7 @@ public class AxEvent extends AxConcept { * @param target the target of the event */ public AxEvent(final AxArtifactKey key, final String nameSpace, final String source, final String target) { - this(key, nameSpace, source, target, new TreeMap<>()); + this(key, nameSpace, source, target, new TreeMap<>(), ""); } /** @@ -165,9 +174,10 @@ public class AxEvent extends AxConcept { * @param source the source of the event * @param target the target of the event * @param parameterMap the map of parameters that the event has + * @param toscaPolicyState the TOSCA policy processing status that event is flagged with */ public AxEvent(final AxArtifactKey key, final String nameSpace, final String source, final String target, - final SortedMap<String, AxField> parameterMap) { + final SortedMap<String, AxField> parameterMap, final String toscaPolicyState) { super(); Assertions.argumentNotNull(key, "key may not be null"); Assertions.argumentNotNull(nameSpace, "nameSpace may not be null"); @@ -180,6 +190,7 @@ public class AxEvent extends AxConcept { this.source = source; this.target = target; this.parameterMap = parameterMap; + this.toscaPolicyState = toscaPolicyState; } /** @@ -327,6 +338,24 @@ public class AxEvent extends AxConcept { } /** + * Gets the TOSCA policy processing status from the event. + * + * @return the TOSCA policy processing status + */ + public String getToscaPolicyState() { + return toscaPolicyState; + } + + /** + * Sets the TOSCA policy processing status on the event. + * + * @param toscaPolicyState the TOSCA policy processing status + */ + public void setToscaPolicyState(String toscaPolicyState) { + this.toscaPolicyState = toscaPolicyState; + } + + /** * {@inheritDoc}. */ @Override @@ -363,10 +392,17 @@ public class AxEvent extends AxConcept { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "value on parameter " + eventParameterEntry.getKey() + " may not be null")); } else { - result = vaidateEventParameters(eventParameterEntry, result); + result = validateEventParameters(eventParameterEntry, result); } } + if (!Strings.isNullOrEmpty(toscaPolicyState) + && !EnumUtils.isValidEnum(AxToscaPolicyProcessingStatus.class, toscaPolicyState)) { + result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "toscaPolicyState on event is not a valid enum. Valid values are: " + + Arrays.asList(AxToscaPolicyProcessingStatus.values()))); + } + return result; } @@ -377,7 +413,7 @@ public class AxEvent extends AxConcept { * @param result the validation result to append to * @return The validation result */ - private AxValidationResult vaidateEventParameters(final Entry<String, AxField> eventParameterEntry, + private AxValidationResult validateEventParameters(final Entry<String, AxField> eventParameterEntry, final AxValidationResult result) { if (!eventParameterEntry.getKey().equals(eventParameterEntry.getValue().getKey().getLocalName())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, @@ -424,6 +460,8 @@ public class AxEvent extends AxConcept { builder.append(target); builder.append(",parameter="); builder.append(parameterMap); + builder.append(",toscaPolicyState="); + builder.append(toscaPolicyState); builder.append(")"); return builder.toString(); } @@ -450,6 +488,7 @@ public class AxEvent extends AxConcept { copy.setNameSpace(nameSpace); copy.setSource(source); copy.setTarget(target); + copy.setToscaPolicyState(toscaPolicyState); return copy; } @@ -466,6 +505,7 @@ public class AxEvent extends AxConcept { result = prime * result + source.hashCode(); result = prime * result + target.hashCode(); result = prime * result + parameterMap.hashCode(); + result = prime * result + toscaPolicyState.hashCode(); return result; } @@ -498,6 +538,9 @@ public class AxEvent extends AxConcept { if (!target.equals(other.target)) { return false; } + if (!toscaPolicyState.equals(other.toscaPolicyState)) { + return false; + } return parameterMap.equals(other.parameterMap); } @@ -532,7 +575,10 @@ public class AxEvent extends AxConcept { if (!parameterMap.equals(other.parameterMap)) { return (parameterMap.hashCode() - other.parameterMap.hashCode()); } + if (!toscaPolicyState.equals(other.toscaPolicyState)) { + return toscaPolicyState.compareTo(other.toscaPolicyState); + } return 0; } -} +}
\ No newline at end of file diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java index 21601d770..111d27f70 100644 --- a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java +++ b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +33,7 @@ import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; 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.AxToscaPolicyProcessingStatus; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; @@ -51,7 +53,7 @@ public class EventsTest { assertNotNull(new AxEvent(new AxArtifactKey(), "namespace")); assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target")); assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target")); - assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target", parameterMap)); + assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target", parameterMap, "")); final AxEvent event = new AxEvent(); @@ -72,6 +74,9 @@ public class EventsTest { event.setParameterMap(parameterMap); assertEquals(0, event.getParameterMap().size()); + event.setToscaPolicyState(AxToscaPolicyProcessingStatus.ENTRY.name()); + assertEquals(AxToscaPolicyProcessingStatus.ENTRY.name(), event.getToscaPolicyState()); + final AxField eventField = new AxField(new AxReferenceKey(eventKey, "Field0"), new AxArtifactKey("Field0Schema", "0.0.1")); event.getParameterMap().put(eventField.getKey().getLocalName(), eventField); @@ -178,6 +183,12 @@ public class EventsTest { result = event.validate(result); assertEquals(ValidationResult.VALID, result.getValidationResult()); + event.setToscaPolicyState("invalid_enum"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + event.setToscaPolicyState(AxToscaPolicyProcessingStatus.ENTRY.name()); + event.clean(); event.afterUnmarshal(null, null); @@ -192,25 +203,36 @@ public class EventsTest { assertEquals(event, clonedEvent); assertNotNull(event); assertNotEquals(event, (Object) "Hello"); - assertNotEquals( - event, new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap)); - assertNotEquals(event, new AxEvent(eventKey, "namespace1", "source", "target", parameterMap)); - assertNotEquals(event, new AxEvent(eventKey, "namespace", "source2", "target", parameterMap)); - assertNotEquals(event, new AxEvent(eventKey, "namespace", "source", "target3", parameterMap)); - assertNotEquals(event, new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty)); - assertEquals(event, new AxEvent(eventKey, "namespace", "source", "target", parameterMap)); + assertNotEquals(event, new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name())); + assertNotEquals(event, new AxEvent(eventKey, "namespace1", "source", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name())); + assertNotEquals(event, new AxEvent(eventKey, "namespace", "source2", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name())); + assertNotEquals(event, new AxEvent(eventKey, "namespace", "source", "target3", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name())); + assertNotEquals(event, new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty, + AxToscaPolicyProcessingStatus.ENTRY.name())); + assertEquals(event, new AxEvent(eventKey, "namespace", "source", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name())); assertEquals(0, event.compareTo(event)); assertEquals(0, event.compareTo(clonedEvent)); assertNotEquals(0, event.compareTo(new AxArtifactKey())); assertNotEquals(0, event.compareTo(null)); assertNotEquals(0, event - .compareTo(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty))); - assertEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMap))); + .compareTo(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name()))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name()))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name()))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name()))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty, + AxToscaPolicyProcessingStatus.ENTRY.name()))); + assertEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMap, + AxToscaPolicyProcessingStatus.ENTRY.name()))); assertNotNull(event.getKeys()); @@ -292,4 +314,4 @@ public class EventsTest { assertEquals(1, events.getAll("EventName", "0.0.1").size()); assertEquals(0, events.getAll("NonExistantEventsName").size()); } -} +}
\ No newline at end of file |