diff options
Diffstat (limited to 'model/policy-model/src/main/java/org')
28 files changed, 0 insertions, 6608 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 deleted file mode 100644 index 0564d5854..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java +++ /dev/null @@ -1,355 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,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 java.util.List; -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.common.utils.validation.Assertions; - -/** - * This class holds Logic for executing a task or task selection on an Apex policy state. The flavour of the logic - * describes the type of logic being used and it may be a language identifier such as "Javascript" or "Jython". The - * logic itself is held as a string. The {@link AxLogic} instance is used by the Apex engine to start an executor with - * the required flavour. Once the executor is started, the Apex engine passes the logic to the executor and the executor - * executes it. In the Apex engine, executors are deployed as plugins. Apex also provides the executor with run-time - * context, which makes context such as input fields, output fields, and context albums available to the task at - * runtime. - * - * <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. - */ -public class AxLogic extends AxConcept { - private static final long serialVersionUID = -4260562004005697328L; - - private static final String WHITESPACE_REGEXP = "\\s+$"; - - private static final String LOGIC_FLAVOUR_TOKEN = "logicFlavour"; - private static final String KEY_NULL_MESSAGE = "key may not be null"; - private static final String LOGIC_FLAVOUR_NULL_MESSAGE = "logicFlavour may not be null"; - private static final String LOGIC_NULL_MESSAGE = "logic may not be null"; - - /** Regular expression that specifies the allowed characters in logic flavour tokens. */ - public static final String LOGIC_FLAVOUR_REGEXP = "[A-Za-z0-9\\-_]+"; - - /** When logic flavour is undefined, it has this value. */ - public static final String LOGIC_FLAVOUR_UNDEFINED = "UNDEFINED"; - - /** The maximum permissible size of a logic definition. */ - public static final int MAX_LOGIC_SIZE = 32672; // The maximum size supported by Apache Derby - - private AxReferenceKey key; - private String logicFlavour; - private String logic; - - /** - * The Default Constructor creates a logic instance with a null key, undefined logic flavour and a null logic - * string. - */ - public AxLogic() { - this(new AxReferenceKey()); - logicFlavour = LOGIC_FLAVOUR_UNDEFINED; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxLogic(final AxLogic copyConcept) { - super(copyConcept); - } - - /** - * The Key Constructor creates a logic instance with the given reference key, undefined logic flavour and a null - * logic string. - * - * @param key the reference key of the logic - */ - public AxLogic(final AxReferenceKey key) { - this(key, LOGIC_FLAVOUR_UNDEFINED, ""); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents key and the logic - * local name and all of its fields defined. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxLogic(final AxReferenceKey parentKey, final String logicName, final String logicFlavour, - final String logic) { - this(new AxReferenceKey(parentKey, logicName), logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance with the given reference key and all of its fields defined. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxLogic(final AxReferenceKey key, final String logicFlavour, final String logic) { - super(); - Assertions.argumentNotNull(key, KEY_NULL_MESSAGE); - Assertions.argumentNotNull(logicFlavour, LOGIC_FLAVOUR_NULL_MESSAGE); - Assertions.argumentNotNull(logic, LOGIC_NULL_MESSAGE); - - this.key = key; - this.logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP); - this.logic = logic.replaceAll(WHITESPACE_REGEXP, ""); - } - - /** - * This Constructor creates a logic instance with the given reference key and logic flavour, the logic is provided - * by the given logic reader instance. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxLogic(final AxReferenceKey key, final String logicFlavour, final AxLogicReader logicReader) { - super(); - Assertions.argumentNotNull(key, KEY_NULL_MESSAGE); - Assertions.argumentNotNull(logicFlavour, LOGIC_FLAVOUR_NULL_MESSAGE); - Assertions.argumentNotNull(logicReader, "logicReader may not be null"); - - this.key = key; - this.logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP); - logic = logicReader.readLogic(this); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - return key.getKeys(); - } - - /** - * Sets the key. - * - * @param key the key - */ - public void setKey(final AxReferenceKey key) { - Assertions.argumentNotNull(key, KEY_NULL_MESSAGE); - this.key = key; - } - - /** - * Gets the logic flavour. - * - * @return the logic flavour - */ - public String getLogicFlavour() { - return logicFlavour; - } - - /** - * Sets the logic flavour. - * - * @param logicFlavour the logic flavour - */ - public void setLogicFlavour(final String logicFlavour) { - this.logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP); - } - - /** - * Gets the logic. - * - * @return the logic - */ - public String getLogic() { - return logic; - } - - /** - * Sets the logic. - * - * @param logic the logic - */ - public void setLogic(final String logic) { - Assertions.argumentNotNull(logic, LOGIC_NULL_MESSAGE); - this.logic = logic.replaceAll(WHITESPACE_REGEXP, ""); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key is a null key")); - } - - result = key.validate(result); - - if (logicFlavour.replaceAll(WHITESPACE_REGEXP, "").length() == 0 - || logicFlavour.equals(LOGIC_FLAVOUR_UNDEFINED)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "logic flavour is not defined")); - } - - String flavourValidationString = Assertions.getStringParameterValidationMessage(LOGIC_FLAVOUR_TOKEN, - logicFlavour, LOGIC_FLAVOUR_REGEXP); - if (flavourValidationString != null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "logic flavour invalid-" + flavourValidationString)); - } - - if (logic.replaceAll(WHITESPACE_REGEXP, "").length() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "no logic specified, logic may not be blank")); - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - if (key != null) { - key.clean(); - } - logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP); - logic = logic.replaceAll(WHITESPACE_REGEXP, ""); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",logicFlavour="); - builder.append(logicFlavour); - builder.append(",logic="); - builder.append(logic); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxLogic.class); - - final AxLogic copy = ((AxLogic) copyObject); - copy.setKey(new AxReferenceKey(key)); - copy.setLogicFlavour(logicFlavour); - copy.setLogic(logic); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + logicFlavour.hashCode(); - result = prime * result + logic.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxLogic other = (AxLogic) obj; - if (!key.equals(other.key)) { - return false; - } - if (!logicFlavour.equals(other.logicFlavour)) { - return false; - } - return logic.equals(other.logic); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxLogic other = (AxLogic) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!logicFlavour.equals(other.logicFlavour)) { - return logicFlavour.compareTo(other.logicFlavour); - } - return logic.compareTo(other.logic); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogicReader.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogicReader.java deleted file mode 100644 index 7532f9f34..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogicReader.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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; - -/** - * This interface is used to provide logic to a {@link AxLogic} instance. Implementations usually - * store logic on disk in a structure similar to Java package naming conventions. The logic package - * gives the package path, a directory where a set of logic is defined. Default logic is logic that - * can be used as dummy logic in tasks or states that are filler tasks or states. The actual logic - * is returned by the {@code readLogic()} method. The interface is used mainly by unit test classes - * that generate test logic. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public interface AxLogicReader { - - /** - * Get the logic package path. - * - * @return the logic package path - */ - String getLogicPackage(); - - /** - * Set the logic package path. - * - * @param logicPackage the name of the package that contains the logic for this logic reader - * @return the logic reader on which this method was called, used for daisy chaining - * configuration - */ - AxLogicReader setLogicPackage(final String logicPackage); - - /** - * Get the default logic name. - * - * @return the default logic name - */ - String getDefaultLogic(); - - /** - * Set the default logic name. - * - * @param defaultLogic the default logic name - * @return the logic reader on which this method was called, used for daisy chaining - * configuration - */ - AxLogicReader setDefaultLogic(final String defaultLogic); - - /** - * Read the logic for an AxLogic object. - * - * @param axLogic the AxLogic object - * @return the logic as a string - */ - String readLogic(final AxLogic axLogic); -} 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 deleted file mode 100644 index bb30f46cf..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java +++ /dev/null @@ -1,360 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,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 java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NavigableMap; -import java.util.Set; -import java.util.TreeMap; -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; -import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetterImpl; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -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.common.utils.validation.Assertions; - -/** - * This class is a policy container and holds a map of the policies for an entire Apex model. All Apex models that use - * policies must have an {@link AxPolicies} field. The {@link AxPolicies} class implements the helper methods of the - * {@link AxConceptGetter} interface to allow {@link AxPolicy} instances to be retrieved by calling methods directly on - * this class without referencing the contained map. - * - * <p>Validation checks that the container key is not null. An error is issued if no policies are defined in the - * 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. - */ -public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> { - private static final long serialVersionUID = 4290442590545820316L; - - private AxArtifactKey key; - private Map<AxArtifactKey, AxPolicy> policyMap; - - /** - * The Default Constructor creates a {@link AxPolicies} object with a null artifact key and creates an empty event - * map. - */ - public AxPolicies() { - this(new AxArtifactKey()); - } - - /** - * The Key Constructor creates a {@link AxPolicies} object with the given artifact key and creates an empty event - * map. - * - * @param key the key - */ - public AxPolicies(final AxArtifactKey key) { - this(key, new TreeMap<>()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxPolicies(final AxPolicies copyConcept) { - super(copyConcept); - } - - /** - * This Constructor creates a policy container with all of its fields defined. - * - * @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) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(policyMap, "policyMap may not be null"); - - this.key = key; - this.policyMap = new TreeMap<>(); - this.policyMap.putAll(policyMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - - for (final AxPolicy policy : policyMap.values()) { - keyList.addAll(policy.getKeys()); - } - - return keyList; - } - - /** - * {@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 - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the policy map containing all policies in the policy container. - * - * @return the policy map with all the policies in the container - */ - public Map<AxArtifactKey, AxPolicy> getPolicyMap() { - return policyMap; - } - - /** - * Sets the policy map containing all policies in the policy container. - * - * @param policyMap the policy map with all the policies to be put in the container - */ - public void setPolicyMap(final Map<AxArtifactKey, AxPolicy> policyMap) { - Assertions.argumentNotNull(policyMap, "policyMap may not be null"); - this.policyMap = new TreeMap<>(); - this.policyMap.putAll(policyMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "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")); - } 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")); - } else if (policyEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on policy entry " + entryKey + " may not be null")); - } else { - validate(result, policyEntry, entryKey); - result = policyEntry.getValue().validate(result); - } - } - } - - return result; - } - - private void validate(final AxValidationResult result, final Entry<AxArtifactKey, AxPolicy> policyEntry, - 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())); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - for (final Entry<AxArtifactKey, AxPolicy> policyEntry : policyMap.entrySet()) { - policyEntry.getKey().clean(); - policyEntry.getValue().clean(); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",policyMap="); - builder.append(policyMap); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxPolicies.class); - - final AxPolicies copy = ((AxPolicies) copyObject); - copy.setKey(new AxArtifactKey(key)); - - final Map<AxArtifactKey, AxPolicy> newPolicyMap = new TreeMap<>(); - for (final Entry<AxArtifactKey, AxPolicy> policyMapEntry : policyMap.entrySet()) { - newPolicyMap.put(new AxArtifactKey(policyMapEntry.getKey()), new AxPolicy(policyMapEntry.getValue())); - } - copy.setPolicyMap(newPolicyMap); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + policyMap.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxPolicies other = (AxPolicies) obj; - if (!key.equals(other.key)) { - return false; - } - return policyMap.equals(other.policyMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxPolicies other = (AxPolicies) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!policyMap.equals(other.policyMap)) { - return (policyMap.hashCode() - other.policyMap.hashCode()); - } - - return 0; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxPolicy get(final AxArtifactKey conceptKey) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxPolicy get(final String conceptKeyName) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKeyName); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxPolicy get(final String conceptKeyName, final String conceptKeyVersion) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKeyName, - conceptKeyVersion); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<AxPolicy> getAll(final String conceptKeyName) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).getAll(conceptKeyName); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<AxPolicy> getAll(final String conceptKeyName, final String conceptKeyVersion) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).getAll(conceptKeyName, - 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 deleted file mode 100644 index a47afe4d6..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java +++ /dev/null @@ -1,508 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,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 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 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.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.common.utils.validation.Assertions; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class holds the definition of an Apex policy. A policy is made up of a tree of states, each represented by an - * {@link AxState} instance. The states of a policy are held in a map in the policy. The state tree is built up at - * policy design time by a policy editor and each state is connected to its next state by an {@link AxStateOutput} - * instance. - * - * <p>Execution of a policy is triggered by an event. A policy starts execution from its first state so the trigger - * event for the first sate is the trigger event for the entire policy. Execution from that first state can continue to - * one or more subsequent states and so on down branches of states. The state output of the final state in a branch has - * no next state, indicating the end of execution of that branch. Therefore, the set of output events from final states - * in the policy are the possible set of output events on the policy. A state may only be used once in the state tree of - * a policy and recursive execution of states in the same execution branch is not allowed, so the same state may not - * execute more than once on a single execution of a policy. - * - * <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} - * </ol> - */ -public class AxPolicy extends AxConcept { - private static final long serialVersionUID = -1775614096390365941L; - - // Logger for this class - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AxPolicy.class); - - @SerializedName("policyKey") - private AxArtifactKey key; - private String template; - - @SerializedName("state") - private Map<String, AxState> stateMap; - private String firstState; - - /** - * The Default Constructor creates a policy instance with a null key, a blank template and undefined first state. - */ - public AxPolicy() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxPolicy(final AxPolicy copyConcept) { - super(copyConcept); - } - - /** - * The Key Constructor creates a policy instance with the given key, a blank template and undefined first state. - * - * @param key the key of the policy - */ - public AxPolicy(final AxArtifactKey key) { - 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 firstState the first state that will execute on this policy - */ - public AxPolicy(final AxArtifactKey key, final String template, final Map<String, AxState> stateMap, - final String firstState) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(template, "template may not be null"); - Assertions.argumentNotNull(stateMap, "stateMap may not be null"); - Assertions.argumentNotNull(firstState, "firstState may not be null"); - - this.key = key; - this.template = template; - this.stateMap = stateMap; - this.firstState = firstState; - } - - /** - * Gets a tree that holds all the possible execution paths for this policy. This method may be used for verification - * of policies, to find the branches of policy execution and the final states of policies. - * - * @return the state tree of the policy, a tree representing the execution branches of the policy - */ - public AxStateTree getStateTree() { - return new AxStateTree(this, stateMap.get(firstState), null); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - for (final AxState state : stateMap.values()) { - keyList.addAll(state.getKeys()); - } - return keyList; - } - - /** - * {@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 - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the policy template for policy editor metadata. - * - * @return the policy template for policy editor metadata - */ - public String getTemplate() { - return template; - } - - /** - * Sets the policy template for policy editor metadata. - * - * @param template the policy template for policy editor metadata - */ - public void setTemplate(final String template) { - Assertions.argumentNotNull(template, "template may not be null"); - this.template = template; - } - - /** - * Gets a map containing the states of the policy. - * - * @return the map of states in the policy - */ - public Map<String, AxState> getStateMap() { - return stateMap; - } - - /** - * Sets a map containing the states of the policy. - * - * @param stateMap a map of states in the policy - */ - public void setStateMap(final Map<String, AxState> stateMap) { - Assertions.argumentNotNull(stateMap, "stateMap may not be null"); - this.stateMap = stateMap; - } - - /** - * Gets the first state of the policy. - * - * @return the first state of the policy - */ - public String getFirstState() { - return firstState; - } - - /** - * Sets the first state of the policy. - * - * @param firstState the first state of the policy - */ - public void setFirstState(final String firstState) { - Assertions.argumentNotNull(firstState, "firstState may not be null"); - this.firstState = firstState; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - 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")); - } - - if (stateMap.size() == 0) { - 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); - } - } - - // Validation continues from this point only if all validation checks this far have been - // passed - if (!result.isOk()) { - return result; - } - - // 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")); - } else { - if (!stateMap.containsKey(firstState)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "first state not found in stateMap")); - } else { - validateStateTree(result); - } - } - - return result; - } - - /** - * Validate a state entry. - * - * @param stateEntry the state entry to validate - * @param result The validation result to append to - * @return The result of the validation - */ - 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")); - 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")); - 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())); - } - - 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")); - } - - 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())); - } - } - - return result; - } - - /** - * Validate a state tree to ensure there are no circular references in it. - * - * @param result The validation result to append to - * @return The result of the validation - */ - private AxValidationResult validateStateTree(AxValidationResult result) { - try { - // Constructor validates policy state tree - AxStateTree policyStateTree = getStateTree(); - - // Check for unused states - final Set<AxState> referencedStateSet = policyStateTree.getReferencedStateSet(); - final Set<AxState> unreferencedStateSet = new TreeSet<>(stateMap.values()); - unreferencedStateSet.removeAll(referencedStateSet); - - 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")); - } - } catch (PolicyRuntimeException pre) { - AxValidationMessage validationMessage = new AxValidationMessage(key, this.getClass(), - ValidationResult.WARNING, "state tree in policy is invalid"); - LOGGER.trace(validationMessage.getMessage(), pre); - result.addValidationMessage(validationMessage); - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - firstState = firstState.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",template="); - builder.append(template); - builder.append(",stateMap="); - builder.append(stateMap); - builder.append(",firstState="); - builder.append(firstState); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxPolicy.class); - - final AxPolicy copy = ((AxPolicy) copyObject); - copy.setKey(new AxArtifactKey(key)); - copy.setTemplate(template); - - final Map<String, AxState> newStateMap = new TreeMap<>(); - for (final Entry<String, AxState> stateMapEntry : stateMap.entrySet()) { - newStateMap.put(stateMapEntry.getKey(), new AxState(stateMapEntry.getValue())); - } - copy.setStateMap(newStateMap); - - copy.setFirstState(firstState); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + template.hashCode(); - result = prime * result + stateMap.hashCode(); - result = prime * result + firstState.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxPolicy other = (AxPolicy) obj; - if (!key.equals(other.key)) { - return false; - } - if (!template.equals(other.template)) { - return false; - } - if (!stateMap.equals(other.stateMap)) { - return false; - } - return firstState.equals(other.firstState); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxPolicy other = (AxPolicy) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!template.equals(other.template)) { - return template.compareTo(other.template); - } - if (!stateMap.equals(other.stateMap)) { - return (stateMap.hashCode() - other.stateMap.hashCode()); - } - return firstState.compareTo(other.firstState); - } -} 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 deleted file mode 100644 index e119536fb..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java +++ /dev/null @@ -1,661 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * ================================================================================ - * 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 java.util.List; -import java.util.Map.Entry; -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.AxKeyInformation; -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.service.ModelService; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -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.common.utils.validation.Assertions; - -/** - * A container class for an Apex policy model. This class is a container class that allows an Apex - * model to be constructed that contains definitions of all the context, event, and policy concepts - * required to run policies in Apex. The model contains schema definitions, definitions of events - * and context albums that use those schemas, definitions of tasks for policies and definitions of - * the policies themselves. - * - * <p>An Apex policy model is an important artifact in Apex. At editing time, an Apex editor creates - * and edits a policy model and a policy model is loaded into and is executed by an Apex engine. - * Therefore, an Apex model and the set of policies that it holds is the way that the policy domain - * that an Apex engine or a group of Apex engines executes across is expressed, both at design time - * and run time. The Apex deployment system is responsible for deploying Apex models to and the - * context they need the appropriate engines for execution. - * - * <p>Model registration is carried out by calling the {@code register()} method, which registers the - * policy model and all its constituent containers with the model service. The containers for - * context schemas, events, context albums, tasks, policies, and key information are all registered. - * - * <p>Once a policy model is composed, the overall structure of the policy model and all its references - * can be validated. During validation of a policy model, the validation checks listed below are - * executed: - * <ol> - * <li>The policy model is validated as an Apex model, which validates the existence, correctness, - * and duplication of all keys in the model as well as validating the key information of the keys, - * see validation in {@link AxModel} - * <li>The schemas in the model must be valid, see validation in {@link AxContextSchemas} - * <li>The context albums in the model must be valid, see validation in {@link AxContextAlbums} - * <li>The tasks in the model must be valid, see validation in {@link AxTasks} - * <li>The policies in the model must be valid, see validation in {@link AxPolicies} - * <li>The events in the model must be valid, see validation in {@link AxEvents} - * <li>The context schemas referred to in each field in every event must exist - * <li>The context schemas referred to in every context album must exist - * <li>The context schemas referred to in every task input field and output field must exist - * <li>The context albums referred to in every task must exist - * <li>The context albums referred to in every state must exist - * <li>The trigger event referred to in every state must exist - * <li>The default task referred to in every state must exist - * <li>In a state, an event that triggers a task must contain all the input fields required by that - * task - * <li>In a state, an event that is emitted by a task must contain all the output fields produced by - * that task - * <li>All tasks referred to by a state must exist - * <li>All events referred to on direct state outputs must exist - * </ol> - */ -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; - - private AxPolicies policies; - private AxTasks tasks; - private AxEvents events; - private AxContextAlbums albums; - private AxContextSchemas schemas; - - /** - * The Default Constructor creates a policy model with a null key and empty containers for - * schemas, key information, events, context albums, tasks and policies. - */ - public AxPolicyModel() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxPolicyModel(final AxPolicyModel copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a policy model with the given key and empty containers for - * schemas, key information, events, context albums, tasks and policies. - * - * @param key the key - */ - public AxPolicyModel(final AxArtifactKey key) { - 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()))); - } - - /** - * This Constructor creates a policy model with all of its fields specified. - * - * @param key the key of the policy model - * @param schemas the context schema container for the policy model - * @param keyInformation the key information container for the policy model - * @param events the event container for the policy model - * @param albums the context album container for the policy model - * @param tasks the task container for the policy model - * @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) { - super(key, keyInformation); - Assertions.argumentNotNull(schemas, "schemas may not be null"); - Assertions.argumentNotNull(events, "events may not be null"); - Assertions.argumentNotNull(albums, "albums may not be null"); - Assertions.argumentNotNull(tasks, "tasks may not be null"); - Assertions.argumentNotNull(policies, "policies may not be null"); - - this.schemas = schemas; - this.events = events; - this.albums = albums; - this.tasks = tasks; - this.policies = policies; - } - - /** - * {@inheritDoc}. - */ - @Override - public void register() { - super.register(); - ModelService.registerModel(AxContextSchemas.class, getSchemas()); - ModelService.registerModel(AxEvents.class, getEvents()); - ModelService.registerModel(AxContextAlbums.class, getAlbums()); - ModelService.registerModel(AxTasks.class, getTasks()); - ModelService.registerModel(AxPolicies.class, getPolicies()); - ModelService.registerModel(AxPolicyModel.class, this); - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = super.getKeys(); - - keyList.addAll(schemas.getKeys()); - keyList.addAll(events.getKeys()); - keyList.addAll(albums.getKeys()); - keyList.addAll(tasks.getKeys()); - keyList.addAll(policies.getKeys()); - - return keyList; - } - - /** - * Gets a context model from the policy model. - * - * @return the context model - */ - public AxContextModel getContextModel() { - return new AxContextModel(new AxArtifactKey(albums.getKey().getName() + "_Model", albums.getKey().getVersion()), - getSchemas(), getAlbums(), getKeyInformation()); - } - - /** - * Gets the policy container from the policy model. - * - * @return the policy container with all the policies in the model - */ - public AxPolicies getPolicies() { - return policies; - } - - /** - * Sets the policy container for the policy model. - * - * @param policies the policy container with all the policies in the model - */ - public void setPolicies(final AxPolicies policies) { - Assertions.argumentNotNull(policies, "policies may not be null"); - this.policies = policies; - } - - /** - * Gets the task container from the policy model. - * - * @return the task container with all the tasks in the model - */ - public AxTasks getTasks() { - return tasks; - } - - /** - * Sets the task container from the policy model. - * - * @param tasks the task container with all the tasks in the model - */ - public void setTasks(final AxTasks tasks) { - Assertions.argumentNotNull(tasks, "tasks may not be null"); - this.tasks = tasks; - } - - /** - * Gets the event container from the policy model. - * - * @return the event container with all the events in the model - */ - public AxEvents getEvents() { - return events; - } - - /** - * Sets the event container from the policy model. - * - * @param events the event container with all the events in the model - */ - public void setEvents(final AxEvents events) { - Assertions.argumentNotNull(events, "events may not be null"); - this.events = events; - } - - /** - * Gets the context album container from the policy model. - * - * @return the context album container with all the context albums in the model - */ - public AxContextAlbums getAlbums() { - return albums; - } - - /** - * Sets the context album container from the policy model. - * - * @param albums the context album container with all the context albums in the model - */ - public void setAlbums(final AxContextAlbums albums) { - Assertions.argumentNotNull(albums, "albums may not be null"); - this.albums = albums; - } - - /** - * Gets the context schema container from the policy model. - * - * @return the context schema container with all the context schemas in the model - */ - public AxContextSchemas getSchemas() { - return schemas; - } - - /** - * Sets the context schema container from the policy model. - * - * @param schemas the context schema container with all the context schemas in the model - */ - public void setSchemas(final AxContextSchemas schemas) { - Assertions.argumentNotNull(schemas, "schemas may not be null"); - this.schemas = schemas; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - result = super.validate(result); - result = schemas.validate(result); - result = events.validate(result); - result = albums.validate(result); - result = tasks.validate(result); - result = policies.validate(result); - - validateEventKeys(result); - validateContextAlbumKeys(result); - validateAllTaskKeys(result); - validatePolicyKeys(result); - - return result; - } - - /** - * Validate all fundamental concepts keyed in events exist. - * - * @param result the validation result to return - * @return the result - */ - private AxValidationResult validateEventKeys(final AxValidationResult result) { - for (final AxEvent event : events.getAll(null)) { - for (final AxField field : event.getFields()) { - if (getSchemas().get(field.getSchema()) == null) { - result.addValidationMessage( - new AxValidationMessage(event.getKey(), this.getClass(), ValidationResult.INVALID, - "event field data type " + field.getSchema().getId() + DOES_NOT_EXIST)); - } - } - } - return result; - } - - /** - * Validate all fundamental concepts keyed in concept maps exist. - * - * @param result the validation result to return - * @return the result - */ - private AxValidationResult validateContextAlbumKeys(final AxValidationResult result) { - for (final AxContextAlbum contextAlbum : albums.getAll(null)) { - if (getSchemas().get(contextAlbum.getItemSchema()) == null) { - result.addValidationMessage( - new AxValidationMessage(contextAlbum.getKey(), this.getClass(), ValidationResult.INVALID, - "context album schema " + contextAlbum.getItemSchema().getId() + DOES_NOT_EXIST)); - } - } - return result; - } - - /** - * Validate all fundamental concepts keyed in tasks exist. - * - * @param result the validation result to return - * @return the result - */ - private AxValidationResult validateAllTaskKeys(AxValidationResult result) { - for (final AxTask task : tasks.getAll(null)) { - validateTaskKeys(task, result); - } - return result; - } - - /** - * Validate all fundamental concepts keyed in tasks exist. - * - * @param task The task to validate the keys of - * @param result the validation result to return - * @return the result - */ - private AxValidationResult validateTaskKeys(final AxTask task, AxValidationResult result) { - for (final AxArtifactKey contextAlbumKey : task.getContextAlbumReferences()) { - if (albums.get(contextAlbumKey) == null) { - result.addValidationMessage(new AxValidationMessage(task.getKey(), this.getClass(), - ValidationResult.INVALID, "task context album " + contextAlbumKey.getId() + DOES_NOT_EXIST)); - } - } - return result; - } - - /** - * Validate all fundamental concepts keyed in policies exist. - * - * @param result the validation result to return - * @return the result - */ - private AxValidationResult validatePolicyKeys(final AxValidationResult result) { - for (final AxPolicy policy : policies.getAll(null)) { - for (final AxState state : policy.getStateMap().values()) { - validateStateReferences(state, result); - } - } - - return result; - } - - /** - * Validate that the references used on a state are valid. - * - * @param state The state to check - * @param result the validation result to append to - */ - private void validateStateReferences(AxState state, AxValidationResult result) { - for (final AxArtifactKey contextAlbumKey : state.getContextAlbumReferences()) { - if (albums.get(contextAlbumKey) == null) { - result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(), - ValidationResult.INVALID, "state context album " + contextAlbumKey.getId() + DOES_NOT_EXIST)); - } - } - - final AxEvent triggerEvent = events.getEventMap().get(state.getTrigger()); - if (triggerEvent == null) { - result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(), - ValidationResult.INVALID, "state trigger event " + state.getTrigger().getId() + DOES_NOT_EXIST)); - } - - final AxTask defaultTask = tasks.getTaskMap().get(state.getDefaultTask()); - if (defaultTask == null) { - result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(), - ValidationResult.INVALID, "state default task " + state.getDefaultTask().getId() + DOES_NOT_EXIST)); - } - - for (final AxStateOutput stateOutput : state.getStateOutputs().values()) { - if (events.getEventMap().get(stateOutput.getOutgoingEvent()) == null) { - result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(), - ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId() - + " for state output " + stateOutput.getId() + DOES_NOT_EXIST)); - } - } - - validateEventTaskFieldCompatibilityOnState(state, result); - } - - /** - * Validate that the fields on tasks and events that trigger them and are output by them are - * compatible for all tasks used on a state. - * - * @param state The state to check - * @param result the validation result to append to - */ - private void validateEventTaskFieldCompatibilityOnState(AxState state, AxValidationResult result) { - // Check task output fields and event fields are compatible for tasks that directly - // reference state outputs - for (final Entry<AxArtifactKey, AxStateTaskReference> taskRefEntry : state.getTaskReferences().entrySet()) { - if (!taskRefEntry.getValue().getStateTaskOutputType().equals(AxStateTaskOutputType.DIRECT)) { - continue; - } - - final AxTask usedTask = tasks.getTaskMap().get(taskRefEntry.getKey()); - if (usedTask == null) { - result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(), - ValidationResult.INVALID, "state task " + taskRefEntry.getKey().getId() + DOES_NOT_EXIST)); - } else { - AxStateOutput stateOutput = - state.getStateOutputs().get(taskRefEntry.getValue().getOutput().getKey().getLocalName()); - validateEventTaskFieldCompatibilityOnStateOutput(state, usedTask, stateOutput, result); - } - } - } - - /** - * Validate that the fields on a task of a state output and the events that trigger it are - * compatible. - * - * @param state The state to check - * @param task The task to check - * @param stateOutput The state output to check - * @param result the validation result to append to - */ - private void validateEventTaskFieldCompatibilityOnStateOutput(final AxState state, final AxTask task, - 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")); - - } else { - final AxEvent usedEvent = events.getEventMap().get(stateOutput.getOutgoingEvent()); - if (usedEvent == null) { - result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(), - ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId() - + " for state output " + stateOutput.getId() + DOES_NOT_EXIST)); - } - } - } - - /** - * 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 - */ - @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()); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - super.clean(); - policies.clean(); - tasks.clean(); - events.clean(); - albums.clean(); - schemas.clean(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append(super.toString()); - builder.append(",policies="); - builder.append(policies); - builder.append(",tasks="); - builder.append(tasks); - builder.append(",events="); - builder.append(events); - builder.append(",albums="); - builder.append(albums); - builder.append(",schemas="); - builder.append(schemas); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxPolicyModel.class); - - final AxPolicyModel copy = ((AxPolicyModel) copyObject); - super.copyTo(targetObject); - copy.setPolicies(new AxPolicies(policies)); - copy.setTasks(new AxTasks(tasks)); - copy.setEvents(new AxEvents(events)); - copy.setAlbums(new AxContextAlbums(albums)); - copy.setSchemas(new AxContextSchemas(schemas)); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + super.hashCode(); - result = prime * result + policies.hashCode(); - result = prime * result + tasks.hashCode(); - result = prime * result + events.hashCode(); - result = prime * result + albums.hashCode(); - result = prime * result + schemas.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - throw new IllegalArgumentException("comparison object may not be null"); - } - - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxPolicyModel other = (AxPolicyModel) obj; - if (!super.equals(other)) { - return false; - } - if (!policies.equals(other.policies)) { - return false; - } - if (!tasks.equals(other.tasks)) { - return false; - } - if (!events.equals(other.events)) { - return false; - } - if (!albums.equals(other.albums)) { - return false; - } - return schemas.equals(other.schemas); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - Assertions.argumentNotNull(otherObj, "comparison object may not be null"); - - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxPolicyModel other = (AxPolicyModel) otherObj; - if (!super.equals(other)) { - return super.compareTo(other); - } - if (!policies.equals(other.policies)) { - return policies.compareTo(other.policies); - } - if (!tasks.equals(other.tasks)) { - return tasks.compareTo(other.tasks); - } - if (!events.equals(other.events)) { - return events.compareTo(other.events); - } - if (!albums.equals(other.albums)) { - return albums.compareTo(other.albums); - } - return schemas.compareTo(other.schemas); - } -} 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 deleted file mode 100644 index ae8efbff4..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java +++ /dev/null @@ -1,870 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd. - * Modifications Copyright (C) 2019-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 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 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.AxKeyUse; -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.common.utils.validation.Assertions; - -/** - * This class holds the definition of a single state in a policy. A state is a single stage in a policy. A state has a - * single input event, its trigger. A state can output many events, but can only output one event on a single execution. - * After it executes, a state can pass control to another state or can simply emit its event to an external system. In - * the case where a state passes control to another state, the output event of the state becomes the input event of the - * next state. The outputs of a state {@link AxStateOutput} are held as a map in the state. Each state output contains - * the outgoing event of the state and optionally the next state to pass control to. - * - * <p>A state uses tasks {@link AxTask} to execute its logic. A state holds its tasks in a map and must have at least - * one task. A state uses Task Selection Logic {@link AxTaskSelectionLogic} to select which task should be executed in a - * given execution cycle. Optional Task Selection Logic can use fields on the incoming event and information from the - * context albums available on the state to decide what task to execute in a given context. The default task of a state - * is the task that is executed when task Selection Logic is not specified. In cases where only a single task is - * specified on a state, the default task must be that task and the state always executes that task. - * - * <p>What happens when a state completes its execution cycle depends on the task that is selected for execution by the - * state. Therefore, the action to be performed a state on execution of each task must be defined in the state as a - * {@link AxStateTaskReference} instance for each task defined in the state. The {@link AxStateTaskReference} instance - * defines the action to be performed as either a {@link AxStateTaskOutputType} of {@link AxStateTaskOutputType#DIRECT} - * or {@link AxStateTaskOutputType#LOGIC} and contains an {@link AxReferenceKey} reference to the instance that will - * complete the state output. - * - * <p>In the case of direct output, the {@link AxReferenceKey} reference in the {@link AxStateTaskReference} instance is - * a reference to an {@link AxStateOutput} instance. The state output defines the event to be emitted by the state and - * the next state to pass control to if any. All fields of the executed task are marshaled onto the outgoing event - * automatically by Apex. - * - * <p>In the case of logic output, the {@link AxReferenceKey} reference in the {@link AxStateTaskReference} instance is - * a reference to State Finalizer Logic in an {@link AxStateFinalizerLogic} instance, which selects the - * {@link AxStateOutput} that the state will use. The state finalizer logic uses fields emitted by the executed task and - * information from the context albums available on the state to decide what {@link AxStateOutput} to select in a given - * context. The state output defines the event to be emitted by the state and the next state to pass control to if any. - * The State Finalizer Logic instances for the state are held in a map in the state. State Finalizer Logic must marshal - * the fields of the output event in whatever manner it wishes; Apex does not automatically transfer the output fields - * from the task directly to the output event. - * - * <p>The Task Selection Logic instance or State Finalizer Logic instances in a state may use information in context - * albums to arrive at their task or state output selections. The context albums that the state uses and that should be - * made available to the state by Apex policy distribution are held as a set of references to context albums in the - * state. - * - * <p>During validation of a state, the validation checks listed below are executed: <ol> <li>The policy key must not be - * a null key and must be valid, see validation in {@link AxReferenceKey} <li>The trigger event key must not be a null - * key and must be valid, see validation in {@link AxArtifactKey} <li>At least one state output must be defined <li>Each - * state output in a state must have that state as its parent <li>Each state output must be valid, see validation in - * {@link AxStateOutput} <li>The next state defined in a state output must be unique in a state <li>The default task key - * must not be a null key and must be valid, see validation in {@link AxArtifactKey} <li>The default task must appear in - * the task map of the state <li>At least one task must be defined on the state <li>Each task key on the task map for - * the state must not be a null key and must be valid, see validation in {@link AxArtifactKey} <li>All state task - * references for each task in the state must exist and must be valid, see validation in {@link AxStateTaskReference} - * <li>Each state task reference in a state must have that state as its parent <li>For direct state outputs from tasks, - * the state output must be defined on the state <li>For logic state outputs from tasks, the State Finalizer Logic must - * be defined on the state <li>An observation is issued for each state output defined on the state that is not used as a - * direct output on a task <li>An observation is issued for each state finalizer logic instance defined on the state - * that is not used as an output on a task <li>Each context album key on the context album set for the state must not be - * a null key and must be valid, see validation in {@link AxArtifactKey} <li>Task Selection logic in a state must have - * that state as its parent <li>Task Selection logic in a state must be valid, see validation in - * {@link AxTaskSelectionLogic} <li>Each State Finalizer logic instance in a state must have that state as its parent - * <li>Each State Finalizer logic instance in a state must be valid, see validation in {@link AxStateFinalizerLogic} - * </ol> - */ -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; - - - - @SerializedName("stateKey") - private AxReferenceKey key; - - private AxArtifactKey trigger; - private Map<String, AxStateOutput> stateOutputs; - - @SerializedName("contextAlbumReference") - private Set<AxArtifactKey> contextAlbumReferenceSet; - - private AxTaskSelectionLogic taskSelectionLogic; - private Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap; - private AxArtifactKey defaultTask; - - @SerializedName("taskReferences") - private Map<AxArtifactKey, AxStateTaskReference> taskReferenceMap; - - /** - * The Default Constructor creates a state with a null reference key and with default values for all other fields. - */ - public AxState() { - this(new AxReferenceKey()); - contextAlbumReferenceSet = new TreeSet<>(); - taskReferenceMap = new TreeMap<>(); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxState(final AxState copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a state with the given reference key and with default values for all other fields. - * - * @param key the reference key of the state - */ - public AxState(final AxReferenceKey key) { - // @formatter:off - this(new AxStateParamsBuilder() - .key(key) // Key - .trigger(AxArtifactKey.getNullKey()) // Trigger Reference - .stateOutputs(new TreeMap<>()) // State Outputs - .contextAlbumReferenceSet(new TreeSet<>()) // Context Album Refs - .taskSelectionLogic(new AxTaskSelectionLogic()) // Task Selection Logic - .stateFinalizerLogicMap(new TreeMap<>()) // State Finalizer Logics - .defaultTask(AxArtifactKey.getNullKey()) // Default Task - .taskReferenceMap(new TreeMap<>()) // Task References - ); - // @formatter:on - } - - /** - * This Constructor creates a state with all its fields defined. - * - * @param axStateParams parameters for state creation - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public AxState(AxStateParamsBuilder axStateParams) { - super(); - Assertions.argumentNotNull(axStateParams.getKey(), "key may not be null"); - Assertions.argumentNotNull(axStateParams.getTrigger(), "trigger may not be null"); - Assertions.argumentNotNull(axStateParams.getStateOutputs(), "stateOutputs may not be null"); - Assertions.argumentNotNull(axStateParams.getContextAlbumReferenceSet(), - "contextAlbumReferenceSet may not be null"); - Assertions.argumentNotNull(axStateParams.getTaskSelectionLogic(), "taskSelectionLogic may not be null"); - Assertions.argumentNotNull(axStateParams.getStateFinalizerLogicMap(), "stateFinalizerLogicMap may not be null"); - Assertions.argumentNotNull(axStateParams.getDefaultTask(), "defaultTask may not be null"); - Assertions.argumentNotNull(axStateParams.getTaskReferenceMap(), "taskReferenceMap may not be null"); - - this.key = axStateParams.getKey(); - this.trigger = axStateParams.getTrigger(); - this.stateOutputs = axStateParams.getStateOutputs(); - this.contextAlbumReferenceSet = axStateParams.getContextAlbumReferenceSet(); - this.taskSelectionLogic = axStateParams.getTaskSelectionLogic(); - this.stateFinalizerLogicMap = axStateParams.getStateFinalizerLogicMap(); - this.defaultTask = axStateParams.getDefaultTask(); - this.taskReferenceMap = axStateParams.getTaskReferenceMap(); - } - // CHECKSTYLE:ON: checkstyle:parameterNumber - - /** - * 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. - */ - @Override - public void buildReferences() { - if (!taskSelectionLogic.getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) { - taskSelectionLogic.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)); - } - - /** - * Gets the names of all the states that this state may pass control to. - * - * @return the list of possible states that may receive control when this state completes execution - */ - public Set<String> getNextStateSet() { - final Set<String> nextStateSet = new TreeSet<>(); - - for (final AxStateOutput stateOutput : stateOutputs.values()) { - nextStateSet.add(stateOutput.getNextState().getLocalName()); - } - return nextStateSet; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - keyList.add(new AxKeyUse(trigger.getKey())); - for (final AxStateOutput stateOutput : stateOutputs.values()) { - keyList.addAll(stateOutput.getKeys()); - } - for (final AxArtifactKey contextAlbumReferenceKey : contextAlbumReferenceSet) { - keyList.add(new AxKeyUse(contextAlbumReferenceKey)); - } - if (!taskSelectionLogic.getKey().equals(AxReferenceKey.getNullKey())) { - keyList.addAll(taskSelectionLogic.getKeys()); - } - for (final Entry<String, AxStateFinalizerLogic> stateFinalizerLogicEntry : stateFinalizerLogicMap.entrySet()) { - keyList.addAll(stateFinalizerLogicEntry.getValue().getKeys()); - } - keyList.add(new AxKeyUse(defaultTask.getKey())); - for (final Entry<AxArtifactKey, AxStateTaskReference> taskReferenceEntry : taskReferenceMap.entrySet()) { - keyList.add(new AxKeyUse(taskReferenceEntry.getKey())); - - // A state output is allowed to be used more than once but we only return one usage as a - // key - for (AxKey referencedKey : taskReferenceEntry.getValue().getKeys()) { - if (keyList.contains(referencedKey)) { - keyList.add(referencedKey); - } - } - } - return keyList; - } - - /** - * Sets the reference key of the state. - * - * @param key the state reference key - */ - public void setKey(final AxReferenceKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the event that triggers the state. - * - * @return the event that triggers the state - */ - public AxArtifactKey getTrigger() { - return trigger; - } - - /** - * Sets the event that triggers the state. - * - * @param trigger the event that triggers the state - */ - public void setTrigger(final AxArtifactKey trigger) { - Assertions.argumentNotNull(trigger, "trigger may not be null"); - this.trigger = trigger; - } - - /** - * Gets the possible state outputs for the state. - * - * @return the the possible state outputs for the state - */ - public Map<String, AxStateOutput> getStateOutputs() { - return stateOutputs; - } - - /** - * Sets the the possible state outputs for the state. - * - * @param stateOutputs the the possible state outputs for the state - */ - public void setStateOutputs(final Map<String, AxStateOutput> stateOutputs) { - Assertions.argumentNotNull(stateOutputs, "stateOutputs may not be null"); - this.stateOutputs = stateOutputs; - } - - /** - * Gets the context album reference set defines the context that may be used by Task Selection Logic and State - * Finalizer Logic in the state. - * - * @return the context album reference set defines the context that may be used by Task Selection Logic and State - * Finalizer Logic in the state - */ - public Set<AxArtifactKey> getContextAlbumReferences() { - return contextAlbumReferenceSet; - } - - /** - * Sets the context album reference set defines the context that may be used by Task Selection Logic and State - * Finalizer Logic in the state. - * - * @param contextAlbumReferences the context album reference set defines the context that may be used by Task - * Selection Logic and State Finalizer Logic in the state - */ - public void setContextAlbumReferences(final Set<AxArtifactKey> contextAlbumReferences) { - Assertions.argumentNotNull(contextAlbumReferences, "contextAlbumReferenceSet may not be null"); - this.contextAlbumReferenceSet = contextAlbumReferences; - } - - /** - * Gets the task selection logic that selects the task a state executes in an execution cycle. - * - * @return the task selection logic that selects the task a state executes in an execution cycle - */ - public AxTaskSelectionLogic getTaskSelectionLogic() { - return taskSelectionLogic; - } - - /** - * Sets the task selection logic that selects the task a state executes in an execution cycle. - * - * @param taskSelectionLogic the task selection logic that selects the task a state executes in an execution cycle - */ - public void setTaskSelectionLogic(final AxTaskSelectionLogic taskSelectionLogic) { - Assertions.argumentNotNull(taskSelectionLogic, "taskSelectionLogic may not be null"); - this.taskSelectionLogic = taskSelectionLogic; - } - - /** - * Check if task selection logic has been specified the state. - * - * @return true, if task selection logic has been specified - */ - public boolean checkSetTaskSelectionLogic() { - return !taskSelectionLogic.getKey().equals(AxReferenceKey.getNullKey()); - } - - /** - * Gets the state finalizer logic instances that selects the state output to use after a task executes in a state - * execution cycle. - * - * @return the state finalizer logic instances that selects the state output to use after a task executes in a state - * execution cycle - */ - public Map<String, AxStateFinalizerLogic> getStateFinalizerLogicMap() { - return stateFinalizerLogicMap; - } - - /** - * Sets the state finalizer logic instances that selects the state output to use after a task executes in a state - * execution cycle. - * - * @param stateFinalizerLogicMap the state finalizer logic instances that selects the state output to use after a - * task executes in a state execution cycle - */ - public void setStateFinalizerLogicMap(final Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap) { - Assertions.argumentNotNull(stateFinalizerLogicMap, "stateFinalizerLogic may not be null"); - this.stateFinalizerLogicMap = stateFinalizerLogicMap; - } - - /** - * Gets the default task that will execute in a state if Task Selection Logic is not specified. - * - * @return the default task that will execute in a state if Task Selection Logic is not specified - */ - public AxArtifactKey getDefaultTask() { - return defaultTask; - } - - /** - * Sets the default task that will execute in a state if Task Selection Logic is not specified. - * - * @param defaultTask the default task that will execute in a state if Task Selection Logic is not specified - */ - public void setDefaultTask(final AxArtifactKey defaultTask) { - Assertions.argumentNotNull(defaultTask, "defaultTask may not be null"); - this.defaultTask = defaultTask; - } - - /** - * Gets the task reference map that defines the tasks for the state and how the task outputs are handled. - * - * @return the task reference map that defines the tasks for the state and how the task outputs are handled - */ - public Map<AxArtifactKey, AxStateTaskReference> getTaskReferences() { - return taskReferenceMap; - } - - /** - * Sets the task reference map that defines the tasks for the state and how the task outputs are handled. - * - * @param taskReferences the task reference map that defines the tasks for the state and how the task outputs are - * handled - */ - public void setTaskReferences(final Map<AxArtifactKey, AxStateTaskReference> taskReferences) { - Assertions.argumentNotNull(taskReferences, "taskReferenceMap may not be null"); - this.taskReferenceMap = taskReferences; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key is a null key")); - } - - result = key.validate(result); - - if (trigger.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "trigger is a null key: " + trigger)); - } - result = trigger.validate(result); - - if (stateOutputs.size() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "stateOutputs may not be empty")); - } else { - validateStateOutputs(result); - } - - validateContextAlbumReferences(result); - result = validateTaskSelectionLogic(result); - validateStateFinalizerLogics(result); - - if (defaultTask.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "default task has a null key: " + defaultTask)); - } - result = defaultTask.validate(result); - - if (taskReferenceMap.size() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "taskReferenceMap may not be empty")); - } else { - validateStateTaskReferences(result); - } - - return result; - } - - /** - * Validate the state outputs of the state. - * - * @param result the validation result to append to - */ - private void validateStateOutputs(AxValidationResult result) { - final Set<String> nextStateNameSet = new TreeSet<>(); - for (final Entry<String, AxStateOutput> stateOutputEntry : stateOutputs.entrySet()) { - if (stateOutputEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "null state output value found on state output " + stateOutputEntry.getKey())); - } else { - if (!stateOutputEntry.getValue().getKey().getParentReferenceKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent key on state output " + stateOutputEntry.getKey() - + DOES_NOT_EQUAL_STATE_KEY)); - } - - if (stateOutputEntry.getValue().getNextState().getLocalName().equals(key.getLocalName())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "state output next state " - + stateOutputEntry.getValue().getNextState().getLocalName() - + " may not be this state")); - - } - - if (nextStateNameSet.contains(stateOutputEntry.getValue().getNextState().getLocalName())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "duplicate state output next state name " - + stateOutputEntry.getValue().getNextState().getLocalName() - + " found")); - } else { - nextStateNameSet.add(stateOutputEntry.getValue().getNextState().getLocalName()); - } - result = stateOutputEntry.getValue().validate(result); - } - } - } - - /** - * Validate the context album references of the state. - * - * @param result the validation result to append to - */ - private void validateContextAlbumReferences(AxValidationResult result) { - for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) { - if (contextAlbumReference.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on context album reference entry " + contextAlbumReference.getKey() - + " may not be the null key")); - } - - result = contextAlbumReference.validate(result); - } - } - - /** - * Validate the task selection logic of the state. - * - * @param result the validation result to append to - * @return the result of the validation - */ - private AxValidationResult validateTaskSelectionLogic(AxValidationResult result) { - if (!taskSelectionLogic.getKey().equals(AxReferenceKey.getNullKey())) { - if (!taskSelectionLogic.getKey().getParentReferenceKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "taskSelectionLogic key " + taskSelectionLogic.getKey().getId() - + DOES_NOT_EQUAL_STATE_KEY)); - } - result = taskSelectionLogic.validate(result); - } - - return result; - } - - /** - * Validate all the state finalizer logic of the state. - * - * @param result the validation result to append to - */ - private void validateStateFinalizerLogics(AxValidationResult result) { - for (final Entry<String, AxStateFinalizerLogic> stateFinalizerLogicEntry : stateFinalizerLogicMap.entrySet()) { - if (stateFinalizerLogicEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "null state finalizer logic value found on state finalizer entry " - + stateFinalizerLogicEntry.getKey())); - } else { - if (!stateFinalizerLogicEntry.getValue().getKey().getParentReferenceKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "stateFinalizerLogic parent key " - + stateFinalizerLogicEntry.getValue().getKey().getId() - + DOES_NOT_EQUAL_STATE_KEY)); - } - - result = stateFinalizerLogicEntry.getValue().validate(result); - } - } - } - - /** - * Validate the tasks used the state. - * - * @param result the validation result to append to - */ - private void validateStateTaskReferences(AxValidationResult result) { - final Set<String> usedStateOutputNameSet = new TreeSet<>(); - final Set<String> usedStateFinalizerLogicNameSet = new TreeSet<>(); - - for (final Entry<AxArtifactKey, AxStateTaskReference> taskRefEntry : taskReferenceMap.entrySet()) { - if (taskRefEntry.getKey().equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "task has a null key: " + taskRefEntry.getKey())); - } - result = taskRefEntry.getKey().validate(result); - - if (taskRefEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "null task reference value found on task reference " + taskRefEntry.getKey())); - } else { - result = validateStateTaskReference(taskRefEntry.getKey(), taskRefEntry.getValue(), - usedStateOutputNameSet, usedStateFinalizerLogicNameSet, result); - } - } - - final Set<String> unUsedStateOutputNameSet = new TreeSet<>(stateOutputs.keySet()); - unUsedStateOutputNameSet.removeAll(usedStateOutputNameSet); - for (final String unUsedStateOutputName : unUsedStateOutputNameSet) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION, - "state output " + unUsedStateOutputName + " is not used directly by any task")); - } - - final Set<String> usnUedStateFinalizerLogicNameSet = new TreeSet<>(stateFinalizerLogicMap.keySet()); - usnUedStateFinalizerLogicNameSet.removeAll(usedStateFinalizerLogicNameSet); - for (final String unusedStateFinalizerLogicName : usnUedStateFinalizerLogicNameSet) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION, - "state finalizer logic " + unusedStateFinalizerLogicName + " is not used by any task")); - } - - if (!taskReferenceMap.containsKey(defaultTask)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "defaultTask " + defaultTask + " not found in taskReferenceMap")); - } - } - - /** - * Validate the references of a task used in a state. - * - * @param taskKey The key of the task - * @param taskReference the task reference of the task - * @param stateOutputNameSet State outputs that have been used so far, will be appended for this task reference - * @param stateFinalizerLogicNameSet State finalizers that have been used so far, may be appended if this task - * reference uses a finalzier - * @param result the validation result to append to - * @return the result of the validation - */ - private AxValidationResult validateStateTaskReference(final AxArtifactKey taskKey, - final AxStateTaskReference taskReference, Set<String> stateOutputNameSet, - Set<String> stateFinalizerLogicNameSet, AxValidationResult result) { - if (!taskReference.getKey().getParentReferenceKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "stateTaskReference parent key " + taskReference.getKey().getId() - + DOES_NOT_EQUAL_STATE_KEY)); - } - - if (taskReference.getStateTaskOutputType().equals(AxStateTaskOutputType.DIRECT)) { - if (stateOutputs.containsKey(taskReference.getOutput().getLocalName())) { - stateOutputNameSet.add(taskReference.getOutput().getLocalName()); - } else { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "state output for task " + taskKey + " not found in stateOutputs")); - } - } else if (taskReference.getStateTaskOutputType().equals(AxStateTaskOutputType.LOGIC)) { - if (stateFinalizerLogicMap.containsKey(taskReference.getOutput().getLocalName())) { - stateFinalizerLogicNameSet.add(taskReference.getOutput().getLocalName()); - } else { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "state finalizer logic for task " + taskKey + " not found in stateFinalizerLogicMap")); - } - } else { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "stateTaskReference task output type " + taskReference.getStateTaskOutputType() - + " is invalid")); - } - - return taskReference.validate(result); - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - trigger.clean(); - for (final AxStateOutput stateOutput : stateOutputs.values()) { - stateOutput.clean(); - } - for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) { - contextAlbumReference.clean(); - } - taskSelectionLogic.clean(); - for (final AxStateFinalizerLogic stateFinalizerLogic : stateFinalizerLogicMap.values()) { - stateFinalizerLogic.clean(); - } - defaultTask.clean(); - for (final AxStateTaskReference taskReference : taskReferenceMap.values()) { - taskReference.clean(); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("stateKey="); - builder.append(key); - builder.append(",trigger="); - builder.append(trigger); - builder.append(",stateOutputs="); - builder.append(stateOutputs); - builder.append(",contextAlbumReferenceSet="); - builder.append(contextAlbumReferenceSet); - builder.append(",taskSelectionLogic="); - builder.append(taskSelectionLogic); - builder.append(",stateFinalizerLogicSet="); - builder.append(stateFinalizerLogicMap); - builder.append(",defaultTask="); - builder.append(defaultTask); - builder.append(",taskReferenceMap="); - builder.append(taskReferenceMap); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxState.class); - - final AxState copy = ((AxState) copyObject); - copy.setKey(new AxReferenceKey(key)); - copy.setTrigger(new AxArtifactKey(trigger)); - - final Map<String, AxStateOutput> newStateOutputs = new TreeMap<>(); - for (final Entry<String, AxStateOutput> stateOutputEntry : stateOutputs.entrySet()) { - newStateOutputs.put(stateOutputEntry.getKey(), new AxStateOutput(stateOutputEntry.getValue())); - } - copy.setStateOutputs(newStateOutputs); - - final Set<AxArtifactKey> newContextUsage = new TreeSet<>(); - for (final AxArtifactKey contextAlbumReferenceItem : contextAlbumReferenceSet) { - newContextUsage.add(new AxArtifactKey(contextAlbumReferenceItem)); - } - copy.setContextAlbumReferences(newContextUsage); - - copy.setTaskSelectionLogic(new AxTaskSelectionLogic(taskSelectionLogic)); - - final Map<String, AxStateFinalizerLogic> newStateFinalizerLogicMap = new TreeMap<>(); - for (final Entry<String, AxStateFinalizerLogic> stateFinalizerLogicEntry : stateFinalizerLogicMap.entrySet()) { - newStateFinalizerLogicMap.put(stateFinalizerLogicEntry.getKey(), - new AxStateFinalizerLogic(stateFinalizerLogicEntry.getValue())); - } - copy.setStateFinalizerLogicMap(newStateFinalizerLogicMap); - - copy.setDefaultTask(new AxArtifactKey(defaultTask)); - - final Map<AxArtifactKey, AxStateTaskReference> newTaskReferenceMap = new TreeMap<>(); - for (final Entry<AxArtifactKey, AxStateTaskReference> taskReferenceEntry : taskReferenceMap.entrySet()) { - newTaskReferenceMap.put(new AxArtifactKey(taskReferenceEntry.getKey()), - new AxStateTaskReference(taskReferenceEntry.getValue())); - } - copy.setTaskReferences(newTaskReferenceMap); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + trigger.hashCode(); - result = prime * result + stateOutputs.hashCode(); - result = prime * result + contextAlbumReferenceSet.hashCode(); - result = prime * result + taskSelectionLogic.hashCode(); - result = prime * result + stateFinalizerLogicMap.hashCode(); - result = prime * result + defaultTask.hashCode(); - result = prime * result + taskReferenceMap.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxState other = (AxState) obj; - if (!key.equals(other.key)) { - return false; - } - if (!trigger.equals(other.trigger)) { - return false; - } - if (!stateOutputs.equals(other.stateOutputs)) { - return false; - } - if (!contextAlbumReferenceSet.equals(other.contextAlbumReferenceSet)) { - return false; - } - if (!taskSelectionLogic.equals(other.taskSelectionLogic)) { - return false; - } - if (!stateFinalizerLogicMap.equals(other.stateFinalizerLogicMap)) { - return false; - } - if (!defaultTask.equals(other.defaultTask)) { - return false; - } - return taskReferenceMap.equals(other.taskReferenceMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - return compareObjectFields((AxState) otherObj); - } - - /** - * Compare the object fields on this state to another state. - * - * @param other the other state to compare with - * @return the result of the comparison - */ - private int compareObjectFields(final AxState other) { - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!trigger.equals(other.trigger)) { - return trigger.compareTo(other.trigger); - } - if (!stateOutputs.equals(other.stateOutputs)) { - return stateOutputs.hashCode() - other.stateOutputs.hashCode(); - } - if (!contextAlbumReferenceSet.equals(other.contextAlbumReferenceSet)) { - return (contextAlbumReferenceSet.hashCode() - other.contextAlbumReferenceSet.hashCode()); - } - if (!taskSelectionLogic.equals(other.taskSelectionLogic)) { - return taskSelectionLogic.compareTo(other.taskSelectionLogic); - } - if (!stateFinalizerLogicMap.equals(other.stateFinalizerLogicMap)) { - return stateFinalizerLogicMap.hashCode() - other.stateFinalizerLogicMap.hashCode(); - } - if (!defaultTask.equals(other.defaultTask)) { - return defaultTask.compareTo(other.defaultTask); - } - if (!taskReferenceMap.equals(other.taskReferenceMap)) { - return (taskReferenceMap.hashCode() - other.taskReferenceMap.hashCode()); - } - - return 0; - } -} 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 deleted file mode 100644 index 31ffedea8..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * ============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 org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -/** - * This class holds State Finalizer Logic for {@link AxState} states in Apex. It is a specialization - * of the {@link AxLogic} class, so that State Finalizer Logic in Apex states can be strongly typed. - * - * <p>State Finalizer Logic is used to select the output {@link AxStateOutput} that a state will use. - * The logic uses fields emitted by the executed {@link AxTask} task and information from the - * context albums available on a state to decide what state output {@link AxStateOutput} to select - * in a given context. State Finalizer Logic must marshal the output fields from the task onto the - * output event in whatever manner is appropriate for the domain being handled. - * - * <p>Validation uses standard Apex Logic validation, see validation in {@link AxLogic}. - */ -public class AxStateFinalizerLogic extends AxLogic { - private static final long serialVersionUID = 2090324845463750391L; - - /** - * The Default Constructor creates a logic instance with a null key, undefined logic flavour and - * a null logic string. - */ - public AxStateFinalizerLogic() { - super(); - } - - /** - * The Key Constructor creates a logic instance with the given reference key, undefined logic - * flavour and a null logic string. - * - * @param key the reference key of the logic - */ - public AxStateFinalizerLogic(final AxReferenceKey key) { - super(key, LOGIC_FLAVOUR_UNDEFINED, ""); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents - * key and the logic local name and all of its fields defined. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxStateFinalizerLogic(final AxReferenceKey parentKey, final String logicName, final String logicFlavour, - final String logic) { - super(parentKey, logicName, logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance with the given reference key and all of its fields - * defined. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxStateFinalizerLogic(final AxReferenceKey key, final String logicFlavour, final String logic) { - super(key, logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance by cloning the fields from another logic instance - * into this logic instance. - * - * @param logic the logic instance to clone from - */ - public AxStateFinalizerLogic(final AxLogic logic) { - super(new AxReferenceKey(logic.getKey()), logic.getLogicFlavour(), logic.getLogic()); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents - * key and the logic local name, the given logic flavour, with the logic being provided by the - * given logic reader instance. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxStateFinalizerLogic(final AxReferenceKey parentKey, final String logicName, final String logicFlavour, - final AxLogicReader logicReader) { - super(new AxReferenceKey(parentKey, logicName), logicFlavour, logicReader); - } - - /** - * This Constructor creates a logic instance with the given reference key and logic flavour, the - * logic is provided by the given logic reader instance. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxStateFinalizerLogic(final AxReferenceKey key, final String logicFlavour, final AxLogicReader logicReader) { - super(key, logicFlavour, logicReader); - } -} 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 deleted file mode 100644 index 7d4695290..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java +++ /dev/null @@ -1,291 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * ================================================================================ - * 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 com.google.gson.annotations.SerializedName; -import java.util.List; -import java.util.Set; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -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.AxKeyUse; -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.common.utils.validation.Assertions; - -/** - * This class defines a single output that a state can have. A state can have many outputs with each - * output defined as an instance of this class. Each state output defines the output event that will - * be emitted when this output is selected and optionally the next state that is executed when this - * state output is selected. If no next state is defined (the next state is a null - * {@link AxReferenceKey} key), then this state output outputs its event to an external system and - * is an output state for the full policy. - * - * <p>During validation of a state output, the validation checks listed below are executed: - * <ol> - * <li>The state output key must not be a null key and must be valid, see validation in - * {@link AxReferenceKey} - * <li>The outgoing event key must not be a null key and must be valid, see validation in - * {@link AxArtifactKey} - * <li>The next state key must be valid, see validation in {@link AxReferenceKey} - * </ol> - */ -@Getter -@Setter -public class AxStateOutput extends AxConcept { - private static final long serialVersionUID = 8041771382337655535L; - - @NonNull - private AxReferenceKey key; - - @NonNull - private AxArtifactKey outgoingEvent; - - @SerializedName("outgoingEventReference") - private Set<AxArtifactKey> outgoingEventSet; - - @NonNull - private AxReferenceKey nextState; - // @formatter:on - - /** - * The Default Constructor creates a state output instance with a null reference key, outgoing - * event key and next state reference key. - */ - public AxStateOutput() { - this(new AxReferenceKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxStateOutput(final AxStateOutput copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a state output instance with the given reference key, outgoing - * event key and next state reference key. - * - * @param key the reference key for the state output - */ - public AxStateOutput(final AxReferenceKey key) { - this(key, // Key - AxArtifactKey.getNullKey(), // Outgoing Event - AxReferenceKey.getNullKey() // Next State - ); - } - - /** - * This Constructor creates a state output with a reference key composed of the given parent key - * and with a local name composed from the parent key local name concatenated with the next - * state's local name. The next state and outgoing event of the state output are set as - * specified. - * - * @param parentKey the parent key of the state output - * @param nextState the next state to which execution will pass on use of this state output - * @param outgoingEvent the outgoing event emitted on use of this state output - */ - public AxStateOutput(final AxReferenceKey parentKey, final AxReferenceKey nextState, - final AxArtifactKey outgoingEvent) { - this(new AxReferenceKey(parentKey, parentKey.getLocalName() + '_' + nextState.getLocalName()), outgoingEvent, - nextState); - } - - /** - * This Constructor creates a state output with the specified reference key. The next state and - * outgoing event of the state output are set as specified. - * - * @param key the key - * @param nextState the next state to which execution will pass on use of this state output - * @param outgoingEvent the outgoing event emitted on use of this state output - */ - public AxStateOutput(final AxReferenceKey key, final AxArtifactKey outgoingEvent, final AxReferenceKey nextState) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(outgoingEvent, "outgoingEvent may not be null"); - Assertions.argumentNotNull(nextState, "nextState may not be null"); - - this.key = key; - this.outgoingEvent = outgoingEvent; - this.nextState = nextState; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - keyList.add(new AxKeyUse(outgoingEvent)); - - if (!nextState.equals(AxReferenceKey.getNullKey())) { - keyList.add(new AxKeyUse(nextState)); - } - - return keyList; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (outgoingEvent.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "outgoingEvent reference is a null key, an outgoing event must be specified")); - } - result = outgoingEvent.validate(result); - - // Note: Null keys are allowed on nextState as there may not be a next state - result = nextState.validate(result); - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - outgoingEvent.clean(); - nextState.clean(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("stateKey="); - builder.append(key); - builder.append(",outgoingEvent="); - builder.append(outgoingEvent); - builder.append(",nextState="); - builder.append(nextState); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxStateOutput.class); - - final AxStateOutput copy = ((AxStateOutput) copyObject); - copy.setKey(new AxReferenceKey(key)); - copy.setOutgoingEvent(new AxArtifactKey(outgoingEvent)); - copy.setNextState(nextState); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + outgoingEvent.hashCode(); - result = prime * result + nextState.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxStateOutput other = (AxStateOutput) obj; - if (!key.equals(other.key)) { - return false; - } - if (!outgoingEvent.equals(other.outgoingEvent)) { - return false; - } - return nextState.equals(other.nextState); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxStateOutput other = (AxStateOutput) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!outgoingEvent.equals(other.outgoingEvent)) { - return outgoingEvent.compareTo(other.outgoingEvent); - } - return nextState.compareTo(other.nextState); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateParamsBuilder.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateParamsBuilder.java deleted file mode 100644 index 6ef6e0b0a..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateParamsBuilder.java +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * ================================================================================ - * 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 java.util.Map; -import java.util.Set; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -public class AxStateParamsBuilder { - private AxReferenceKey key; - private AxArtifactKey trigger; - private Map<String, AxStateOutput> stateOutputs; - private Set<AxArtifactKey> contextAlbumReferenceSet; - private AxTaskSelectionLogic taskSelectionLogic; - private Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap; - private AxArtifactKey defaultTask; - private Map<AxArtifactKey, AxStateTaskReference> taskReferenceMap; - - public AxReferenceKey getKey() { - return key; - } - - public AxArtifactKey getTrigger() { - return trigger; - } - - public Map<String, AxStateOutput> getStateOutputs() { - return stateOutputs; - } - - public Set<AxArtifactKey> getContextAlbumReferenceSet() { - return contextAlbumReferenceSet; - } - - public AxTaskSelectionLogic getTaskSelectionLogic() { - return taskSelectionLogic; - } - - public Map<String, AxStateFinalizerLogic> getStateFinalizerLogicMap() { - return stateFinalizerLogicMap; - } - - public AxArtifactKey getDefaultTask() { - return defaultTask; - } - - public Map<AxArtifactKey, AxStateTaskReference> getTaskReferenceMap() { - return taskReferenceMap; - } - - /** - * Setter method. - * - * @param key the reference key of the state - * @return builder object - */ - public AxStateParamsBuilder key(AxReferenceKey key) { - this.key = key; - return this; - } - - /** - * Setter method. - * - * @param trigger the event that triggers the state - * @return builder object - */ - public AxStateParamsBuilder trigger(AxArtifactKey trigger) { - this.trigger = trigger; - return this; - } - - /** - * Setter method. - * - * @param stateOutputs the possible state outputs for the state - * @return builder object - */ - public AxStateParamsBuilder stateOutputs(Map<String, AxStateOutput> stateOutputs) { - this.stateOutputs = stateOutputs; - return this; - } - - /** - * Setter method. - * - * @param contextAlbumReferenceSet the context album reference set defines the context that may - * be used by Task Selection Logic and State Finalizer Logic in the state - * @return builder object - */ - public AxStateParamsBuilder contextAlbumReferenceSet(Set<AxArtifactKey> contextAlbumReferenceSet) { - this.contextAlbumReferenceSet = contextAlbumReferenceSet; - return this; - } - - /** - * Setter method. - * - * @param taskSelectionLogic the task selection logic that selects the task a state executes in - * an execution cycle - * @return builder object - */ - public AxStateParamsBuilder taskSelectionLogic(AxTaskSelectionLogic taskSelectionLogic) { - this.taskSelectionLogic = taskSelectionLogic; - return this; - } - - /** - * Setter method. - * - * @param stateFinalizerLogicMap the state finalizer logic instances that selects the state - * output to use after a task executes in a state execution cycle - * @return builder object - */ - public AxStateParamsBuilder stateFinalizerLogicMap( - Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap) { - this.stateFinalizerLogicMap = stateFinalizerLogicMap; - return this; - } - - /** - * Setter method. - * - * @param defaultTask the default task that will execute in a state if Task Selection Logic is - * not specified - * @return builder object - */ - public AxStateParamsBuilder defaultTask(AxArtifactKey defaultTask) { - this.defaultTask = defaultTask; - return this; - } - - /** - * Setter method. - * - * @param taskReferenceMap the task reference map that defines the tasks for the state and how - * @return builder object - */ - public AxStateParamsBuilder taskReferenceMap(Map<AxArtifactKey, AxStateTaskReference> taskReferenceMap) { - this.taskReferenceMap = taskReferenceMap; - return this; - } -} 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 deleted file mode 100644 index 171747c0c..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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; - -/** - * 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. - */ -public enum AxStateTaskOutputType { - /** The state output selection for the task has not been defined. */ - UNDEFINED, - /** - * Direct state output selection has been selected, the task will select a {@link AxStateOutput} - * directly. - */ - DIRECT, - /** - * Logic state output selection has been selected, the task will select a {@link AxStateOutput} - * using logic defined in a {@link AxStateFinalizerLogic} instance. - */ - LOGIC -} 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 deleted file mode 100644 index 748eca92d..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java +++ /dev/null @@ -1,339 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 java.util.List; -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.AxKeyUse; -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.common.utils.validation.Assertions; - -/** - * This class defines the type of output handling that will be used when a task in a state completes - * execution. Each task {@link AxTask} in a state {@link AxState} must select a state output - * {@link AxStateOutput} in order to pass its fields to an output event. Therefore, each task has an - * associated instance of this class that defines how the state output of the state is selected and - * how the output fields of the task are marshaled onto the fields of the output event. A - * {@link AxStateTaskReference} instance defines the task output handling as either - * {@link AxStateTaskOutputType#DIRECT} or {@link AxStateTaskOutputType#LOGIC}. In the case of - * {@link AxStateTaskOutputType#DIRECT} output selection, the output reference key held in this - * {@link AxStateTaskReference} instance to an instance of an {@link AxStateOutput} class. In the - * case of {@link AxStateTaskOutputType#LOGIC} output selection, the output reference key held in - * this {@link AxStateTaskReference} instance to an instance of an {@link AxStateFinalizerLogic} - * class. See the explanation in the {@link AxState} class for a full description of this handling. - * - * <p>During validation of a state task reference, the validation checks listed below are executed: - * <ol> - * <li>The state task reference key must not be a null key and must be valid, see validation in - * {@link AxReferenceKey} - * <li>The output type must be defined, that is not equal to {@link AxStateTaskOutputType#UNDEFINED} - * <li>The output key must not be a null key and must be valid, see validation in - * {@link AxReferenceKey} - * </ol> - */ -public class AxStateTaskReference extends AxConcept { - private static final long serialVersionUID = 8041771382337655535L; - - private AxReferenceKey key; - private AxStateTaskOutputType outputType; - private AxReferenceKey output; - - /** - * The Default Constructor creates a state task reference with a null reference key, an - * undefined output type and a null output reference key. - */ - public AxStateTaskReference() { - this(new AxReferenceKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxStateTaskReference(final AxStateTaskReference copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a state task reference with the given reference key, an - * undefined output type and a null output reference key. - * - * @param key the key - */ - public AxStateTaskReference(final AxReferenceKey key) { - this(key, // Key - AxStateTaskOutputType.UNDEFINED, // Output type - AxReferenceKey.getNullKey()); // Output - } - - /** - * This Constructor creates a state task reference instance with a reference key composed from - * the given parent key with a local name composed by concatenating the name of the task key - * with the local name of the output. The output type and output are set to the given values. - * - * @param parentKey the parent key to use for the key of the state task reference - * @param taskKey the task key to use for the first part of the state task reference local name - * @param outputType the type of output to perform when this state task reference instance is - * used - * @param output the output to perform when this state task reference instance is used - */ - public AxStateTaskReference(final AxReferenceKey parentKey, final AxArtifactKey taskKey, - final AxStateTaskOutputType outputType, final AxReferenceKey output) { - this(new AxReferenceKey(parentKey, taskKey.getName() + '_' + outputType.name() + '_' + output.getLocalName()), - outputType, output); - } - - /** - * This Constructor creates a state task reference instance with the given reference key and all - * its fields defined. - * - * @param key the key of the state task reference - * @param outputType the type of output to perform when this state task reference instance is - * used - * @param output the output to perform when this state task reference instance is used - */ - public AxStateTaskReference(final AxReferenceKey key, final AxStateTaskOutputType outputType, - final AxReferenceKey output) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(outputType, "outputType may not be null"); - Assertions.argumentNotNull(output, "output may not be null"); - - this.key = key; - this.outputType = outputType; - this.output = output; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - - if (!output.equals(AxReferenceKey.getNullKey())) { - keyList.add(new AxKeyUse(output)); - } - - return keyList; - } - - /** - * Sets the key of the state task reference. - * - * @param key the key of the state task reference - */ - public void setKey(final AxReferenceKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the type of output to perform when this state task reference instance is used. - * - * @return the the type of output to perform when this state task reference instance is used - */ - public AxStateTaskOutputType getStateTaskOutputType() { - return outputType; - } - - /** - * Sets the type of output to perform when this state task reference instance is used. - * - * @param stateTaskOutputType the type of output to perform when this state task reference - * instance is used - */ - public void setStateTaskOutputType(final AxStateTaskOutputType stateTaskOutputType) { - Assertions.argumentNotNull(stateTaskOutputType, "outputType may not be null"); - this.outputType = stateTaskOutputType; - } - - /** - * Gets the output to perform when this state task reference instance is used. - * - * @return the output to perform when this state task reference instance is used - */ - public AxReferenceKey getOutput() { - return output; - } - - /** - * Sets the output to perform when this state task reference instance is used. - * - * @param output the output to perform when this state task reference instance is used - */ - public void setOutput(final AxReferenceKey output) { - Assertions.argumentNotNull(output, "output may not be null"); - this.output = output; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (outputType == AxStateTaskOutputType.UNDEFINED) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "outputType may not be UNDEFINED")); - } - - if (output.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "output key " + output.getId() + " is a null key")); - } - result = output.validate(result); - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - output.clean(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("stateKey="); - builder.append(key); - builder.append(",outputType="); - builder.append(outputType); - builder.append(",output="); - builder.append(output); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxStateTaskReference.class); - - final AxStateTaskReference copy = ((AxStateTaskReference) copyObject); - copy.setKey(new AxReferenceKey(key)); - copy.setStateTaskOutputType(AxStateTaskOutputType.valueOf(outputType.name())); - copy.setOutput(output); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + outputType.hashCode(); - result = prime * result + output.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxStateTaskReference other = (AxStateTaskReference) obj; - if (!key.equals(other.key)) { - return false; - } - if (outputType != other.outputType) { - return false; - } - return output.equals(other.output); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxStateTaskReference other = (AxStateTaskReference) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!outputType.equals(other.outputType)) { - return outputType.compareTo(other.outputType); - } - return output.compareTo(other.output); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTree.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTree.java deleted file mode 100644 index a27e1af1e..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTree.java +++ /dev/null @@ -1,173 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import lombok.EqualsAndHashCode; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * The Class is used to return the tree that represents the state branches or chains in a policy. It - * creates a tree that holds the state fan out branches in a policy that starts from the given top - * state of the tree. Each branch from a state is held in a set of next states for the top state and - * each branch in the state tree is itself a {@link AxStateTree} instance. - * - * <p>Validation checks for recursive state use, in other words validation forbids the use of a given - * state more than once in a state tree. - */ -@EqualsAndHashCode -public class AxStateTree implements Comparable<AxStateTree> { - private final AxState thisState; - private final Set<AxStateTree> nextStates; - - /** - * This constructor recursively creates a state tree for the given policy starting at the given - * state. - * - * @param policy the policy from which to read states - * @param thisState the state to start state tree construction at - * @param referencedStateNameSet a set of state names already referenced in the tree, null for - * the first recursive call - */ - public AxStateTree(final AxPolicy policy, final AxState thisState, Set<AxReferenceKey> referencedStateNameSet) { - Assertions.argumentNotNull(policy, "policy may not be null"); - Assertions.argumentNotNull(thisState, "thisState may not be null"); - - this.thisState = thisState; - nextStates = new TreeSet<>(); - - for (final AxStateOutput stateOutput : thisState.getStateOutputs().values()) { - final AxState nextState = policy.getStateMap().get(stateOutput.getNextState().getLocalName()); - - // Check for end of state branch - if (stateOutput.getNextState().equals(AxReferenceKey.getNullKey())) { - continue; - } - - if (referencedStateNameSet == null) { - referencedStateNameSet = new LinkedHashSet<>(); - referencedStateNameSet.add(thisState.getKey()); - } - - // Check for state tree loops - if (referencedStateNameSet.contains(nextState.getKey())) { - throw new PolicyRuntimeException("loop detected in state tree for policy " + policy.getId() + " state " - + thisState.getKey().getLocalName() + ", next state " + nextState.getKey().getLocalName() - + " referenced more than once"); - } - referencedStateNameSet.add(stateOutput.getNextState()); - nextStates.add(new AxStateTree(policy, nextState, referencedStateNameSet)); - } - } - - /** - * Gets the state for this state tree node. - * - * @return the state - */ - public AxState getState() { - return thisState; - } - - /** - * Gets the next states for this state tree node. - * - * @return the next states - */ - public Set<AxStateTree> getNextStates() { - return nextStates; - } - - /** - * Gets the list of states referenced by this state tree as a list. - * - * @return the list of states referenced - */ - public List<AxState> getReferencedStateList() { - final List<AxState> referencedStateList = new ArrayList<>(); - - referencedStateList.add(thisState); - for (final AxStateTree nextStateTree : nextStates) { - referencedStateList.addAll(nextStateTree.getReferencedStateList()); - } - - return referencedStateList; - } - - /** - * Gets the list of states referenced by this state tree as a set. - * - * @return the set of states referenced - */ - public Set<AxState> getReferencedStateSet() { - final Set<AxState> referencedStateSet = new TreeSet<>(); - - referencedStateSet.add(thisState); - for (final AxStateTree nextStateTree : nextStates) { - referencedStateSet.addAll(nextStateTree.getReferencedStateSet()); - } - - return referencedStateSet; - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxStateTree otherObj) { - Assertions.argumentNotNull(otherObj, "comparison object may not be null"); - - if (this == otherObj) { - return 0; - } - - final AxStateTree other = otherObj; - int result = thisState.compareTo(other.thisState); - if (result != 0) { - return result; - } - - result = Integer.compare(nextStates.size(), other.nextStates.size()); - if (result != 0) { - return result; - } - - Iterator<AxStateTree> iter1 = nextStates.iterator(); - Iterator<AxStateTree> iter2 = other.nextStates.iterator(); - - while (iter1.hasNext()) { - result = iter1.next().compareTo(iter2.next()); - if (result != 0) { - return result; - } - } - - return 0; - } -} 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 deleted file mode 100644 index c8b6baf4b..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java +++ /dev/null @@ -1,405 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2022 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * ================================================================================ - * 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 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 lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -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.AxKeyUse; -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.eventmodel.concepts.AxEvent; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * This class holds the definition of a task in Apex. A task is executed by a state and performs - * some domain specific logic to carry out work required to be done by a policy. The Task Logic that - * is executed by a task is held in a {@link AxTaskLogic} instance. - * - * <p>A task has a set of input fields and output fields, which are passed to and are emitted from the - * task during a task execution cycle. A task may have task parameters {@link AxTaskParameter}, - * which are configuration values passed to a task at initialization time. - * - * <p>The Task Logic in a task may use information in context albums to perform their domain specific - * work. The context albums that the task uses and that should be made available to the task by Apex - * policy distribution are held as a set of references to context albums in the task. - * - * <p>During validation of a task, the validation checks listed below are executed: - * <ol> - * <li>The task key must not be a null key and must be valid, see validation in - * {@link AxArtifactKey} - * <li>The parent of each task parameter of a task must be that task - * <li>Each task parameter must be valid, see validation in {@link AxTaskParameter} - * <li>The parent of the task logic in a task must be that task - * <li>The task logic must be valid, see validation in {@link AxTaskLogic} - * </ol> - */ -@Getter -@Setter -public class AxTask extends AxConcept { - private static final String DOES_NOT_EQUAL_TASK_KEY = " does not equal task key"; - - private static final long serialVersionUID = 5374237330697362762L; - - @NonNull - private AxArtifactKey key; - - private AxEvent inputEvent; - private Map<String, AxEvent> outputEvents; - private Map<String, AxTaskParameter> taskParameters; - - @SerializedName("contextAlbumReference") - @NonNull - private Set<AxArtifactKey> contextAlbumReferenceSet; - - @NonNull - private AxTaskLogic taskLogic; - - /** - * The Default Constructor creates a task with a null key no input or output fields, no task - * parameters, no context album references and no logic. - */ - public AxTask() { - this(new AxArtifactKey()); - contextAlbumReferenceSet = new TreeSet<>(); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxTask(final AxTask copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a task with the given key no input or output fields, no task - * parameters, no context album references and no logic. - * - * @param key the key of the task - */ - public AxTask(final AxArtifactKey key) { - this(key, // Task Key - new TreeMap<>(), // Task Parameters - new TreeSet<>(), // Context Album References - new AxTaskLogic(new AxReferenceKey(key)) // Task Logic - ); - } - - /** - * This Constructor defines all the fields of the task. - * - * @param key the key of the task - * @param taskParameters the task parameters that are used to initialize tasks of this type - * @param contextAlbumReferenceSet the context album reference set defines the context that may - * be used by Task Logic in the state - * @param taskLogic the task logic that performs the domain specific work of the task - */ - public AxTask(final AxArtifactKey key, final Map<String, AxTaskParameter> taskParameters, - final Set<AxArtifactKey> contextAlbumReferenceSet, final AxTaskLogic taskLogic) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(taskParameters, "taskParameters may not be null"); - Assertions.argumentNotNull(contextAlbumReferenceSet, "contextAlbumReferenceSet may not be null"); - Assertions.argumentNotNull(taskLogic, "taskLogic may not be null"); - - this.key = key; - this.taskParameters = taskParameters; - this.contextAlbumReferenceSet = contextAlbumReferenceSet; - this.taskLogic = taskLogic; - } - - /** - * 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. - */ - @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)); - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - for (final AxTaskParameter taskParameter : taskParameters.values()) { - keyList.addAll(taskParameter.getKeys()); - } - for (final AxArtifactKey contextAlbumKey : contextAlbumReferenceSet) { - keyList.add(new AxKeyUse(contextAlbumKey)); - } - keyList.addAll(taskLogic.getKeys()); - return keyList; - } - - /** - * Gets the context album reference set defines the context that may be used by Task Logic in - * the state. - * - * @return the context album reference set defines the context that may be used by Task Logic in - * the state - */ - public Set<AxArtifactKey> getContextAlbumReferences() { - return contextAlbumReferenceSet; - } - - /** - * Sets the context album reference set defines the context that may be used by Task Logic in - * the state. - * - * @param contextAlbumReferences the context album reference set defines the context that may be - * used by Task Logic in the state - */ - public void setContextAlbumReferences(final Set<AxArtifactKey> contextAlbumReferences) { - Assertions.argumentNotNull(contextAlbumReferences, "contextAlbumReferences may not be null"); - this.contextAlbumReferenceSet = contextAlbumReferences; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - for (final Entry<String, AxTaskParameter> taskParameterEntry : taskParameters.entrySet()) { - result = validateTaskParameterEntry(taskParameterEntry, result); - } - - for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) { - result = validateContextAlbumReference(contextAlbumReference, result); - } - - if (!taskLogic.getKey().getParentArtifactKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "taskLogic parent key " + taskLogic.getKey().getId() + DOES_NOT_EQUAL_TASK_KEY)); - } - - return taskLogic.validate(result); - } - - /** - * Validate a task parameter entry. - * - * @param taskParameterEntry the task parameter entry to validate - * @param result The validation result to append to - * @return The result of the validation - */ - private AxValidationResult validateTaskParameterEntry(final Entry<String, AxTaskParameter> taskParameterEntry, - AxValidationResult result) { - if (taskParameterEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "null input task parameter value found on task parameter " + taskParameterEntry.getKey())); - } else { - if (!taskParameterEntry.getValue().getKey().getParentArtifactKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent key on task parameter " + taskParameterEntry.getKey() + DOES_NOT_EQUAL_TASK_KEY)); - } - - result = taskParameterEntry.getValue().validate(result); - } - - return result; - } - - /** - * Validate a context album reference entry. - * - * @param contextAlbumReference the context album reference entry to validate - * @param result The validation result to append to - * @return The result of the validation - */ - private AxValidationResult validateContextAlbumReference(final AxArtifactKey contextAlbumReference, - AxValidationResult result) { - if (contextAlbumReference.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on context item reference entry " + contextAlbumReference.getKey() - + " may not be the null key")); - } - - return contextAlbumReference.validate(result); - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - for (final AxTaskParameter parameter : taskParameters.values()) { - parameter.clean(); - } - for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) { - contextAlbumReference.clean(); - } - taskLogic.clean(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",taskParameters="); - builder.append(taskParameters); - builder.append(",contextAlbumReferenceSet="); - builder.append(contextAlbumReferenceSet); - builder.append(",taskLogic="); - builder.append(taskLogic); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxTask.class); - - final AxTask copy = ((AxTask) copyObject); - copy.setKey(key); - - final Map<String, AxTaskParameter> newTaskParameter = new TreeMap<>(); - for (final Entry<String, AxTaskParameter> taskParameterEntry : taskParameters.entrySet()) { - newTaskParameter.put(taskParameterEntry.getKey(), new AxTaskParameter(taskParameterEntry.getValue())); - } - copy.setTaskParameters(newTaskParameter); - - final Set<AxArtifactKey> newContextUsage = new TreeSet<>(); - for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) { - newContextUsage.add(new AxArtifactKey(contextAlbumReference)); - } - copy.setContextAlbumReferences(newContextUsage); - - copy.setTaskLogic(new AxTaskLogic(taskLogic)); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + taskParameters.hashCode(); - result = prime * result + contextAlbumReferenceSet.hashCode(); - result = prime * result + taskLogic.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxTask other = (AxTask) obj; - if (!key.equals(other.key)) { - return false; - } - if (!taskParameters.equals(other.taskParameters)) { - return false; - } - if (!contextAlbumReferenceSet.equals(other.contextAlbumReferenceSet)) { - return false; - } - return taskLogic.equals(other.taskLogic); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxTask other = (AxTask) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!taskParameters.equals(other.taskParameters)) { - return (taskParameters.hashCode() - other.taskParameters.hashCode()); - } - if (!contextAlbumReferenceSet.equals(other.contextAlbumReferenceSet)) { - return (contextAlbumReferenceSet.hashCode() - other.contextAlbumReferenceSet.hashCode()); - } - return taskLogic.compareTo(other.taskLogic); - } -} 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 deleted file mode 100644 index 8665d9e3e..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * ============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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -/** - * This class holds Task Logic for {@link AxTask} tasks in Apex. It is a specialization of the - * {@link AxLogic} class, so that Task Logic in Apex states can be strongly typed. - * - * <p>Task Logic is used to execute tasks {@link AxTask} in Apex. The logic uses fields on the incoming - * trigger event and information from the context albums available on a task to get context during - * execution. The task logic populates the output fields of the task. - * - * <p>Validation uses standard Apex Logic validation, see validation in {@link AxLogic}. - */ -public class AxTaskLogic extends AxLogic { - private static final long serialVersionUID = 2090324845463750391L; - - /** - * The Default Constructor creates a logic instance with a null key, undefined logic flavour and - * a null logic string. - */ - public AxTaskLogic() { - super(); - } - - /** - * The Key Constructor creates a logic instance with the given reference key, undefined logic - * flavour and a null logic string. - * - * @param key the reference key of the logic - */ - public AxTaskLogic(final AxReferenceKey key) { - super(key, LOGIC_FLAVOUR_UNDEFINED, ""); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents - * key and the logic local name and all of its fields defined. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxTaskLogic(final AxArtifactKey parentKey, final String logicName, final String logicFlavour, - final String logic) { - super(new AxReferenceKey(parentKey, logicName), logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance with the given reference key and all of its fields - * defined. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxTaskLogic(final AxReferenceKey key, final String logicFlavour, final String logic) { - super(key, logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance by cloning the fields from another logic instance - * into this logic instance. - * - * @param logic the logic instance to clone from - */ - public AxTaskLogic(final AxLogic logic) { - super(new AxReferenceKey(logic.getKey()), logic.getLogicFlavour(), logic.getLogic()); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents - * key and the logic local name, the given logic flavour, with the logic being provided by the - * given logic reader instance. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxTaskLogic(final AxArtifactKey parentKey, final String logicName, final String logicFlavour, - final AxLogicReader logicReader) { - super(new AxReferenceKey(parentKey, logicName), logicFlavour, logicReader); - } - - /** - * This Constructor creates a logic instance with the given reference key and logic flavour, the - * logic is provided by the given logic reader instance. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxTaskLogic(final AxReferenceKey key, final String logicFlavour, final AxLogicReader logicReader) { - super(key, logicFlavour, logicReader); - } -} 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 deleted file mode 100644 index a468ec499..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java +++ /dev/null @@ -1,253 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,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 java.util.List; -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.common.utils.validation.Assertions; - -/** - * This class is used to specify the configuration parameters that may be passed to a task - * {@link AxTask}. Task parameters are read from a configuration file when Apex starts and are - * passed to the task by the Apex engine when a task is executed. Each task parameter has a key and - * a default value. If the task parameter is not set in a configuration file, the task uses its - * default value. - */ -public class AxTaskParameter extends AxConcept { - private static final long serialVersionUID = 7351688156934099977L; - - private AxReferenceKey key; - private String defaultValue; - - /** - * The Default Constructor creates a task parameter with a null reference key and a null default - * value. - */ - public AxTaskParameter() { - this(new AxReferenceKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxTaskParameter(final AxTaskParameter copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a task parameter with the given reference key and a null - * default value. - * - * @param taskParameterKey the task parameter key - */ - public AxTaskParameter(final AxReferenceKey taskParameterKey) { - this(taskParameterKey, ""); - } - - /** - * The Default Constructor creates a task parameter with the given reference key and default - * value. - * - * @param key the reference key of the task parameter - * @param defaultValue the default value of the task parameter - */ - public AxTaskParameter(final AxReferenceKey key, final String defaultValue) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(defaultValue, "defaultValue may not be null"); - - this.key = key; - this.defaultValue = defaultValue.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - return key.getKeys(); - } - - /** - * Sets the reference key of the task parameter. - * - * @param key the reference key of the task parameter - */ - public void setKey(final AxReferenceKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the default value of the task parameter. - * - * @return the default value of the task parameter - */ - public String getTaskParameterValue() { - return defaultValue; - } - - /** - * Sets the default value of the task parameter. - * - * @param defaultValue the default value of the task parameter - */ - public void setDefaultValue(final String defaultValue) { - Assertions.argumentNotNull(defaultValue, "defaultValue may not be null"); - this.defaultValue = defaultValue.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxReferenceKey.getNullKey())) { - result.addValidationMessage( - new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (defaultValue.trim().length() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING, - "no defaultValue specified, defaultValue is blank")); - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - defaultValue = defaultValue.trim(); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",defaultValue="); - builder.append(defaultValue); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxTaskParameter.class); - - final AxTaskParameter copy = ((AxTaskParameter) copyObject); - copy.setKey(new AxReferenceKey(key)); - copy.setDefaultValue(defaultValue); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + defaultValue.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - - final AxTaskParameter other = (AxTaskParameter) obj; - if (!key.equals(other.key)) { - return false; - } - return defaultValue.equals(other.defaultValue); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxTaskParameter other = (AxTaskParameter) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - return defaultValue.compareTo(other.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 deleted file mode 100644 index b9cfd802d..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============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 org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -/** - * This class holds Task Selection Logic for {@link AxState} states in Apex. It is a specialization - * of the {@link AxLogic} class, so that Task Selection Logic in Apex states can be strongly typed. - * - * <p>Task Selection Logic is used to select the task {@link AxTask} that a state will execute. The - * logic uses fields on the incoming trigger event and information from the context albums available - * on a state to decide what task {@link AxTask} to select for execution in a given context. - * - * <p>Validation uses standard Apex Logic validation, see validation in {@link AxLogic}. - */ -public class AxTaskSelectionLogic extends AxLogic { - private static final long serialVersionUID = 2090324845463750391L; - - /** - * The Default Constructor creates a logic instance with a null key, undefined logic flavour and - * a null logic string. - */ - public AxTaskSelectionLogic() { - super(); - } - - /** - * The Key Constructor creates a logic instance with the given reference key, undefined logic - * flavour and a null logic string. - * - * @param key the reference key of the logic - */ - public AxTaskSelectionLogic(final AxReferenceKey key) { - super(key, LOGIC_FLAVOUR_UNDEFINED, ""); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents - * key and the logic local name and all of its fields defined. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxTaskSelectionLogic(final AxReferenceKey parentKey, final String logicName, final String logicFlavour, - final String logic) { - super(parentKey, logicName, logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance with the given reference key and all of its fields - * defined. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logic the actual logic as a string - */ - public AxTaskSelectionLogic(final AxReferenceKey key, final String logicFlavour, final String logic) { - super(key, logicFlavour, logic); - } - - /** - * This Constructor creates a logic instance by cloning the fields from another logic instance - * into this logic instance. - * - * @param logic the logic instance to clone from - */ - public AxTaskSelectionLogic(final AxLogic logic) { - super(new AxReferenceKey(logic.getKey()), logic.getLogicFlavour(), logic.getLogic()); - } - - /** - * This Constructor creates a logic instance with a reference key constructed from the parents - * key and the logic local name, the given logic flavour, with the logic being provided by the - * given logic reader instance. - * - * @param parentKey the reference key of the parent of this logic - * @param logicName the logic name, held as the local name of the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxTaskSelectionLogic(final AxReferenceKey parentKey, final String logicName, final String logicFlavour, - final AxLogicReader logicReader) { - super(new AxReferenceKey(parentKey, logicName), logicFlavour, logicReader); - } - - /** - * This Constructor creates a logic instance with the given reference key and logic flavour, the - * logic is provided by the given logic reader instance. - * - * @param key the reference key of this logic - * @param logicFlavour the flavour of this logic - * @param logicReader the logic reader to use to read the logic for this logic instance - */ - public AxTaskSelectionLogic(final AxReferenceKey key, final String logicFlavour, final AxLogicReader logicReader) { - super(key, logicFlavour, logicReader); - } -} 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 deleted file mode 100644 index f9ccafd54..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.java +++ /dev/null @@ -1,351 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,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 java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.NavigableMap; -import java.util.Set; -import java.util.TreeMap; -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; -import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetterImpl; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -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.common.utils.validation.Assertions; - -/** - * This class is a task container and holds a map of the tasks for an entire Apex model. All Apex - * models that use tasks must have an {@link AxTasks} field. The {@link AxTasks} class implements - * the helper methods of the {@link AxConceptGetter} interface to allow {@link AxTask} instances to - * be retrieved by calling methods directly on this class without referencing the contained map. - * - * <p>Validation checks that the container key is not null. An error is issued if no tasks are defined - * 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. - */ -public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> { - private static final long serialVersionUID = 4290442590545820316L; - - private AxArtifactKey key; - private Map<AxArtifactKey, AxTask> taskMap; - - /** - * The Default Constructor creates a {@link AxTasks} object with a null artifact key and creates - * an empty event map. - */ - public AxTasks() { - this(new AxArtifactKey()); - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public AxTasks(final AxTasks copyConcept) { - super(copyConcept); - } - - /** - * The Keyed Constructor creates a {@link AxTasks} object with the given artifact key and - * creates an empty event map. - * - * @param key the key - */ - public AxTasks(final AxArtifactKey key) { - this(key, new TreeMap<>()); - } - - /** - * This Constructor creates a task container with all of its fields defined. - * - * @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) { - super(); - Assertions.argumentNotNull(key, "key may not be null"); - Assertions.argumentNotNull(taskMap, "taskMap may not be null"); - - this.key = key; - this.taskMap = new TreeMap<>(); - this.taskMap.putAll(taskMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - - /** - * {@inheritDoc}. - */ - @Override - public List<AxKey> getKeys() { - final List<AxKey> keyList = key.getKeys(); - - for (final AxTask task : taskMap.values()) { - keyList.addAll(task.getKeys()); - } - - return keyList; - } - - /** - * {@inheritDoc}. - */ - @Override - public void buildReferences() { - taskMap.values().stream().forEach(task -> task.buildReferences()); - } - - /** - * Sets the task container key. - * - * @param key the task container key - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the tasks stored in the task container. - * - * @return the tasks stored in the task container - */ - public Map<AxArtifactKey, AxTask> getTaskMap() { - return taskMap; - } - - /** - * Sets the tasks to be stored in the task container. - * - * @param taskMap the tasks to be stored in the task container - */ - public void setTaskMap(final Map<AxArtifactKey, AxTask> taskMap) { - Assertions.argumentNotNull(taskMap, "taskMap may not be null"); - this.taskMap = new TreeMap<>(); - this.taskMap.putAll(taskMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxValidationResult validate(final AxValidationResult resultIn) { - AxValidationResult result = resultIn; - - if (key.equals(AxArtifactKey.getNullKey())) { - result.addValidationMessage( - 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")); - } 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")); - } else if (taskEntry.getValue() == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "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())); - } - - result = taskEntry.getValue().validate(result); - } - } - } - - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public void clean() { - key.clean(); - for (final Entry<AxArtifactKey, AxTask> taskEntry : taskMap.entrySet()) { - taskEntry.getKey().clean(); - taskEntry.getValue().clean(); - } - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append(this.getClass().getSimpleName()); - builder.append(":("); - builder.append("key="); - builder.append(key); - builder.append(",taskMap="); - builder.append(taskMap); - builder.append(")"); - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxConcept copyTo(final AxConcept targetObject) { - Assertions.argumentNotNull(targetObject, "target may not be null"); - - final Object copyObject = targetObject; - Assertions.instanceOf(copyObject, AxTasks.class); - - final AxTasks copy = ((AxTasks) copyObject); - copy.setKey(new AxArtifactKey(key)); - - final Map<AxArtifactKey, AxTask> newTaskMap = new TreeMap<>(); - for (final Entry<AxArtifactKey, AxTask> taskMapEntry : taskMap.entrySet()) { - newTaskMap.put(new AxArtifactKey(taskMapEntry.getKey()), new AxTask(taskMapEntry.getValue())); - } - copy.setTaskMap(newTaskMap); - - return copy; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + key.hashCode(); - result = prime * result + taskMap.hashCode(); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - final AxTasks other = (AxTasks) obj; - if (!key.equals(other.key)) { - return false; - } - return taskMap.equals(other.taskMap); - } - - /** - * {@inheritDoc}. - */ - @Override - public int compareTo(final AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); - } - - final AxTasks other = (AxTasks) otherObj; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (!taskMap.equals(other.taskMap)) { - return (taskMap.hashCode() - other.taskMap.hashCode()); - } - - return 0; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxTask get(final AxArtifactKey conceptKey) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKey); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxTask get(final String conceptKeyName) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKeyName); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxTask get(final String conceptKeyName, final String conceptKeyVersion) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKeyName, - conceptKeyVersion); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<AxTask> getAll(final String conceptKeyName) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).getAll(conceptKeyName); - } - - /** - * {@inheritDoc}. - */ - @Override - public Set<AxTask> getAll(final String conceptKeyName, final String conceptKeyVersion) { - return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).getAll(conceptKeyName, - conceptKeyVersion); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyException.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyException.java deleted file mode 100644 index 271e0c2af..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyException.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 org.onap.policy.apex.model.basicmodel.concepts.ApexException; - -/** - * This exception is raised if an error occurs in an Apex policy or in Apex policy handling. - * - * @author Liam Fallon - */ -public class PolicyException extends ApexException { - private static final long serialVersionUID = -8507246953751956974L; - - /** - * Instantiates a new apex policy exception with a message. - * - * @param message the message - */ - public PolicyException(final String message) { - super(message); - } - - /** - * Instantiates a new apex policy exception with a message and a caused by exception. - * - * @param message the message - * @param exception the exception that caused this exception to be thrown - */ - public PolicyException(final String message, final Exception exception) { - super(message, exception); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyRuntimeException.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyRuntimeException.java deleted file mode 100644 index 7ad293187..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyRuntimeException.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; - -/** - * This exception is raised if a runtime error occurs in an Apex policy or in Apex policy handling. - * - * @author Liam Fallon - */ -public class PolicyRuntimeException extends ApexRuntimeException { - private static final long serialVersionUID = -8507246953751956974L; - - /** - * Instantiates a new apex policy runtime exception with a message. - * - * @param message the message - */ - public PolicyRuntimeException(final String message) { - super(message); - } - - /** - * Instantiates a new apex policy runtime exception with a message and a caused by exception. - * - * @param message the message - * @param exception the exception that caused this exception to be thrown - */ - public PolicyRuntimeException(final String message, final Exception exception) { - super(message, exception); - } -} 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 deleted file mode 100644 index acf0e8221..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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========================================================= - */ - -/** - * 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) - */ -package org.onap.policy.apex.model.policymodel.concepts; diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java deleted file mode 100644 index 6731caf30..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java +++ /dev/null @@ -1,178 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * ================================================================================ - * 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 java.util.Map.Entry; -import java.util.Set; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; -import org.onap.policy.apex.model.eventmodel.concepts.AxField; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.policymodel.concepts.AxState; -import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; -import org.onap.policy.apex.model.policymodel.concepts.AxTask; -import org.onap.policy.common.utils.validation.Assertions; - -/** - * This class analyses a policy model and shows what the usage of each context album, context item, data type, and event - * is. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class PolicyAnalyser { - /** - * Perform an analysis on a policy model. - * - * @param policyModel The policy model - * @return the analysis result of the policy model - */ - public PolicyAnalysisResult analyse(final AxPolicyModel policyModel) { - Assertions.argumentNotNull(policyModel, "policyModel may not be null"); - - final PolicyAnalysisResult result = new PolicyAnalysisResult(policyModel); - - for (final AxPolicy policy : policyModel.getPolicies().getPolicyMap().values()) { - for (final AxState state : policy.getStateMap().values()) { - analyseState(state, result); - } - } - - for (final AxTask task : policyModel.getTasks().getTaskMap().values()) { - analyseTask(task, result); - } - - for (final AxEvent event : policyModel.getEvents().getEventMap().values()) { - analyseEvent(event, result); - } - - for (final AxContextAlbum contextAlbum : policyModel.getAlbums().getAll(null)) { - result.getContextSchemaUsage().get(contextAlbum.getItemSchema()).add(contextAlbum.getKey()); - } - - return result; - } - - /** - * Perform an analysis on a single policy in a policy model. - * - * @param policyModel The policy model - * @param policy The policy - * @return the analysis result of the policy model - */ - public PolicyAnalysisResult analyse(final AxPolicyModel policyModel, final AxPolicy policy) { - Assertions.argumentNotNull(policyModel, "policyModel may not be null"); - Assertions.argumentNotNull(policy, "policy may not be null"); - - final PolicyAnalysisResult result = new PolicyAnalysisResult(policyModel); - - for (final AxState state : policy.getStateMap().values()) { - analyseState(state, result); - } - - // Only analyse tasks used by this policy - for (final Entry<AxArtifactKey, Set<AxKey>> taskUsageEntry : result.getTaskUsage().entrySet()) { - // If the usage set is empty, then we skip the task as its not used in the policy - if (!taskUsageEntry.getValue().isEmpty()) { - analyseTask(policyModel.getTasks().getTaskMap().get(taskUsageEntry.getKey()), result); - } - } - - // Only analyse events used by this policy, same approach as for tasks - for (final Entry<AxArtifactKey, Set<AxKey>> eventUsageEntry : result.getEventUsage().entrySet()) { - if (!eventUsageEntry.getValue().isEmpty()) { - analyseEvent(policyModel.getEvents().getEventMap().get(eventUsageEntry.getKey()), result); - } - } - - // Only analyse context albums used by this policy, same approach as for tasks - for (final Entry<AxArtifactKey, Set<AxKey>> contextAlbumUsageEntry : result.getContextAlbumUsage().entrySet()) { - if (!contextAlbumUsageEntry.getValue().isEmpty()) { - final AxContextAlbum contextAlbum = policyModel.getAlbums().get(contextAlbumUsageEntry.getKey()); - result.getContextSchemaUsage().get(contextAlbum.getItemSchema()).add(contextAlbum.getKey()); - } - } - - for (final AxEvent event : policyModel.getEvents().getEventMap().values()) { - analyseEvent(event, result); - } - - for (final AxContextAlbum contextAlbum : policyModel.getAlbums().getAll(null)) { - result.getContextSchemaUsage().get(contextAlbum.getItemSchema()).add(contextAlbum.getKey()); - } - - return result; - } - - /** - * Analyse the usage of concepts by a state. - * - * @param state the state to analyse - * @param result the result - */ - private void analyseState(final AxState state, final PolicyAnalysisResult result) { - // Event usage by state - result.getEventUsage().get(state.getTrigger()).add(state.getKey()); - for (final AxStateOutput stateOutput : state.getStateOutputs().values()) { - result.getEventUsage().get(stateOutput.getOutgoingEvent()).add(state.getKey()); - } - - // State Context Usage - for (final AxArtifactKey contextAlbumKey : state.getContextAlbumReferences()) { - result.getContextAlbumUsage().get(contextAlbumKey).add(state.getKey()); - } - - // Task usage by state - for (final AxArtifactKey task : state.getTaskReferences().keySet()) { - result.getTaskUsage().get(task).add(state.getKey()); - } - } - - /** - * Analyse the usage of concepts by a task. - * - * @param task the task to analyse - * @param result the result - */ - private void analyseTask(final AxTask task, final PolicyAnalysisResult result) { - // Task Context Usage - for (final AxArtifactKey contextAlbumKey : task.getContextAlbumReferences()) { - result.getContextAlbumUsage().get(contextAlbumKey).add(task.getKey()); - } - } - - /** - * Analyse the usage of concepts by an event. - * - * @param event the event to analyse - * @param result the result of the analysis - */ - private void analyseEvent(final AxEvent event, final PolicyAnalysisResult result) { - // Event data type usage - for (final AxField eventField : event.getFields()) { - result.getContextSchemaUsage().get(eventField.getSchema()).add(event.getKey()); - } - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalysisResult.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalysisResult.java deleted file mode 100644 index 96bdc57d0..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalysisResult.java +++ /dev/null @@ -1,266 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 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 java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -/** - * This class finds and holds the usage of context schemas, context albums, events, and tasks by the policies in a - * policy model. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class PolicyAnalysisResult { - // Usage of context schemas - private final Map<AxArtifactKey, Set<AxKey>> contextSchemaUsage = new TreeMap<>(); - - // Usage of context maps - private final Map<AxArtifactKey, Set<AxKey>> contextAlbumUsage = new TreeMap<>(); - - // Usage of events - private final Map<AxArtifactKey, Set<AxKey>> eventUsage = new TreeMap<>(); - - // Usage of tasks - private final Map<AxArtifactKey, Set<AxKey>> taskUsage = new TreeMap<>(); - - /** - * This constructor creates a {@link PolicyAnalysisResult} instance that holds maps that contain the usage of - * context schemas, contxt albums, events, and tasks by all policies in a policy model. - * - * @param policyModel the policy model to analyse - */ - public PolicyAnalysisResult(final AxPolicyModel policyModel) { - for (final AxArtifactKey contextSchemaKey : policyModel.getSchemas().getSchemasMap().keySet()) { - contextSchemaUsage.put(contextSchemaKey, new TreeSet<>()); - } - - for (final Entry<AxArtifactKey, AxContextAlbum> contextAlbumEntry : policyModel.getAlbums().getAlbumsMap() - .entrySet()) { - contextAlbumUsage.put(contextAlbumEntry.getKey(), new TreeSet<>()); - } - - for (final AxArtifactKey eventKey : policyModel.getEvents().getEventMap().keySet()) { - eventUsage.put(eventKey, new TreeSet<>()); - } - - for (final AxArtifactKey taskKey : policyModel.getTasks().getTaskMap().keySet()) { - taskUsage.put(taskKey, new TreeSet<>()); - } - } - - /** - * Gets the context schemas used by policies in the policy model. - * - * @return the context schemas used by policies in the policy model - */ - public Map<AxArtifactKey, Set<AxKey>> getContextSchemaUsage() { - return contextSchemaUsage; - } - - /** - * Gets the context albums used by policies in the policy model. - * - * @return the context albums used by policies in the policy model - */ - public Map<AxArtifactKey, Set<AxKey>> getContextAlbumUsage() { - return contextAlbumUsage; - } - - /** - * Gets the events used by policies in the policy model. - * - * @return the events used by policies in the policy model - */ - public Map<AxArtifactKey, Set<AxKey>> getEventUsage() { - return eventUsage; - } - - /** - * Gets the tasks used by policies in the policy model. - * - * @return the tasks used by policies in the policy model - */ - public Map<AxArtifactKey, Set<AxKey>> getTaskUsage() { - return taskUsage; - } - - /** - * Gets the context schemas used by policies in the policy model. - * - * @return the context schemas used by policies in the policy model - */ - public Set<AxArtifactKey> getUsedContextSchemas() { - return getUsedKeySet(contextSchemaUsage); - } - - /** - * Gets the context albums used by policies in the policy model. - * - * @return the context albums used by policies in the policy model - */ - public Set<AxArtifactKey> getUsedContextAlbums() { - return getUsedKeySet(contextAlbumUsage); - } - - /** - * Gets the events used by policies in the policy model. - * - * @return the events used by policies in the policy model - */ - public Set<AxArtifactKey> getUsedEvents() { - return getUsedKeySet(eventUsage); - } - - /** - * Gets the tasks used by policies in the policy model. - * - * @return the tasks used by policies in the policy model - */ - public Set<AxArtifactKey> getUsedTasks() { - return getUsedKeySet(taskUsage); - } - - /** - * Gets the context schemas in the policy model that were not used by any policies in the policy model. - * - * @return the unused context schemas - */ - public Set<AxArtifactKey> getUnusedContextSchemas() { - return getUnusedKeySet(contextSchemaUsage); - } - - /** - * Gets the context albums in the policy model that were not used by any policies in the policy model. - * - * @return the unused context albums - */ - public Set<AxArtifactKey> getUnusedContextAlbums() { - return getUnusedKeySet(contextAlbumUsage); - } - - /** - * Gets the events in the policy model that were not used by any policies in the policy model. - * - * @return the unused events - */ - public Set<AxArtifactKey> getUnusedEvents() { - return getUnusedKeySet(eventUsage); - } - - /** - * Gets the tasks in the policy model that were not used by any policies in the policy model. - * - * @return the unused tasks - */ - public Set<AxArtifactKey> getUnusedTasks() { - return getUnusedKeySet(taskUsage); - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - - builder.append(getUsageMapString("Context Schema usage", contextSchemaUsage)); - builder.append(getUsageMapString("Context Album usage", contextAlbumUsage)); - builder.append(getUsageMapString("Event usage", eventUsage)); - builder.append(getUsageMapString("Task usage", taskUsage)); - - return builder.toString(); - } - - /** - * Gets the usage map string. - * - * @param header the header - * @param usageMap the usage map - * @return the usage map string - */ - private String getUsageMapString(final String header, final Map<? extends AxKey, Set<AxKey>> usageMap) { - final StringBuilder builder = new StringBuilder(); - - builder.append(header); - builder.append('\n'); - for (final Entry<? extends AxKey, Set<AxKey>> usageEntry : usageMap.entrySet()) { - builder.append(" "); - builder.append(usageEntry.getKey().getId()); - if (usageEntry.getValue().isEmpty()) { - builder.append(" (unused)\n"); - continue; - } - - builder.append('\n'); - for (final AxKey usageKey : usageEntry.getValue()) { - builder.append(" "); - builder.append(usageKey.getId()); - builder.append("\n"); - } - } - return builder.toString(); - } - - /** - * Gets the used key set. - * - * @param usageMap the usage map - * @return the used key set - */ - private Set<AxArtifactKey> getUsedKeySet(final Map<AxArtifactKey, Set<AxKey>> usageMap) { - final Set<AxArtifactKey> usedKeySet = new TreeSet<>(); - - for (final Entry<AxArtifactKey, Set<AxKey>> usageEntry : usageMap.entrySet()) { - if (!usageEntry.getValue().isEmpty()) { - usedKeySet.add(usageEntry.getKey()); - } - } - - return usedKeySet; - } - - /** - * Gets the unused key set. - * - * @param usageMap the usage map - * @return the unused key set - */ - private Set<AxArtifactKey> getUnusedKeySet(final Map<AxArtifactKey, Set<AxKey>> usageMap) { - final Set<AxArtifactKey> usedKeySet = new TreeSet<>(); - - for (final Entry<AxArtifactKey, Set<AxKey>> usageEntry : usageMap.entrySet()) { - if (usageEntry.getValue().isEmpty()) { - usedKeySet.add(usageEntry.getKey()); - } - } - - return usedKeySet; - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyComparer.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyComparer.java deleted file mode 100644 index 5a947c596..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyComparer.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicies; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; - -/** - * This class compares the policies in two {@link AxPolicies} objects and returns the differences. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class PolicyComparer { - /** - * Compare two {@link AxPolicies} objects, comparing their policy maps one after another. - * - * @param left the left policies - * @param right the right policies - * @return the difference - */ - public KeyedMapDifference<AxArtifactKey, AxPolicy> compare(final AxPolicies left, final AxPolicies right) { - // Find the difference between the AxPolicy objects - return new KeyedMapComparer<AxArtifactKey, AxPolicy>().compareMaps(left.getPolicyMap(), right.getPolicyMap()); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java deleted file mode 100644 index f70068454..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 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 org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.policymodel.concepts.AxLogic; -import org.onap.policy.apex.model.policymodel.concepts.AxLogicReader; -import org.onap.policy.apex.model.policymodel.concepts.PolicyRuntimeException; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class is used to read Task Logic and Task Selection Logic from files into a string. A - * {@link PolicyLogicReader} can then be used to provide the logic on a {@link AxLogic} class - * constructor. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class PolicyLogicReader implements AxLogicReader { - private static final String DOT_JAVA = ".java."; - - private static final XLogger LOGGER = XLoggerFactory.getXLogger(PolicyModelSplitter.class); - - // The path of the logic package - private String logicPackage = ""; - - // Flag indicating if default logic should be returned - private String defaultLogic; - - /** - * {@inheritDoc}. - */ - @Override - public String getLogicPackage() { - return logicPackage; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxLogicReader setLogicPackage(final String incomingLogicPackage) { - this.logicPackage = incomingLogicPackage; - return this; - } - - /** - * {@inheritDoc}. - */ - @Override - public String getDefaultLogic() { - return defaultLogic; - } - - /** - * {@inheritDoc}. - */ - @Override - public AxLogicReader setDefaultLogic(final String incomingDefaultLogic) { - this.defaultLogic = incomingDefaultLogic; - return this; - } - - /** - * {@inheritDoc}. - */ - @Override - public String readLogic(final AxLogic axLogic) { - // Java uses compiled logic, other executor types run scripts - if ("JAVA".equals(axLogic.getLogicFlavour())) { - // Check if we're using the default logic - if (defaultLogic != null) { - // Return the java class name for the default logic - return logicPackage + DOT_JAVA + defaultLogic; - } else { - // Return the java class name for the logic - if (axLogic.getKey().getParentLocalName().equals(AxKey.NULL_KEY_NAME)) { - return logicPackage + DOT_JAVA + axLogic.getKey().getParentKeyName() - + axLogic.getKey().getLocalName(); - } else { - return logicPackage + DOT_JAVA + axLogic.getKey().getParentKeyName() - + axLogic.getKey().getParentLocalName() + axLogic.getKey().getLocalName(); - } - } - } - // Now, we read in the script - - // Get the package name of the current package and convert dots to slashes for the file path - String fullLogicFilePath = logicPackage.replace(".", "/"); - - // Now, the logic should be in a sub directory for the logic executor type - fullLogicFilePath += "/" + axLogic.getLogicFlavour().toLowerCase(); - - // Check if we're using the default logic - if (defaultLogic != null) { - // Default logic - fullLogicFilePath += "/" + defaultLogic; - } else { - if (axLogic.getKey().getParentLocalName().equals(AxKey.NULL_KEY_NAME)) { - fullLogicFilePath += "/" + axLogic.getKey().getParentKeyName() + axLogic.getKey().getLocalName(); - } else { - fullLogicFilePath += "/" + axLogic.getKey().getParentKeyName() - + axLogic.getKey().getParentLocalName() + axLogic.getKey().getLocalName(); - } - } - - // Now get the type of executor to find the extension of the file - fullLogicFilePath += "." + axLogic.getLogicFlavour().toLowerCase(); - - final String logicString = ResourceUtils.getResourceAsString(fullLogicFilePath); - - // Check if the logic was found - if (logicString == null || logicString.length() == 0) { - String errorMessage = "logic not found for logic \"" + fullLogicFilePath + "\""; - LOGGER.warn(errorMessage); - throw new PolicyRuntimeException(errorMessage); - } - - // Return the right trimmed logic string - return logicString.replaceAll("\\s+$", ""); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparer.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparer.java deleted file mode 100644 index f3bbdcbcf..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparer.java +++ /dev/null @@ -1,268 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.policymodel.concepts.AxTask; -import org.onap.policy.apex.model.utilities.comparison.KeyComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyDifference; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; - -/** - * This class compares two policy models {@link AxPolicyModel} and holds the result of that comparison. It compares - * policy models on their keys, their context schema differences, their event differences, their context album - * differences, their task differences, their policy differences, and their key information differences. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class PolicyModelComparer { - // Comparison of policy model keys - private final KeyDifference<AxArtifactKey> policyModelsKeyDifference; - - // Comparison of context schemas - private final KeyDifference<AxArtifactKey> contextSchemasKeyDifference; - private KeyedMapDifference<AxArtifactKey, AxContextSchema> contextSchemaCompareResult = new KeyedMapDifference<>(); - - // Comparison of events - private final KeyDifference<AxArtifactKey> eventsKeyDifference; - private KeyedMapDifference<AxArtifactKey, AxEvent> eventComparisonResult = new KeyedMapDifference<>(); - - // Comparison of context albums - private final KeyDifference<AxArtifactKey> contextAlbumKeyDifference; - private KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextAlbumComparisonResult = new KeyedMapDifference<>(); - - // Comparison of tasks - private final KeyDifference<AxArtifactKey> tasksKeyDifference; - private KeyedMapDifference<AxArtifactKey, AxTask> taskComparisonResult = new KeyedMapDifference<>(); - - // Comparison of policies - private final KeyDifference<AxArtifactKey> policiesKeyDifference; - private KeyedMapDifference<AxArtifactKey, AxPolicy> policyComparisonResult = new KeyedMapDifference<>(); - - // Comparison of key information - private final KeyDifference<AxArtifactKey> keyInformationKeyDifference; - private KeyedMapDifference<AxArtifactKey, AxKeyInfo> keyInfoComparisonResult = new KeyedMapDifference<>(); - - /** - * The Constructor. - * - * @param left the left - * @param right the right - */ - public PolicyModelComparer(final AxPolicyModel left, final AxPolicyModel right) { - // @formatter:off - policyModelsKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - contextSchemasKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - eventsKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - contextAlbumKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - tasksKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - policiesKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - keyInformationKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey()); - - contextSchemaCompareResult = new KeyedMapComparer<AxArtifactKey, AxContextSchema>().compareMaps( - left.getSchemas().getSchemasMap(), right.getSchemas().getSchemasMap()); - eventComparisonResult = new KeyedMapComparer<AxArtifactKey, AxEvent>().compareMaps( - left.getEvents().getEventMap(), right.getEvents().getEventMap()); - contextAlbumComparisonResult = new KeyedMapComparer<AxArtifactKey, AxContextAlbum>().compareMaps( - left.getAlbums().getAlbumsMap(), right.getAlbums().getAlbumsMap()); - taskComparisonResult = new KeyedMapComparer<AxArtifactKey, AxTask>() - .compareMaps(left.getTasks().getTaskMap(), right.getTasks().getTaskMap()); - policyComparisonResult = new KeyedMapComparer<AxArtifactKey, AxPolicy>().compareMaps( - left.getPolicies().getPolicyMap(), right.getPolicies().getPolicyMap()); - keyInfoComparisonResult = new KeyedMapComparer<AxArtifactKey, AxKeyInfo>().compareMaps( - left.getKeyInformation().getKeyInfoMap(), right.getKeyInformation().getKeyInfoMap()); - // @formatter:on - } - - /** - * Gets the difference between policy model keys on the two models. - * - * @return the difference between policy model keys - */ - public KeyDifference<AxArtifactKey> getPolicyModelsKeyDifference() { - return policyModelsKeyDifference; - } - - /** - * Gets the difference between context schema keys on the two models. - * - * @return the difference between context schema keys - */ - public KeyDifference<AxArtifactKey> getContextSchemaKeyDifference() { - return contextSchemasKeyDifference; - } - - /** - * Gets the difference between context schemas on the two models. - * - * @return the difference between context schemas - */ - public KeyedMapDifference<AxArtifactKey, AxContextSchema> getContextSchemaComparisonResult() { - return contextSchemaCompareResult; - } - - /** - * Gets the difference between event keys on the two models. - * - * @return the difference between event keys - */ - public KeyDifference<AxArtifactKey> getEventKeyDifference() { - return eventsKeyDifference; - } - - /** - * Gets the difference between the events on the two models. - * - * @return the difference between the events - */ - public KeyedMapDifference<AxArtifactKey, AxEvent> getEventComparisonResult() { - return eventComparisonResult; - } - - /** - * Gets the difference between context album keys on the two models. - * - * @return the difference between context album keys - */ - public KeyDifference<AxArtifactKey> getContextAlbumKeyDifference() { - return contextAlbumKeyDifference; - } - - /** - * Gets the difference between the context albums on the two models. - * - * @return the difference between the context albums - */ - public KeyedMapDifference<AxArtifactKey, AxContextAlbum> getContextAlbumComparisonResult() { - return contextAlbumComparisonResult; - } - - /** - * Gets the difference between task keys on the two models. - * - * @return the difference between task keys - */ - public KeyDifference<AxArtifactKey> getTaskKeyDifference() { - return tasksKeyDifference; - } - - /** - * Gets the difference between the tasks on the two models. - * - * @return the difference between the tasks - */ - public KeyedMapDifference<AxArtifactKey, AxTask> getTaskComparisonResult() { - return taskComparisonResult; - } - - /** - * Gets the difference between policy keys on the two models. - * - * @return the difference between policy keys - */ - public KeyDifference<AxArtifactKey> getPolicykeyDifference() { - return policiesKeyDifference; - } - - /** - * Gets the difference between the policies on the two models. - * - * @return the difference between the policies - */ - public KeyedMapDifference<AxArtifactKey, AxPolicy> getPolicyComparisonResult() { - return policyComparisonResult; - } - - /** - * Gets the difference between key information keys on the two models. - * - * @return the difference between key information keys - */ - public KeyDifference<AxArtifactKey> getKeyInformationKeyDifference() { - return keyInformationKeyDifference; - } - - /** - * Gets the difference between the key information on the two models. - * - * @return the difference between the key information - */ - public KeyedMapDifference<AxArtifactKey, AxKeyInfo> getKeyInfoComparisonResult() { - return keyInfoComparisonResult; - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return asString(true, true); - } - - /** - * As string. - * - * @param diffsOnly the diffs only - * @param keysOnly the keys only - * @return the string - */ - public String asString(final boolean diffsOnly, final boolean keysOnly) { - final StringBuilder builder = new StringBuilder(); - - builder.append("****** policy map differences ******\n"); - builder.append(policyModelsKeyDifference.asString(diffsOnly)); - - builder.append("*** context schema differences ***\n"); - builder.append(contextSchemasKeyDifference.asString(diffsOnly)); - builder.append(contextSchemaCompareResult.asString(diffsOnly, keysOnly)); - - builder.append("*** event differences ***\n"); - builder.append(eventsKeyDifference.asString(diffsOnly)); - builder.append(eventComparisonResult.asString(diffsOnly, keysOnly)); - - builder.append("*** context album differences ***\n"); - builder.append(contextAlbumKeyDifference.asString(diffsOnly)); - builder.append(contextAlbumComparisonResult.asString(diffsOnly, keysOnly)); - - builder.append("*** task differences ***\n"); - builder.append(tasksKeyDifference.asString(diffsOnly)); - builder.append(taskComparisonResult.asString(diffsOnly, keysOnly)); - - builder.append("*** policy differences ***\n"); - builder.append(policiesKeyDifference.asString(diffsOnly)); - builder.append(policyComparisonResult.asString(diffsOnly, keysOnly)); - - builder.append("*** key information differences ***\n"); - builder.append(keyInformationKeyDifference.asString(diffsOnly)); - builder.append(keyInfoComparisonResult.asString(diffsOnly, keysOnly)); - - builder.append("***********************************\n"); - - return builder.toString(); - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java deleted file mode 100644 index ae0dda814..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java +++ /dev/null @@ -1,183 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved. - * ================================================================================ - * 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 java.util.Map; -import java.util.Map.Entry; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.policymodel.concepts.AxTask; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * Helper class used to merge information from two policy models together into a single policy - * model. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public final class PolicyModelMerger { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(PolicyModelMerger.class); - - /** - * Private constructor used to prevent sub class instantiation. - */ - private PolicyModelMerger() { - } - - /** - * Get a merged policy model with information from two policy models merged into a larger policy - * model. - * - * @param leftPolicyModel the source Apex Model - * @param rightPolicyModel the policies to include in sub policy model - * @param useLeftOnMatches if true, uses concepts from the left model if concepts with common - * keys are found, if false it uses the concepts from the right model - * @param failOnDuplicateKeys whether to fail or not on the occurence of duplicate concept keys - * @return the new Destination Model - * @throws ApexModelException on model transfer errors - */ - public static AxPolicyModel getMergedPolicyModel(final AxPolicyModel leftPolicyModel, - final AxPolicyModel rightPolicyModel, final boolean useLeftOnMatches, final boolean failOnDuplicateKeys) - throws ApexModelException { - return getMergedPolicyModel(leftPolicyModel, rightPolicyModel, useLeftOnMatches, false, failOnDuplicateKeys); - } - - /** - * Get a merged policy model with information from two policy models merged into a larger policy - * model. - * - * @param leftPolicyModel the source Apex Model - * @param rightPolicyModel the policies to include in sub policy model - * @param useLeftOnMatches if true, uses concepts from the left model if concepts with common - * keys are found, if false it uses the concepts from the right model - * @param ignoreInvalidSource Ignore errors on the source model, do the best you can - * @param failOnDuplicateKeys whether to fail or not on the occurence of duplicate concept keys - * @return the new Destination Model - * @throws ApexModelException on model transfer errors - */ - public static AxPolicyModel getMergedPolicyModel(final AxPolicyModel leftPolicyModel, - final AxPolicyModel rightPolicyModel, final boolean useLeftOnMatches, final boolean ignoreInvalidSource, - final boolean failOnDuplicateKeys) throws ApexModelException { - - if (!ignoreInvalidSource) { - validateModels(leftPolicyModel, "left"); - validateModels(rightPolicyModel, "right"); - } - - // The new policy model uses the favoured copy side as its base - final AxPolicyModel mergedPolicyModel = - (useLeftOnMatches ? new AxPolicyModel(leftPolicyModel) : new AxPolicyModel(rightPolicyModel)); - - // The Compared to policy model is the unfavoured side - final AxPolicyModel copyFromPolicyModel = - (useLeftOnMatches ? new AxPolicyModel(rightPolicyModel) : new AxPolicyModel(leftPolicyModel)); - - Map<AxArtifactKey, AxKeyInfo> mergedKeyInfoMap = mergedPolicyModel.getKeyInformation().getKeyInfoMap(); - Map<AxArtifactKey, AxContextSchema> mergedSchemasMap = mergedPolicyModel.getSchemas().getSchemasMap(); - Map<AxArtifactKey, AxEvent> mergedEventMap = mergedPolicyModel.getEvents().getEventMap(); - Map<AxArtifactKey, AxContextAlbum> mergedAlbumsMap = mergedPolicyModel.getAlbums().getAlbumsMap(); - Map<AxArtifactKey, AxTask> mergedTaskMap = mergedPolicyModel.getTasks().getTaskMap(); - Map<AxArtifactKey, AxPolicy> mergedPolicyMap = mergedPolicyModel.getPolicies().getPolicyMap(); - - Map<AxArtifactKey, AxKeyInfo> copyOverKeyInfoMap = copyFromPolicyModel.getKeyInformation().getKeyInfoMap(); - Map<AxArtifactKey, AxContextSchema> copyOverSchemasMap = copyFromPolicyModel.getSchemas().getSchemasMap(); - Map<AxArtifactKey, AxEvent> copyOverEventMap = copyFromPolicyModel.getEvents().getEventMap(); - Map<AxArtifactKey, AxContextAlbum> copyOverAlbumsMap = copyFromPolicyModel.getAlbums().getAlbumsMap(); - Map<AxArtifactKey, AxTask> copyOverTaskMap = copyFromPolicyModel.getTasks().getTaskMap(); - Map<AxArtifactKey, AxPolicy> copyOverPolicyMap = copyFromPolicyModel.getPolicies().getPolicyMap(); - - if (failOnDuplicateKeys) { - StringBuilder errorMessage = new StringBuilder(); - checkForDuplicateItem(mergedSchemasMap, copyOverSchemasMap, errorMessage, "schema"); - checkForDuplicateItem(mergedEventMap, copyOverEventMap, errorMessage, "event"); - checkForDuplicateItem(mergedAlbumsMap, copyOverAlbumsMap, errorMessage, "album"); - checkForDuplicateItem(mergedTaskMap, copyOverTaskMap, errorMessage, "task"); - checkForDuplicateItem(mergedPolicyMap, copyOverPolicyMap, errorMessage, "policy"); - if (errorMessage.length() > 0) { - throw new ApexModelException(errorMessage.toString()); - } - } else { - // Remove entries that already exist - copyOverKeyInfoMap.keySet().removeIf(mergedKeyInfoMap::containsKey); - copyOverSchemasMap.keySet().removeIf(mergedSchemasMap::containsKey); - copyOverEventMap.keySet().removeIf(mergedEventMap::containsKey); - copyOverAlbumsMap.keySet().removeIf(mergedAlbumsMap::containsKey); - copyOverTaskMap.keySet().removeIf(mergedTaskMap::containsKey); - copyOverPolicyMap.keySet().removeIf(mergedPolicyMap::containsKey); - } - // Now add all the concepts that must be copied over - mergedKeyInfoMap.putAll(copyOverKeyInfoMap); - mergedSchemasMap.putAll(copyOverSchemasMap); - mergedEventMap.putAll(copyOverEventMap); - mergedAlbumsMap.putAll(copyOverAlbumsMap); - mergedTaskMap.putAll(copyOverTaskMap); - mergedPolicyMap.putAll(copyOverPolicyMap); - - // That's it, return the model - return mergedPolicyModel; - } - - /** - * Method to check for duplicate items. - * - * @param <V> the concept type - * @param mergedItemsMap the map to which items are copied - * @param copyOverItemsMap the map from where items are copied - * @param errorMessage error message in case of any duplicate concepts - * @param itemType the type of concept to specify distinguished error messages - */ - public static <V> void checkForDuplicateItem(Map<AxArtifactKey, V> mergedItemsMap, - Map<AxArtifactKey, V> copyOverItemsMap, StringBuilder errorMessage, String itemType) { - for (Entry<AxArtifactKey, V> entry : copyOverItemsMap.entrySet()) { - V item = mergedItemsMap.get(entry.getKey()); - // same item with different definitions cannot occur in multiple policies - if (null != item) { - if (item.equals(entry.getValue())) { - LOGGER.info("Same {} - {} is used by multiple policies.", itemType, entry.getKey().getId()); - } else { - errorMessage.append("\n Same " + itemType + " - ").append(entry.getKey().getId()) - .append(" with different definitions used in different policies"); - } - } - } - } - - private static void validateModels(AxPolicyModel policyModel, String position) throws ApexModelException { - // Validate the model - final AxValidationResult validationResult = new AxValidationResult(); - policyModel.validate(validationResult); - if (!validationResult.isValid()) { - String message = position + " model is invalid: " + validationResult.toString(); - LOGGER.warn(message); - throw new ApexModelException(message); - } - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java deleted file mode 100644 index 1f1c27a83..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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 java.util.Collection; -import java.util.Set; -import java.util.TreeSet; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * Helper class used to extract information from a policy model into a policy model that is a subset of the original - * policy model. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public final class PolicyModelSplitter { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(PolicyModelSplitter.class); - - /** - * Private constructor used to prevent sub class instantiation. - */ - private PolicyModelSplitter() { - // Private constructor to block subclassing - } - - /** - * Get a sub policy model with only the information required for the specified policies from a larger policy model. - * - * @param sourcePolicyModel the source Apex Model - * @param subPolicies the policies to include in sub policy model - * @return the new Destination Model - * @throws ApexModelException on model transfer errors - */ - public static AxPolicyModel getSubPolicyModel(final AxPolicyModel sourcePolicyModel, - final Collection<AxArtifactKey> subPolicies) throws ApexModelException { - return getSubPolicyModel(sourcePolicyModel, subPolicies, false); - } - - /** - * Get a sub policy model with only the information required for the specified policies from a larger policy model. - * - * @param sourcePolicyModel the source Apex Model - * @param subPolicies the policies to include in sub policy model - * @param ignoreInvalidSource Ignore errors on the source model, do the best you can - * @return the new Destination Model - * @throws ApexModelException on model transfer errors - */ - public static AxPolicyModel getSubPolicyModel(final AxPolicyModel sourcePolicyModel, - final Collection<AxArtifactKey> subPolicies, final boolean ignoreInvalidSource) throws ApexModelException { - // Validate the source model - if (!ignoreInvalidSource) { - final AxValidationResult sourceValidationResult = new AxValidationResult(); - sourcePolicyModel.validate(sourceValidationResult); - if (!sourceValidationResult.isValid()) { - String message = "source model is invalid: " + sourceValidationResult.toString(); - LOGGER.warn(message); - throw new ApexModelException(message); - } - } - - // The new policy model - final AxPolicyModel newPolicyModel = new AxPolicyModel(sourcePolicyModel.getKey()); - newPolicyModel.getKeyInformation().setKey(sourcePolicyModel.getKeyInformation().getKey()); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(sourcePolicyModel.getKey())); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getKeyInformation().getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap() - .get(sourcePolicyModel.getKeyInformation().getKey())); - - // Get the events, tasks, context maps, and data types used by each policy - final Set<AxArtifactKey> contextSchemaSet = new TreeSet<>(); - final Set<AxArtifactKey> eventSet = new TreeSet<>(); - final Set<AxArtifactKey> contextAlbumSet = new TreeSet<>(); - final Set<AxArtifactKey> taskSet = new TreeSet<>(); - - newPolicyModel.getPolicies().setKey(sourcePolicyModel.getPolicies().getKey()); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getPolicies().getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(sourcePolicyModel.getPolicies().getKey())); - for (final AxArtifactKey subPolicyKey : subPolicies) { - final AxPolicy subPolicy = sourcePolicyModel.getPolicies().getPolicyMap().get(subPolicyKey); - if (subPolicy == null) { - LOGGER.warn("source sub policy not found: {}", subPolicyKey); - continue; - } - - // Transfer the policy across - newPolicyModel.getPolicies().getPolicyMap().put(subPolicyKey, subPolicy); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(subPolicyKey, - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(subPolicyKey)); - - // Get the references for this policy - final PolicyAnalysisResult analysisResult = new PolicyAnalyser().analyse(sourcePolicyModel, subPolicy); - contextSchemaSet.addAll(analysisResult.getUsedContextSchemas()); - eventSet.addAll(analysisResult.getUsedEvents()); - contextAlbumSet.addAll(analysisResult.getUsedContextAlbums()); - taskSet.addAll(analysisResult.getUsedTasks()); - - } - - // Now add all the referenced data types, events, context maps, and tasks to the policy - // model - newPolicyModel.getSchemas().setKey(sourcePolicyModel.getSchemas().getKey()); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getSchemas().getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(sourcePolicyModel.getSchemas().getKey())); - for (final AxArtifactKey contextSchemaKey : contextSchemaSet) { - newPolicyModel.getSchemas().getSchemasMap().put(contextSchemaKey, - sourcePolicyModel.getSchemas().getSchemasMap().get(contextSchemaKey)); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(contextSchemaKey, - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(contextSchemaKey)); - } - newPolicyModel.getEvents().setKey(sourcePolicyModel.getEvents().getKey()); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getEvents().getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(sourcePolicyModel.getEvents().getKey())); - for (final AxArtifactKey eventKey : eventSet) { - newPolicyModel.getEvents().getEventMap().put(eventKey, - sourcePolicyModel.getEvents().getEventMap().get(eventKey)); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(eventKey, - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(eventKey)); - } - newPolicyModel.getAlbums().setKey(sourcePolicyModel.getAlbums().getKey()); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getAlbums().getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(sourcePolicyModel.getAlbums().getKey())); - for (final AxArtifactKey contextAlbumKey : contextAlbumSet) { - newPolicyModel.getAlbums().getAlbumsMap().put(contextAlbumKey, - sourcePolicyModel.getAlbums().getAlbumsMap().get(contextAlbumKey)); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(contextAlbumKey, - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(contextAlbumKey)); - } - newPolicyModel.getTasks().setKey(sourcePolicyModel.getTasks().getKey()); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(sourcePolicyModel.getTasks().getKey(), - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(sourcePolicyModel.getTasks().getKey())); - for (final AxArtifactKey taskKey : taskSet) { - newPolicyModel.getTasks().getTaskMap().put(taskKey, sourcePolicyModel.getTasks().getTaskMap().get(taskKey)); - newPolicyModel.getKeyInformation().getKeyInfoMap().put(taskKey, - sourcePolicyModel.getKeyInformation().getKeyInfoMap().get(taskKey)); - } - - // That's it, return the model - return newPolicyModel; - } -} diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/package-info.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/package-info.java deleted file mode 100644 index f84befd26..000000000 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -/** - * Contains utility classes used to handle APEX polcies and policy models. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -package org.onap.policy.apex.model.policymodel.handling; |