aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@ericsson.com>2018-05-28 10:58:07 +0100
committerwaqas.ikram <waqas.ikram@ericsson.com>2018-05-28 14:35:30 +0100
commit55d93a12cc5575c872724f48585304b5eec77fea (patch)
treeac5e44c5670bbcc5e68cceb1694f87348c371e1b
parent6029d25f5f3ad43fe02ffe1a4beb1eda0a6ae5e3 (diff)
Adding policy-model, model-api & engine-model
Change-Id: I56702b8f0953457d493f894d155b2a6ddc87b10c Issue-ID: POLICY-856 Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
-rw-r--r--model/engine-model/pom.xml66
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java395
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java46
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java545
-rw-r--r--model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java34
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java187
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java193
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java102
-rw-r--r--model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java127
-rw-r--r--model/engine-model/src/test/resources/META-INF/persistence.xml71
-rw-r--r--model/engine-model/src/test/resources/logback-test.xml70
-rw-r--r--model/model-api/pom.xml40
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexAPIResult.java284
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexEditorAPI.java948
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java192
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java78
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java1239
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java282
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java240
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java385
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java244
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java207
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java630
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java1383
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java893
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/package-info.java27
-rw-r--r--model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/package-info.java27
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestAPIResult.java80
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextAlbum.java173
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextSchema.java152
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIEvent.java196
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIKeyInfo.java136
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIPolicy.java1022
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPITask.java484
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java259
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelFacade.java110
-rw-r--r--model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelHandlerFacade.java147
-rw-r--r--model/model-api/src/test/resources/META-INF/persistence.xml69
-rw-r--r--model/model-api/src/test/resources/logback-test.xml74
-rw-r--r--model/model-api/src/test/resources/models/PolicyModel.json708
-rw-r--r--model/model-api/src/test/resources/models/PolicyModel.junk9
-rw-r--r--model/model-api/src/test/resources/models/PolicyModel.xml759
-rw-r--r--model/policy-model/pom.xml72
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java419
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogicReader.java74
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java429
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java536
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java737
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java1020
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java137
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java389
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java48
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java400
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTree.java157
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java745
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java136
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java299
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java135
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.java425
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyException.java51
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyRuntimeException.java51
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java35
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java186
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalysisResult.java266
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyComparer.java46
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java153
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparer.java271
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java155
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java165
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/package-info.java26
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java84
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestExceptions.java53
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestLogic.java181
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicies.java433
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicyModel.java357
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestState.java475
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateOutput.java137
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateTaskReference.java160
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTaskParameter.java116
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTasks.java331
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModel.java139
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModelCreator.java448
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyAnalyser.java60
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyLogicReader.java114
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelComparer.java129
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelMerger.java109
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelSplitter.java95
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/utils/PolicyModelValidator.java41
-rw-r--r--model/policy-model/src/test/resources/META-INF/persistence.xml69
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt15
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt14
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt71
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt70
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt8
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt69
-rw-r--r--model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt69
-rw-r--r--model/policy-model/src/test/resources/logback-test.xml74
-rw-r--r--model/policy-model/src/test/resources/path/to/apex/logic/funkylogic/LogicParent_LogicParentLocalName_LogicInstanceName.funkylogic21
-rw-r--r--model/pom.xml3
99 files changed, 24821 insertions, 0 deletions
diff --git a/model/engine-model/pom.xml b/model/engine-model/pom.xml
new file mode 100644
index 000000000..347a78de2
--- /dev/null
+++ b/model/engine-model/pom.xml
@@ -0,0 +1,66 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.model</groupId>
+ <artifactId>model</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>engine-model</artifactId>
+ <name>${project.artifactId}</name>
+ <description>Engine Models used in Apex</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.apex-pdp.model</groupId>
+ <artifactId>policy-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-xml-schema</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>org.onap.policy.apex.model.basicmodel.handling.ApexSchemaGenerator</mainClass>
+ <classpathScope>compile</classpathScope>
+ <arguments>
+ <argument>org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel</argument>
+ <argument>${project.build.directory}/model/xml/apex-engine-model.xsd</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java
new file mode 100644
index 000000000..b7733c6a3
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineModel.java
@@ -0,0 +1,395 @@
+/*-
+ * ============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.enginemodel.concepts;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Enumerated;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+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.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.utilities.Assertions;
+
+/**
+ * A container class for an Apex engine model. This class is a container class that allows an Apex
+ * model to be constructed that contains the current context {@link AxContextModel}, current state
+ * {@link AxEngineState} and current statistics {@link AxEngineStats} of an Apex engine. This model
+ * is used by an Apex engine to pass its current execution state to any system that wishes to query
+ * that information. The time stamp of the engine model is the time at which the state and
+ * statistics of the engine were read.
+ * <p>
+ * Validation checks that the current state {@link AxEngineState} is defined and that the time stamp
+ * is set on the engine model.
+ */
+@Entity
+@Table(name = "AxEngineModel")
+@XmlRootElement(name = "apexEngineModel", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxEngineModel", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"timestamp", "state", "stats"})
+
+public class AxEngineModel extends AxContextModel {
+ private static final long serialVersionUID = 6381235864606564046L;
+ private static final int HASH_CODE_PRIME = 32;
+
+ @Column(name = "timestamp")
+ private long timestamp;
+
+ @Enumerated
+ @Column(name = "state")
+ @XmlElement(required = true)
+ private AxEngineState state;
+
+ // @formatter:off
+ @JoinColumns({
+ @JoinColumn(name = "statsParentKeyName", referencedColumnName = "parentKeyName", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "statsParentKeyVersion", referencedColumnName = "parentKeyVersion", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "statsParentLocalName ", referencedColumnName = "parentLocalName", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "statsLocalName", referencedColumnName = "localName", updatable = false,
+ insertable = false)})
+ private AxEngineStats stats;
+ // @formatter:on
+
+ /**
+ * The Default Constructor creates an engine model with a null key and all its fields undefined.
+ */
+ public AxEngineModel() {
+ this(new AxArtifactKey());
+ timestamp = -1;
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEngineModel(final AxEngineModel copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The Keyed Constructor creates an engine model with the given key and all its fields
+ * undefined.
+ *
+ * @param key the engine model key
+ */
+ public AxEngineModel(final AxArtifactKey key) {
+ this(key, new AxContextSchemas(new AxArtifactKey(key.getName() + "_DataTypes", key.getVersion())),
+ new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion())),
+ new AxContextAlbums(new AxArtifactKey(key.getName() + "_Context", key.getVersion())));
+ }
+
+ /**
+ * This Constructor creates an engine model with its context model data types all defined, the
+ * state of the engine model is undefined.
+ *
+ * @param key the engine model key
+ * @param contextSchemas the context schemas used by the engine model
+ * @param keyInformation the key information used by the engine model
+ * @param contextAlbums the context albums used by the engine model
+ */
+ public AxEngineModel(final AxArtifactKey key, final AxContextSchemas contextSchemas,
+ final AxKeyInformation keyInformation, final AxContextAlbums contextAlbums) {
+ this(key, contextSchemas, keyInformation, contextAlbums, AxEngineState.UNDEFINED,
+ new AxEngineStats(new AxReferenceKey(key, "_EngineStats", key.getVersion())));
+ }
+
+ /**
+ * This Constructor creates an engine model with all its fields defined.
+ *
+ * @param key the engine model key
+ * @param contextSchemas the context schemas used by the engine model
+ * @param keyInformation the key information used by the engine model
+ * @param contextAlbums the context albums used by the engine model
+ * @param state the state of the engine in the engine model
+ * @param stats the statistics of the engine in the engine model
+ */
+ public AxEngineModel(final AxArtifactKey key, final AxContextSchemas contextSchemas,
+ final AxKeyInformation keyInformation, final AxContextAlbums contextAlbums, final AxEngineState state,
+ final AxEngineStats stats) {
+ super(key, contextSchemas, contextAlbums, keyInformation);
+ Assertions.argumentNotNull(state, "state may not be null");
+ Assertions.argumentNotNull(stats, "stats may not be null");
+
+ this.state = state;
+ this.stats = stats;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = super.getKeys();
+ keyList.addAll(stats.getKeys());
+ return keyList;
+ }
+
+ /**
+ * Gets the time stamp at which the engine model measurements were taken.
+ *
+ * @return the time stamp at which the engine model measurements were taken
+ */
+ public long getTimestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Gets the time stamp at which the engine model measurements were taken as a string.
+ *
+ * @return the time stamp string
+ */
+ public String getTimeStampString() {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(timestamp);
+ }
+
+ /**
+ * Sets the time stamp at which the engine model measurements were taken.
+ *
+ * @param timestamp the time stamp at which the engine model measurements were taken
+ */
+ public void setTimestamp(final long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ /**
+ * Gets the state of the engine at the time the measurements were taken.
+ *
+ * @return the state of the engine at the time the measurements were taken
+ */
+ public AxEngineState getState() {
+ return state;
+ }
+
+ /**
+ * Sets the state of the engine.
+ *
+ * @param state the state of the engine
+ */
+ public void setState(final AxEngineState state) {
+ Assertions.argumentNotNull(state, "state may not be null");
+ this.state = state;
+ }
+
+ /**
+ * Gets the statistics of the engine at the time the measurements were taken.
+ *
+ * @return the statistics of the engine at the time the measurements were taken
+ */
+ public AxEngineStats getStats() {
+ return stats;
+ }
+
+ /**
+ * Sets the the statistics of the engine.
+ *
+ * @param stats the the statistics of the engine
+ */
+ public void setStats(final AxEngineStats stats) {
+ Assertions.argumentNotNull(stats, "stats may not be null");
+ this.stats = stats;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#validate(org.onap.policy.apex
+ * .model .basicmodel.concepts.AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult resultIn) {
+ AxValidationResult result = resultIn;
+
+ result = stats.validate(result);
+
+ if (timestamp == -1) {
+ result.addValidationMessage(new AxValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ this.getClass().getSimpleName() + " - timestamp is not set"));
+ }
+
+ if (state == AxEngineState.UNDEFINED) {
+ result.addValidationMessage(new AxValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ this.getClass().getSimpleName() + " - state is UNDEFINED"));
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#clean()
+ */
+ @Override
+ public void clean() {
+ super.clean();
+ stats.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append(super.toString());
+ builder.append(",timestamp=");
+ builder.append(timestamp);
+ builder.append(",state=");
+ builder.append(state);
+ builder.append(",stats=");
+ builder.append(stats);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEngineModel.class);
+
+ final AxEngineModel copy = ((AxEngineModel) copyObject);
+ super.copyTo(targetObject);
+ copy.timestamp = timestamp;
+ copy.setState(state);
+ copy.setStats(new AxEngineStats(stats));
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + super.hashCode();
+ result = prime * result + (int) (timestamp ^ (timestamp >>> HASH_CODE_PRIME));
+ result = prime * result + state.hashCode();
+ result = prime * result + stats.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#equals(java.lang.Object)
+ */
+ @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 AxEngineModel other = (AxEngineModel) obj;
+ if (!super.equals(other)) {
+ return false;
+ }
+ if (timestamp != other.timestamp) {
+ return false;
+ }
+ if (!state.equals(other.state)) {
+ return false;
+ }
+ return stats.equals(other.stats);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.contextmodel.concepts.AxContextModel#compareTo(org.onap.policy.
+ * apex.model.basicmodel.concepts.AxConcept)
+ */
+ @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 AxEngineModel other = (AxEngineModel) otherObj;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+ if (timestamp != other.timestamp) {
+ return (int) (timestamp - other.timestamp);
+ }
+ if (!state.equals(other.state)) {
+ return state.compareTo(other.state);
+ }
+ return stats.compareTo(other.stats);
+ }
+}
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java
new file mode 100644
index 000000000..f77fe1910
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineState.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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.enginemodel.concepts;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * This enumeration indicates the execution state of an Apex engine.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxEngineState", namespace = "http://www.onap.org/policy/apex-pdp")
+public enum AxEngineState {
+ /** The state of the engine is not known. */
+ UNDEFINED,
+ /** The engine is stopped. */
+ STOPPED,
+ /** The engine is running and is waiting to execute a policy. */
+ READY,
+ /** The engine is running and is executing a policy. */
+ EXECUTING,
+ /** The engine has been ordered to stop and is stoping. */
+ STOPPING;
+}
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
new file mode 100644
index 000000000..b7593e751
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/AxEngineStats.java
@@ -0,0 +1,545 @@
+/*-
+ * ============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.enginemodel.concepts;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.utilities.Assertions;
+
+/**
+ * This class is a java bean that is used to record statistics on Apex engines as they execute.
+ * Statistics on the number of events, the amount of time taken to execute the last policy, the
+ * average policy execution time, the up time of the engine, and the time stamp of the last engine
+ * start are recorded.
+ */
+
+@Entity
+@Table(name = "AxEngineStats")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexEngineStats", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxEngineStats", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = {"key", "timeStamp",
+ "eventCount", "lastExecutionTime", "averageExecutionTime", "upTime", "lastStart"})
+public class AxEngineStats extends AxConcept {
+ private static final long serialVersionUID = -6981129081962785368L;
+ private static final int HASH_CODE_PRIME = 32;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxReferenceKey key;
+
+ @Column
+ @XmlElement(required = true)
+ private long timeStamp;
+
+ @Column
+ @XmlElement(required = true)
+ private long eventCount;
+
+ @Column
+ @XmlElement(required = true)
+ private long lastExecutionTime;
+
+ @Column
+ @XmlElement(required = true)
+ private double averageExecutionTime;
+
+ @Column
+ @XmlElement(required = true)
+ private long upTime;
+
+ @Transient
+ private transient long lastEnterTime;
+
+ @Column
+ @XmlElement(required = true)
+ private long lastStart;
+
+ /**
+ * The Default Constructor creates an engine statistics instance with a null key and with all
+ * values cleared.
+ */
+ public AxEngineStats() {
+ this(new AxReferenceKey());
+ timeStamp = 0;
+ eventCount = 0;
+ lastExecutionTime = 0;
+ averageExecutionTime = 0;
+ upTime = 0;
+ lastEnterTime = 0;
+ lastStart = 0;
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEngineStats(final AxEngineStats copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The Keyed Constructor creates an engine statistics instance with the given key and all values
+ * cleared.
+ *
+ * @param key the key
+ */
+ public AxEngineStats(final AxReferenceKey key) {
+ this(key, 0, 0, 0, 0, 0, 0);
+ }
+
+ /**
+ * This Constructor creates an engine statistics instance with all its fields set.
+ *
+ * @param key the engine statistics key
+ * @param timeStamp the time stamp at which the statistics were recorded
+ * @param eventCount the number of events processed by the engine
+ * @param lastExecutionTime the amount of time taken to execute the last policy
+ * @param averageExecutionTime the average amount of time taken to execute a policy
+ * @param upTime the time that has elapsed since the policy engine was started
+ * @param lastStart the time at which the policy engine was last started
+ */
+ public AxEngineStats(final AxReferenceKey key, final long timeStamp, final long eventCount,
+ final long lastExecutionTime, final double averageExecutionTime, final long upTime, final long lastStart) {
+ super();
+ Assertions.argumentNotNull(key, "key may not be null");
+
+ this.key = key;
+ this.timeStamp = timeStamp;
+ this.eventCount = eventCount;
+ this.lastExecutionTime = lastExecutionTime;
+ this.averageExecutionTime = averageExecutionTime;
+ this.upTime = upTime;
+ this.lastStart = lastStart;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ return key.getKeys();
+ }
+
+ /**
+ * Sets the engine statistics key.
+ *
+ * @param key the engine statistics key
+ */
+ public void setKey(final AxReferenceKey key) {
+ Assertions.argumentNotNull(key, "key may not be null");
+ this.key = key;
+ }
+
+ /**
+ * Gets the time stamp at which the statistics were recorded.
+ *
+ * @return the time stamp at which the statistics were recorded
+ */
+ public long getTimeStamp() {
+ return timeStamp;
+ }
+
+ /**
+ * Gets the time stamp at which the statistics were recorded as a string.
+ *
+ * @return the time stamp at which the statistics were recorded as a string
+ */
+ public String getTimeStampString() {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(timeStamp);
+ }
+
+ /**
+ * Sets the time stamp at which the statistics were recorded.
+ *
+ * @param timeStamp the time stamp at which the statistics were recorded
+ */
+ public void setTimeStamp(final long timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ /**
+ * Gets the number of events processed by the engine.
+ *
+ * @return the number of events processed by the engine
+ */
+ public long getEventCount() {
+ return eventCount;
+ }
+
+ /**
+ * Sets the number of events processed by the engine.
+ *
+ * @param eventCount the number of events processed by the engine
+ */
+ public void setEventCount(final long eventCount) {
+ this.eventCount = eventCount;
+ }
+
+ /**
+ * Gets the amount of time taken to execute the last policy.
+ *
+ * @return the amount of time taken to execute the last policy
+ */
+ public long getLastExecutionTime() {
+ return lastExecutionTime;
+ }
+
+ /**
+ * Sets the amount of time taken to execute the last policy.
+ *
+ * @param lastExecutionTime the amount of time taken to execute the last policy
+ */
+ public void setLastExecutionTime(final long lastExecutionTime) {
+ this.lastExecutionTime = lastExecutionTime;
+ }
+
+ /**
+ * Gets the average amount of time taken to execute a policy.
+ *
+ * @return the average amount of time taken to execute a policy
+ */
+ public double getAverageExecutionTime() {
+ return averageExecutionTime;
+ }
+
+ /**
+ * Sets the average amount of time taken to execute a policy.
+ *
+ * @param averageExecutionTime the average amount of time taken to execute a policy
+ */
+ public void setAverageExecutionTime(final double averageExecutionTime) {
+ this.averageExecutionTime = averageExecutionTime;
+ }
+
+ /**
+ * Gets the time that has elapsed since the policy engine was started.
+ *
+ * @return the time that has elapsed since the policy engine was started
+ */
+ public long getUpTime() {
+ if (this.getLastStart() != 0) {
+ return upTime + (timeStamp - this.getLastStart());
+ }
+ return upTime;
+ }
+
+ /**
+ * Sets the time that has elapsed since the policy engine was started.
+ *
+ * @param upTime the time that has elapsed since the policy engine was started
+ */
+ public void setUpTime(final long upTime) {
+ this.upTime = upTime;
+ }
+
+ /**
+ * Sets the time at which the policy engine was last started.
+ *
+ * @param lastStart the time at which the policy engine was last started
+ */
+ private void setLastStart(final long lastStart) {
+ this.lastStart = lastStart;
+ }
+
+ /**
+ * Gets the time at which the policy engine was last started.
+ *
+ * @return the time at which the policy engine was last started
+ */
+ private long getLastStart() {
+ return lastStart;
+ }
+
+ /**
+ * Resets all the statistic values to zero.
+ */
+ public synchronized void reset() {
+ timeStamp = 0;
+ eventCount = 0;
+ lastExecutionTime = 0;
+ averageExecutionTime = 0;
+ upTime = 0;
+ lastEnterTime = 0;
+ lastStart = 0;
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it starts executing a
+ * policy.
+ *
+ * @param eventkey the key of the event that is being executed
+ */
+ public synchronized void executionEnter(final AxArtifactKey eventkey) {
+ final long now = System.currentTimeMillis();
+ eventCount++;
+ if (eventCount < 0) {
+ eventCount = 2;
+ }
+ lastEnterTime = now;
+ timeStamp = now;
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it completes executing a
+ * policy.
+ */
+ public synchronized void executionExit() {
+ final long now = System.currentTimeMillis();
+ lastExecutionTime = now - lastEnterTime;
+
+ averageExecutionTime = ((averageExecutionTime * (eventCount - 1.0)) + lastExecutionTime) / eventCount;
+ lastEnterTime = 0;
+ timeStamp = System.currentTimeMillis();
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it is started.
+ */
+ public synchronized void engineStart() {
+ final long now = System.currentTimeMillis();
+ timeStamp = now;
+ this.setLastStart(now);
+ }
+
+ /**
+ * Updates the statistics when called, used by the Apex engine when it is stopped.
+ */
+ public synchronized void engineStop() {
+ final long now = System.currentTimeMillis();
+ timeStamp = now;
+ upTime += (timeStamp - this.getLastStart());
+ this.setLastStart(0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult result) {
+ if (key.equals(AxReferenceKey.getNullKey())) {
+ result.addValidationMessage(
+ new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ return key.validate(result);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append("engineKey=");
+ builder.append(key);
+ builder.append(",timeStamp=");
+ builder.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(timeStamp));
+ builder.append(",eventCount=");
+ builder.append(eventCount);
+ builder.append(",lastExecutionTime=");
+ builder.append(lastExecutionTime);
+ builder.append(",averageExecutionTime=");
+ builder.append(averageExecutionTime);
+ builder.append(",upTime=");
+ builder.append(getUpTime());
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEngineStats.class);
+
+ final AxEngineStats copy = ((AxEngineStats) copyObject);
+ copy.setKey(new AxReferenceKey(key));
+ copy.setTimeStamp(timeStamp);
+ copy.setEventCount(eventCount);
+ copy.setLastExecutionTime(lastExecutionTime);
+ copy.setAverageExecutionTime(averageExecutionTime);
+ copy.setUpTime(upTime);
+ copy.setLastStart(lastStart);
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + (int) (timeStamp ^ (timeStamp >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (eventCount ^ (eventCount >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (lastExecutionTime ^ (lastExecutionTime >>> HASH_CODE_PRIME));
+ result = prime * result + ((int) averageExecutionTime ^ ((int) averageExecutionTime >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (upTime ^ (upTime >>> HASH_CODE_PRIME));
+ result = prime * result + (int) (getLastStart() ^ (getLastStart() >>> HASH_CODE_PRIME));
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final AxEngineStats other = (AxEngineStats) obj;
+ if (!key.equals(other.key)) {
+ return false;
+ }
+ if (timeStamp != other.timeStamp) {
+ return false;
+ }
+ if (eventCount != other.eventCount) {
+ return false;
+ }
+ if (lastExecutionTime != other.lastExecutionTime) {
+ return false;
+ }
+ if (averageExecutionTime != other.averageExecutionTime) {
+ return false;
+ }
+ if (upTime != other.upTime) {
+ return false;
+ }
+ return getLastStart() == other.getLastStart();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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 AxEngineStats other = (AxEngineStats) otherObj;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+ if (timeStamp != other.timeStamp) {
+ return (int) (timeStamp - other.timeStamp);
+ }
+ if (eventCount != other.eventCount) {
+ return (int) (eventCount - other.eventCount);
+ }
+ if (lastExecutionTime != other.lastExecutionTime) {
+ return (int) (lastExecutionTime - other.lastExecutionTime);
+ }
+ if (averageExecutionTime != other.averageExecutionTime) {
+ return (int) (averageExecutionTime - other.averageExecutionTime);
+ }
+ if (upTime != other.upTime) {
+ return (int) (upTime - other.upTime);
+ }
+ if (getLastStart() != other.getLastStart()) {
+ return (int) (getLastStart() - other.getLastStart());
+ }
+
+ return 0;
+ }
+}
diff --git a/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java
new file mode 100644
index 000000000..ea47c6993
--- /dev/null
+++ b/model/engine-model/src/main/java/org/onap/policy/apex/model/enginemodel/concepts/package-info.java
@@ -0,0 +1,34 @@
+/*-
+ * ============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 the concepts required to receive state information and statistcs from running APEX
+ * engines.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
+ xmlns = {@XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "")})
+
+package org.onap.policy.apex.model.enginemodel.concepts;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java
new file mode 100644
index 000000000..86530462c
--- /dev/null
+++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java
@@ -0,0 +1,187 @@
+/*-
+ * ============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.enginemodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestEngineModel {
+
+ @Test
+ public void testEnginetModel() {
+ assertNotNull(new AxEngineModel());
+ assertNotNull(new AxEngineModel(new AxArtifactKey()));
+ assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
+ new AxContextAlbums()));
+ assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
+ new AxContextAlbums(), AxEngineState.UNDEFINED, new AxEngineStats()));
+
+ final AxArtifactKey modelKey = new AxArtifactKey("ModelName", "0.0.1");
+ final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey albumKey = new AxArtifactKey("AlbumKey", "0.0.1");
+ final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxEngineStats stats = new AxEngineStats(new AxReferenceKey(modelKey, "EngineStats"));
+ final AxEngineStats otherStats = new AxEngineStats();
+ otherStats.setAverageExecutionTime(100);
+
+ final AxEngineModel model = new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats);
+ model.register();
+
+ try {
+ model.setKey(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("key may not be null", e.getMessage());
+ }
+
+ model.setKey(modelKey);
+ assertEquals("ModelName:0.0.1", model.getKey().getID());
+ assertEquals("ModelName:0.0.1", model.getKeys().get(0).getID());
+
+ final long timestamp = System.currentTimeMillis();
+ model.setTimestamp(timestamp);
+ assertEquals(timestamp, model.getTimestamp());
+ model.setTimestamp(-1);
+ assertTrue(model.getTimeStampString().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}"));
+
+ try {
+ model.setState(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("state may not be null", e.getMessage());
+ }
+
+ for (final AxEngineState state : AxEngineState.values()) {
+ model.setState(state);
+ assertEquals(state, model.getState());
+ }
+
+ model.setState(AxEngineState.READY);
+ assertEquals(AxEngineState.READY, model.getState());
+
+ try {
+ model.setStats(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("stats may not be null", e.getMessage());
+ }
+
+ model.setStats(stats);
+ assertEquals(stats, model.getStats());
+
+ model.clean();
+ assertNotNull(model);
+ assertEquals("AxEngineModel:(AxEngineModel:(AxEngineModel:(key=A", model.toString().substring(0, 50));
+
+ final AxEngineModel clonedModel = new AxEngineModel(model);
+
+ assertFalse(model.hashCode() == 0);
+
+ assertTrue(model.equals(model));
+ assertTrue(model.equals(clonedModel));
+ assertFalse(model.equals("Hello"));
+ assertFalse(model.equals(new AxEngineModel(new AxArtifactKey())));
+ assertFalse(model.equals(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
+ new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
+ new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats)));
+ assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats)));
+ assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats)));
+ model.setTimestamp(timestamp);
+ assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ model.setTimestamp(0);
+ assertTrue(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+
+ model.setTimestamp(-1);
+ assertEquals(0, model.compareTo(model));
+ assertEquals(0, model.compareTo(clonedModel));
+ assertNotEquals(0, model.compareTo(new AxArtifactKey()));
+ assertFalse(model.equals(new AxEngineModel(new AxArtifactKey())));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats)));
+ model.setTimestamp(timestamp);
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ model.setTimestamp(0);
+ assertEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+
+ model.setTimestamp(timestamp);
+ AxValidationResult result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.setTimestamp(-1);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.setTimestamp(timestamp);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.setState(AxEngineState.UNDEFINED);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.setState(AxEngineState.READY);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+}
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java
new file mode 100644
index 000000000..f5fdcbb1f
--- /dev/null
+++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java
@@ -0,0 +1,193 @@
+/*-
+ * ============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.enginemodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestEngineStats {
+
+ @Test
+ public void testEngineStats() {
+ assertNotNull(new AxEngineStats());
+ assertNotNull(new AxEngineStats(new AxReferenceKey()));
+
+ final AxReferenceKey statsKey = new AxReferenceKey("EngineKey", "0.0.1", "EngineStats");
+ final AxEngineStats stats = new AxEngineStats(statsKey);
+
+ try {
+ stats.setKey(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("key may not be null", e.getMessage());
+ }
+
+ stats.setKey(statsKey);
+ assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKey().getID());
+ assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKeys().get(0).getID());
+
+ stats.setAverageExecutionTime(123.45);
+ assertEquals(new Double(123.45), new Double(stats.getAverageExecutionTime()));
+
+ stats.setEventCount(987);
+ assertEquals(987, stats.getEventCount());
+
+ final long lastExecutionTime = System.currentTimeMillis();
+ stats.setLastExecutionTime(lastExecutionTime);
+ assertEquals(lastExecutionTime, stats.getLastExecutionTime());
+
+ final long timestamp = System.currentTimeMillis();
+ stats.setTimeStamp(timestamp);
+ assertEquals(timestamp, stats.getTimeStamp());
+ assertNotNull(stats.getTimeStampString());
+
+ final long upTime = System.currentTimeMillis() - timestamp;
+ stats.setUpTime(upTime);
+ assertEquals(upTime, stats.getUpTime());
+
+ stats.engineStart();
+ assertTrue(stats.getUpTime() > -1);
+ stats.engineStop();
+ assertTrue(stats.getUpTime() >= 0);
+
+ stats.engineStop();
+
+ stats.reset();
+
+ stats.setEventCount(-2);
+ stats.executionEnter(new AxArtifactKey());
+ assertEquals(2, stats.getEventCount());
+
+ stats.setEventCount(10);
+ stats.executionEnter(new AxArtifactKey());
+ assertEquals(11, stats.getEventCount());
+
+ stats.reset();
+ stats.engineStart();
+ stats.setEventCount(4);
+ stats.executionEnter(new AxArtifactKey());
+ try {
+ Thread.sleep(10);
+ } catch (final Exception e) {
+ fail("test should not throw an exeption");
+ }
+ stats.executionExit();
+ final double avExecutionTime = stats.getAverageExecutionTime();
+ System.err.println(avExecutionTime);
+ assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 3.0);
+ stats.engineStop();
+
+ AxValidationResult result = new AxValidationResult();
+ result = stats.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stats.setKey(new AxReferenceKey());
+ result = new AxValidationResult();
+ result = stats.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stats.setKey(statsKey);
+ result = new AxValidationResult();
+ result = stats.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stats.clean();
+ stats.reset();
+
+ final AxEngineStats clonedStats = new AxEngineStats(stats);
+ assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50));
+
+ assertNotNull(stats.getKeys());
+
+ assertFalse(stats.hashCode() == 0);
+
+ assertTrue(stats.equals(stats));
+ assertTrue(stats.equals(clonedStats));
+ assertFalse(stats.equals(null));
+ assertFalse(stats.equals("Hello"));
+ assertFalse(stats.equals(new AxEngineStats(new AxReferenceKey())));
+
+ assertEquals(0, stats.compareTo(stats));
+ assertEquals(0, stats.compareTo(clonedStats));
+ assertNotEquals(0, stats.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, stats.compareTo(null));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(new AxReferenceKey())));
+
+ stats.setTimeStamp(1);
+ assertFalse(stats.equals(new AxEngineStats(statsKey)));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setTimeStamp(0);
+ assertTrue(stats.equals(new AxEngineStats(statsKey)));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setEventCount(1);
+ assertFalse(stats.equals(new AxEngineStats(statsKey)));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setEventCount(0);
+ assertTrue(stats.equals(new AxEngineStats(statsKey)));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setLastExecutionTime(1);
+ assertFalse(stats.equals(new AxEngineStats(statsKey)));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setLastExecutionTime(0);
+ assertTrue(stats.equals(new AxEngineStats(statsKey)));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setAverageExecutionTime(1);
+ assertFalse(stats.equals(new AxEngineStats(statsKey)));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setAverageExecutionTime(0);
+ assertTrue(stats.equals(new AxEngineStats(statsKey)));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setUpTime(1);
+ assertFalse(stats.equals(new AxEngineStats(statsKey)));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setUpTime(0);
+ assertTrue(stats.equals(new AxEngineStats(statsKey)));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.engineStart();
+ assertFalse(stats.equals(new AxEngineStats(statsKey)));
+ final AxEngineStats newStats = new AxEngineStats(statsKey);
+ newStats.setTimeStamp(stats.getTimeStamp());
+ assertFalse(stats.equals(newStats));
+ assertNotEquals(0, stats.compareTo(newStats));
+ stats.engineStop();
+ stats.reset();
+ assertTrue(stats.equals(new AxEngineStats(statsKey)));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ }
+}
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java
new file mode 100644
index 000000000..c1e6f3f37
--- /dev/null
+++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java
@@ -0,0 +1,102 @@
+/*-
+ * ============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.enginemodel.handling;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
+
+public class TestApexEngineModel {
+ private Connection connection;
+ TestApexModel<AxEngineModel> testApexModel;
+
+ @Before
+ public void setup() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
+
+ testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new TestApexEngineModelCreator());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ connection.close();
+ new File("derby.log").delete();
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertTrue(result.toString().equals(VALID_MODEL_STRING));
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertTrue(result.toString().equals(INVALID_MODEL_STRING));
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
+ }
+
+ @Test
+ public void testModelWriteReadXML() throws Exception {
+ testApexModel.testApexModelWriteReadXML();
+ }
+
+ @Test
+ public void testModelWriteReadJSON() throws Exception {
+ testApexModel.testApexModelWriteReadJSON();
+ }
+
+ @Test
+ public void testModelWriteReadJPA() throws Exception {
+ final DAOParameters daoParameters = new DAOParameters();
+ daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
+ daoParameters.setPersistenceUnit("DAOTest");
+
+ testApexModel.testApexModelWriteReadJPA(daoParameters);
+ }
+
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=AnEngine,version=0.0.1):org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:AxEngineModel - state is UNDEFINED\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=AnEngine,version=0.0.1):org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:AxEngineModel - timestamp is not set\n"
+ + "AxArtifactKey:(name=AnEngine,version=0.0.1):org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:AxEngineModel - state is UNDEFINED\n"
+ + "********************************";
+}
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java
new file mode 100644
index 000000000..4a4a0cc88
--- /dev/null
+++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java
@@ -0,0 +1,127 @@
+/*-
+ * ============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.enginemodel.handling;
+
+import java.util.UUID;
+
+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.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+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.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats;
+
+public class TestApexEngineModelCreator implements TestApexModelCreator<AxEngineModel> {
+
+ @Override
+ public AxEngineModel getModel() {
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
+
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
+ schemas.getSchemasMap().put(schema0.getKey(), schema0);
+ schemas.getSchemasMap().put(schema1.getKey(), schema1);
+
+ final AxContextAlbum album0 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema1.getKey());
+
+ final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
+ albums.getAlbumsMap().put(album0.getKey(), album0);
+
+ final AxEngineModel engineModel = new AxEngineModel(new AxArtifactKey("AnEngine", "0.0.1"));
+ engineModel.setSchemas(schemas);
+ engineModel.setAlbums(albums);
+ engineModel.setTimestamp(System.currentTimeMillis());
+ engineModel.setState(AxEngineState.EXECUTING);
+ engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
+ System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
+ engineModel.getKeyInformation().generateKeyInfo(engineModel);
+
+ final AxValidationResult result = new AxValidationResult();
+ engineModel.validate(result);
+
+ return engineModel;
+ }
+
+ @Override
+ public AxEngineModel getInvalidModel() {
+ final AxEngineModel engineModel = getModel();
+
+ engineModel.setTimestamp(System.currentTimeMillis());
+ engineModel.setState(AxEngineState.UNDEFINED);
+ engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
+ System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
+ engineModel.getKeyInformation().generateKeyInfo(engineModel);
+
+ return engineModel;
+ }
+
+ public AxEngineModel getMalstructuredModel() {
+ final AxEngineModel engineModel = getModel();
+
+ engineModel.setTimestamp(-1);
+ engineModel.setState(AxEngineState.UNDEFINED);
+
+ return engineModel;
+ }
+
+ @Override
+ public AxEngineModel getObservationModel() {
+ final AxEngineModel engineModel = getModel();
+
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
+
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
+ new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
+ new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000002"), ""));
+
+ return engineModel;
+ }
+
+ @Override
+ public AxEngineModel getWarningModel() {
+ final AxEngineModel engineModel = getModel();
+
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
+
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
+ new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
+ new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
+
+ return engineModel;
+ }
+}
diff --git a/model/engine-model/src/test/resources/META-INF/persistence.xml b/model/engine-model/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..717d1a540
--- /dev/null
+++ b/model/engine-model/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
+ <persistence-unit name="DAOTest" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+
+ <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDATAConditioner</class>
+ <class>org.onap.policy.apex.model.basicmodel.dao.converters.UUID2String</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxConcept</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.TestEntity</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextModel</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxInputField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxOutputField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvent</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvents</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEventModel</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTask</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTasks</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateOutput</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxState</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicy</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicies</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel</class>
+ <class>org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel</class>
+ <class>org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats</class>
+
+ <properties>
+ <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:apex_test" />
+ <property name="javax.persistence.target-database" value="Derby" />
+ <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
+
+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
+ <property name="eclipselink.ddl-generation.output-mode" value="database" />
+ <property name="eclipselink.logging.level" value="INFO" />
+ </properties>
+ </persistence-unit>
+</persistence>
diff --git a/model/engine-model/src/test/resources/logback-test.xml b/model/engine-model/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..034511335
--- /dev/null
+++ b/model/engine-model/src/test/resources/logback-test.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<configuration>
+
+ <contextName>Apex</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" />
+
+ <!-- USE FOR STD OUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <logger name="org.infinispan" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex_ctxt.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="TRACE" additivity="false">
+ <appender-ref ref="CTXT_FILE" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+</configuration>
diff --git a/model/model-api/pom.xml b/model/model-api/pom.xml
new file mode 100644
index 000000000..3fd4b27b5
--- /dev/null
+++ b/model/model-api/pom.xml
@@ -0,0 +1,40 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.model</groupId>
+ <artifactId>model</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>model-api</artifactId>
+ <name>${project.artifactId}</name>
+ <description>APIs for editing Apex models</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>policy-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexAPIResult.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexAPIResult.java
new file mode 100644
index 000000000..2e4328fc5
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexAPIResult.java
@@ -0,0 +1,284 @@
+/*-
+ * ============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.modelapi;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The Class ApexEditorAPIResult return the result of and messages from all model API method calls
+ * on the {@link ApexModel} API.
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class ApexAPIResult {
+
+ /**
+ * This enumeration is used to represent the result status of a call on the {@link ApexModel}
+ * API.
+ */
+ @XmlEnum(value = String.class)
+ public enum RESULT {
+ /** The method call succeeded. */
+ SUCCESS,
+ /** The method call succeeded and all operations are now completed. */
+ FINISHED,
+ /** The method call for a create operation failed because the concept already exists. */
+ CONCEPT_EXISTS,
+ /**
+ * The method call for a create operation failed because multiple concepts already exists.
+ */
+ MULTIPLE_CONCEPTS_EXIST,
+ /** The method call on a concept failed because the referenced concept does not exist. */
+ CONCEPT_DOES_NOT_EXIST,
+ /** The method call failed because no action was specified on the method call. */
+ NO_ACTION_SPECIFIED,
+ /**
+ * The method call failed because of a structural error, a missing reference, or other error
+ * on the model.
+ */
+ FAILED,
+ /**
+ * The method call failed for another reason such as the method call is not implemented yet
+ * on the concept on which it was called.
+ */
+ OTHER_ERROR
+ }
+
+ private RESULT result;
+ private List<String> messages = new ArrayList<>();
+
+ /**
+ * The Default Constructor creates a result for a successful operation with no messages.
+ */
+ public ApexAPIResult() {
+ result = RESULT.SUCCESS;
+ }
+
+ /**
+ * This Constructor creates a result with the given result status with no messages.
+ *
+ * @param result the result status to use on this result
+ */
+ public ApexAPIResult(final RESULT result) {
+ this.result = result;
+ }
+
+ /**
+ * This Constructor creates a result with the given result status and message.
+ *
+ * @param result the result status to use on this result
+ * @param message the message to return with the result
+ */
+ public ApexAPIResult(final RESULT result, final String message) {
+ this.result = result;
+ addMessage(message);
+ }
+
+ /**
+ * This Constructor creates a result with the given result status and {@link Throwable} object
+ * such as an exception. The message and stack trace from the {@link Throwable} object are added
+ * to the message list of this message.
+ *
+ * @param result the result status to use on this result
+ * @param throwable the throwable object from which to add the message and stack trace
+ */
+ public ApexAPIResult(final RESULT result, final Throwable throwable) {
+ this.result = result;
+ addThrowable(throwable);
+ }
+
+ /**
+ * This Constructor creates a result with the given result status, message, and
+ * {@link Throwable} object such as an exception. The message and stack trace from the
+ * {@link Throwable} object are added to the message list of this message.
+ *
+ * @param result the result status to use on this result
+ * @param message the message to return with the result
+ * @param throwable the throwable object from which to add the message and stack trace
+ */
+ public ApexAPIResult(final RESULT result, final String message, final Throwable throwable) {
+ this.result = result;
+ addMessage(message);
+ addThrowable(throwable);
+ }
+
+ /**
+ * This message is a utility message that checks if the result of an operation on the API was
+ * OK.
+ *
+ * @return true, if the result indicates the API operation succeeded
+ */
+ @XmlAttribute(required = true)
+ public boolean isOK() {
+ return result == RESULT.SUCCESS || result == RESULT.FINISHED;
+ }
+
+ /**
+ * This message is a utility message that checks if the result of an operation on the API was
+ * not OK.
+ *
+ * @return true, if the result indicates the API operation did not succeed
+ */
+ public boolean isNOK() {
+ return !isOK();
+ }
+
+ /**
+ * Gets the result status of an API operation.
+ *
+ * @return the result status
+ */
+ @XmlAttribute(required = true)
+ public RESULT getResult() {
+ return result;
+ }
+
+ /**
+ * Sets the result status of an API operation.
+ *
+ * @param result the result status
+ */
+ public void setResult(final RESULT result) {
+ this.result = result;
+ }
+
+ /**
+ * Gets the list of messages returned by an API operation.
+ *
+ * @return the list of messages returned by an API operation
+ */
+ @XmlElementWrapper(required = false, nillable = true)
+ @XmlElement(nillable = true, name = "message")
+ public List<String> getMessages() {
+ return messages;
+ }
+
+ /**
+ * Sets the list of messages to return as a result of an API operation.
+ *
+ * @param messages the list of messages to return as a result of an API operation
+ */
+ public void setMessages(final List<String> messages) {
+ this.messages = messages;
+ }
+
+ /**
+ * Gets all the messages returned by an API operation as a single string.
+ *
+ * @return the messages returned by an API operation as a single string
+ */
+ @XmlElement(required = true, name = "content")
+ public String getMessage() {
+ final StringBuilder builder = new StringBuilder();
+ for (final String message : messages) {
+ builder.append(message);
+ builder.append('\n');
+ }
+
+ return builder.toString();
+ }
+
+ /**
+ * Adds a message from an API operation to the bottom of the list of messages to be returned.
+ *
+ * @param message the message from an API operation to add to the bottom of the list of messages
+ * to be returned
+ */
+ public void addMessage(final String message) {
+ if (message != null && message.trim().length() > 0) {
+ messages.add(message);
+ }
+ }
+
+ /**
+ * Adds the message and stack trace from a {@link Throwable} object such as an exception from an
+ * API operation to the bottom of the list of messages to be returned.
+ *
+ * @param throwable the {@link Throwable} object such as an exception from an API operation from
+ * which the message and stack trace are to be extracted and placed at the bottom of the
+ * list of messages to be returned
+ */
+ public void addThrowable(final Throwable throwable) {
+ final StringWriter throwableStringWriter = new StringWriter();
+ final PrintWriter throwablePrintWriter = new PrintWriter(throwableStringWriter);
+ throwable.printStackTrace(throwablePrintWriter);
+ messages.add(throwable.getMessage());
+ messages.add(throwableStringWriter.toString());
+ }
+
+ /**
+ * Gets a representation of the {@link ApexAPIResult} instance as a JSON string.
+ *
+ * @return the result instance JSON string
+ */
+ public String toJSON() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("{\n");
+
+ builder.append("\"result\": \"");
+ builder.append(result.toString());
+ builder.append("\",\n");
+
+ builder.append("\"messages\": [");
+ boolean first = true;
+ for (final String message : messages) {
+ if (first) {
+ builder.append("\n\"");
+ first = false;
+ } else {
+ builder.append(",\n\"");
+ }
+ builder.append(message.replaceAll("\"", "\\\\\""));
+ builder.append("\"");
+ }
+ builder.append("]\n");
+
+ builder.append("}\n");
+
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("result: ");
+ builder.append(result);
+ builder.append('\n');
+ builder.append(getMessage());
+ return builder.toString();
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexEditorAPI.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexEditorAPI.java
new file mode 100644
index 000000000..617cbc786
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexEditorAPI.java
@@ -0,0 +1,948 @@
+/*-
+ * ============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.modelapi;
+
+/**
+ * The Interface ApexEditorAPI is used to manipulate Apex models.
+ */
+public interface ApexEditorAPI {
+ /*
+ * Model API Methods
+ */
+
+ /**
+ * Create model.
+ *
+ * @param name name of the model
+ * @param version version of the model, set to null to use the default version
+ * @param uuid model UUID, set to null to generate a UUID
+ * @param description model description, set to null to generate a description
+ * @return result of the operation
+ */
+ ApexAPIResult createModel(final String name, final String version, final String uuid, final String description);
+
+ /**
+ * Update model.
+ *
+ * @param name name of the model
+ * @param version version of the model, set to null to update the latest version
+ * @param uuid key information UUID, set to null to not update
+ * @param description policy description, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updateModel(final String name, final String version, final String uuid, final String description);
+
+ /**
+ * Get the key of an Apex model.
+ *
+ * @return the result of the operation
+ */
+ ApexAPIResult getModelKey();
+
+ /**
+ * List an Apex model.
+ *
+ * @return the result of the operation
+ */
+ ApexAPIResult listModel();
+
+ /**
+ * Delete an Apex model, clear all the concepts in the model.
+ *
+ * @return the result of the operation
+ */
+ ApexAPIResult deleteModel();
+
+ /*
+ * Key Information API Methods
+ */
+
+ /**
+ * Create key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to use the default
+ * version
+ * @param uuid key information UUID, set to null to generate a UUID
+ * @param description key information description, set to null to generate a description
+ * @return result of the operation
+ */
+ ApexAPIResult createKeyInformation(final String name, final String version, final String uuid,
+ final String description);
+
+ /**
+ * Update key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to update the
+ * latest version
+ * @param uuid key information UUID, set to null to not update
+ * @param description key information description, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updateKeyInformation(final String name, final String version, final String uuid,
+ final String description);
+
+ /**
+ * List key information.
+ *
+ * @param name name of the concept for the key information, set to null to list all
+ * @param version starting version of the concept for the key information, set to null to list
+ * all versions
+ * @return result of the operation
+ */
+ ApexAPIResult listKeyInformation(final String name, final String version);
+
+ /**
+ * Delete key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to delete all
+ * versions
+ * @return result of the operation
+ */
+ ApexAPIResult deleteKeyInformation(final String name, final String version);
+
+ /**
+ * Validate key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to validate all
+ * versions
+ * @return result of the operation
+ */
+ ApexAPIResult validateKeyInformation(final String name, final String version);
+
+ /*
+ * Context Schema API Methods
+ */
+
+ /**
+ * Create a context schema.
+ *
+ * @param name name of the context schema
+ * @param version version of the context schema, set to null to use the default version
+ * @param schemaFlavour a final String identifying the flavour of this context schema
+ * @param schemaDefinition a final String containing the definition of this context schema
+ * @param uuid context schema UUID, set to null to generate a UUID
+ * @param description context schema description, set to null to generate a description
+ * @return result of the operation
+ */
+ ApexAPIResult createContextSchema(final String name, final String version, final String schemaFlavour,
+ final String schemaDefinition, final String uuid, final String description);
+
+ /**
+ * Update a context schema.
+ *
+ * @param name name of the context schema
+ * @param version version of the context schema, set to null to update the latest version
+ * @param schemaFlavour a final String identifying the flavour of this context schema
+ * @param schemaDefinition a final String containing the definition of this context schema
+ * @param uuid context schema UUID, set to null to not update
+ * @param description context schema description, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updateContextSchema(final String name, final String version, final String schemaFlavour,
+ final String schemaDefinition, final String uuid, final String description);
+
+ /**
+ * List context schemas.
+ *
+ * @param name name of the context schema, set to null to list all
+ * @param version starting version of the context schema, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult listContextSchemas(final String name, final String version);
+
+ /**
+ * Delete a context schema.
+ *
+ * @param name name of the context schema
+ * @param version version of the context schema, set to null to delete all versions
+ * @return result of the operation
+ */
+ ApexAPIResult deleteContextSchema(final String name, final String version);
+
+ /**
+ * Validate context schemas.
+ *
+ * @param name name of the context schema, set to null to list all
+ * @param version starting version of the context schema, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult validateContextSchemas(final String name, final String version);
+
+ /*
+ * Event API Methods
+ */
+
+ /**
+ * Create an event.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the default version
+ * @param nameSpace of the event, set to null to use the default value
+ * @param source of the event, set to null to use the default value
+ * @param target of the event, set to null to use the default value
+ * @param uuid event UUID, set to null to generate a UUID
+ * @param description event description, set to null to generate a description
+ * @return result of the operation
+ */
+ ApexAPIResult createEvent(final String name, final String version, final String nameSpace, final String source,
+ final String target, final String uuid, final String description);
+
+ /**
+ * Update an event.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the latest version
+ * @param nameSpace of the event, set to null to not update
+ * @param source of the event, set to null to not update
+ * @param target of the event, set to null to not update
+ * @param uuid event UUID, set to null to not update
+ * @param description event description, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updateEvent(final String name, final String version, final String nameSpace, final String source,
+ final String target, final String uuid, final String description);
+
+ /**
+ * List events.
+ *
+ * @param name name of the event, set to null to list all
+ * @param version starting version of the event, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult listEvent(final String name, final String version);
+
+ /**
+ * Delete an event.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to delete all versions
+ * @return result of the operation
+ */
+ ApexAPIResult deleteEvent(final String name, final String version);
+
+ /**
+ * Validate events.
+ *
+ * @param name name of the event, set to null to list all
+ * @param version starting version of the event, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult validateEvent(final String name, final String version);
+
+ /**
+ * Create an event parameter.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the latest version
+ * @param parName of the parameter
+ * @param contextSchemaName name of the parameter context schema
+ * @param contextSchemaVersion version of the parameter context schema, set to null to use the
+ * latest version
+ * @param optional true if the event parameter is optional, false otherwise
+ * @return result of the operation
+ */
+ ApexAPIResult createEventPar(final String name, final String version, final String parName,
+ final String contextSchemaName, final String contextSchemaVersion, boolean optional);
+
+ /**
+ * List event parameters.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to list latest version
+ * @param parName name of the parameter, set to null to list all parameters of the event
+ * @return result of the operation
+ */
+ ApexAPIResult listEventPar(final String name, final String version, final String parName);
+
+ /**
+ * Delete an event parameter.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the latest version
+ * @param parName of the parameter, set to null to delete all parameters
+ * @return result of the operation
+ */
+ ApexAPIResult deleteEventPar(final String name, final String version, final String parName);
+
+ /*
+ * Context Album API Methods
+ */
+
+ /**
+ * Create a context album.
+ *
+ * @param name name of the context album
+ * @param version version of the context album, set to null to use the default version
+ * @param scope of the context album
+ * @param writable "true" or "t" if the context album is writable, set to null or any other
+ * value for a read-only album
+ * @param contextSchemaName name of the parameter context schema
+ * @param contextSchemaVersion version of the parameter context schema, set to null to use the
+ * latest version
+ * @param uuid context album UUID, set to null to generate a UUID
+ * @param description context album description, set to null to generate a description
+ * @return result of the operation
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ ApexAPIResult createContextAlbum(final String name, final String version, final String scope, final String writable,
+ final String contextSchemaName, final String contextSchemaVersion, final String uuid,
+ final String description);
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * Update a context album.
+ *
+ * @param name name of the context album
+ * @param version version of the context album, set to null to use the default version
+ * @param scope of the context album
+ * @param writable "true" or "t" if the context album is writable, set to null or any other
+ * value for a read-only album
+ * @param contextSchemaName name of the parameter context schema
+ * @param contextSchemaVersion version of the parameter context schema, set to null to use the
+ * latest version
+ * @param uuid context album UUID, set to null to generate a UUID
+ * @param description context album description, set to null to generate a description
+ * @return result of the operation
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ ApexAPIResult updateContextAlbum(final String name, final String version, final String scope, final String writable,
+ final String contextSchemaName, final String contextSchemaVersion, final String uuid,
+ final String description);
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * List context albums.
+ *
+ * @param name name of the context album, set to null to list all
+ * @param version starting version of the context album, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult listContextAlbum(final String name, final String version);
+
+ /**
+ * Delete a context album.
+ *
+ * @param name name of the context album
+ * @param version version of the context album, set to null to delete versions
+ * @return result of the operation
+ */
+ ApexAPIResult deleteContextAlbum(final String name, final String version);
+
+ /**
+ * Validate context albums.
+ *
+ * @param name name of the context album, set to null to list all
+ * @param version starting version of the context album, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult validateContextAlbum(final String name, final String version);
+
+ /*
+ * Task API Methods
+ */
+
+ /**
+ * Create a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the default version
+ * @param uuid task UUID, set to null to generate a UUID
+ * @param description task description, set to null to generate a description
+ * @return result of the operation
+ */
+ ApexAPIResult createTask(final String name, final String version, final String uuid, final String description);
+
+ /**
+ * Update a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param uuid task UUID, set to null to not update
+ * @param description task description, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updateTask(final String name, final String version, final String uuid, final String description);
+
+ /**
+ * List tasks.
+ *
+ * @param name name of the task, set to null to list all
+ * @param version starting version of the task, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult listTask(final String name, final String version);
+
+ /**
+ * Delete a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult deleteTask(final String name, final String version);
+
+ /**
+ * Validate tasks.
+ *
+ * @param name name of the task, set to null to list all
+ * @param version starting version of the task, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult validateTask(final String name, final String version);
+
+ /**
+ * Create logic for a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param logicFlavour the task logic flavour for the task, set to null to use the default task
+ * logic flavour
+ * @param logic the source code for the logic of the task
+ * @return result of the operation
+ */
+ ApexAPIResult createTaskLogic(final String name, final String version, final String logicFlavour,
+ final String logic);
+
+ /**
+ * Update logic for a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param logicFlavour the task logic flavour for the task, set to null to not update
+ * @param logic the source code for the logic of the task, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updateTaskLogic(final String name, final String version, final String logicFlavour,
+ final String logic);
+
+ /**
+ * List task logic.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to list the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult listTaskLogic(final String name, final String version);
+
+ /**
+ * Delete logic for a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult deleteTaskLogic(final String name, final String version);
+
+ /**
+ * Create a task input field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the input field
+ * @param contextSchemaName name of the input field context schema
+ * @param contextSchemaVersion version of the input field context schema, set to null to use the
+ * latest version
+ * @param optional true if the task field is optional, false otherwise
+ * @return result of the operation
+ */
+ ApexAPIResult createTaskInputField(final String name, final String version, final String fieldName,
+ final String contextSchemaName, final String contextSchemaVersion, boolean optional);
+
+ /**
+ * List task input fields.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName field name of the input field, set to null to list all input fields of the
+ * task
+ * @return result of the operation
+ */
+ ApexAPIResult listTaskInputField(final String name, final String version, final String fieldName);
+
+ /**
+ * Delete a task input field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the input field, set to null to delete all input fields
+ * @return result of the operation
+ */
+ ApexAPIResult deleteTaskInputField(final String name, final String version, final String fieldName);
+
+ /**
+ * Create a task output field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the output field
+ * @param contextSchemaName name of the output field context schema
+ * @param contextSchemaVersion version of the output field context schema, set to null to use
+ * the latest version
+ * @param optional true if the task field is optional, false otherwise
+ * @return result of the operation
+ */
+ ApexAPIResult createTaskOutputField(final String name, final String version, final String fieldName,
+ final String contextSchemaName, final String contextSchemaVersion, boolean optional);
+
+ /**
+ * List task output fields.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName field name of the output field, set to null to list all output fields of the
+ * task
+ * @return result of the operation
+ */
+ ApexAPIResult listTaskOutputField(final String name, final String version, final String fieldName);
+
+ /**
+ * Delete a task output field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the output field, set to null to delete all output fields
+ * @return result of the operation
+ */
+ ApexAPIResult deleteTaskOutputField(final String name, final String version, final String fieldName);
+
+ /**
+ * Create a task parameter.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param parName of the parameter
+ * @param defaultValue of the parameter
+ * @return result of the operation
+ */
+ ApexAPIResult createTaskParameter(final String name, final String version, final String parName,
+ final String defaultValue);
+
+ /**
+ * List task parameters.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param parName name of the parameter, set to null to list all parameters of the task
+ * @return result of the operation
+ */
+ ApexAPIResult listTaskParameter(final String name, final String version, final String parName);
+
+ /**
+ * Delete a task parameter.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param parName of the parameter, set to null to delete all task parameters
+ * @return result of the operation
+ */
+ ApexAPIResult deleteTaskParameter(final String name, final String version, final String parName);
+
+ /**
+ * Create a task context album reference.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param contextAlbumName name of the context album for the context album reference
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult createTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion);
+
+ /**
+ * List task context album references.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to list all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult listTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion);
+
+ /**
+ * Delete a task context album reference.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to delete all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult deleteTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion);
+
+ /*
+ * Policy API Methods
+ */
+
+ /**
+ * Create a policy.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the default version
+ * @param template template used to create the policy, set to null to use the default template
+ * @param firstState the first state of the policy
+ * @param uuid policy UUID, set to null to generate a UUID
+ * @param description policy description, set to null to generate a description
+ * @return result of the operation
+ */
+ ApexAPIResult createPolicy(final String name, final String version, final String template, final String firstState,
+ final String uuid, final String description);
+
+ /**
+ * Update a policy.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param template template used to create the policy, set to null to not update
+ * @param firstState the first state of the policy
+ * @param uuid policy UUID, set to null to not update
+ * @param description policy description, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updatePolicy(final String name, final String version, final String template, final String firstState,
+ final String uuid, final String description);
+
+ /**
+ * List policies.
+ *
+ * @param name name of the policy, set to null to list all
+ * @param version starting version of the policy, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicy(final String name, final String version);
+
+ /**
+ * Delete a policy.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicy(final String name, final String version);
+
+ /**
+ * Validate policies.
+ *
+ * @param name name of the policy, set to null to list all
+ * @param version starting version of the policy, set to null to list all versions
+ * @return result of the operation
+ */
+ ApexAPIResult validatePolicy(final String name, final String version);
+
+ /**
+ * Create a policy state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param triggerName name of the trigger event for this state
+ * @param triggerVersion version of the trigger event for this state, set to null to use the
+ * latest version
+ * @param defaultTaskName the default task name
+ * @param defaltTaskVersion the default task version, set to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult createPolicyState(final String name, final String version, final String stateName,
+ final String triggerName, final String triggerVersion, final String defaultTaskName,
+ final String defaltTaskVersion);
+
+ /**
+ * Update a policy state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param triggerName name of the trigger event for this state, set to null to not update
+ * @param triggerVersion version of the trigger event for this state, set to use latest version
+ * of trigger event
+ * @param defaultTaskName the default task name, set to null to not update
+ * @param defaltTaskVersion the default task version, set to use latest version of default task
+ * @return result of the operation
+ */
+ ApexAPIResult updatePolicyState(final String name, final String version, final String stateName,
+ final String triggerName, final String triggerVersion, final String defaultTaskName,
+ final String defaltTaskVersion);
+
+ /**
+ * List policy states.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state, set to null to list all states of the policy
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicyState(final String name, final String version, final String stateName);
+
+ /**
+ * Delete a policy state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state, set to null to delete all states
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicyState(final String name, final String version, final String stateName);
+
+ /**
+ * Create task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param logicFlavour the task selection logic flavour for the state, set to null to use the
+ * default task logic flavour
+ * @param logic the source code for the logic of the state
+ * @return result of the operation
+ */
+ ApexAPIResult createPolicyStateTaskSelectionLogic(final String name, final String version, final String stateName,
+ final String logicFlavour, final String logic);
+
+ /**
+ * Update task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param logicFlavour the task selection logic flavour for the state, set to null to not update
+ * @param logic the source code for the logic of the state, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updatePolicyStateTaskSelectionLogic(final String name, final String version, final String stateName,
+ final String logicFlavour, final String logic);
+
+ /**
+ * List task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicyStateTaskSelectionLogic(final String name, final String version, final String stateName);
+
+ /**
+ * Delete task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicyStateTaskSelectionLogic(final String name, final String version, final String stateName);
+
+ /**
+ * Create a policy state output.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output
+ * @param eventName name of the output event for this state output
+ * @param eventVersion version of the output event for this state output, set to null to use the
+ * latest version
+ * @param nextState for this state to transition to, set to null if this is the last state that
+ * the policy transitions to on this branch
+ * @return result of the operation
+ */
+ ApexAPIResult createPolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName, final String eventName, final String eventVersion, final String nextState);
+
+ /**
+ * List policy state outputs.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output, set to null to list all outputs of the state
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName);
+
+ /**
+ * Delete a policy state output.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output, set to null to delete all state outputs
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName);
+
+ /**
+ * Create policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @param logicFlavour the policy finalizer logic flavour for the state, set to null to use the
+ * default task logic flavour
+ * @param logic the source code for the logic of the state
+ * @return result of the operation
+ */
+ ApexAPIResult createPolicyStateFinalizerLogic(final String name, final String version, final String stateName,
+ final String finalizerLogicName, final String logicFlavour, final String logic);
+
+ /**
+ * Update policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @param logicFlavour the policy finalizer logic flavour for the state, set to null to not
+ * update
+ * @param logic the source code for the logic of the state, set to null to not update
+ * @return result of the operation
+ */
+ ApexAPIResult updatePolicyStateFinalizerLogic(final String name, final String version, final String stateName,
+ final String finalizerLogicName, final String logicFlavour, final String logic);
+
+ /**
+ * List policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicyStateFinalizerLogic(final String name, final String version, final String stateName,
+ final String finalizerLogicName);
+
+ /**
+ * Delete policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicyStateFinalizerLogic(final String name, final String version, final String stateName,
+ final String finalizerLogicName);
+
+ /**
+ * Create a policy state task reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskLocalName the task local name
+ * @param taskName name of the task
+ * @param taskVersion version of the task, set to null to use the latest version
+ * @param outputType Type of output for the task, must be DIRECT for direct output to a state
+ * output or LOGIC for output to state finalizer logic
+ * @param outputName the name of the state output or state state finalizer logic to handle the
+ * task output
+ * @return result of the operation
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ ApexAPIResult createPolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskLocalName, final String taskName, final String taskVersion, final String outputType,
+ final String outputName);
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * List policy state task references.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskName name of the task, set to null to list all task references
+ * @param taskVersion version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskName, final String taskVersion);
+
+ /**
+ * Delete a policy state task reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskName name of the task, set to null to delete all task references
+ * @param taskVersion version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskName, final String taskVersion);
+
+ /**
+ * Create a policy state context album reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult createPolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion);
+
+ /**
+ * List policy state context album references.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to list all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult listPolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion);
+
+ /**
+ * Delete a policy state context album reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the default version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to delete all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ ApexAPIResult deletePolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion);
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java
new file mode 100644
index 000000000..c9190b8db
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java
@@ -0,0 +1,192 @@
+/*
+ * ============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.modelapi;
+
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+/**
+ * The Interface ApexModelAPI provides functional methods that allow Apex models to be managed.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public interface ApexModel extends ApexEditorAPI {
+ /**
+ * Make a deep copy of the Model.
+ *
+ * @return the result of the operation
+ */
+ ApexModel clone();
+
+ /**
+ * Load an Apex model from a string.
+ *
+ * @param modelString the string with the model
+ * @return the result of the operation
+ */
+ ApexAPIResult loadFromString(String modelString);
+
+ /**
+ * Load an Apex model from a file.
+ *
+ * @param fileName the file name of the file with the model
+ * @return the result of the operation
+ */
+ ApexAPIResult loadFromFile(String fileName);
+
+ /**
+ * Save an Apex model to a file.
+ *
+ * @param fileName the file name
+ * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default JSON format
+ * @return the result of the operation
+ */
+ ApexAPIResult saveToFile(String fileName, boolean xmlFlag);
+
+ /**
+ * Load an Apex model from a database.
+ *
+ * @param modelName the name of the model to load
+ * @param modelVersion the version of the model to load, loads the policy model from the database with this name, if more than one exist, an exception is
+ * thrown
+ * @param daoParameters the parameters to use to access the database over JDBC
+ * @return the result of the operation
+ */
+ ApexAPIResult loadFromDatabase(String modelName, String modelVersion, DAOParameters daoParameters);
+
+ /**
+ * Save an Apex model to a database.
+ *
+ * @param daoParameters the parameters to use to access the database over JDBC
+ * @return the result of the operation
+ */
+ ApexAPIResult saveToDatabase(DAOParameters daoParameters);
+
+ /**
+ * Read an APEX model from a location identified by a URL.
+ *
+ * @param urlString the url string
+ * @return the result of the operation
+ */
+ ApexAPIResult readFromURL(String urlString);
+
+ /**
+ * Write an APEX model to a location identified by a URL.
+ *
+ * @param urlString the URL to read the model from
+ * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default JSON format
+ * @return the result of the operation
+ */
+ ApexAPIResult writeToURL(String urlString, boolean xmlFlag);
+
+ /**
+ * Analyse an Apex model that shows the concept usage references of a policy model.
+ *
+ * @return the result of the operation
+ */
+ ApexAPIResult analyse();
+
+ /**
+ * Validate an Apex model, checking all concepts and references in the model.
+ *
+ * @return the result of the operation
+ */
+ ApexAPIResult validate();
+
+ /**
+ * Compare to Apex models, returning the differences between the models.
+ *
+ * @param otherModelFileName the file name of the other model
+ * @param diffsOnly only returns differences between the model when set
+ * @param keysOnly only returns the keys that are different when set, when not set values are also returned
+ * @return the result of the operation
+ */
+ ApexAPIResult compare(String otherModelFileName, boolean diffsOnly, boolean keysOnly);
+
+ /**
+ * Compare two Apex models, returning the differences between the models.
+ *
+ * @param otherModelString the other model as a string
+ * @param diffsOnly only returns differences between the model when set
+ * @param keysOnly only returns the keys that are different when set, when not set values are also returned
+ * @return the result of the operation
+ */
+ ApexAPIResult compareWithString(String otherModelString, boolean diffsOnly, boolean keysOnly);
+
+ /**
+ * Split out a sub model from an Apex model that contains a given subset of the policies in the original model.
+ *
+ * @param targetModelName the file name of the target model in which to store the model split out from the original model
+ * @param splitOutPolicies the policies form the original model to include in the split out model, specified as a comma delimited list of policy names
+ * @return the result of the operation
+ */
+ ApexAPIResult split(String targetModelName, String splitOutPolicies);
+
+ /**
+ * Split out a sub model from an Apex model that contains a given subset of the policies in the original model, return the split model in the result as a
+ * string.
+ *
+ * @param splitOutPolicies the policies form the original model to include in the split out model, specified as a comma delimited list of policy names
+ * @return the result of the operation
+ */
+ ApexAPIResult split(String splitOutPolicies);
+
+ /**
+ * Merge two Apex models together.
+ *
+ * @param mergeInModelName the file name of the model to merge into the current model
+ * @param keepOriginal if this flag is set to true, if a concept exists in both models, the original model copy of that concept is kept, if the flag is set
+ * to false, then the copy of the concept from the mergeInModel overwrites the concept in the original model
+ * @return the result of the operation
+ */
+ ApexAPIResult merge(String mergeInModelName, boolean keepOriginal);
+
+ /**
+ * Merge two Apex models together.
+ *
+ * @param otherModelString the model to merge as a string
+ * @param keepOriginal if this flag is set to true, if a concept exists in both models, the original model copy of that concept is kept, if the flag is set
+ * to false, then the copy of the concept from the mergeInModel overwrites the concept in the original model
+ * @return the result of the operation
+ */
+ ApexAPIResult mergeWithString(String otherModelString, boolean keepOriginal);
+
+ /**
+ * Get the raw policy model being used by this model.
+ *
+ * @return the policy model
+ */
+ AxPolicyModel getPolicyModel();
+
+ /**
+ * Set the raw policy model being used by this model.
+ *
+ * @param policyModel the policy model
+ */
+ void setPolicyModel(AxPolicyModel policyModel);
+
+ /**
+ * Builds the raw policy model being used by this model.
+ *
+ * @return the policy model
+ */
+ AxPolicyModel build();
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java
new file mode 100644
index 000000000..ad0f0b4fa
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java
@@ -0,0 +1,78 @@
+/*-
+ * ============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.modelapi;
+
+import java.util.Properties;
+
+import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
+
+/**
+ * A factory for creating ApexModel objects using the Apex Model implementation.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexModelFactory {
+
+ /**
+ * Creates a new ApexModel object from its implementation.
+ *
+ * @param apexProperties default values and other configuration information for the apex model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ * @return the apex model
+ */
+ public ApexModel createApexModel(final Properties apexProperties, final boolean jsonMode) {
+ return new ApexModelImpl(setDefaultPropertyValues(apexProperties), jsonMode);
+ }
+
+ /**
+ * Sets default property values for Apex properties that must be set for the Apex model
+ * implementation if those properties are not already set.
+ *
+ * @param apexPropertiesIn the default property values
+ * @return the properties
+ */
+ private Properties setDefaultPropertyValues(final Properties apexPropertiesIn) {
+ Properties apexProperties = apexPropertiesIn;
+
+ if (apexProperties == null) {
+ apexProperties = new Properties();
+ }
+
+ if (apexProperties.getProperty("DEFAULT_CONCEPT_VERSION") == null) {
+ apexProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
+ }
+ if (apexProperties.getProperty("DEFAULT_EVENT_NAMESPACE") == null) {
+ apexProperties.setProperty("DEFAULT_EVENT_NAMESPACE", "org.onap.policy.apex");
+ }
+ if (apexProperties.getProperty("DEFAULT_EVENT_SOURCE") == null) {
+ apexProperties.setProperty("DEFAULT_EVENT_SOURCE", "source");
+ }
+ if (apexProperties.getProperty("DEFAULT_EVENT_TARGET") == null) {
+ apexProperties.setProperty("DEFAULT_EVENT_TARGET", "target");
+ }
+ if (apexProperties.getProperty("DEFAULT_POLICY_TEMPLATE") == null) {
+ apexProperties.setProperty("DEFAULT_POLICY_TEMPLATE", "FREEFORM");
+ }
+
+ return apexProperties;
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java
new file mode 100644
index 000000000..5303e9502
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java
@@ -0,0 +1,1239 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+/**
+ * This class is an implementation of a facade on an Apex model for editors of Apex models.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public final class ApexModelImpl implements ApexModel {
+ private static final int HASH_CODE_PRIME_0 = 31;
+ private static final int HASH_CODE_PRIME_1 = 1231;
+ private static final int HASH_CODE_PRIME_2 = 1237;
+
+ // The policy model being acted upon
+ private AxPolicyModel policyModel = new AxPolicyModel();
+
+ // The file name for the loaded file
+ private String fileName = null;
+
+ // Facade classes for working towards the real Apex model
+ // @formatter:off
+ private ModelFacade modelFacade;
+ private KeyInformationFacade keyInformationFacade;
+ private ContextSchemaFacade contextSchemaFacade;
+ private EventFacade eventFacade;
+ private ContextAlbumFacade contextAlbumFacade;
+ private TaskFacade taskFacade;
+ private PolicyFacade policyFacade;
+ private ModelHandlerFacade modelHandlerFacade;
+ // @formatter:on
+
+ private Properties apexProperties;
+ private boolean jsonMode;
+
+ /**
+ * Create an implementation of the Apex editor and model APIs.
+ *
+ * @param apexProperties The properties to use for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public ApexModelImpl(final Properties apexProperties, final boolean jsonMode) {
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ // @formatter:off
+ this.modelFacade = new ModelFacade(this, apexProperties, jsonMode);
+ this.keyInformationFacade = new KeyInformationFacade(this, apexProperties, jsonMode);
+ this.contextSchemaFacade = new ContextSchemaFacade(this, apexProperties, jsonMode);
+ this.eventFacade = new EventFacade(this, apexProperties, jsonMode);
+ this.contextAlbumFacade = new ContextAlbumFacade(this, apexProperties, jsonMode);
+ this.taskFacade = new TaskFacade(this, apexProperties, jsonMode);
+ this.policyFacade = new PolicyFacade(this, apexProperties, jsonMode);
+ this.modelHandlerFacade = new ModelHandlerFacade(this, apexProperties, jsonMode);
+ // @formatter:on
+ }
+
+ /**
+ * Constructor, prevents this class being sub-classed.
+ */
+ private ApexModelImpl() {}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#clone()
+ */
+ @Override
+ public ApexModel clone() {
+ ApexModelImpl ret = new ApexModelImpl();
+ // @formatter:off
+ ret.policyModel = new AxPolicyModel(policyModel);
+ ret.fileName = this.fileName;
+ ret.apexProperties = this.apexProperties;
+ ret.jsonMode = this.jsonMode;
+ ret.modelFacade = new ModelFacade(ret, this.apexProperties, this.jsonMode);
+ ret.keyInformationFacade = new KeyInformationFacade(ret, this.apexProperties, this.jsonMode);
+ ret.contextSchemaFacade = new ContextSchemaFacade(ret, this.apexProperties, this.jsonMode);
+ ret.eventFacade = new EventFacade(ret, this.apexProperties, this.jsonMode);
+ ret.contextAlbumFacade = new ContextAlbumFacade(ret, this.apexProperties, this.jsonMode);
+ ret.taskFacade = new TaskFacade(ret, this.apexProperties, this.jsonMode);
+ ret.policyFacade = new PolicyFacade(ret, this.apexProperties, this.jsonMode);
+ ret.modelHandlerFacade = new ModelHandlerFacade(ret, this.apexProperties, this.jsonMode);
+ // @formatter:on
+
+ return ret;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#createModel(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createModel(final String name, final String version, final String uuid,
+ final String description) {
+ return modelFacade.createModel(name, version, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#updateModel(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updateModel(final String name, final String version, final String uuid,
+ final String description) {
+ return modelFacade.updateModel(name, version, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexEditorAPI#getModelKey()
+ */
+ @Override
+ public ApexAPIResult getModelKey() {
+ return modelFacade.getModelKey();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listModel()
+ */
+ @Override
+ public ApexAPIResult listModel() {
+ return modelFacade.listModel();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteModel()
+ */
+ @Override
+ public ApexAPIResult deleteModel() {
+ return modelFacade.deleteModel();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createKeyInformation(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createKeyInformation(final String name, final String version, final String uuid,
+ final String description) {
+ return keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updateKeyInformation(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updateKeyInformation(final String name, final String version, final String uuid,
+ final String description) {
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listKeyInformation(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listKeyInformation(final String name, final String version) {
+ return keyInformationFacade.listKeyInformation(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteKeyInformation(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteKeyInformation(final String name, final String version) {
+ return keyInformationFacade.deleteKeyInformation(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#validateKeyInformation(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult validateKeyInformation(final String name, final String version) {
+ return keyInformationFacade.validateKeyInformation(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createContextSchema(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createContextSchema(final String name, final String version, final String schemaFlavour,
+ final String schemaDefinition, final String uuid, final String description) {
+ return contextSchemaFacade.createContextSchema(name, version, schemaFlavour, schemaDefinition, uuid,
+ description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updateContextSchema(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updateContextSchema(final String name, final String version, final String schemaFlavour,
+ final String schemaDefinition, final String uuid, final String description) {
+ return contextSchemaFacade.updateContextSchema(name, version, schemaFlavour, schemaDefinition, uuid,
+ description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listContextSchemas(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listContextSchemas(final String name, final String version) {
+ return contextSchemaFacade.listContextSchemas(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteContextSchema(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteContextSchema(final String name, final String version) {
+ return contextSchemaFacade.deleteContextSchema(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#validateContextSchemas(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult validateContextSchemas(final String name, final String version) {
+ return contextSchemaFacade.validateContextSchemas(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createEvent(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createEvent(final String name, final String version, final String nameSpace,
+ final String source, final String target, final String uuid, final String description) {
+ return eventFacade.createEvent(name, version, nameSpace, source, target, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updateEvent(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updateEvent(final String name, final String version, final String nameSpace,
+ final String source, final String target, final String uuid, final String description) {
+ return eventFacade.updateEvent(name, version, nameSpace, source, target, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listEvent(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listEvent(final String name, final String version) {
+ return eventFacade.listEvent(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteEvent(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteEvent(final String name, final String version) {
+ return eventFacade.deleteEvent(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#validateEvent(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult validateEvent(final String name, final String version) {
+ return eventFacade.validateEvent(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#createEventPar(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean)
+ */
+ @Override
+ public ApexAPIResult createEventPar(final String name, final String version, final String parName,
+ final String contextSchemaName, final String contextSchemaVersion, final boolean optional) {
+ return eventFacade.createEventPar(name, version, parName, contextSchemaName, contextSchemaVersion, optional);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listEventPar(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listEventPar(final String name, final String version, final String parName) {
+ return eventFacade.listEventPar(name, version, parName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteEventPar(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteEventPar(final String name, final String version, final String parName) {
+ return eventFacade.deleteEventPar(name, version, parName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#createContextAlbum(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ public ApexAPIResult createContextAlbum(final String name, final String version, final String scope,
+ final String writable, final String contextSchemaName, final String contextSchemaVersion, final String uuid,
+ final String description) {
+ return contextAlbumFacade.createContextAlbum(name, version, scope, writable, contextSchemaName,
+ contextSchemaVersion, uuid, description);
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.modelapi.ApexEditorAPI#updateContextAlbum(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ @Override
+ public ApexAPIResult updateContextAlbum(final String name, final String version, final String scope,
+ final String writable, final String contextSchemaName, final String contextSchemaVersion, final String uuid,
+ final String description) {
+ return contextAlbumFacade.updateContextAlbum(name, version, scope, writable, contextSchemaName,
+ contextSchemaVersion, uuid, description);
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listContextAlbum(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listContextAlbum(final String name, final String version) {
+ return contextAlbumFacade.listContextAlbum(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteContextAlbum(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteContextAlbum(final String name, final String version) {
+ return contextAlbumFacade.deleteContextAlbum(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#validateContextAlbum(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult validateContextAlbum(final String name, final String version) {
+ return contextAlbumFacade.validateContextAlbum(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createTask(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createTask(final String name, final String version, final String uuid,
+ final String description) {
+ return taskFacade.createTask(name, version, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updateTask(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updateTask(final String name, final String version, final String uuid,
+ final String description) {
+ return taskFacade.updateTask(name, version, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listTask(java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listTask(final String name, final String version) {
+ return taskFacade.listTask(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteTask(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteTask(final String name, final String version) {
+ return taskFacade.deleteTask(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#validateTask(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult validateTask(final String name, final String version) {
+ return taskFacade.validateTask(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createTaskLogic(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createTaskLogic(final String name, final String version, final String logicFlavour,
+ final String logic) {
+ return taskFacade.createTaskLogic(name, version, logicFlavour, logic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updateTaskLogic(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updateTaskLogic(final String name, final String version, final String logicFlavour,
+ final String logic) {
+ return taskFacade.updateTaskLogic(name, version, logicFlavour, logic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listTaskLogic(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listTaskLogic(final String name, final String version) {
+ return taskFacade.listTaskLogic(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteTaskLogic(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteTaskLogic(final String name, final String version) {
+ return taskFacade.deleteTaskLogic(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createTaskInputField(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.boolean)
+ */
+ @Override
+ public ApexAPIResult createTaskInputField(final String name, final String version, final String fieldName,
+ final String dataTypeName, final String dataTypeVersion, final boolean optional) {
+ return taskFacade.createTaskInputField(name, version, fieldName, dataTypeName, dataTypeVersion, optional);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listTaskInputField(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listTaskInputField(final String name, final String version, final String fieldName) {
+ return taskFacade.listTaskInputField(name, version, fieldName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteTaskInputField(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteTaskInputField(final String name, final String version, final String fieldName) {
+ return taskFacade.deleteTaskInputField(name, version, fieldName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createTaskOutputField(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.boolean)
+ */
+ @Override
+ public ApexAPIResult createTaskOutputField(final String name, final String version, final String fieldName,
+ final String dataTypeName, final String dataTypeVersion, final boolean optional) {
+ return taskFacade.createTaskOutputField(name, version, fieldName, dataTypeName, dataTypeVersion, optional);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listTaskOutputField(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listTaskOutputField(final String name, final String version, final String fieldName) {
+ return taskFacade.listTaskOutputField(name, version, fieldName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteTaskOutputField(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteTaskOutputField(final String name, final String version, final String fieldName) {
+ return taskFacade.deleteTaskOutputField(name, version, fieldName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createTaskParameter(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createTaskParameter(final String name, final String version, final String parName,
+ final String defaultValue) {
+ return taskFacade.createTaskParameter(name, version, parName, defaultValue);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listTaskParameter(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listTaskParameter(final String name, final String version, final String parName) {
+ return taskFacade.listTaskParameter(name, version, parName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteTaskParameter(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteTaskParameter(final String name, final String version, final String parName) {
+ return taskFacade.deleteTaskParameter(name, version, parName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createTaskContextRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion) {
+ return taskFacade.createTaskContextRef(name, version, contextAlbumName, contextAlbumVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listTaskContextRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion) {
+ return taskFacade.listTaskContextRef(name, version, contextAlbumName, contextAlbumVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deleteTaskContextRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deleteTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion) {
+ return taskFacade.deleteTaskContextRef(name, version, contextAlbumName, contextAlbumVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createPolicy(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createPolicy(final String name, final String version, final String template,
+ final String firstState, final String uuid, final String description) {
+ return policyFacade.createPolicy(name, version, template, firstState, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updatePolicy(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updatePolicy(final String name, final String version, final String template,
+ final String firstState, final String uuid, final String description) {
+ return policyFacade.updatePolicy(name, version, template, firstState, uuid, description);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listPolicy(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicy(final String name, final String version) {
+ return policyFacade.listPolicy(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deletePolicy(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicy(final String name, final String version) {
+ return policyFacade.deletePolicy(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#validatePolicy(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult validatePolicy(final String name, final String version) {
+ return policyFacade.validatePolicy(name, version);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createPolicyState(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createPolicyState(final String name, final String version, final String stateName,
+ final String triggerName, final String triggerVersion, final String defaultTaskName,
+ final String defaltTaskVersion) {
+ return policyFacade.createPolicyState(name, version, stateName, triggerName, triggerVersion, defaultTaskName,
+ defaltTaskVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#updatePolicyState(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updatePolicyState(final String name, final String version, final String stateName,
+ final String triggerName, final String triggerVersion, final String defaultTaskName,
+ final String defaltTaskVersion) {
+ return policyFacade.updatePolicyState(name, version, stateName, triggerName, triggerVersion, defaultTaskName,
+ defaltTaskVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listPolicyState(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicyState(final String name, final String version, final String stateName) {
+ return policyFacade.listPolicyState(name, version, stateName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deletePolicyState(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicyState(final String name, final String version, final String stateName) {
+ return policyFacade.deletePolicyState(name, version, stateName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.auth.api.ApexEditorAPI#createPolicyStateTaskSelectionLogic(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createPolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName, final String logicFlavour, final String logic) {
+ return policyFacade.createPolicyStateTaskSelectionLogic(name, version, stateName, logicFlavour, logic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.auth.api.ApexEditorAPI#updatePolicyStateTaskSelectionLogic(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updatePolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName, final String logicFlavour, final String logic) {
+ return policyFacade.updatePolicyStateTaskSelectionLogic(name, version, stateName, logicFlavour, logic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listPolicyStateTaskSelectionLogic(java.lang.
+ * String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName) {
+ return policyFacade.listPolicyStateTaskSelectionLogic(name, version, stateName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.auth.api.ApexEditorAPI#deletePolicyStateTaskSelectionLogic(java.lang.
+ * String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName) {
+ return policyFacade.deletePolicyStateTaskSelectionLogic(name, version, stateName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#createPolicyStateOutput(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createPolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName, final String eventName, final String eventVersion, final String nextState) {
+ return policyFacade.createPolicyStateOutput(name, version, stateName, outputName, eventName, eventVersion,
+ nextState);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listPolicyStateOutput(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName) {
+ return policyFacade.listPolicyStateOutput(name, version, stateName, outputName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deletePolicyStateOutput(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName) {
+ return policyFacade.deletePolicyStateOutput(name, version, stateName, outputName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.modelapi.ApexEditorAPI#createPolicyStateFinalizerLogic(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createPolicyStateFinalizerLogic(final String name, final String version,
+ final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) {
+ return policyFacade.createPolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName, logicFlavour,
+ logic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.modelapi.ApexEditorAPI#updatePolicyStateFinalizerLogic(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public ApexAPIResult updatePolicyStateFinalizerLogic(final String name, final String version,
+ final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) {
+ return policyFacade.updatePolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName, logicFlavour,
+ logic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.modelapi.ApexEditorAPI#listPolicyStateFinalizerLogic(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicyStateFinalizerLogic(final String name, final String version, final String stateName,
+ final String finalizerLogicName) {
+ return policyFacade.listPolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.modelapi.ApexEditorAPI#deletePolicyStateFinalizerLogic(java.lang.
+ * String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicyStateFinalizerLogic(final String name, final String version,
+ final String stateName, final String finalizerLogicName) {
+ return policyFacade.deletePolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.modelapi.ApexEditorAPI#createPolicyStateTaskRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ @Override
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ public ApexAPIResult createPolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskLocalName, final String taskName, final String taskVersion, final String outputType,
+ final String outputName) {
+ return policyFacade.createPolicyStateTaskRef(name, version, stateName, taskLocalName, taskName, taskVersion,
+ outputType, outputName);
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listPolicyStateTaskRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskName, final String taskVersion) {
+ return policyFacade.listPolicyStateTaskRef(name, version, stateName, taskName, taskVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#deletePolicyStateTaskRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskName, final String taskVersion) {
+ return policyFacade.deletePolicyStateTaskRef(name, version, stateName, taskName, taskVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.auth.api.ApexEditorAPI#createPolicyStateContextRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult createPolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion) {
+ return policyFacade.createPolicyStateContextRef(name, version, stateName, contextAlbumName,
+ contextAlbumVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexEditorAPI#listPolicyStateContextRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult listPolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion) {
+ return policyFacade.listPolicyStateContextRef(name, version, stateName, contextAlbumName, contextAlbumVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.auth.api.ApexEditorAPI#deletePolicyStateContextRef(java.lang.String,
+ * java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult deletePolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion) {
+ return policyFacade.deletePolicyStateContextRef(name, version, stateName, contextAlbumName,
+ contextAlbumVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#loadFromString(java.lang.String)
+ */
+ @Override
+ public ApexAPIResult loadFromString(final String modelString) {
+ return modelHandlerFacade.loadFromString(modelString);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#loadFromFile(java.lang.String)
+ */
+ @Override
+ // CHECKSTYLE:OFF: checkstyle:HiddenField
+ public ApexAPIResult loadFromFile(final String fileName) {
+ this.fileName = fileName;
+ return modelHandlerFacade.loadFromFile(fileName);
+ }
+ // CHECKSTYLE:ON: checkstyle:HiddenField
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#saveToFile(java.lang.String, boolean)
+ */
+ @Override
+ public ApexAPIResult saveToFile(final String saveFileName, final boolean xmlFlag) {
+ if (saveFileName == null) {
+ return modelHandlerFacade.saveToFile(fileName, xmlFlag);
+ } else {
+ return modelHandlerFacade.saveToFile(saveFileName, xmlFlag);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.modelapi.ApexModel#loadFromDatabase(java.lang.String,
+ * java.lang.String, org.onap.policy.apex.model.basicmodel.dao.DAOParameters)
+ */
+ @Override
+ public ApexAPIResult loadFromDatabase(final String modelName, final String modelVersion,
+ final DAOParameters daoParameters) {
+ return modelHandlerFacade.loadFromDatabase(modelName, modelVersion, daoParameters);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.modelapi.ApexModel#saveToDatabase(org.onap.policy.apex.model.
+ * basicmodel. dao.DAOParameters)
+ */
+ @Override
+ public ApexAPIResult saveToDatabase(final DAOParameters daoParameters) {
+ return modelHandlerFacade.saveToDatabase(daoParameters);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#readFromURL(java.lang.String)
+ */
+ @Override
+ public ApexAPIResult readFromURL(final String urlString) {
+ return modelHandlerFacade.readFromURL(urlString);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#writeToURL(java.lang.String, boolean)
+ */
+ @Override
+ public ApexAPIResult writeToURL(final String urlString, final boolean xmlFlag) {
+ return modelHandlerFacade.writeToURL(urlString, xmlFlag);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#analyse()
+ */
+ @Override
+ public ApexAPIResult analyse() {
+ return modelHandlerFacade.analyse();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#validate()
+ */
+ @Override
+ public ApexAPIResult validate() {
+ return modelHandlerFacade.validate();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#compare(java.lang.String, boolean, boolean)
+ */
+ @Override
+ public ApexAPIResult compare(final String otherModelFileName, final boolean diffsOnly, final boolean keysOnly) {
+ return modelHandlerFacade.compare(otherModelFileName, diffsOnly, keysOnly);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#compareWithString(java.lang.String,
+ * boolean, boolean)
+ */
+ @Override
+ public ApexAPIResult compareWithString(final String otherModelString, final boolean diffsOnly,
+ final boolean keysOnly) {
+ return modelHandlerFacade.compareWithString(otherModelString, diffsOnly, keysOnly);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#split(java.lang.String, java.lang.String)
+ */
+ @Override
+ public ApexAPIResult split(final String targetModelFileName, final String splitOutPolicies) {
+ return modelHandlerFacade.split(targetModelFileName, splitOutPolicies);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#split(java.lang.String)
+ */
+ @Override
+ public ApexAPIResult split(final String splitOutPolicies) {
+ return modelHandlerFacade.split(splitOutPolicies);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#merge(java.lang.String, boolean)
+ */
+ @Override
+ public ApexAPIResult merge(final String mergeInModelFileName, final boolean keepOriginal) {
+ return modelHandlerFacade.merge(mergeInModelFileName, keepOriginal);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#mergeWithString(java.lang.String, boolean)
+ */
+ @Override
+ public ApexAPIResult mergeWithString(final String otherModelString, final boolean keepOriginal) {
+ return modelHandlerFacade.mergeWithString(otherModelString, keepOriginal);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = HASH_CODE_PRIME_0;
+ int result = 1;
+ result = prime * result + ((apexProperties == null) ? 0 : apexProperties.hashCode());
+ result = prime * result + ((contextAlbumFacade == null) ? 0 : contextAlbumFacade.hashCode());
+ result = prime * result + ((contextSchemaFacade == null) ? 0 : contextSchemaFacade.hashCode());
+ result = prime * result + ((eventFacade == null) ? 0 : eventFacade.hashCode());
+ result = prime * result + ((fileName == null) ? 0 : fileName.hashCode());
+ result = prime * result + (jsonMode ? HASH_CODE_PRIME_1 : HASH_CODE_PRIME_2);
+ result = prime * result + ((keyInformationFacade == null) ? 0 : keyInformationFacade.hashCode());
+ result = prime * result + ((modelFacade == null) ? 0 : modelFacade.hashCode());
+ result = prime * result + ((modelHandlerFacade == null) ? 0 : modelHandlerFacade.hashCode());
+ result = prime * result + ((policyFacade == null) ? 0 : policyFacade.hashCode());
+ result = prime * result + ((policyModel == null) ? 0 : policyModel.hashCode());
+ result = prime * result + ((taskFacade == null) ? 0 : taskFacade.hashCode());
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.auth.api.ApexModel#getModel()
+ */
+ @Override
+ public AxPolicyModel getPolicyModel() {
+ return policyModel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.auth.api.ApexModel#setPolicyModel(org.onap.policy.apex.core.policymodel.
+ * concepts.AxPolicyModel)
+ */
+ @Override
+ public void setPolicyModel(final AxPolicyModel policyModel) {
+ this.policyModel = policyModel;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.core.modelapi.ApexModel#build()
+ */
+ @Override
+ public AxPolicyModel build() {
+ return policyModel;
+ }
+
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java
new file mode 100644
index 000000000..57d05025a
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java
@@ -0,0 +1,282 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+import java.util.Set;
+
+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.ApexModelStringWriter;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+
+/**
+ * This class acts as a facade for operations towards a policy model for context album operations.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ContextAlbumFacade {
+ private static final String CONCEPT = "concept ";
+ private static final String CONCEPT_S = "concept(s) ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String DO_ES_NOT_EXIST = " do(es) not exist";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // Facade classes for working towards the real Apex model
+ private final KeyInformationFacade keyInformationFacade;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor that creates a context album facade for the Apex Model API.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public ContextAlbumFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode);
+ }
+
+ /**
+ * Create a context album.
+ *
+ * @param name name of the context album
+ * @param version version of the context album, set to null to use the default version
+ * @param scope of the context album
+ * @param writable "true" or "t" if the context album is writable, set to null or any other
+ * value for a read-only album
+ * @param contextSchemaName name of the parameter context schema
+ * @param contextSchemaVersion version of the parameter context schema, set to null to use the
+ * latest version
+ * @param uuid context album UUID, set to null to generate a UUID
+ * @param description context album description, set to null to generate a description
+ * @return result of the operation
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ public ApexAPIResult createContextAlbum(final String name, final String version, final String scope,
+ final String writable, final String contextSchemaName, final String contextSchemaVersion, final String uuid,
+ final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION"));
+ }
+
+ if (apexModel.getPolicyModel().getAlbums().getAlbumsMap().containsKey(key)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + key.getID() + " already exists");
+ }
+
+ final AxContextSchema schema =
+ apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion);
+ if (schema == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST);
+ }
+
+ final AxContextAlbum contextAlbum = new AxContextAlbum(key);
+ contextAlbum.setScope(scope);
+ contextAlbum.setItemSchema(schema.getKey());
+
+ if (writable != null
+ && (writable.trim().equalsIgnoreCase("true") || writable.trim().equalsIgnoreCase("t"))) {
+ contextAlbum.setWritable(true);
+ } else {
+ contextAlbum.setWritable(false);
+ }
+
+ apexModel.getPolicyModel().getAlbums().getAlbumsMap().put(key, contextAlbum);
+
+ if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) {
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } else {
+ return keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * Update a context album.
+ *
+ * @param name name of the context album
+ * @param version version of the context album, set to null to use the default version
+ * @param scope of the context album
+ * @param writable "true" or "t" if the context album is writable, set to null or any other
+ * value for a read-only album
+ * @param contextSchemaName name of the parameter context schema
+ * @param contextSchemaVersion version of the parameter context schema, set to null to use the
+ * latest version
+ * @param uuid context album UUID, set to null to generate a UUID
+ * @param description context album description, set to null to generate a description
+ * @return result of the operation
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ public ApexAPIResult updateContextAlbum(final String name, final String version, final String scope,
+ final String writable, final String contextSchemaName, final String contextSchemaVersion, final String uuid,
+ final String description) {
+ try {
+ final AxContextAlbum contextAlbum = apexModel.getPolicyModel().getAlbums().get(name, version);
+ if (contextAlbum == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (scope != null) {
+ contextAlbum.setScope(scope);
+ }
+ if (writable != null) {
+ if (writable.trim().equalsIgnoreCase("true") || writable.trim().equalsIgnoreCase("t")) {
+ contextAlbum.setWritable(true);
+ } else {
+ contextAlbum.setWritable(false);
+ }
+ }
+
+ if (contextSchemaName != null) {
+ final AxContextSchema schema =
+ apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion);
+ if (schema == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST);
+ }
+ contextAlbum.setItemSchema(schema.getKey());
+ }
+
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * List context albums.
+ *
+ * @param name name of the context album, set to null to list all
+ * @param version starting version of the context album, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult listContextAlbum(final String name, final String version) {
+ try {
+ final Set<AxContextAlbum> contextAlbumSet = apexModel.getPolicyModel().getAlbums().getAll(name, version);
+ if (name != null && contextAlbumSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxContextAlbum contextAlbum : contextAlbumSet) {
+ result.addMessage(new ApexModelStringWriter<AxContextAlbum>(false).writeString(contextAlbum,
+ AxContextAlbum.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a context album.
+ *
+ * @param name name of the context album
+ * @param version version of the context album, set to null to delete versions
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteContextAlbum(final String name, final String version) {
+ try {
+ if (version != null) {
+ final AxArtifactKey key = new AxArtifactKey(name, version);
+ if (apexModel.getPolicyModel().getAlbums().getAlbumsMap().remove(key) != null) {
+ return new ApexAPIResult();
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + key.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ final Set<AxContextAlbum> contextAlbumSet = apexModel.getPolicyModel().getAlbums().getAll(name, version);
+ if (contextAlbumSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxContextAlbum contextAlbum : contextAlbumSet) {
+ result.addMessage(new ApexModelStringWriter<AxContextAlbum>(false).writeString(contextAlbum,
+ AxContextAlbum.class, jsonMode));
+ apexModel.getPolicyModel().getAlbums().getAlbumsMap().remove(contextAlbum.getKey());
+ keyInformationFacade.deleteKeyInformation(name, version);
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Validate context albums.
+ *
+ * @param name name of the context album, set to null to list all
+ * @param version starting version of the context album, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult validateContextAlbum(final String name, final String version) {
+ try {
+ final Set<AxContextAlbum> contextAlbumSet = apexModel.getPolicyModel().getAlbums().getAll(name, version);
+ if (contextAlbumSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxContextAlbum contextAlbum : contextAlbumSet) {
+ final AxValidationResult validationResult = contextAlbum.validate(new AxValidationResult());
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(contextAlbum.getKey(),
+ AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java
new file mode 100644
index 000000000..3f7f75652
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java
@@ -0,0 +1,240 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+import java.util.Set;
+
+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.ApexModelStringWriter;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class acts as a facade for operations towards a policy model for context schema operations.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ContextSchemaFacade {
+ private static final String CONCEPT = "concept ";
+ private static final String CONCEPT_S = "concept(s) ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String DO_ES_NOT_EXIST = " do(es) not exist";
+ private static final String ALREADY_EXISTS = " already exists";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // Facade classes for working towards the real Apex model
+ private final KeyInformationFacade keyInformationFacade;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor to create the context schema facade for the Model API.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise set to false
+ */
+ public ContextSchemaFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode);
+ }
+
+ /**
+ * Create a context schema.
+ *
+ * @param name name of the context schema
+ * @param version version of the context schema, set to null to use the default version
+ * @param schemaFlavour a string identifying the flavour of this context schema
+ * @param schemaDefinition a string containing the definition of this context schema
+ * @param uuid context schema UUID, set to null to generate a UUID
+ * @param description context schema description, set to null to generate a description
+ * @return result of the operation
+ */
+ public ApexAPIResult createContextSchema(final String name, final String version, final String schemaFlavour, final String schemaDefinition,
+ final String uuid, final String description) {
+ try {
+ Assertions.argumentNotNull(schemaFlavour, "schemaFlavour may not be null");
+
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ }
+ else {
+ key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION"));
+ }
+
+ if (apexModel.getPolicyModel().getSchemas().getSchemasMap().containsKey(key)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, CONCEPT + key.getID() + ALREADY_EXISTS);
+ }
+
+ apexModel.getPolicyModel().getSchemas().getSchemasMap().put(key, new AxContextSchema(key, schemaFlavour, schemaDefinition));
+
+ if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) {
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ }
+ else {
+ return keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ }
+ }
+ catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update a context schema.
+ *
+ * @param name name of the context schema
+ * @param version version of the context schema, set to null to update the latest version
+ * @param schemaFlavour a string identifying the flavour of this context schema
+ * @param schemaDefinition a string containing the definition of this context schema
+ * @param uuid context schema UUID, set to null to not update
+ * @param description context schema description, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updateContextSchema(final String name, final String version, final String schemaFlavour, final String schemaDefinition,
+ final String uuid, final String description) {
+ try {
+ final AxContextSchema schema = apexModel.getPolicyModel().getSchemas().get(name, version);
+ if (schema == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (schemaFlavour != null) {
+ schema.setSchemaFlavour(schemaFlavour);
+ }
+
+ if (schemaDefinition != null) {
+ schema.setSchema(schemaDefinition);
+ }
+
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ }
+ catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List context schemas.
+ *
+ * @param name name of the context schema, set to null to list all
+ * @param version starting version of the context schema, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult listContextSchemas(final String name, final String version) {
+ try {
+ final Set<AxContextSchema> schemaSet = apexModel.getPolicyModel().getSchemas().getAll(name, version);
+ if (name != null && schemaSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxContextSchema schema : schemaSet) {
+ result.addMessage(new ApexModelStringWriter<AxContextSchema>(false).writeString(schema, AxContextSchema.class, jsonMode));
+ }
+ return result;
+ }
+ catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a context schema.
+ *
+ * @param name name of the context schema
+ * @param version version of the context schema, set to null to delete all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteContextSchema(final String name, final String version) {
+ try {
+ if (version != null) {
+ final AxArtifactKey key = new AxArtifactKey(name, version);
+ final AxContextSchema removedSchema = apexModel.getPolicyModel().getSchemas().getSchemasMap().remove(key);
+ if (removedSchema != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxContextSchema>(false).writeString(removedSchema, AxContextSchema.class, jsonMode));
+ }
+ else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT + key.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ final Set<AxContextSchema> schemaSet = apexModel.getPolicyModel().getSchemas().getAll(name, version);
+ if (schemaSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxContextSchema schema : schemaSet) {
+ result.addMessage(new ApexModelStringWriter<AxContextSchema>(false).writeString(schema, AxContextSchema.class, jsonMode));
+ apexModel.getPolicyModel().getSchemas().getSchemasMap().remove(schema.getKey());
+ keyInformationFacade.deleteKeyInformation(name, version);
+ }
+ return result;
+ }
+ catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Validate context schemas.
+ *
+ * @param name name of the context schema, set to null to list all
+ * @param version starting version of the context schema, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult validateContextSchemas(final String name, final String version) {
+ try {
+ final Set<AxContextSchema> schemaSet = apexModel.getPolicyModel().getSchemas().getAll(name, version);
+ if (schemaSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxContextSchema schema : schemaSet) {
+ final AxValidationResult validationResult = schema.validate(new AxValidationResult());
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(schema.getKey(), AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ }
+ return result;
+ }
+ catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java
new file mode 100644
index 000000000..095d4f9f4
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java
@@ -0,0 +1,385 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+import java.util.Set;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class acts as a facade for operations towards a policy model for event operations
+ * operations.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class EventFacade {
+ private static final String CONCEPT = "concept ";
+ private static final String CONCEPT_S = "concept(s) ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String DO_ES_NOT_EXIST = " do(es) not exist";
+ private static final String ALREADY_EXISTS = " already exists";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // Facade classes for working towards the real Apex model
+ private final KeyInformationFacade keyInformationFacade;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor to create an event facade for the Model API.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public EventFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode);
+ }
+
+ /**
+ * Create an event.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the default version
+ * @param nameSpace of the event, set to null to use the default value
+ * @param source of the event, set to null to use the default value
+ * @param target of the event, set to null to use the default value
+ * @param uuid event UUID, set to null to generate a UUID
+ * @param description event description, set to null to generate a description
+ * @return result of the operation
+ */
+ public ApexAPIResult createEvent(final String name, final String version, final String nameSpace,
+ final String source, final String target, final String uuid, final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION"));
+ }
+
+ if (apexModel.getPolicyModel().getEvents().getEventMap().containsKey(key)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, CONCEPT + key.getID() + ALREADY_EXISTS);
+ }
+
+ final AxEvent event = new AxEvent(key);
+
+ event.setNameSpace((nameSpace != null ? nameSpace : apexProperties.getProperty("DEFAULT_EVENT_NAMESPACE")));
+ event.setSource((source != null ? source : apexProperties.getProperty("DEFAULT_EVENT_SOURCE")));
+ event.setTarget((target != null ? target : apexProperties.getProperty("DEFAULT_EVENT_TARGET")));
+
+ apexModel.getPolicyModel().getEvents().getEventMap().put(key, event);
+
+ if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) {
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } else {
+ return keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update an event.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the latest version
+ * @param nameSpace of the event, set to null to not update
+ * @param source of the event, set to null to not update
+ * @param target of the event, set to null to not update
+ * @param uuid event UUID, set to null to not update
+ * @param description event description, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updateEvent(final String name, final String version, final String nameSpace,
+ final String source, final String target, final String uuid, final String description) {
+ try {
+ final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version);
+ if (event == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (nameSpace != null) {
+ event.setNameSpace(nameSpace);
+ }
+ if (source != null) {
+ event.setSource(source);
+ }
+ if (target != null) {
+ event.setTarget(target);
+ }
+
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List events.
+ *
+ * @param name name of the event, set to null to list all
+ * @param version starting version of the event, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult listEvent(final String name, final String version) {
+ try {
+ final Set<AxEvent> eventSet = apexModel.getPolicyModel().getEvents().getAll(name, version);
+ if (name != null && eventSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxEvent event : eventSet) {
+ result.addMessage(
+ new ApexModelStringWriter<AxEvent>(false).writeString(event, AxEvent.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete an event.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to delete all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteEvent(final String name, final String version) {
+ try {
+ if (version != null) {
+ final AxArtifactKey key = new AxArtifactKey(name, version);
+ final AxEvent removedEvent = apexModel.getPolicyModel().getEvents().getEventMap().remove(key);
+ if (removedEvent != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS, new ApexModelStringWriter<AxEvent>(false)
+ .writeString(removedEvent, AxEvent.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + key.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ final Set<AxEvent> eventSet = apexModel.getPolicyModel().getEvents().getAll(name, version);
+ if (eventSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxEvent event : eventSet) {
+ result.addMessage(
+ new ApexModelStringWriter<AxEvent>(false).writeString(event, AxEvent.class, jsonMode));
+ apexModel.getPolicyModel().getEvents().getEventMap().remove(event.getKey());
+ keyInformationFacade.deleteKeyInformation(name, version);
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Validate events.
+ *
+ * @param name name of the event, set to null to list all
+ * @param version starting version of the event, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult validateEvent(final String name, final String version) {
+ try {
+ final Set<AxEvent> eventSet = apexModel.getPolicyModel().getEvents().getAll(name, version);
+ if (eventSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxEvent event : eventSet) {
+ final AxValidationResult validationResult = event.validate(new AxValidationResult());
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(event.getKey(),
+ AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create an event parameter.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the latest version
+ * @param parName of the parameter
+ * @param contextSchemaName name of the parameter context schema
+ * @param contextSchemaVersion version of the parameter context schema, set to null to use the
+ * latest version
+ * @param optional true if the event parameter is optional, false otherwise
+ * @return result of the operation
+ */
+ public ApexAPIResult createEventPar(final String name, final String version, final String parName,
+ final String contextSchemaName, final String contextSchemaVersion, final boolean optional) {
+ try {
+ Assertions.argumentNotNull(parName, "parName may not be null");
+
+ final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version);
+ if (event == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey = new AxReferenceKey(event.getKey(), parName);
+
+ if (event.getParameterMap().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ final AxContextSchema schema =
+ apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion);
+ if (schema == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST);
+ }
+
+ event.getParameterMap().put(refKey.getLocalName(), new AxField(refKey, schema.getKey(), optional));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List event parameters.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to list latest version
+ * @param parName name of the parameter, set to null to list all parameters of the event
+ * @return result of the operation
+ */
+ public ApexAPIResult listEventPar(final String name, final String version, final String parName) {
+ try {
+ final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version);
+ if (event == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (parName != null) {
+ final AxField eventField = event.getParameterMap().get(parName);
+ if (eventField != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxField>(false).writeString(eventField, AxField.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (event.getParameterMap().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no parameters defined on event " + event.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxField eventPar : event.getParameterMap().values()) {
+ result.addMessage(
+ new ApexModelStringWriter<AxField>(false).writeString(eventPar, AxField.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete an event parameter.
+ *
+ * @param name name of the event
+ * @param version version of the event, set to null to use the latest version
+ * @param parName of the parameter, set to null to delete all parameters
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteEventPar(final String name, final String version, final String parName) {
+ try {
+ final AxEvent event = apexModel.getPolicyModel().getEvents().get(name, version);
+ if (event == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ if (parName != null) {
+ if (event.getParameterMap().containsKey(parName)) {
+ result.addMessage(new ApexModelStringWriter<AxField>(false)
+ .writeString(event.getParameterMap().get(parName), AxField.class, jsonMode));
+ event.getParameterMap().remove(parName);
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (event.getParameterMap().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no parameters defined on event " + event.getKey().getID());
+ }
+
+ for (final AxField eventPar : event.getParameterMap().values()) {
+ result.addMessage(
+ new ApexModelStringWriter<AxField>(false).writeString(eventPar, AxField.class, jsonMode));
+ }
+ event.getParameterMap().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java
new file mode 100644
index 000000000..d9b9cef1a
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java
@@ -0,0 +1,244 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+
+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.ApexModelStringWriter;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+
+/**
+ * This class acts as a facade for operations towards a policy model for key information operations.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class KeyInformationFacade {
+ private static final String CONCEPT = "concept ";
+ private static final String CONCEPT_S = "concept(s) ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String DO_ES_NOT_EXIST = " do(es) not exist";
+ private static final String ALREADY_EXISTS = " already exists";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor to create a key information facade for the Model API.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public KeyInformationFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+ }
+
+ /**
+ * Create key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to use the default
+ * version
+ * @param uuid key information UUID, set to null to generate a UUID
+ * @param description key information description, set to null to generate a description
+ * @return result of the operation
+ */
+ public ApexAPIResult createKeyInformation(final String name, final String version, final String uuid,
+ final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION"));
+ }
+
+ if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, CONCEPT + key.getID() + ALREADY_EXISTS);
+ }
+
+ final AxKeyInfo keyInfo = new AxKeyInfo(key);
+ if (description != null) {
+ keyInfo.setDescription(description);
+ }
+ if (uuid != null) {
+ keyInfo.setUuid(UUID.fromString(uuid));
+ } else {
+ // generate a reproducible UUID
+ keyInfo.setUuid(AxKeyInfo.generateReproducibleUUID(keyInfo.getID() + keyInfo.getDescription()));
+ }
+ apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().put(key, keyInfo);
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to update the
+ * latest version
+ * @param uuid key information UUID, set to null to not update
+ * @param description key information description, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updateKeyInformation(final String name, final String version, final String uuid,
+ final String description) {
+ try {
+ final AxKeyInfo keyInfo = apexModel.getPolicyModel().getKeyInformation().get(name, version);
+ if (keyInfo == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ":" + version + DOES_NOT_EXIST);
+ }
+
+ if (description != null) {
+ keyInfo.setDescription(description);
+ }
+
+ if (uuid != null) {
+ keyInfo.setUuid(UUID.fromString(uuid));
+ } else {
+ // generate a reproducible UUID
+ keyInfo.setUuid(AxKeyInfo.generateReproducibleUUID(keyInfo.getID() + keyInfo.getDescription()));
+ }
+
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List key information.
+ *
+ * @param name name of the concept for the key information, set to null to list all
+ * @param version starting version of the concept for the key information, set to null to list
+ * all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult listKeyInformation(final String name, final String version) {
+ try {
+ final Set<AxKeyInfo> keyInfoSet = apexModel.getPolicyModel().getKeyInformation().getAll(name, version);
+ if (name != null && keyInfoSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxKeyInfo keyInfo : keyInfoSet) {
+ result.addMessage(
+ new ApexModelStringWriter<AxKeyInfo>(false).writeString(keyInfo, AxKeyInfo.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to delete all
+ * versions
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteKeyInformation(final String name, final String version) {
+ try {
+ if (version != null) {
+ final AxArtifactKey key = new AxArtifactKey(name, version);
+ final AxKeyInfo removedKeyInfo =
+ apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().remove(key);
+ if (removedKeyInfo != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS, new ApexModelStringWriter<AxKeyInfo>(false)
+ .writeString(removedKeyInfo, AxKeyInfo.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + key.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ final Set<AxKeyInfo> keyInfoSet = apexModel.getPolicyModel().getKeyInformation().getAll(name, version);
+ if (keyInfoSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxKeyInfo keyInfo : keyInfoSet) {
+ result.addMessage(
+ new ApexModelStringWriter<AxKeyInfo>(false).writeString(keyInfo, AxKeyInfo.class, jsonMode));
+ apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().remove(keyInfo.getKey());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Validate key information.
+ *
+ * @param name name of the concept for the key information
+ * @param version version of the concept for the key information, set to null to validate all
+ * versions
+ * @return result of the operation
+ */
+ public ApexAPIResult validateKeyInformation(final String name, final String version) {
+ try {
+ final Set<AxKeyInfo> keyInfoSet = apexModel.getPolicyModel().getKeyInformation().getAll(name, version);
+ if (keyInfoSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxKeyInfo keyInfo : keyInfoSet) {
+ final AxValidationResult validationResult = keyInfo.validate(new AxValidationResult());
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(keyInfo.getKey(),
+ AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java
new file mode 100644
index 000000000..2a6dd3ebf
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java
@@ -0,0 +1,207 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class acts as a facade for operations towards a policy model.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ModelFacade {
+ private static final String CONCEPT = "concept ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String ALREADY_CREATED = " already created";
+ private static final String NO_VERSION_SPECIFIED = ", no version specified";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // Facade classes for working towards the real Apex model
+ private final KeyInformationFacade keyInformationFacade;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor to create a model facade for the Apex model.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public ModelFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ Assertions.argumentNotNull(apexModel, "apexModel may not be null");
+ Assertions.argumentNotNull(apexProperties, "apexProperties may not be null");
+
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode);
+ }
+
+ /**
+ * Create model.
+ *
+ * @param name name of the model
+ * @param version version of the model, set to null to use the default version
+ * @param uuid model UUID, set to null to generate a UUID
+ * @param description model description, set to null to generate a description
+ * @return result of the operation
+ */
+ public ApexAPIResult createModel(final String name, final String version, final String uuid,
+ final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ final String defaultVersion = apexProperties.getProperty("DEFAULT_CONCEPT_VERSION");
+ if (defaultVersion != null) {
+ key.setVersion(defaultVersion);
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, CONCEPT + name + NO_VERSION_SPECIFIED);
+ }
+ }
+
+ if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + apexModel.getPolicyModel().getKey().getID() + ALREADY_CREATED);
+ }
+
+ apexModel.setPolicyModel(new AxPolicyModel(key));
+
+ ApexAPIResult result;
+
+ result = keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ if (result.getResult().equals(ApexAPIResult.RESULT.SUCCESS)) {
+ apexModel.getPolicyModel().getKeyInformation().generateKeyInfo(apexModel.getPolicyModel());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update model.
+ *
+ * @param name name of the model
+ * @param version version of the model, set to null to update the latest version
+ * @param uuid key information UUID, set to null to not update
+ * @param description policy description, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updateModel(final String name, final String version, final String uuid,
+ final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ final String defaultVersion = apexProperties.getProperty("DEFAULT_CONCEPT_VERSION");
+ if (defaultVersion != null) {
+ key.setVersion(defaultVersion);
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED,
+ CONCEPT + apexModel.getPolicyModel().getKey().getID() + NO_VERSION_SPECIFIED);
+ }
+ }
+
+ if (apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + apexModel.getPolicyModel().getKey().getID() + DOES_NOT_EXIST);
+ }
+
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Get the key of an Apex model.
+ *
+ * @return the result of the operation
+ */
+ public ApexAPIResult getModelKey() {
+ try {
+ final ApexAPIResult result = new ApexAPIResult();
+ final AxArtifactKey modelkey = apexModel.getPolicyModel().getKey();
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(modelkey, AxArtifactKey.class,
+ jsonMode));
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List an Apex model.
+ *
+ * @return the result of the operation
+ */
+ public ApexAPIResult listModel() {
+ try {
+ final ApexAPIResult result = new ApexAPIResult();
+ result.addMessage(new ApexModelStringWriter<AxPolicyModel>(false).writeString(apexModel.getPolicyModel(),
+ AxPolicyModel.class, jsonMode));
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete an Apex model, clear all the concepts in the model.
+ *
+ * @return the result of the operation
+ */
+ public ApexAPIResult deleteModel() {
+ // @formatter:off
+ apexModel.getPolicyModel().getSchemas() .getSchemasMap() .clear();
+ apexModel.getPolicyModel().getEvents() .getEventMap() .clear();
+ apexModel.getPolicyModel().getAlbums() .getAlbumsMap() .clear();
+ apexModel.getPolicyModel().getTasks() .getTaskMap() .clear();
+ apexModel.getPolicyModel().getPolicies() .getPolicyMap() .clear();
+ apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap() .clear();
+ // @formatter:on
+
+ apexModel.setPolicyModel(new AxPolicyModel());
+
+ return new ApexAPIResult();
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
new file mode 100644
index 000000000..89a656a40
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java
@@ -0,0 +1,630 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Files;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
+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.dao.ApexDao;
+import org.onap.policy.apex.model.basicmodel.dao.ApexDaoFactory;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+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.handling.PolicyAnalyser;
+import org.onap.policy.apex.model.policymodel.handling.PolicyAnalysisResult;
+import org.onap.policy.apex.model.policymodel.handling.PolicyModelComparer;
+import org.onap.policy.apex.model.policymodel.handling.PolicyModelMerger;
+import org.onap.policy.apex.model.policymodel.handling.PolicyModelSplitter;
+import org.onap.policy.apex.model.utilities.Assertions;
+import org.onap.policy.apex.model.utilities.ResourceUtils;
+import org.onap.policy.apex.model.utilities.TextFileUtils;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class acts as a facade for model handling for the Apex Model API.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ModelHandlerFacade {
+ private static final String FOUND_IN_DATABASE = " found in database";
+ private static final String FILE_NAME_MAY_NOT_BE_NULL = "fileName may not be null";
+ private static final String MODEL = "model ";
+ private static final String ALREADY_LOADED = " already loaded";
+
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ModelHandlerFacade.class);
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * This Constructor creates a model handling facade for the given {@link ApexModel}.
+ *
+ * @param apexModel the apex model to manipulate
+ * @param apexProperties properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public ModelHandlerFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ Assertions.argumentNotNull(apexModel, "apexModel may not be null");
+ Assertions.argumentNotNull(apexProperties, "apexProperties may not be null");
+
+ this.apexModel = apexModel;
+ this.jsonMode = jsonMode;
+ }
+
+ /**
+ * Load an Apex model from a string.
+ *
+ * @param modelString the string with the model
+ * @return the result of the operation
+ */
+ public ApexAPIResult loadFromString(final String modelString) {
+ Assertions.argumentNotNull(modelString, "modelString may not be null");
+
+ if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ MODEL + apexModel.getPolicyModel().getKey().getID() + ALREADY_LOADED);
+ }
+
+ ApexAPIResult result = new ApexAPIResult();
+ AxPolicyModel newPolicyModel = loadModelFromString(modelString, result);
+ apexModel.setPolicyModel(newPolicyModel != null ? newPolicyModel : new AxPolicyModel());
+
+ return result;
+ }
+
+ /**
+ * Load an Apex model from a file.
+ *
+ * @param fileName the file name of the file with the model
+ * @return the result of the operation
+ */
+ public ApexAPIResult loadFromFile(final String fileName) {
+ Assertions.argumentNotNull(fileName, FILE_NAME_MAY_NOT_BE_NULL);
+
+ if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ MODEL + apexModel.getPolicyModel().getKey().getID() + ALREADY_LOADED);
+ }
+
+ ApexAPIResult result = new ApexAPIResult();
+ AxPolicyModel newPolicyModel = loadModelFromFile(fileName, result);
+ apexModel.setPolicyModel(newPolicyModel != null ? newPolicyModel : new AxPolicyModel());
+
+ return result;
+ }
+
+ /**
+ * Save an Apex model to a file.
+ *
+ * @param fileName the file name
+ * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default
+ * JSON format
+ * @return the result of the operation
+ */
+ public ApexAPIResult saveToFile(final String fileName, final boolean xmlFlag) {
+ Assertions.argumentNotNull(fileName, FILE_NAME_MAY_NOT_BE_NULL);
+
+ ApexModelFileWriter<AxPolicyModel> apexModelFileWriter = new ApexModelFileWriter<>(false);
+
+ try {
+ if (xmlFlag) {
+ apexModelFileWriter.apexModelWriteXMLFile(apexModel.getPolicyModel(), AxPolicyModel.class, fileName);
+ } else {
+ apexModelFileWriter.apexModelWriteJSONFile(apexModel.getPolicyModel(), AxPolicyModel.class, fileName);
+ }
+ return new ApexAPIResult();
+ } catch (ApexException e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Load an Apex model from a database.
+ *
+ * @param modelName the name of the model to load
+ * @param modelVersion the version of the model to load, loads the policy model from the
+ * database with this name, if more than one exist, an exception is thrown
+ * @param daoParameters the parameters to use to access the database over JDBC
+ * @return the result of the operation
+ */
+ public ApexAPIResult loadFromDatabase(final String modelName, final String modelVersion,
+ final DAOParameters daoParameters) {
+ Assertions.argumentNotNull(modelName, "modelName may not be null");
+ Assertions.argumentNotNull(daoParameters, "daoParameters may not be null");
+
+ if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ MODEL + apexModel.getPolicyModel().getKey().getID() + ALREADY_LOADED);
+ }
+
+ ApexDao apexDao = null;
+ try {
+ apexDao = new ApexDaoFactory().createApexDao(daoParameters);
+ apexDao.init(daoParameters);
+
+ // Single specific model requested
+ if (modelVersion != null) {
+ AxPolicyModel daoPolicyModel =
+ apexDao.get(AxPolicyModel.class, new AxArtifactKey(modelName, modelVersion));
+
+ if (daoPolicyModel != null) {
+ apexModel.setPolicyModel(daoPolicyModel);
+ return new ApexAPIResult();
+ } else {
+ apexModel.setPolicyModel(new AxPolicyModel());
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, "no policy model with name " + modelName
+ + " and version " + modelVersion + FOUND_IN_DATABASE);
+ }
+ }
+ // Fishing expedition
+ else {
+ return searchInDatabase(modelName, apexDao, apexModel);
+ }
+ } catch (ApexException | ApexRuntimeException e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ } finally {
+ if (apexDao != null) {
+ apexDao.close();
+ }
+ }
+ }
+
+ /**
+ * Search for an Apex model in the database.
+ *
+ * @param modelName the name of the model to load
+ * @param apexDao the DAO to use to find the model
+ * @param apexModel the APEX model we are loading the found model into
+ * @return the result of the operation
+ */
+ private ApexAPIResult searchInDatabase(String modelName, ApexDao apexDao, ApexModel apexModel) {
+ AxPolicyModel foundPolicyModel = null;
+
+ List<AxPolicyModel> policyModelList = apexDao.getAll(AxPolicyModel.class);
+ for (AxPolicyModel dbPolicyModel : policyModelList) {
+ if (dbPolicyModel.getKey().getName().equals(modelName)) {
+ if (foundPolicyModel == null) {
+ foundPolicyModel = dbPolicyModel;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED,
+ "more than one policy model with name " + modelName + FOUND_IN_DATABASE);
+ }
+ }
+ }
+
+ if (foundPolicyModel != null) {
+ apexModel.setPolicyModel(foundPolicyModel);
+ return new ApexAPIResult();
+ } else {
+ apexModel.setPolicyModel(new AxPolicyModel());
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED,
+ "no policy model with name " + modelName + FOUND_IN_DATABASE);
+ }
+ }
+
+ /**
+ * Save an Apex model to a database.
+ *
+ * @param daoParameters the parameters to use to access the database over JDBC
+ * @return the result of the operation
+ */
+ public ApexAPIResult saveToDatabase(final DAOParameters daoParameters) {
+ ApexDao apexDao = null;
+
+ try {
+ apexDao = new ApexDaoFactory().createApexDao(daoParameters);
+ apexDao.init(daoParameters);
+
+ apexDao.create(apexModel.getPolicyModel());
+ return new ApexAPIResult();
+ } catch (ApexException e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ } finally {
+ if (apexDao != null) {
+ apexDao.close();
+ }
+ }
+ }
+
+ /**
+ * Read an APEX model from a location identified by a URL.
+ *
+ * @param urlString the url string
+ * @return the result of the operation
+ */
+ public ApexAPIResult readFromURL(final String urlString) {
+ Assertions.argumentNotNull(urlString, "urlString may not be null");
+
+ if (!apexModel.getPolicyModel().getKey().equals(AxArtifactKey.getNullKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ MODEL + apexModel.getPolicyModel().getKey().getID() + ALREADY_LOADED);
+ }
+
+ URL apexModelURL;
+ try {
+ apexModelURL = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ApexAPIResult result = new ApexAPIResult(ApexAPIResult.RESULT.FAILED);
+ result.addMessage("URL string " + urlString + " is not a valid URL");
+ result.addThrowable(e);
+ return result;
+ }
+
+ try {
+ ApexModelReader<AxPolicyModel> apexModelReader = new ApexModelReader<>(AxPolicyModel.class);
+ apexModelReader.setValidateFlag(false);
+ AxPolicyModel newPolicyModel = apexModelReader.read(apexModelURL.openStream());
+ apexModel.setPolicyModel(newPolicyModel != null ? newPolicyModel : new AxPolicyModel());
+ return new ApexAPIResult();
+ } catch (ApexModelException | IOException e) {
+ apexModel.setPolicyModel(new AxPolicyModel());
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Write an APEX model to a location identified by a URL.
+ *
+ * @param urlString the URL to read the model from
+ * @param xmlFlag if true, save the file in XML format, otherwise save the file in the default
+ * JSON format
+ * @return the result of the operation
+ */
+ public ApexAPIResult writeToURL(final String urlString, final boolean xmlFlag) {
+ Assertions.argumentNotNull(urlString, "urlString may not be null");
+
+ URL apexModelURL;
+ try {
+ apexModelURL = new URL(urlString);
+ } catch (MalformedURLException e) {
+ ApexAPIResult result = new ApexAPIResult(ApexAPIResult.RESULT.FAILED);
+ result.addMessage("URL string " + urlString + " is not a valid URL");
+ result.addThrowable(e);
+ return result;
+ }
+
+ try {
+ ApexModelWriter<AxPolicyModel> apexModelWriter = new ApexModelWriter<>(AxPolicyModel.class);
+ apexModelWriter.setValidateFlag(false);
+ apexModelWriter.setJsonOutput(!xmlFlag);
+
+ // Open the URL for output and write the model
+ URLConnection urlConnection = apexModelURL.openConnection();
+ urlConnection.setDoOutput(true);
+
+ apexModelWriter.write(apexModel.getPolicyModel(), urlConnection.getOutputStream());
+ return new ApexAPIResult();
+ } catch (ApexModelException | IOException e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Analyse an Apex model that shows the concept usage references of a policy model.
+ *
+ * @return the result of the operation
+ */
+ public ApexAPIResult analyse() {
+ PolicyAnalysisResult analysisResult = new PolicyAnalyser().analyse(apexModel.getPolicyModel());
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS, analysisResult.toString());
+ }
+
+ /**
+ * Validate an Apex model, checking all concepts and references in the model.
+ *
+ * @return the result of the operation
+ */
+ public ApexAPIResult validate() {
+ ApexAPIResult result = new ApexAPIResult();
+ try {
+ AxValidationResult validationResult = apexModel.getPolicyModel().validate(new AxValidationResult());
+
+ if (!validationResult.isValid()) {
+ result.setResult(ApexAPIResult.RESULT.FAILED);
+ }
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
+ .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ return result;
+ } catch (Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Compare to Apex models, returning the differences between the models.
+ *
+ * @param otherModelFileName the file name of the other model
+ * @param diffsOnly only returns differences between the model when set
+ * @param keysOnly only returns the keys that are different when set, when not set values are
+ * also returned
+ * @return the result of the operation
+ */
+ public ApexAPIResult compare(final String otherModelFileName, final boolean diffsOnly, final boolean keysOnly) {
+ ApexAPIResult result = new ApexAPIResult();
+ try {
+ AxPolicyModel otherPolicyModel = loadModelFromFile(otherModelFileName, result);
+ if (!result.getResult().equals(ApexAPIResult.RESULT.SUCCESS)) {
+ return result;
+ }
+
+ PolicyModelComparer policyModelComparer =
+ new PolicyModelComparer(apexModel.getPolicyModel(), otherPolicyModel);
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
+ .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
+ result.addMessage(policyModelComparer.toString());
+
+ return result;
+ } catch (Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Compare two Apex models, returning the differences between the models.
+ *
+ * @param otherModelString the other model as a string
+ * @param diffsOnly only returns differences between the model when set
+ * @param keysOnly only returns the keys that are different when set, when not set values are
+ * also returned
+ * @return the result of the operation
+ */
+ public ApexAPIResult compareWithString(final String otherModelString, final boolean diffsOnly,
+ final boolean keysOnly) {
+ ApexAPIResult result = new ApexAPIResult();
+ try {
+ AxPolicyModel otherPolicyModel = loadModelFromString(otherModelString, result);
+ if (!result.getResult().equals(ApexAPIResult.RESULT.SUCCESS)) {
+ return result;
+ }
+
+ PolicyModelComparer policyModelComparer =
+ new PolicyModelComparer(apexModel.getPolicyModel(), otherPolicyModel);
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
+ .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class, jsonMode));
+ result.addMessage(policyModelComparer.toString());
+
+ return result;
+ } catch (Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Split out a sub model from an Apex model that contains a given subset of the policies in the
+ * original model.
+ *
+ * @param targetModelName the file name of the target model in which to store the model split
+ * out from the original model
+ * @param splitOutPolicies the policies form the original model to include in the split out
+ * model, specified as a comma delimited list of policy names
+ * @return the result of the operation
+ */
+ public ApexAPIResult split(final String targetModelName, final String splitOutPolicies) {
+ Set<AxArtifactKey> requiredPolicySet = new LinkedHashSet<>();
+
+ // Split the policy names on comma
+ String[] policyNames = splitOutPolicies.split(",");
+
+ // Iterate over the policy names
+ for (String policyName : policyNames) {
+ // Split out this specific policy
+ AxPolicy requiredPolicy = apexModel.getPolicyModel().getPolicies().get(policyName);
+
+ if (requiredPolicy != null) {
+ requiredPolicySet.add(requiredPolicy.getKey());
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED,
+ "policy for policy name " + policyName + " not found in model");
+ }
+ }
+
+ try {
+ AxPolicyModel splitPolicyModel =
+ PolicyModelSplitter.getSubPolicyModel(apexModel.getPolicyModel(), requiredPolicySet, false);
+
+ ApexModelFileWriter<AxPolicyModel> apexModelFileWriter = new ApexModelFileWriter<>(false);
+ apexModelFileWriter.apexModelWriteJSONFile(splitPolicyModel, AxPolicyModel.class, targetModelName);
+ return new ApexAPIResult();
+ } catch (ApexException e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Split out a sub model from an Apex model that contains a given subset of the policies in the
+ * original model, return the split model in the result as a string.
+ *
+ * @param splitOutPolicies the policies form the original model to include in the split out
+ * model, specified as a comma delimited list of policy names
+ * @return the result of the operation
+ */
+ public ApexAPIResult split(final String splitOutPolicies) {
+ ApexAPIResult splitResult = new ApexAPIResult();
+ File tempSplitPolicyFile = null;
+ try {
+ tempSplitPolicyFile = File.createTempFile("ApexTempPolicy", null);
+
+ // Split the policy into a temporary file
+ splitResult = split(tempSplitPolicyFile.getCanonicalPath(), splitOutPolicies);
+ if (splitResult.isNOK()) {
+ return splitResult;
+ }
+
+ // Get the policy model into a string
+ String splitPolicyModelString = TextFileUtils.getTextFileAsString(tempSplitPolicyFile.getCanonicalPath());
+
+ // Return the policy model
+ splitResult.addMessage(splitPolicyModelString);
+ return splitResult;
+ } catch (Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED,
+ "split of policy model " + apexModel.getPolicyModel().getID() + " failed", e);
+ } finally {
+ if (tempSplitPolicyFile != null) {
+ try {
+ Files.delete(tempSplitPolicyFile.toPath());
+ } catch (IOException e) {
+ LOGGER.debug("delete of temporary file failed", e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Merge two Apex models together.
+ *
+ * @param mergeInModelName the file name of the model to merge into the current model
+ * @param keepOriginal if this flag is set to true, if a concept exists in both models, the
+ * original model copy of that concept is kept, if the flag is set to false, then the
+ * copy of the concept from the mergeInModel overwrites the concept in the original model
+ * @return the result of the operation
+ */
+ public ApexAPIResult merge(final String mergeInModelName, final boolean keepOriginal) {
+ ApexAPIResult result = new ApexAPIResult();
+ AxPolicyModel mergeInPolicyModel = loadModelFromFile(mergeInModelName, result);
+ if (!result.getResult().equals(ApexAPIResult.RESULT.SUCCESS)) {
+ return result;
+ }
+
+ try {
+ AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(apexModel.getPolicyModel(),
+ mergeInPolicyModel, keepOriginal, false);
+ apexModel.setPolicyModel(mergedPolicyModel != null ? mergedPolicyModel : new AxPolicyModel());
+ return new ApexAPIResult();
+ } catch (ApexModelException e) {
+ apexModel.setPolicyModel(new AxPolicyModel());
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Merge two Apex models together.
+ *
+ * @param otherModelString the model to merge as a string
+ * @param keepOriginal if this flag is set to true, if a concept exists in both models, the
+ * original model copy of that concept is kept, if the flag is set to false, then the
+ * copy of the concept from the mergeInModel overwrites the concept in the original model
+ * @return the result of the operation
+ */
+ public ApexAPIResult mergeWithString(final String otherModelString, final boolean keepOriginal) {
+ ApexAPIResult result = new ApexAPIResult();
+ AxPolicyModel mergeInPolicyModel = loadModelFromString(otherModelString, result);
+ if (!result.getResult().equals(ApexAPIResult.RESULT.SUCCESS)) {
+ return result;
+ }
+
+ try {
+ AxPolicyModel mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(apexModel.getPolicyModel(),
+ mergeInPolicyModel, keepOriginal, false);
+ apexModel.setPolicyModel(mergedPolicyModel != null ? mergedPolicyModel : new AxPolicyModel());
+ return new ApexAPIResult();
+ } catch (ApexModelException e) {
+ apexModel.setPolicyModel(new AxPolicyModel());
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Load a policy model from a file.
+ *
+ * @param fileName the name of the file containing the model
+ * @param result the result of the operation
+ * @return the model
+ */
+ private AxPolicyModel loadModelFromFile(final String fileName, final ApexAPIResult result) {
+ Assertions.argumentNotNull(fileName, FILE_NAME_MAY_NOT_BE_NULL);
+
+ AxPolicyModel readModel = null;
+
+ final URL apexModelURL = ResourceUtils.getLocalFile(fileName);
+ if (apexModelURL == null) {
+ result.setResult(ApexAPIResult.RESULT.FAILED);
+ result.addMessage("file " + fileName + " not found");
+ return null;
+ }
+
+ try {
+ ApexModelReader<AxPolicyModel> apexModelReader = new ApexModelReader<>(AxPolicyModel.class);
+ apexModelReader.setValidateFlag(false);
+ readModel = apexModelReader.read(apexModelURL.openStream());
+ result.setResult(ApexAPIResult.RESULT.SUCCESS);
+ return readModel;
+ } catch (Exception e) {
+ result.setResult(ApexAPIResult.RESULT.FAILED);
+ result.addThrowable(e);
+ return null;
+ }
+ }
+
+ /**
+ * Load a policy model from a string.
+ *
+ * @param modelString the string containing the model
+ * @param result the result of the operation
+ * @return the model
+ */
+ private AxPolicyModel loadModelFromString(final String modelString, final ApexAPIResult result) {
+ Assertions.argumentNotNull(modelString, "modelString may not be null");
+
+ AxPolicyModel readModel = null;
+
+ InputStream modelStringStream = new ByteArrayInputStream(modelString.getBytes());
+
+ try {
+ ApexModelReader<AxPolicyModel> apexModelReader = new ApexModelReader<>(AxPolicyModel.class);
+ apexModelReader.setValidateFlag(false);
+ readModel = apexModelReader.read(modelStringStream);
+ result.setResult(ApexAPIResult.RESULT.SUCCESS);
+ return readModel;
+ } catch (Exception e) {
+ result.setResult(ApexAPIResult.RESULT.FAILED);
+ result.addThrowable(e);
+ return null;
+ }
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java
new file mode 100644
index 000000000..f33627e44
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java
@@ -0,0 +1,1383 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Map.Entry;
+import java.util.Properties;
+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.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
+import org.onap.policy.apex.model.policymodel.concepts.AxState;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
+import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class acts as a facade for operations towards a policy model for policy operations.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class PolicyFacade {
+ private static final String STATE_NAME_MAY_NOT_BE_NULL = "stateName may not be null";
+ private static final String DOES_NOT_EXIST_ON_STATE = " does not exist on state ";
+ private static final String STATE_FINALIZER_LOGIC = "state finalizer logic ";
+ private static final String DO_ES_NOT_EXIST = " do(es) not exist";
+ private static final String CONCEPT_S = "concept(s) ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String CONCEPT = "concept ";
+ private static final String ALREADY_EXISTS = " already exists";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // Facade classes for working towards the real Apex model
+ private final KeyInformationFacade keyInformationFacade;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor that creates a policy facade for the Apex Model API.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public PolicyFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode);
+ }
+
+ /**
+ * Create a policy.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the default version
+ * @param template template used to create the policy, set to null to use the default template
+ * @param firstState the first state of the policy
+ * @param uuid policy UUID, set to null to generate a UUID
+ * @param description policy description, set to null to generate a description
+ * @return result of the operation
+ */
+ public ApexAPIResult createPolicy(final String name, final String version, final String template,
+ final String firstState, final String uuid, final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION"));
+ }
+
+ String t = template;
+ if (t == null) {
+ t = apexProperties.getProperty("DEFAULT_POLICY_TEMPLATE");
+ }
+
+ if (apexModel.getPolicyModel().getPolicies().getPolicyMap().containsKey(key)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, CONCEPT + key.getID() + ALREADY_EXISTS);
+ }
+
+ final AxPolicy policy = new AxPolicy(key);
+ policy.setTemplate(t);
+ policy.setFirstState(firstState);
+
+ apexModel.getPolicyModel().getPolicies().getPolicyMap().put(key, policy);
+
+ if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) {
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } else {
+ return keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update a policy.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param template template used to create the policy, set to null to not update
+ * @param firstState the first state of the policy
+ * @param uuid policy UUID, set to null to not update
+ * @param description policy description, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updatePolicy(final String name, final String version, final String template,
+ final String firstState, final String uuid, final String description) {
+ try {
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (template != null) {
+ policy.setTemplate(template);
+ }
+ if (firstState != null) {
+ policy.setFirstState(firstState);
+ }
+
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List policies.
+ *
+ * @param name name of the policy, set to null to list all
+ * @param version starting version of the policy, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicy(final String name, final String version) {
+ try {
+ final Set<AxPolicy> policySet = apexModel.getPolicyModel().getPolicies().getAll(name, version);
+ if (name != null && policySet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxPolicy policy : policySet) {
+ result.addMessage(
+ new ApexModelStringWriter<AxPolicy>(false).writeString(policy, AxPolicy.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a policy.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicy(final String name, final String version) {
+ try {
+ if (version != null) {
+ final AxArtifactKey key = new AxArtifactKey(name, version);
+ final AxPolicy removedPolicy = apexModel.getPolicyModel().getPolicies().getPolicyMap().remove(key);
+ if (removedPolicy != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS, new ApexModelStringWriter<AxPolicy>(false)
+ .writeString(removedPolicy, AxPolicy.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + key.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ final Set<AxPolicy> policySet = apexModel.getPolicyModel().getPolicies().getAll(name, version);
+ if (policySet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxPolicy policy : policySet) {
+ result.addMessage(
+ new ApexModelStringWriter<AxPolicy>(false).writeString(policy, AxPolicy.class, jsonMode));
+ apexModel.getPolicyModel().getPolicies().getPolicyMap().remove(policy.getKey());
+ keyInformationFacade.deleteKeyInformation(name, version);
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Validate policies.
+ *
+ * @param name name of the policy, set to null to list all
+ * @param version starting version of the policy, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult validatePolicy(final String name, final String version) {
+ try {
+ final Set<AxPolicy> policySet = apexModel.getPolicyModel().getPolicies().getAll(name, version);
+ if (policySet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxPolicy policy : policySet) {
+ final AxValidationResult validationResult = policy.validate(new AxValidationResult());
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(policy.getKey(),
+ AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a policy state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param triggerName name of the trigger event for this state
+ * @param triggerVersion version of the trigger event for this state, set to null to use the
+ * latest version
+ * @param defaultTaskName the default task name
+ * @param defaltTaskVersion the default task version, set to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult createPolicyState(final String name, final String version, final String stateName,
+ final String triggerName, final String triggerVersion, final String defaultTaskName,
+ final String defaltTaskVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey = new AxReferenceKey(policy.getKey(), stateName);
+
+ if (policy.getStateMap().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ final AxEvent triggerEvent = apexModel.getPolicyModel().getEvents().get(triggerName, triggerVersion);
+ if (triggerEvent == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST);
+ }
+
+ final AxTask defaultTask = apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion);
+ if (defaultTask == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST);
+ }
+
+ final AxState state = new AxState(refKey);
+ state.setTrigger(triggerEvent.getKey());
+ state.setDefaultTask(defaultTask.getKey());
+
+ policy.getStateMap().put(state.getKey().getLocalName(), state);
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update a policy state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param triggerName name of the trigger event for this state, set to null to not update
+ * @param triggerVersion version of the trigger event for this state, set to use latest version
+ * of trigger event
+ * @param defaultTaskName the default task name, set to null to not update
+ * @param defaltTaskVersion the default task version, set to use latest version of default task
+ * @return result of the operation
+ */
+ public ApexAPIResult updatePolicyState(final String name, final String version, final String stateName,
+ final String triggerName, final String triggerVersion, final String defaultTaskName,
+ final String defaltTaskVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (triggerName != null) {
+ final AxEvent triggerEvent = apexModel.getPolicyModel().getEvents().get(triggerName, triggerVersion);
+ if (triggerEvent == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + triggerName + ':' + triggerVersion + DOES_NOT_EXIST);
+ }
+ state.setTrigger(triggerEvent.getKey());
+ }
+
+ if (defaultTaskName != null) {
+ final AxTask defaultTask =
+ apexModel.getPolicyModel().getTasks().get(defaultTaskName, defaltTaskVersion);
+ if (defaultTask == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + defaultTaskName + ':' + defaltTaskVersion + DOES_NOT_EXIST);
+ }
+ state.setDefaultTask(defaultTask.getKey());
+ }
+
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List policy states.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state, set to null to list all states of the policy
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicyState(final String name, final String version, final String stateName) {
+ try {
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (stateName != null) {
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxState>(false).writeString(state, AxState.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + state + DOES_NOT_EXIST);
+ }
+ } else {
+ if (policy.getStateMap().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no states defined on policy " + policy.getKey().getID());
+ }
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxState state : policy.getStateMap().values()) {
+ result.addMessage(
+ new ApexModelStringWriter<AxState>(false).writeString(state, AxState.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a policy state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state, set to null to delete all states
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicyState(final String name, final String version, final String stateName) {
+ try {
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ if (stateName != null) {
+ if (policy.getStateMap().containsKey(stateName)) {
+ result.addMessage(new ApexModelStringWriter<AxState>(false)
+ .writeString(policy.getStateMap().get(stateName), AxState.class, jsonMode));
+ policy.getStateMap().remove(stateName);
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + stateName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (policy.getStateMap().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no states defined on policy " + policy.getKey().getID());
+ }
+ for (final AxState state : policy.getStateMap().values()) {
+ result.addMessage(
+ new ApexModelStringWriter<AxState>(false).writeString(state, AxState.class, jsonMode));
+ }
+ policy.getStateMap().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param logicFlavour the task selection logic flavour for the state, set to null to use the
+ * default task logic flavour
+ * @param logic the source code for the logic of the state
+ * @return result of the operation
+ */
+ public ApexAPIResult createPolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName, final String logicFlavour, final String logic) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ // There is only one logic item associated with a state so we use a hard coded logic
+ // name
+ final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), "TaskSelectionLogic");
+
+ if (!state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ state.setTaskSelectionLogic(new AxTaskSelectionLogic(refKey, logicFlavour, logic));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param logicFlavour the task selection logic flavour for the state, set to null to not update
+ * @param logic the source code for the logic of the state, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updatePolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName, final String logicFlavour, final String logic) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + state.getTaskSelectionLogic().getKey().getID() + DOES_NOT_EXIST);
+ }
+
+ final AxTaskSelectionLogic taskSelectionLogic = state.getTaskSelectionLogic();
+ if (logicFlavour != null) {
+ taskSelectionLogic.setLogicFlavour(logicFlavour);
+ }
+ if (logic != null) {
+ taskSelectionLogic.setLogic(logic);
+ }
+
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxTaskSelectionLogic>(false).writeString(state.getTaskSelectionLogic(),
+ AxTaskSelectionLogic.class, jsonMode));
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete task selection logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicyStateTaskSelectionLogic(final String name, final String version,
+ final String stateName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (state.getTaskSelectionLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + state.getTaskSelectionLogic().getKey().getID() + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ result.addMessage(new ApexModelStringWriter<AxTaskSelectionLogic>(false)
+ .writeString(state.getTaskSelectionLogic(), AxTaskSelectionLogic.class, jsonMode));
+ state.setTaskSelectionLogic(new AxTaskSelectionLogic());
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a policy state output.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output
+ * @param eventName name of the output event for this state output
+ * @param eventVersion version of the output event for this state output, set to null to use the
+ * latest version
+ * @param nextState for this state to transition to, set to null if this is the last state that
+ * the policy transitions to on this branch
+ * @return result of the operation
+ */
+ public ApexAPIResult createPolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName, final String eventName, final String eventVersion, final String nextState) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+ Assertions.argumentNotNull(outputName, "outputName may not be null");
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "Policy concept " + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "State concept " + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), outputName);
+ if (state.getStateOutputs().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ "Output concept " + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ final AxEvent event = apexModel.getPolicyModel().getEvents().get(eventName, eventVersion);
+ if (event == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "Event concept " + eventName + ':' + eventVersion + DOES_NOT_EXIST);
+ }
+
+ AxReferenceKey nextStateKey = AxReferenceKey.getNullKey();
+ if (nextState != null && !(AxReferenceKey.getNullKey().getLocalName().equals(nextState))) {
+ if (state.getKey().getLocalName().equals(nextState)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED,
+ "next state " + nextState + " of a state cannot be the state itself");
+ }
+ nextStateKey = new AxReferenceKey(state.getKey().getParentArtifactKey(), nextState);
+
+ if (!policy.getStateMap().containsKey(nextState)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "Next state concept " + nextStateKey.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ state.getStateOutputs().put(refKey.getLocalName(), new AxStateOutput(refKey, event.getKey(), nextStateKey));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List policy state outputs.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output, set to null to list all outputs of the state
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (outputName != null) {
+ final AxStateOutput stateOutput = state.getStateOutputs().get(outputName);
+ if (stateOutput != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxStateOutput>(false).writeString(stateOutput,
+ AxStateOutput.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + state.getKey().getID() + ':' + outputName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (state.getStateOutputs().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no state output concepts exist for state " + state.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+
+ for (final AxStateOutput stateOutput : state.getStateOutputs().values()) {
+ result.addMessage(new ApexModelStringWriter<AxStateOutput>(false).writeString(stateOutput,
+ AxStateOutput.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a policy state output.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param outputName of the state output, set to null to delete all state outputs
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicyStateOutput(final String name, final String version, final String stateName,
+ final String outputName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (outputName != null) {
+ final AxStateOutput stateOutput = state.getStateOutputs().get(outputName);
+ if (stateOutput != null) {
+ final ApexAPIResult result = new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxStateOutput>(false).writeString(stateOutput,
+ AxStateOutput.class, jsonMode));
+ state.getStateOutputs().remove(outputName);
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + state.getKey().getID() + ':' + outputName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (state.getStateOutputs().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no state output concepts exist for state " + state.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+
+ for (final Entry<String, AxStateOutput> stateOutputEntry : state.getStateOutputs().entrySet()) {
+ result.addMessage(new ApexModelStringWriter<AxStateOutput>(false)
+ .writeString(stateOutputEntry.getValue(), AxStateOutput.class, jsonMode));
+ }
+ state.getStateOutputs().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @param logicFlavour the policy finalizer logic flavour for the state, set to null to use the
+ * default task logic flavour
+ * @param logic the source code for the logic of the state
+ * @return result of the operation
+ */
+ public ApexAPIResult createPolicyStateFinalizerLogic(final String name, final String version,
+ final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+ Assertions.argumentNotNull(finalizerLogicName, "finalizerlogicName may not be null");
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName);
+
+ if (state.getStateFinalizerLogicMap().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ state.getStateFinalizerLogicMap().put(finalizerLogicName,
+ new AxStateFinalizerLogic(refKey, logicFlavour, logic));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @param logicFlavour the policy finalizer logic flavour for the state, set to null to not
+ * update
+ * @param logic the source code for the logic of the state, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updatePolicyStateFinalizerLogic(final String name, final String version,
+ final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+ Assertions.argumentNotNull(finalizerLogicName, "finalizerLogicName may not be null");
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName);
+ final AxStateFinalizerLogic stateFinalizerLogic =
+ state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName());
+ if (stateFinalizerLogic == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ STATE_FINALIZER_LOGIC + refKey.getID() + DOES_NOT_EXIST);
+ }
+
+ if (logicFlavour != null) {
+ stateFinalizerLogic.setLogicFlavour(logicFlavour);
+ }
+ if (logic != null) {
+ stateFinalizerLogic.setLogic(logic);
+ }
+
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicyStateFinalizerLogic(final String name, final String version, final String stateName,
+ final String finalizerLogicName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (finalizerLogicName != null) {
+ final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName);
+ final AxStateFinalizerLogic stateFinalizerLogic =
+ state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName());
+ if (stateFinalizerLogic == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ STATE_FINALIZER_LOGIC + refKey.getID() + DOES_NOT_EXIST);
+ }
+
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxStateFinalizerLogic>(false).writeString(stateFinalizerLogic,
+ AxStateFinalizerLogic.class, jsonMode));
+ } else {
+ if (state.getStateFinalizerLogicMap().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no state finalizer logic defined on state " + state.getKey().getID());
+ }
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxStateFinalizerLogic stateFinalizerLogic : state.getStateFinalizerLogicMap().values()) {
+ result.addMessage(new ApexModelStringWriter<AxStateFinalizerLogic>(false)
+ .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete policy finalizer logic for a state.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param finalizerLogicName name of the state finalizer logic
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicyStateFinalizerLogic(final String name, final String version,
+ final String stateName, final String finalizerLogicName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ if (finalizerLogicName != null) {
+ final AxReferenceKey refKey = new AxReferenceKey(state.getKey(), finalizerLogicName);
+ final AxStateFinalizerLogic stateFinalizerLogic =
+ state.getStateFinalizerLogicMap().get(refKey.getKey().getLocalName());
+ if (stateFinalizerLogic == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ STATE_FINALIZER_LOGIC + refKey.getID() + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ result.addMessage(new ApexModelStringWriter<AxStateFinalizerLogic>(false)
+ .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class, jsonMode));
+ state.getStateFinalizerLogicMap().remove(refKey.getLocalName());
+ return result;
+ } else {
+ if (state.getStateFinalizerLogicMap().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no state finalizer logic defined on state " + state.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxStateFinalizerLogic stateFinalizerLogic : state.getStateFinalizerLogicMap().values()) {
+ result.addMessage(new ApexModelStringWriter<AxStateFinalizerLogic>(false)
+ .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class, jsonMode));
+ }
+ state.getStateFinalizerLogicMap().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a policy state task reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskLocalName the task local name
+ * @param taskName name of the task
+ * @param taskVersion version of the task, set to null to use the latest version
+ * @param outputType Type of output for the task, must be DIRECT for direct output to a state
+ * output or LOGIC for output to state finalizer logic
+ * @param outputName the name of the state output or state state finalizer logic to handle the
+ * task output
+ * @return result of the operation
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ public ApexAPIResult createPolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskLocalName, final String taskName, final String taskVersion, final String outputType,
+ final String outputName) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+ Assertions.argumentNotNull(outputName, "outputName may not be null");
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(taskName, taskVersion);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + taskName + ':' + taskVersion + DOES_NOT_EXIST);
+ }
+
+ if (state.getTaskReferences().containsKey(task.getKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, "task " + task.getKey().getID()
+ + " already has reference with output " + state.getTaskReferences().get(task.getKey()));
+ }
+
+ AxReferenceKey refKey;
+ if (taskLocalName == null) {
+ refKey = new AxReferenceKey(state.getKey(), state.getKey().getParentKeyName());
+ } else {
+ refKey = new AxReferenceKey(state.getKey(), taskLocalName);
+ }
+
+ // The reference to the output we're using here
+ final AxReferenceKey outputRefKey = new AxReferenceKey(state.getKey(), outputName);
+
+ final AxStateTaskOutputType stateTaskOutputType = AxStateTaskOutputType.valueOf(outputType);
+ if (stateTaskOutputType.equals(AxStateTaskOutputType.DIRECT)) {
+ if (!state.getStateOutputs().containsKey(outputRefKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "state output concept " + outputRefKey.getID() + DOES_NOT_EXIST);
+ }
+ } else if (stateTaskOutputType.equals(AxStateTaskOutputType.LOGIC)) {
+ if (!state.getStateFinalizerLogicMap().containsKey(outputRefKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "state finalizer logic concept " + outputRefKey.getID() + DOES_NOT_EXIST);
+ }
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, "output type " + outputType + " invalid");
+ }
+
+ state.getTaskReferences().put(task.getKey(),
+ new AxStateTaskReference(refKey, stateTaskOutputType, outputRefKey));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * List policy state task references.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskName name of the task, set to null to list all task references
+ * @param taskVersion version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskName, final String taskVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ boolean found = false;
+ for (final Entry<AxArtifactKey, AxStateTaskReference> taskReferenceEntry : state.getTaskReferences()
+ .entrySet()) {
+ if (taskName == null) {
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
+ .writeString(taskReferenceEntry.getKey(), AxArtifactKey.class, jsonMode));
+ result.addMessage(new ApexModelStringWriter<AxStateTaskReference>(false)
+ .writeString(taskReferenceEntry.getValue(), AxStateTaskReference.class, jsonMode));
+ found = true;
+ continue;
+ }
+ if (!taskReferenceEntry.getKey().getName().equals(taskName)) {
+ continue;
+ }
+
+ if (taskVersion != null && !taskReferenceEntry.getKey().getVersion().equals(taskVersion)) {
+ continue;
+ }
+
+ found = true;
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false)
+ .writeString(taskReferenceEntry.getKey(), AxArtifactKey.class, jsonMode));
+ result.addMessage(new ApexModelStringWriter<AxStateTaskReference>(false)
+ .writeString(taskReferenceEntry.getValue(), AxStateTaskReference.class, jsonMode));
+ }
+ if (found) {
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no task references found for state " + state.getKey().getID());
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a policy state task reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param taskName name of the task, set to null to delete all task references
+ * @param taskVersion version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicyStateTaskRef(final String name, final String version, final String stateName,
+ final String taskName, final String taskVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final Set<AxArtifactKey> deleteSet = new TreeSet<>();
+
+ for (final AxArtifactKey taskReferenceKey : state.getTaskReferences().keySet()) {
+ if (taskName == null) {
+ deleteSet.add(taskReferenceKey);
+ continue;
+ }
+ if (!taskReferenceKey.getName().equals(taskName)) {
+ continue;
+ }
+
+ if (taskVersion != null && !taskReferenceKey.getVersion().equals(taskVersion)) {
+ continue;
+ }
+ deleteSet.add(taskReferenceKey);
+ }
+ if (deleteSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + taskName + ':' + taskVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxArtifactKey keyToDelete : deleteSet) {
+ state.getTaskReferences().remove(keyToDelete);
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(keyToDelete,
+ AxArtifactKey.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a policy state context album reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult createPolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final AxContextAlbum contextAlbum =
+ apexModel.getPolicyModel().getAlbums().get(contextAlbumName, contextAlbumVersion);
+ if (contextAlbum == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST);
+ }
+
+ if (state.getContextAlbumReferences().contains(contextAlbum.getKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, "concept album reference for concept "
+ + contextAlbum.getKey().getID() + " already exists in state");
+ }
+
+ state.getContextAlbumReferences().add(contextAlbum.getKey());
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List policy state context album references.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the latest version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to list all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult listPolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ boolean found = false;
+ for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) {
+ if (contextAlbumName == null) {
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey,
+ AxArtifactKey.class, jsonMode));
+ found = true;
+ continue;
+ }
+
+ if (!albumKey.getName().equals(contextAlbumName)) {
+ continue;
+ }
+
+ if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) {
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey,
+ AxArtifactKey.class, jsonMode));
+ found = true;
+ }
+ }
+ if (!found) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT + contextAlbumName + ':'
+ + contextAlbumVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getID());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a policy state context album reference.
+ *
+ * @param name name of the policy
+ * @param version version of the policy, set to null to use the default version
+ * @param stateName of the state
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to delete all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult deletePolicyStateContextRef(final String name, final String version, final String stateName,
+ final String contextAlbumName, final String contextAlbumVersion) {
+ try {
+ Assertions.argumentNotNull(stateName, STATE_NAME_MAY_NOT_BE_NULL);
+
+ final AxPolicy policy = apexModel.getPolicyModel().getPolicies().get(name, version);
+ if (policy == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxState state = policy.getStateMap().get(stateName);
+ if (state == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + policy.getKey().getID() + ':' + stateName + DOES_NOT_EXIST);
+ }
+
+ final Set<AxArtifactKey> deleteSet = new TreeSet<>();
+
+ for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) {
+ if (contextAlbumName == null) {
+ deleteSet.add(albumKey);
+ continue;
+ }
+
+ if (!albumKey.getName().equals(contextAlbumName)) {
+ continue;
+ }
+
+ if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) {
+ deleteSet.add(albumKey);
+ }
+ }
+ if (deleteSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT + contextAlbumName + ':'
+ + contextAlbumVersion + DOES_NOT_EXIST_ON_STATE + state.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxArtifactKey keyToDelete : deleteSet) {
+ state.getContextAlbumReferences().remove(keyToDelete);
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(keyToDelete,
+ AxArtifactKey.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java
new file mode 100644
index 000000000..923814daf
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java
@@ -0,0 +1,893 @@
+/*-
+ * ============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.modelapi.impl;
+
+import java.util.Properties;
+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.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
+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.AxInputField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class acts as a facade for operations towards a policy model for task operations.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TaskFacade {
+ private static final String CONCEPT = "concept ";
+ private static final String CONCEPT_S = "concept(s) ";
+ private static final String DOES_NOT_EXIST = " does not exist";
+ private static final String DO_ES_NOT_EXIST = " do(es) not exist";
+ private static final String ALREADY_EXISTS = " already exists";
+
+ // Apex model we're working towards
+ private final ApexModel apexModel;
+
+ // Properties to use for the model
+ private final Properties apexProperties;
+
+ // Facade classes for working towards the real Apex model
+ private final KeyInformationFacade keyInformationFacade;
+
+ // JSON output on list/delete if set
+ private final boolean jsonMode;
+
+ /**
+ * Constructor that creates a task facade for the Apex Model API.
+ *
+ * @param apexModel the apex model
+ * @param apexProperties Properties for the model
+ * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
+ * set to false
+ */
+ public TaskFacade(final ApexModel apexModel, final Properties apexProperties, final boolean jsonMode) {
+ this.apexModel = apexModel;
+ this.apexProperties = apexProperties;
+ this.jsonMode = jsonMode;
+
+ keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties, jsonMode);
+ }
+
+ /**
+ * Create a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the default version
+ * @param uuid task UUID, set to null to generate a UUID
+ * @param description task description, set to null to generate a description
+ * @return result of the operation
+ */
+ public ApexAPIResult createTask(final String name, final String version, final String uuid,
+ final String description) {
+ try {
+ final AxArtifactKey key = new AxArtifactKey();
+ key.setName(name);
+ if (version != null) {
+ key.setVersion(version);
+ } else {
+ key.setVersion(apexProperties.getProperty("DEFAULT_CONCEPT_VERSION"));
+ }
+
+ if (apexModel.getPolicyModel().getTasks().getTaskMap().containsKey(key)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, CONCEPT + key.getID() + ALREADY_EXISTS);
+ }
+
+ apexModel.getPolicyModel().getTasks().getTaskMap().put(key, new AxTask(key));
+
+ if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) {
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } else {
+ return keyInformationFacade.createKeyInformation(name, version, uuid, description);
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param uuid task UUID, set to null to not update
+ * @param description task description, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updateTask(final String name, final String version, final String uuid,
+ final String description) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ return keyInformationFacade.updateKeyInformation(name, version, uuid, description);
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List tasks.
+ *
+ * @param name name of the task, set to null to list all
+ * @param version starting version of the task, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult listTask(final String name, final String version) {
+ try {
+ final Set<AxTask> taskSet = apexModel.getPolicyModel().getTasks().getAll(name, version);
+ if (name != null && taskSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxTask task : taskSet) {
+ result.addMessage(new ApexModelStringWriter<AxTask>(false).writeString(task, AxTask.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteTask(final String name, final String version) {
+ try {
+ if (version != null) {
+ final AxArtifactKey key = new AxArtifactKey(name, version);
+ final AxTask removedTask = apexModel.getPolicyModel().getTasks().getTaskMap().remove(key);
+ if (removedTask != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxTask>(false).writeString(removedTask, AxTask.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + key.getID() + DOES_NOT_EXIST);
+ }
+ }
+
+ final Set<AxTask> taskSet = apexModel.getPolicyModel().getTasks().getAll(name, version);
+ if (taskSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxTask task : taskSet) {
+ result.addMessage(new ApexModelStringWriter<AxTask>(false).writeString(task, AxTask.class, jsonMode));
+ apexModel.getPolicyModel().getTasks().getTaskMap().remove(task.getKey());
+ keyInformationFacade.deleteKeyInformation(name, version);
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Validate tasks.
+ *
+ * @param name name of the task, set to null to list all
+ * @param version starting version of the task, set to null to list all versions
+ * @return result of the operation
+ */
+ public ApexAPIResult validateTask(final String name, final String version) {
+ try {
+ final Set<AxTask> taskSet = apexModel.getPolicyModel().getTasks().getAll(name, version);
+ if (taskSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT_S + name + ':' + version + DO_ES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxTask task : taskSet) {
+ final AxValidationResult validationResult = task.validate(new AxValidationResult());
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(task.getKey(),
+ AxArtifactKey.class, jsonMode));
+ result.addMessage(validationResult.toString());
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create logic for a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param logicFlavour the task logic flavour for the task, set to null to use the default task
+ * logic flavour
+ * @param logic the source code for the logic of the task
+ * @return result of the operation
+ */
+ public ApexAPIResult createTaskLogic(final String name, final String version, final String logicFlavour,
+ final String logic) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ // There is only one logic item associated with a task so we use a hard coded logic name
+ final AxReferenceKey refKey = new AxReferenceKey(task.getKey(), "TaskLogic");
+
+ if (!task.getTaskLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ task.setTaskLogic(new AxTaskLogic(refKey, logicFlavour, logic));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Update logic for a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param logicFlavour the task logic flavour for the task, set to null to not update
+ * @param logic the source code for the logic of the task, set to null to not update
+ * @return result of the operation
+ */
+ public ApexAPIResult updateTaskLogic(final String name, final String version, final String logicFlavour,
+ final String logic) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (task.getTaskLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + task.getTaskLogic().getKey().getID() + DOES_NOT_EXIST);
+ }
+
+ final AxTaskLogic taskLogic = task.getTaskLogic();
+ if (logicFlavour != null) {
+ taskLogic.setLogicFlavour(logicFlavour);
+ }
+ if (logic != null) {
+ taskLogic.setLogic(logic);
+ }
+
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List task logic.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to list the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult listTaskLogic(final String name, final String version) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS, new ApexModelStringWriter<AxTaskLogic>(false)
+ .writeString(task.getTaskLogic(), AxTaskLogic.class, jsonMode));
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete logic for a task.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteTaskLogic(final String name, final String version) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (task.getTaskLogic().getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + task.getTaskLogic().getKey().getID() + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ result.addMessage(new ApexModelStringWriter<AxTaskLogic>(false).writeString(task.getTaskLogic(),
+ AxTaskLogic.class, jsonMode));
+ task.setTaskLogic(new AxTaskLogic());
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a task input field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the input field
+ * @param contextSchemaName name of the input field context schema
+ * @param contextSchemaVersion version of the input field context schema, set to null to use the
+ * latest version
+ * @param optional true if the task field is optional, false otherwise
+ * @return result of the operation
+ */
+ public ApexAPIResult createTaskInputField(final String name, final String version, final String fieldName,
+ final String contextSchemaName, final String contextSchemaVersion, final boolean optional) {
+ try {
+ Assertions.argumentNotNull(fieldName, "fieldName may not be null");
+
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey =
+ new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(), "inputFields", fieldName);
+
+ if (task.getInputFields().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ final AxContextSchema schema =
+ apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion);
+ if (schema == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST);
+ }
+
+ task.getInputFields().put(refKey.getLocalName(), new AxInputField(refKey, schema.getKey(), optional));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List task input fields.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName field name of the input field, set to null to list all input fields of the
+ * task
+ * @return result of the operation
+ */
+ public ApexAPIResult listTaskInputField(final String name, final String version, final String fieldName) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (fieldName != null) {
+ final AxInputField inputField = task.getInputFields().get(fieldName);
+ if (inputField != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxInputField>(false).writeString(inputField, AxInputField.class,
+ jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + inputField + DOES_NOT_EXIST);
+ }
+ } else {
+ if (task.getInputFields().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no input fields defined on task " + task.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxInputField field : task.getInputFields().values()) {
+ result.addMessage(new ApexModelStringWriter<AxInputField>(false).writeString(field,
+ AxInputField.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+
+ }
+
+ /**
+ * Delete a task input field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the input field, set to null to delete all input fields
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteTaskInputField(final String name, final String version, final String fieldName) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ if (fieldName != null) {
+ if (task.getInputFields().containsKey(fieldName)) {
+ result.addMessage(new ApexModelStringWriter<AxInputField>(false)
+ .writeString(task.getInputFields().get(fieldName), AxInputField.class, jsonMode));
+ task.getInputFields().remove(fieldName);
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + fieldName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (task.getInputFields().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no input fields defined on task " + task.getKey().getID());
+ }
+
+ for (final AxInputField field : task.getInputFields().values()) {
+ result.addMessage(new ApexModelStringWriter<AxInputField>(false).writeString(field,
+ AxInputField.class, jsonMode));
+ }
+ task.getInputFields().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+
+ }
+
+ /**
+ * Create a task output field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the output field
+ * @param contextSchemaName name of the output field context schema
+ * @param contextSchemaVersion version of the output field context schema, set to null to use
+ * the latest version
+ * @param optional true if the task field is optional, false otherwise
+ * @return result of the operation
+ */
+ public ApexAPIResult createTaskOutputField(final String name, final String version, final String fieldName,
+ final String contextSchemaName, final String contextSchemaVersion, final boolean optional) {
+ try {
+ Assertions.argumentNotNull(fieldName, "fieldName may not be null");
+
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey =
+ new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(), "outputFields", fieldName);
+
+ if (task.getOutputFields().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ final AxContextSchema schema =
+ apexModel.getPolicyModel().getSchemas().get(contextSchemaName, contextSchemaVersion);
+ if (schema == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextSchemaName + ':' + contextSchemaVersion + DOES_NOT_EXIST);
+ }
+
+ task.getOutputFields().put(refKey.getLocalName(), new AxOutputField(refKey, schema.getKey(), optional));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List task output fields.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName field name of the output field, set to null to list all output fields of the
+ * task
+ * @return result of the operation
+ */
+ public ApexAPIResult listTaskOutputField(final String name, final String version, final String fieldName) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (fieldName != null) {
+ final AxOutputField outputField = task.getOutputFields().get(fieldName);
+ if (outputField != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxOutputField>(false).writeString(outputField,
+ AxOutputField.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + outputField + DOES_NOT_EXIST);
+ }
+ } else {
+ if (task.getOutputFields().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no output fields defined on task " + task.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxOutputField field : task.getOutputFields().values()) {
+ result.addMessage(new ApexModelStringWriter<AxOutputField>(false).writeString(field,
+ AxOutputField.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a task output field.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param fieldName of the output field, set to null to delete all output fields
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteTaskOutputField(final String name, final String version, final String fieldName) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ if (fieldName != null) {
+ if (task.getOutputFields().containsKey(fieldName)) {
+ result.addMessage(new ApexModelStringWriter<AxOutputField>(false)
+ .writeString(task.getOutputFields().get(fieldName), AxOutputField.class, jsonMode));
+ task.getOutputFields().remove(fieldName);
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + fieldName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (task.getOutputFields().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no output fields defined on task " + task.getKey().getID());
+ }
+
+ for (final AxOutputField field : task.getOutputFields().values()) {
+ result.addMessage(new ApexModelStringWriter<AxOutputField>(false).writeString(field,
+ AxOutputField.class, jsonMode));
+ }
+ task.getOutputFields().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a task parameter.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param parName of the parameter
+ * @param defaultValue of the parameter
+ * @return result of the operation
+ */
+ public ApexAPIResult createTaskParameter(final String name, final String version, final String parName,
+ final String defaultValue) {
+ try {
+ Assertions.argumentNotNull(parName, "parName may not be null");
+
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxReferenceKey refKey = new AxReferenceKey(task.getKey(), parName);
+
+ if (task.getTaskParameters().containsKey(refKey.getLocalName())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS,
+ CONCEPT + refKey.getID() + ALREADY_EXISTS);
+ }
+
+ task.getTaskParameters().put(refKey.getLocalName(), new AxTaskParameter(refKey, defaultValue));
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List task parameters.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param parName name of the parameter, set to null to list all parameters of the task
+ * @return result of the operation
+ */
+ public ApexAPIResult listTaskParameter(final String name, final String version, final String parName) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ if (parName != null) {
+ final AxTaskParameter taskParameter = task.getTaskParameters().get(parName);
+ if (taskParameter != null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.SUCCESS,
+ new ApexModelStringWriter<AxTaskParameter>(false).writeString(taskParameter,
+ AxTaskParameter.class, jsonMode));
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + taskParameter + DOES_NOT_EXIST);
+ }
+ } else {
+ if (task.getTaskParameters().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no task parameters defined on task " + task.getKey().getID());
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxTaskParameter parameter : task.getTaskParameters().values()) {
+ result.addMessage(new ApexModelStringWriter<AxTaskParameter>(false).writeString(parameter,
+ AxTaskParameter.class, jsonMode));
+ }
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a task parameter.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param parName of the parameter, set to null to delete all task parameters
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteTaskParameter(final String name, final String version, final String parName) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ if (parName != null) {
+ if (task.getTaskParameters().containsKey(parName)) {
+ result.addMessage(new ApexModelStringWriter<AxTaskParameter>(false)
+ .writeString(task.getTaskParameters().get(parName), AxTaskParameter.class, jsonMode));
+ task.getTaskParameters().remove(parName);
+ return result;
+ } else {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + ':' + parName + DOES_NOT_EXIST);
+ }
+ } else {
+ if (task.getTaskParameters().size() == 0) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ "no task parameters defined on task " + task.getKey().getID());
+ }
+
+ for (final AxTaskParameter parameter : task.getTaskParameters().values()) {
+ result.addMessage(new ApexModelStringWriter<AxTaskParameter>(false).writeString(parameter,
+ AxTaskParameter.class, jsonMode));
+ }
+ task.getTaskParameters().clear();
+ return result;
+ }
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Create a task context album reference.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param contextAlbumName name of the context album for the context album reference
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult createTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final AxContextAlbum contextAlbum =
+ apexModel.getPolicyModel().getAlbums().get(contextAlbumName, contextAlbumVersion);
+ if (contextAlbum == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST);
+ }
+
+ if (task.getContextAlbumReferences().contains(contextAlbum.getKey())) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_EXISTS, "context album reference for concept "
+ + contextAlbum.getKey().getID() + " already exists in task");
+ }
+
+ task.getContextAlbumReferences().add(contextAlbum.getKey());
+ return new ApexAPIResult();
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * List task context album references.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to list all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult listTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final ApexAPIResult result = new ApexAPIResult();
+ boolean found = false;
+ for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) {
+ if (contextAlbumName == null) {
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey,
+ AxArtifactKey.class, jsonMode));
+ found = true;
+ continue;
+ }
+
+ if (!albumKey.getName().equals(contextAlbumName)) {
+ continue;
+ }
+
+ if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) {
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey,
+ AxArtifactKey.class, jsonMode));
+ found = true;
+ }
+ }
+ if (!found) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST);
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+
+ /**
+ * Delete a task context album reference.
+ *
+ * @param name name of the task
+ * @param version version of the task, set to null to use the latest version
+ * @param contextAlbumName name of the context album for the context album reference, set to
+ * null to delete all task context album references
+ * @param contextAlbumVersion version of the context album for the context album reference, set
+ * to null to use the latest version
+ * @return result of the operation
+ */
+ public ApexAPIResult deleteTaskContextRef(final String name, final String version, final String contextAlbumName,
+ final String contextAlbumVersion) {
+ try {
+ final AxTask task = apexModel.getPolicyModel().getTasks().get(name, version);
+ if (task == null) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + name + ':' + version + DOES_NOT_EXIST);
+ }
+
+ final Set<AxArtifactKey> deleteSet = new TreeSet<>();
+
+ for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) {
+ if (contextAlbumName == null) {
+ deleteSet.add(albumKey);
+ continue;
+ }
+
+ if (!albumKey.getName().equals(contextAlbumName)) {
+ continue;
+ }
+
+ if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) {
+ deleteSet.add(albumKey);
+ }
+ }
+
+ if (deleteSet.isEmpty()) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST,
+ CONCEPT + contextAlbumName + ':' + contextAlbumVersion + DOES_NOT_EXIST);
+ }
+ final ApexAPIResult result = new ApexAPIResult();
+ for (final AxArtifactKey keyToDelete : deleteSet) {
+ task.getContextAlbumReferences().remove(keyToDelete);
+ result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(keyToDelete,
+ AxArtifactKey.class, jsonMode));
+ }
+ return result;
+ } catch (final Exception e) {
+ return new ApexAPIResult(ApexAPIResult.RESULT.FAILED, e);
+ }
+ }
+}
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/package-info.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/package-info.java
new file mode 100644
index 000000000..f31542044
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/package-info.java
@@ -0,0 +1,27 @@
+/*-
+ * ============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=========================================================
+ */
+
+/**
+ * Provides an implementation of the APEX Model API that holds an APEX model and manipulates its
+ * various parts in response to operations called over the Model API.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+package org.onap.policy.apex.model.modelapi.impl;
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/package-info.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/package-info.java
new file mode 100644
index 000000000..97e8db4ea
--- /dev/null
+++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/package-info.java
@@ -0,0 +1,27 @@
+/*-
+ * ============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=========================================================
+ */
+
+/**
+ * Provides an API to APEX models so that they can be manipulated over a common interface by CLI and
+ * GUI based editors and other development tools.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+package org.onap.policy.apex.model.modelapi;
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestAPIResult.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestAPIResult.java
new file mode 100644
index 000000000..e85357fbf
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestAPIResult.java
@@ -0,0 +1,80 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.ApexAPIResult.RESULT;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestAPIResult {
+
+ @Test
+ public void testAPIResult() {
+ assertNotNull(new ApexAPIResult());
+
+ for (final RESULT result : RESULT.values()) {
+ assertNotNull(new ApexAPIResult(result));
+ }
+
+ assertNotNull(new ApexAPIResult(RESULT.SUCCESS, "Result Message"));
+ assertNotNull(new ApexAPIResult(RESULT.FAILED, new IOException("IO Exception message")));
+ assertNotNull(new ApexAPIResult(RESULT.FAILED, "Result Message", new IOException("IO Exception message")));
+
+ final ApexAPIResult result =
+ new ApexAPIResult(RESULT.FAILED, "Result Message", new IOException("IO Exception message"));
+
+ assertFalse(result.isOK());
+ assertTrue(result.isNOK());
+ assertEquals(RESULT.FAILED, result.getResult());
+ assertEquals("Result Message\nIO Exception message\njava.io.IOExce", result.getMessage().substring(0, 50));
+
+ final ApexAPIResult result2 = new ApexAPIResult(RESULT.SUCCESS);
+ result2.addMessage(null);
+ assertEquals("", result2.getMessage());
+ result2.addMessage("");
+ assertEquals("", result2.getMessage());
+ result2.addMessage("funky message");
+ assertEquals("funky message\n", result2.getMessage());
+
+ result2.setResult(RESULT.OTHER_ERROR);
+ assertEquals(RESULT.OTHER_ERROR, result2.getResult());
+
+ final String[] messages = {"First Message", "Second Message", "Third Message"};
+ result2.setMessages(Arrays.asList(messages));
+ assertEquals("First Message", result2.getMessages().get(0));
+ assertEquals("Second Message", result2.getMessages().get(1));
+ assertEquals("Third Message", result2.getMessages().get(2));
+
+ assertEquals("result: OTHER_ERROR\nFirst Message\nSecond Message\nThird Message\n", result2.toString());
+ assertEquals("{\n" + "\"result\": \"OTHER_ERROR\",\n" + "\"messages\": [\n" + "\"First Message\",\n"
+ + "\"Second Message\",\n" + "\"Third Message\"]\n" + "}\n", result2.toJSON());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextAlbum.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextAlbum.java
new file mode 100644
index 000000000..ad464b187
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextAlbum.java
@@ -0,0 +1,173 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorAPIContextAlbum {
+ @Test
+ public void testContextAlbumCRUD() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.validateContextAlbum(null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateContextAlbum("%%%$£", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createContextAlbum("MyMap002", "0.0.2", "APPLICATION", "true", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextAlbum("MyMap012", "0.1.2", "ZOOBY", "false", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextAlbum("MyMap012", "0.1.4", "UNDEFINED", null, "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextAlbum("MyMap012", null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "+++", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapZooby", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "--++", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createContextAlbum("MyMap002", "0.0.2", "APPLICATION", "true", "MapType", null,
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createContextAlbum("MyMap011", "0.1.2", "APPLICATION", "true", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteContextAlbum("MyMap012", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextAlbum("MyMap012", "0.1.2", "ZOOBY", "false", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.validateContextAlbum(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.updateContextAlbum(null, null, null, null, null, null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap002", "0.0.2", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap002", "0.0.2", "ZOOBY", "true", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap002", "0.0.2", null, null, null, null,
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap012", null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap012", null, null, "true", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap015", null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateContextAlbum("MyMap014", "0.1.5", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "String", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", "0.0.2", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", "0.0.1", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "Hello", "StringType", "0.0.1", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listContextAlbum("@£%%$", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.listContextAlbum(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listContextAlbum("MyMap012", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listContextAlbum("MyMap012", "0.2.5");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listContextAlbum("MyMap014", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteContextAlbum("@£%%$", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.deleteContextAlbum("MyMap012", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteContextAlbum("MyMap012oooo", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 3);
+
+ result = apexModel.deleteContextAlbum("MyMap012", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.deleteContextAlbum("MyMap012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteContextAlbum(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.listContextAlbum(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextSchema.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextSchema.java
new file mode 100644
index 000000000..7eb85da98
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIContextSchema.java
@@ -0,0 +1,152 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorAPIContextSchema {
+ @Test
+ public void testContextSchemaCRUD() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.validateContextSchemas(null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateContextSchemas("%%%$£", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listContextSchemas(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createContextSchema("Hello", "0.0.2", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002671", "A description of hello");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.deleteContextSchema("Hello", "0.1.4");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createContextSchema("Hello2", null, null, "java.lang.String", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextSchema("Hello2", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createContextSchema("Hello2", null, "Java", "java.lang.String", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.Float",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.deleteContextSchema("Hello", "0.1.4");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.validateContextSchemas(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.updateContextSchema(null, null, null, null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, "An updated description of hello");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateContextSchema("Hello", "0.1.2", "Java", "java.lang.Integer",
+ "1fa2e430-f2b2-11e6-bc64-92361f002673", "A further updated description of hola");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.updateContextSchema("Hello2", "0.0.2", null, null, null, "An updated description of hello");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listContextSchemas("@£%%$", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.listContextSchemas("Hello", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 4);
+
+ result = apexModel.listContextSchemas(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 9);
+
+ result = apexModel.deleteContextSchema("@£%%$", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.deleteContextSchema("Hello", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteContextSchema("Hellooooo", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 4);
+
+ result = apexModel.deleteContextSchema("Hello", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 3);
+
+ result = apexModel.deleteContextSchema("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listContextSchemas(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteContextSchema(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(5, result.getMessages().size());
+
+ result = apexModel.listContextSchemas(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIEvent.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIEvent.java
new file mode 100644
index 000000000..da9f48c25
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIEvent.java
@@ -0,0 +1,196 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorAPIEvent {
+ @Test
+ public void testEventCRUD() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.validateEvent(null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateEvent("%%%$£", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEvent("MyEvent012", "0.1.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEvent("MyEvent012", "0.1.4", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEvent("MyEvent012", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEvent("MyEvent012", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createEvent("@£$%^", "0.2.5", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.deleteEvent("MyEvent012", "0.1.4");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEvent("MyEvent012", "0.1.4", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.validateEvent(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.updateContextSchema(null, null, null, null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ result = apexModel.updateEvent("MyEvent012", "0.1.2", "Another Namespace", null, "Another target", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateEvent("MyEvent012", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateEvent("MyEvent015", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateEvent("MyEvent014", "0.1.5", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateEvent("@£$%^^", "0.6.9", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.listEvent("@£$%", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listEvent(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEvent("MyEvent012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEvent("MyEvent012", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEvent("MyEvent012", "0.2.5");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listEvent("MyEvent123", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteEvent("@£$%^", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteEvent("MyEvent012", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteEvent("MyEvent012oooo", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listEvent("MyEvent012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 3);
+
+ result = apexModel.deleteEvent("MyEvent012", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listEvent("MyEvent012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.deleteEvent("MyEvent012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listEvent("MyEvent012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createEventPar("MyEvent123", null, "NewPar00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createEventPar("MyEvent002", "4.5.6", "NewPar00", null, null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createEventPar("MyEvent002", "0.1.4", "NewPar00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", null, null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", "eventContextItem0", null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar01", "eventContextItem0", "0.0.1", false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar02", "eventContextItem0", "0.0.2", true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createEventPar("MyEvent002", null, "NewPar02", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createEventPar("MyEvent002", null, "NewPar03", "eventContextItem0", null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listEventPar("@£%%$", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listEventPar("MyEvent002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEventPar("MyEvent002", "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar01");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteEventPar("@££%%%", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteEventPar("NonExistantEvent", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listEventPar("MyEvent002", null, null).getMessages().size());
+ result = apexModel.deleteEventPar("MyEvent002", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listEventPar("MyEvent002", null, null).getMessages().size());
+ result = apexModel.deleteEventPar("MyEvent002", null, "NewPar02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(3, apexModel.listEventPar("MyEvent002", null, null).getMessages().size());
+ result = apexModel.deleteEventPar("MyEvent002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listEventPar("MyEvent002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteEventPar("MyEvent002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listEventPar("MyEvent002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteEvent(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.listEvent(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIKeyInfo.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIKeyInfo.java
new file mode 100644
index 000000000..c755b9064
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIKeyInfo.java
@@ -0,0 +1,136 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorAPIKeyInfo {
+
+ @Test
+ public void testKeyInfoCRUD() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.validateKeyInformation(null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateKeyInformation("%%%$£", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createKeyInformation(null, null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.createKeyInformation("Hello", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002671",
+ "A description of hello");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002672",
+ "A description of hola");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createKeyInformation("Hello", "0.1.4", "1fa2e430-f2b2-11e6-bc64-92361f002672",
+ "A description of connichi wa");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createKeyInformation("Hello", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createKeyInformation("Hello", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.createKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002672",
+ "A description of hola");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.validateKeyInformation(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.updateKeyInformation(null, null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.updateKeyInformation("Hello", "0.0.2", null, "An updated description of hello");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateKeyInformation("Hello", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002673",
+ "A further updated description of hola");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.updateKeyInformation("Hello2", "0.0.2", null, "An updated description of hello");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listKeyInformation(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.listKeyInformation("%%%$$", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.listKeyInformation("Hello", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 4);
+
+ result = apexModel.deleteKeyInformation("Hello", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteKeyInformation("Hellooooo", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 4);
+
+ result = apexModel.listKeyInformation(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 22);
+
+ result = apexModel.deleteKeyInformation("%%%$$", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.deleteKeyInformation("Hello", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 3);
+
+ result = apexModel.deleteKeyInformation("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteKeyInformation(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(18, result.getMessages().size());
+
+ result = apexModel.listKeyInformation(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIPolicy.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIPolicy.java
new file mode 100644
index 000000000..94861f9d4
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPIPolicy.java
@@ -0,0 +1,1022 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorAPIPolicy {
+ @Test
+ public void MyTestPolicyCRUD() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.validatePolicy(null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validatePolicy("%%%$£", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicy("MyPolicy012", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicy("MyPolicy012", null, "SomeTemplate", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicy("MyPolicy013", null, null, "AState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicy("MyPolicy012", null, "SomeTemplate", "AState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicy("MyPolicy012", "0.1.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicy("MyTestPolicy", "0.0.1", "SomeTemplate", "TestState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deletePolicy("MyPolicy002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.validatePolicy(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.updatePolicy("@£$$", "0.0.2", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicy("MyPolicy002", "0.0.2", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicy("MyPolicy002", "0.0.1", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicy("MyPolicy002", "0.0.2", "SomeOtherTemplate", "BState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicy("MyPolicy012", null, "SomeOtherTemplate", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicy("MyPolicy012", null, null, "CState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicy("MyPolicy012", null, "SomeOtherTemplate", "BState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicy("MyPolicy015", null, "SomeOtherTemplate", "DState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicy("MyPolicy014", "0.1.5", "SomeOtherTemplate", "EState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listPolicy("@£$%%", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicy(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(6, result.getMessages().size());
+ result = apexModel.listPolicy("MyPolicy012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicy("MyPolicy012", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicy("MyPolicy012", "0.2.5");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicy("MyPolicy014", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deletePolicy("@£$%", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.deletePolicy("MyPolicy012", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deletePolicy("MyPolicy012oooo", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listPolicy("MyPolicy012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.deletePolicy("MyPolicy002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 1);
+
+ result = apexModel.listPolicy("MyPolicy012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.deletePolicy("MyPolicy012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.createPolicyState(null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyState("MyPolicy123", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyState("MyPolicy123", null, "AState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.2", "AState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "ATrigger", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "ATask", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "AState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "BState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "CState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "DState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.updatePolicyState(null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyState("MyPolicy123", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyState("MyPolicy123", null, "AState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.2", "AState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "ZState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "ATrigger", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "ATask", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "AState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "BState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "CState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "DState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listPolicyState("MyTestPolicy", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.listPolicyState(null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyState("SomeOtherPolicy", "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyState("SomeOtherPolicy", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "CState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", null, "CState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "AState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "EState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deletePolicyState("@£$$", "0.0.2", "Trigger04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ assertEquals(4, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size());
+ result = apexModel.deletePolicyState("MyTestPolicy", "0.0.2", "Trigger04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size());
+ result = apexModel.deletePolicyState("MyTestPolicy", null, "CState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyState("MyTestPolicy", null, "ZState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(3, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size());
+ result = apexModel.deletePolicyState("MyTestPolicy", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listPolicyState("MyTestPolicy", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyState("MyTestPolicy", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState1", "inEvent", "0.0.1", "task",
+ "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState2", "outEvent0", "0.0.1", "task",
+ "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState3", "outEvent1", "0.0.1", "task",
+ "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createPolicyStateTaskSelectionLogic(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "1.2.3", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "NewTSL00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "UNDEFINED",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "MVEL",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "JAVA",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "JYTHON",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JAVASCRIPT",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JRUBY",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.updatePolicyStateTaskSelectionLogic(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState99", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy2", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy1", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "NonExistantState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "",
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "MVEL",
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy012", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null,
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy015", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy014", "0.1.5", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listPolicyStateTaskSelectionLogic(null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, "looby");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "looby");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.2", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+
+ result = apexModel.deletePolicyStateTaskSelectionLogic(null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, "looby");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", null, "looby");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.2", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null,
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JRUBY",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createPolicyStateOutput(null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", null, "SomeState", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", null, "SomeState", "SomeOutput", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "1.2.3", "TestState1", "SomeOutput", null, null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", null, null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput",
+ "SomeDummyEvent", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "1.2.3", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "0.0.1", "SomeDummyNextState");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "AnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listPolicyStateOutput(null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "SomeState", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "YetAnotherOtherOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deletePolicyStateOutput(null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "SomeState", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState1", "SomeOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "AnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createPolicyStateFinalizerLogic(null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", "SFLName01", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "1.2.3", "TestState1", "SFLName01", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName01", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName01",
+ "NewTSL00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02",
+ "UNDEFINED", "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName04", "JAVA",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName05", "JYTHON",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06",
+ "JAVASCRIPT", "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName07", "JRUBY",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.updatePolicyStateFinalizerLogic(null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState99", "SomeSFLName", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy2", null, "TestState1", "SomeSFLName", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy1", "0.0.2", "TestState1", "SomeSFLName", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "NonEistantSFL", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", "",
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", "MVEL",
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy012", null, "TestState1", "SFLName06", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", null,
+ "Some Other Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy015", null, "TestState1", "SFLName06", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy014", "0.1.5", "TestState1", "SFLName06", null,
+ null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listPolicyStateFinalizerLogic(null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateFinalizerLogic("zooby", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateFinalizerLogic("zooby", null, "looby", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("zooby", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "looby", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(6, result.getMessages().size());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+
+ result = apexModel.deletePolicyStateFinalizerLogic(null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, "looby", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, "looby", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(5, result.getMessages().size());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02",
+ "UNDEFINED", "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName04", "JAVA",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName05", "JYTHON",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06",
+ "JAVASCRIPT", "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName07", "JRUBY",
+ "Some Policy Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createTask("TestTask0", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("TestTask1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("TestTask2", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("TestTask3", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("TestTask4", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createPolicyStateTaskRef(null, null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, null, null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null, null, null,
+ "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "1.2.3", "SomeState", null, null, null, null,
+ "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("AnyOldPolicy", "1.2.3", "SomeState", null, null, null, null,
+ "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", null,
+ null, null, "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName",
+ "SomeTask", "Zooby|", null, "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName",
+ "SomeTask", "0.0.1", null, "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", null, "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "Some Policy Logic", "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "DIRECT", "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "LOGIC", "DummyOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "DIRECT", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "LOGIC", "SomeOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "DIRECT", "SomeOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "NonExistantTask", "0.0.1", "DIRECT", "SomeOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask0", "0.0.1", "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask1", "0.0.1", "DIRECT", "SomeOtherOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask2", "0.0.1", "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask3", "0.0.1", "DIRECT", "SomeOtherOutput");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask4", "0.0.1",
+ "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask4", "0.0.1",
+ "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask4", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask4", "0.0.1", "FUNKY", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask4", "0.0.1", "UNDEFINED", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask4", "0.0.1", "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask0", "0.0.1",
+ "LOGIC", "SFLName07");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.listPolicyStateTaskRef(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskRef("zooby", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateTaskRef("zooby", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("zooby", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(12, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeOldTask", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", "1.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deletePolicyStateTaskRef(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskRef("zooby", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateTaskRef("zooby", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("zooby", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "ADummyTask", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "task", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(12, result.getMessages().size());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(10, result.getMessages().size());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(8, result.getMessages().size());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createPolicyStateContextRef(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "1.2.3", "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("AnyOldPolicy", "1.2.3", "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", "Zooby|");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "task", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyPolicy123", null, null, "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateContextRef("MyPolicy123", null, "TestState1", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "4.5.6", "TestState1", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.1.4", "TestState1", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.listPolicyStateContextRef(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateContextRef("zooby", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateContextRef("zooby", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("zooby", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap04", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "1.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deletePolicyStateContextRef(null, null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateContextRef("zooby", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateContextRef("zooby", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("zooby", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "looby", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "ADummyContextMap", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap04", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", "0.1.5");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum1", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deletePolicy(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(3, result.getMessages().size());
+
+ result = apexModel.listPolicy(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPITask.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPITask.java
new file mode 100644
index 000000000..e39da2876
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexEditorAPITask.java
@@ -0,0 +1,484 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexEditorAPITask {
+ @Test
+ public void testTaskCRUD() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.validateTask(null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateTask("%%%$£", null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.createTask("@^^$^^$", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTask("MyTask012", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("MyTask012", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.listTask(null, null);
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTask("MyTask012", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteTask("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.validateTask(null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.updateTask("@$$$£", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updateTask("MyTask002", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTask("MyTask002", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTask("MyTask012", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTask("MyTask012", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTask("MyTask012", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTask("MyTask015", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateTask("MyTask014", "0.1.5", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listTask("£@£@@£@£", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listTask(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTask("MyTask012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTask("MyTask012", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTask("MyTask012", "0.2.5");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTask("MyTask014", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteTask("@£££@", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteTask("MyTask012", "0.1.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTask("MyTask012oooo", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listTask("MyTask012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 2);
+
+ result = apexModel.deleteTask("MyTask012", "0.1.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listTask("MyTask012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertTrue(result.getMessages().size() == 1);
+
+ result = apexModel.deleteTask("MyTask012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listTask("MyTask012", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.updateTaskLogic("MyTask002", null, "NewLogic00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskLogic("MyTask123", null, "NewLogic00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskLogic("MyTask002", "4.5.6", "NewLogic00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskLogic("MyTask002", "0.1.4", "NewLogic00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "NewLogic00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "UNDEFINED", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "MVEL", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "JAVA", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "JYTHON", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskLogic("MyTask002", null, "JAVASCRIPT", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskLogic("MyTask002", null, "JRUBY", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.2", "", "Some Other Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.2", "MVEL", "Some Other Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTaskLogic("MyTask012", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateTaskLogic("MyTask002", null, null, "Some Other Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTaskLogic("MyTask002", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.updateTaskLogic("MyTask015", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.updateTaskLogic("MyTask014", "0.1.5", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.listTaskLogic("MyTask002", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskLogic("MyTask002", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskLogic(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.deleteTaskLogic("@£@£@£", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteTaskLogic("NonExistantTask", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ assertEquals(1, apexModel.listTaskLogic("MyTask002", null).getMessages().size());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskLogic("MyTask002", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(1, apexModel.listTaskLogic("MyTask002", null).getMessages().size());
+ result = apexModel.createTaskLogic("MyTask002", null, "JRUBY", "Some Task Logic");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskLogic("MyTask002", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskInputField("MyTask123", null, "NewField00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskInputField("MyTask002", "4.5.6", "NewField00", null, null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskInputField("MyTask002", "0.1.4", "NewField00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskInputField("MyTask002", "0.0.2", "NewField00", null, null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.createTaskInputField("MyTask002", "0.0.2", "NewField00", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskInputField("MyTask002", "0.0.2", "NewField00", "eventContextItem0", null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTaskInputField("MyTask002", "0.0.2", "NewField01", "eventContextItem0", "0.0.1",
+ false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskInputField("MyTask002", "0.0.2", "NewField02", "eventContextItem0", "0.0.2", true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskInputField("MyTask002", null, "NewField02", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskInputField("MyTask002", null, "NewField03", "eventContextItem0", null, true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listTaskInputField("@£$%", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listTaskInputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskInputField("MyTask002", "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskInputField("MyTask002", "0.0.2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskInputField("MyTask002", "0.0.2", "NewField01");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskInputField("MyTask002", "0.0.2", "NewField02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskInputField("MyTask002", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteTaskInputField("@£$%", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteTaskInputField("NonExistantTask", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listTaskInputField("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskInputField("MyTask002", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listTaskInputField("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskInputField("MyTask002", null, "NewField02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(3, apexModel.listTaskInputField("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskInputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskInputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTaskInputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskOutputField("MyTask123", null, "NewField00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskOutputField("MyTask002", "4.5.6", "NewField00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskOutputField("MyTask002", "0.1.4", "NewField00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskOutputField("MyTask002", "0.0.2", "NewField00", null, null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.createTaskOutputField("MyTask002", "0.0.2", "NewField00", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskOutputField("MyTask002", "0.0.2", "NewField00", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTaskOutputField("MyTask002", "0.0.2", "NewField01", "eventContextItem0", "0.0.1",
+ false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskOutputField("MyTask002", "0.0.2", "NewField02", "eventContextItem0", "0.0.2",
+ false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskOutputField("MyTask002", null, "NewField02", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskOutputField("MyTask002", null, "NewField03", "eventContextItem0", null, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.listTaskOutputField("@£$%", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listTaskOutputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskOutputField("MyTask002", "0.0.1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskOutputField("MyTask002", "0.0.2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskOutputField("MyTask002", "0.0.2", "NewField01");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskOutputField("MyTask002", "0.0.2", "NewField02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskOutputField("MyTask002", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteTaskOutputField("@£$%", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteTaskOutputField("NonExistantTask", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listTaskOutputField("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskOutputField("MyTask002", "0.0.2", "NewField04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(4, apexModel.listTaskOutputField("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskOutputField("MyTask002", null, "NewField02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(3, apexModel.listTaskOutputField("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskOutputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskOutputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTaskOutputField("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskParameter("MyTask123", null, "NewPar00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskParameter("MyTask002", "4.5.6", "NewPar00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskParameter("MyTask002", "0.1.4", "NewPar00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", "eventContextItem0");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", "eventContextItem0");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar01", "eventContextItem0");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar02", "eventContextItem0");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar02", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar03", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createTaskParameter("MyTask002", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createTaskParameter("MyTask002", null, null, "Default value");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.listTaskParameter("@£$%", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listTaskParameter("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskParameter("MyTask002", "0.0.3", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar01");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteTaskParameter("@£$%", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteTaskParameter("NonExistantTask", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(3, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskParameter("MyTask002", "0.0.2", "NewPar04");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(3, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskParameter("MyTask002", null, "NewPar02");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskParameter("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.listTaskParameter("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTaskParameter("MyTask002", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskContextRef("@£$$", null, "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask002", "4.5.6", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask002", "0.1.4", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "AContextMap00", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum2", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+ result = apexModel.createTaskContextRef("MyTask002", null, "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_EXISTS));
+
+ result = apexModel.listTaskContextRef("@£$%", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.listTaskContextRef("MyTask002", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.1", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "AContextMap04", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", "0.0.1");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", "0.0.2");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteTaskContextRef("@£$%", "0.0.2", "AContextMap04", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ result = apexModel.deleteTaskContextRef("NonExistantTask", "0.0.2", "AContextMap04", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ assertEquals(2, apexModel.listTaskContextRef("MyTask002", null, null, null).getMessages().size());
+ result = apexModel.deleteTaskContextRef("MyTask002", "0.0.2", "AContextMap04", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", "0.0.3");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", "0.1.5");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+ result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.deleteTaskContextRef("MyTask002", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", null, null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST));
+
+ result = apexModel.deleteTask(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.listTask(null, null);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java
new file mode 100644
index 000000000..52029d3a4
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java
@@ -0,0 +1,259 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
+import org.onap.policy.apex.model.utilities.TextFileUtils;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexModelAPI {
+ private Connection connection;
+
+ @Before
+ public void setup() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
+ }
+
+ @After
+ public void teardown() throws Exception {
+ connection.close();
+ new File("derby.log").delete();
+ }
+
+ @Test
+ public void testApexModelLoadFromFile() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.loadFromFile("src/main/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteModel();
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.xml");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteModel();
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.junk");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ assertTrue(result.getMessages().get(0).equals("format of input for Apex concept is neither JSON nor XML"));
+ }
+
+ @Test
+ public void testApexModelSaveToFile() throws IOException {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ final File tempJsonModelFile = File.createTempFile("ApexModelTest", ".json");
+ result = apexModel.saveToFile(tempJsonModelFile.getCanonicalPath(), false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ final ApexModel jsonApexModel = new ApexModelFactory().createApexModel(null, false);
+ result = jsonApexModel.loadFromFile(tempJsonModelFile.getCanonicalPath());
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ tempJsonModelFile.delete();
+
+ final File tempXMLModelFile = File.createTempFile("ApexModelTest", ".xml");
+ result = apexModel.saveToFile(tempXMLModelFile.getCanonicalPath(), true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ final ApexModel xmlApexModel = new ApexModelFactory().createApexModel(null, false);
+ result = xmlApexModel.loadFromFile(tempXMLModelFile.getCanonicalPath());
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+ tempXMLModelFile.delete();
+ }
+
+ @Test
+ public void testApexModelDatabase() throws IOException {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ final DAOParameters daoParameters = new DAOParameters();
+ daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
+ daoParameters.setPersistenceUnit("DAOTest");
+
+ result = apexModel.saveToDatabase(daoParameters);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteModel();
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.loadFromDatabase("PolicyModel", "0.0.1", daoParameters);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteModel();
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.loadFromDatabase("PolicyModel", null, daoParameters);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.deleteModel();
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.loadFromDatabase("VPNPolicyModel", "0.0.1", daoParameters);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ }
+
+ @Test
+ public void testApexModelURL() throws IOException {
+ ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = null;
+
+ try {
+ result = apexModel.readFromURL(null);
+ fail("expecting an IllegalArgumentException");
+ } catch (final Exception e) {
+ assertTrue(e instanceof IllegalArgumentException);
+ }
+
+ try {
+ result = apexModel.writeToURL(null, true);
+ fail("expecting an IllegalArgumentException");
+ } catch (final Exception e) {
+ assertTrue(e instanceof IllegalArgumentException);
+ }
+
+ result = apexModel.readFromURL("zooby/looby");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.writeToURL("zooby/looby", true);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.readFromURL("zooby://zooby/looby");
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ result = apexModel.writeToURL("zooby://zooby/looby", false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+
+ apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ final File tempJsonModelFile = File.createTempFile("ApexModelTest", ".json");
+ result = apexModel.saveToFile(tempJsonModelFile.getCanonicalPath(), false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ final String tempFileURLString = tempJsonModelFile.toURI().toString();
+ result = apexModel.readFromURL(tempFileURLString);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.SUCCESS));
+
+ result = apexModel.writeToURL(tempFileURLString, false);
+ assertTrue(result.getResult().equals(ApexAPIResult.RESULT.FAILED));
+ assertTrue(result.getMessages().get(0).equals("protocol doesn't support output"));
+
+ tempJsonModelFile.delete();
+ }
+
+ @Test
+ public void testApexModelMisc() throws IOException {
+ final ApexModelImpl apexModelImpl = (ApexModelImpl) new ApexModelFactory().createApexModel(null, false);
+
+ ApexAPIResult result = null;
+
+ result = apexModelImpl.getModelKey();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.listModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.createModel("ModelName", "0.0.1", null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "Model Description");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ apexModelImpl.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ result = apexModelImpl.loadFromString(modelString);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ final File tempFile = File.createTempFile("ApexModel", "json");
+ tempFile.deleteOnExit();
+ TextFileUtils.putStringAsFile(modelString, tempFile);
+
+ apexModelImpl.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.loadFromFile(tempFile.getCanonicalPath());
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.saveToFile(null, false);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.analyse();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.validate();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.compare(tempFile.getCanonicalPath(), true, true);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.compareWithString(modelString, true, true);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.split("policy");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.split(tempFile.getCanonicalPath(), "policy");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.merge(tempFile.getCanonicalPath(), true);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModelImpl.mergeWithString(modelString, true);
+ System.err.println(result);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ assertNotEquals(0, apexModelImpl.hashCode());
+ assertNotNull(apexModelImpl.clone());
+ assertNotNull(apexModelImpl.build());
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelFacade.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelFacade.java
new file mode 100644
index 000000000..7f946f5d3
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelFacade.java
@@ -0,0 +1,110 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.Properties;
+import java.util.UUID;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.impl.ModelFacade;
+
+public class TestModelFacade {
+
+ @Test
+ public void testModelFacade() {
+ try {
+ new ModelFacade(null, null, false);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("apexModel may not be null", e.getMessage());
+ }
+
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ try {
+ new ModelFacade(apexModel, null, false);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("apexProperties may not be null", e.getMessage());
+ }
+
+ final Properties modelProperties = new Properties();
+ final ModelFacade mf = new ModelFacade(apexModel, modelProperties, false);
+
+ ApexAPIResult result = mf.createModel(null, null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mf.createModel("ModelName", "0.0.1", null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+ result = mf.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ modelProperties.remove("DEFAULT_CONCEPT_VERSION");
+ result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mf.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = mf.updateModel("name", "0.0.1", UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = mf.getModelKey();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mf.listModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", result.getMessage().substring(0, 50));
+
+ result = mf.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ assertNotNull(mf);
+ }
+}
diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelHandlerFacade.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelHandlerFacade.java
new file mode 100644
index 000000000..f13b8dfd5
--- /dev/null
+++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestModelHandlerFacade.java
@@ -0,0 +1,147 @@
+/*-
+ * ============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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.modelapi.impl.ModelHandlerFacade;
+import org.onap.policy.apex.model.utilities.TextFileUtils;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestModelHandlerFacade {
+
+ @Test
+ public void testModelHandlerFacade() throws IOException {
+ try {
+ new ModelHandlerFacade(null, null, false);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("apexModel may not be null", e.getMessage());
+ }
+
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null, false);
+
+ try {
+ new ModelHandlerFacade(apexModel, null, false);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("apexProperties may not be null", e.getMessage());
+ }
+
+ final Properties modelProperties = new Properties();
+ final ModelHandlerFacade mhf = new ModelHandlerFacade(apexModel, modelProperties, false);
+ assertNotNull(mhf);
+
+ ApexAPIResult result = mhf.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mhf.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mhf.loadFromString(modelString);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mhf.loadFromString(modelString);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ final DAOParameters daoParameters = new DAOParameters();
+ result = mhf.loadFromDatabase("SomeModel", null, daoParameters);
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mhf.loadFromDatabase("SomeModel", null, daoParameters);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.saveToDatabase(daoParameters);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.readFromURL("blah://somewhere/over/the/rainbow");
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.loadFromString(modelString);
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mhf.readFromURL("http://somewhere/over/the/rainbow");
+ assertEquals(ApexAPIResult.RESULT.CONCEPT_EXISTS, result.getResult());
+
+ final File tempFile = File.createTempFile("ApexModel", "json");
+ tempFile.deleteOnExit();
+
+ result = mhf.writeToURL("File:///" + tempFile.getCanonicalPath(), false);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.validate();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = mhf.validate();
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.compare("src/test/resources/models/NonExistant.json", true, true);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.compareWithString("zooby", true, true);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.split("FailSplit", "NonExistantPolicy");
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.split("NonExistantPolicy");
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.merge("src/test/resources/models/NonExistant.json", false);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = mhf.merge("src/test/resources/models/PolicyModel.json", false);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = mhf.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+
+ result = mhf.mergeWithString("@£@$@£", true);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult());
+ result = mhf.mergeWithString(modelString, false);
+ assertEquals(ApexAPIResult.RESULT.FAILED, result.getResult());
+ }
+}
diff --git a/model/model-api/src/test/resources/META-INF/persistence.xml b/model/model-api/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..3db74174c
--- /dev/null
+++ b/model/model-api/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
+ <persistence-unit name="DAOTest" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+
+ <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDATAConditioner</class>
+ <class>org.onap.policy.apex.model.basicmodel.dao.converters.UUID2String</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxConcept</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.TestEntity</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextModel</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxInputField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxOutputField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvent</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvents</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEventModel</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTask</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTasks</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateOutput</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxState</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicy</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicies</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel</class>
+
+ <properties>
+ <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:apex_test" />
+ <property name="javax.persistence.target-database" value="Derby" />
+ <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
+
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="eclipselink.ddl-generation.output-mode" value="database" />
+ <property name="eclipselink.logging.level" value="INFO" />
+ </properties>
+ </persistence-unit>
+</persistence>
diff --git a/model/model-api/src/test/resources/logback-test.xml b/model/model-api/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..114b39c70
--- /dev/null
+++ b/model/model-api/src/test/resources/logback-test.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<configuration>
+
+ <contextName>Apex</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" />
+
+ <!-- USE FOR STD OUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <logger name="org.infinispan" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex_ctxt.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="TRACE" additivity="false">
+ <appender-ref ref="CTXT_FILE" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+</configuration>
diff --git a/model/model-api/src/test/resources/models/PolicyModel.json b/model/model-api/src/test/resources/models/PolicyModel.json
new file mode 100644
index 000000000..81c222609
--- /dev/null
+++ b/model/model-api/src/test/resources/models/PolicyModel.json
@@ -0,0 +1,708 @@
+{
+ "apexPolicyModel" : {
+ "key" : {
+ "name" : "PolicyModel",
+ "version" : "0.0.1"
+ },
+ "keyInformation" : {
+ "key" : {
+ "name" : "KeyInfoMapKey",
+ "version" : "0.0.1"
+ },
+ "keyInfoMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "ContextSchemas",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "ContextSchemas",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e000",
+ "description" : "Generated description for concept referred to by key \"ContextSchemas:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "KeyInfoMapKey",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "KeyInfoMapKey",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e001",
+ "description" : "Generated description for concept referred to by key \"KeyInfoMapKey:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "MapType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MapType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e002",
+ "description" : "Generated description for concept referred to by key \"MapType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "PolicyModel",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PolicyModel",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e003",
+ "description" : "Generated description for concept referred to by key \"PolicyModel:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "StringType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "StringType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e004",
+ "description" : "Generated description for concept referred to by key \"StringType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "context",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "context",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e005",
+ "description" : "Generated description for concept referred to by key \"context:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "contextAlbum0",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "contextAlbum0",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e006",
+ "description" : "Generated description for concept referred to by key \"contextAlbum0:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "contextAlbum1",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "contextAlbum1",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e007",
+ "description" : "Generated description for concept referred to by key \"contextAlbum1:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e008",
+ "description" : "Generated description for concept referred to by key \"eventContextItem0:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e009",
+ "description" : "Generated description for concept referred to by key \"eventContextItem1:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "events",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "events",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e010",
+ "description" : "Generated description for concept referred to by key \"events:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "inEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "inEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e011",
+ "description" : "Generated description for concept referred to by key \"inEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "outEvent0",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "outEvent0",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e012",
+ "description" : "Generated description for concept referred to by key \"outEvent0:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "outEvent1",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "outEvent1",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e013",
+ "description" : "Generated description for concept referred to by key \"outEvent1:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "policies",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "policies",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e014",
+ "description" : "Generated description for concept referred to by key \"policies:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "policy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "policy",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e015",
+ "description" : "Generated description for concept referred to by key \"policy:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "task",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "task",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e016",
+ "description" : "Generated description for concept referred to by key \"task:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "tasks",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "tasks",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0ce9168c-e6df-414f-9646-6da464b6e017",
+ "description" : "Generated description for concept referred to by key \"tasks:0.0.1\""
+ }
+ } ]
+ }
+ },
+ "policies" : {
+ "key" : {
+ "name" : "policies",
+ "version" : "0.0.1"
+ },
+ "policyMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "policy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "policyKey" : {
+ "name" : "policy",
+ "version" : "0.0.1"
+ },
+ "template" : "FREEFORM",
+ "state" : {
+ "entry" : [ {
+ "key" : "state",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "policy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "state"
+ },
+ "trigger" : {
+ "name" : "inEvent",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "stateOutput0",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "policy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "state",
+ "localName" : "stateOutput0"
+ },
+ "outgoingEvent" : {
+ "name" : "outEvent0",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "NULL",
+ "parentKeyVersion" : "0.0.0",
+ "parentLocalName" : "NULL",
+ "localName" : "NULL"
+ }
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "contextAlbum0",
+ "version" : "0.0.1"
+ }, {
+ "name" : "contextAlbum1",
+ "version" : "0.0.1"
+ } ],
+ "taskSelectionLogic" : {
+ "key" : "taskSelectionLogic",
+ "logicFlavour" : "MVEL",
+ "logic" : "Some TS logic"
+ },
+ "stateFinalizerLogicMap" : {
+ "entry" : [ ]
+ },
+ "defaultTask" : {
+ "name" : "task",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "task",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "policy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "state",
+ "localName" : "task"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "policy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "state",
+ "localName" : "stateOutput0"
+ }
+ }
+ } ]
+ }
+ }
+ } ]
+ },
+ "firstState" : "state"
+ }
+ } ]
+ }
+ },
+ "tasks" : {
+ "key" : {
+ "name" : "tasks",
+ "version" : "0.0.1"
+ },
+ "taskMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "task",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "task",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "IEPAR0",
+ "value" : {
+ "key" : "IEPAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "IEPAR1",
+ "value" : {
+ "key" : "IEPAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "OE0PAR0",
+ "value" : {
+ "key" : "OE0PAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE0PAR1",
+ "value" : {
+ "key" : "OE0PAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE1PAR0",
+ "value" : {
+ "key" : "OE1PAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE1PAR1",
+ "value" : {
+ "key" : "OE1PAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ {
+ "key" : "taskParameter0",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "task",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "taskParameter0"
+ },
+ "defaultValue" : "Task parameter 0 value"
+ }
+ }, {
+ "key" : "taskParameter1",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "task",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "taskParameter1"
+ },
+ "defaultValue" : "Task parameter 1 value"
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "contextAlbum0",
+ "version" : "0.0.1"
+ }, {
+ "name" : "contextAlbum1",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "taskLogic",
+ "logicFlavour" : "MVEL",
+ "logic" : "Some task logic"
+ }
+ }
+ } ]
+ }
+ },
+ "events" : {
+ "key" : {
+ "name" : "events",
+ "version" : "0.0.1"
+ },
+ "eventMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "inEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "inEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.model.policymodel.events",
+ "source" : "Source",
+ "target" : "Target",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "IEPAR0",
+ "value" : {
+ "key" : "IEPAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "IEPAR1",
+ "value" : {
+ "key" : "IEPAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "outEvent0",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "outEvent0",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.model.policymodel.events",
+ "source" : "Source",
+ "target" : "Target",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "OE0PAR0",
+ "value" : {
+ "key" : "OE0PAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE0PAR1",
+ "value" : {
+ "key" : "OE0PAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE1PAR0",
+ "value" : {
+ "key" : "OE1PAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE1PAR1",
+ "value" : {
+ "key" : "OE1PAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "outEvent1",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "outEvent1",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.model.policymodel.events",
+ "source" : "Source",
+ "target" : "Target",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "OE1PAR0",
+ "value" : {
+ "key" : "OE1PAR0",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : "OE1PAR1",
+ "value" : {
+ "key" : "OE1PAR1",
+ "fieldSchemaKey" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ }
+ }
+ } ]
+ }
+ },
+ "albums" : {
+ "key" : {
+ "name" : "context",
+ "version" : "0.0.1"
+ },
+ "albums" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "contextAlbum0",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "contextAlbum0",
+ "version" : "0.0.1"
+ },
+ "scope" : "APPLICATION",
+ "isWritable" : true,
+ "itemSchema" : {
+ "name" : "MapType",
+ "version" : "0.0.1"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "contextAlbum1",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "contextAlbum1",
+ "version" : "0.0.1"
+ },
+ "scope" : "GLOBAL",
+ "isWritable" : false,
+ "itemSchema" : {
+ "name" : "StringType",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ }
+ },
+ "schemas" : {
+ "key" : {
+ "name" : "ContextSchemas",
+ "version" : "0.0.1"
+ },
+ "schemas" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "MapType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MapType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A"
+ }
+ }, {
+ "key" : {
+ "name" : "StringType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "StringType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "org.onap.policy.apex.model.policymodel.concepts.TestContextItem000"
+ }
+ }, {
+ "key" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "eventContextItem0",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.String"
+ }
+ }, {
+ "key" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "eventContextItem1",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ } ]
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/model/model-api/src/test/resources/models/PolicyModel.junk b/model/model-api/src/test/resources/models/PolicyModel.junk
new file mode 100644
index 000000000..613a36ad8
--- /dev/null
+++ b/model/model-api/src/test/resources/models/PolicyModel.junk
@@ -0,0 +1,9 @@
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse cursus suscipit faucibus. Pellentesque sagittis, erat placerat ultricies maximus, erat nulla efficitur ex, quis hendrerit tellus urna quis libero. Nullam vitae nisl ut nisl condimentum suscipit. Aenean sagittis condimentum nisi quis condimentum. Suspendisse potenti. Aliquam eget purus a risus viverra volutpat eu eu neque. Phasellus in libero id turpis lobortis malesuada. Praesent dignissim tellus imperdiet faucibus interdum. Donec volutpat, eros non lobortis consectetur, felis arcu consequat purus, a pharetra velit nisi at ante. Etiam ut sem imperdiet justo aliquet tempus at ornare quam.
+
+Integer sed maximus tellus. Nulla venenatis congue massa nec vestibulum. Duis ultrices quis neque ultrices semper. Morbi rhoncus gravida nibh, ut consequat ex. Proin eget ex vel lectus luctus varius. Integer nec consectetur ante. Cras ac aliquam nibh, in fermentum metus. Praesent nec ipsum tristique, ultrices arcu vel, bibendum libero. Curabitur ac odio eget felis blandit accumsan viverra vitae nibh. Integer efficitur eros lectus, et convallis elit consectetur nec. Vivamus tellus sem, vestibulum ut faucibus ut, maximus nec nulla. Donec ex eros, tempus ac justo at, posuere finibus purus. Pellentesque lacinia eu eros nec dignissim. Vestibulum tempus lectus in placerat imperdiet. Sed a diam vitae lorem gravida commodo.
+
+Sed at dolor felis. Ut at luctus libero. Ut faucibus elementum sem. Praesent aliquet tempus magna, eget bibendum nisi ultricies eu. Aenean dictum libero dui, et finibus metus consequat sed. Nullam lobortis diam ut sem imperdiet, nec posuere mauris aliquet. Etiam nec laoreet leo. Vestibulum nec turpis ante. Vivamus imperdiet commodo velit in ultricies. Maecenas facilisis maximus odio vel vestibulum.
+
+Aenean dapibus mi eget eros sodales rhoncus. Mauris dolor mi, feugiat quis egestas id, vestibulum at augue. Vivamus sit amet enim metus. Donec nec ultricies felis. Phasellus aliquam urna lectus, mollis rutrum libero ornare nec. Quisque dictum ante ac dapibus placerat. Ut euismod euismod elit eget commodo. Aenean vestibulum tempus elit quis vestibulum. Integer dapibus ultricies bibendum. Vivamus iaculis egestas magna, a ornare lacus eleifend eu. Fusce non massa ut sapien volutpat molestie vel sit amet sapien. Phasellus hendrerit felis magna, quis pharetra dui finibus sed. Praesent quis accumsan purus, hendrerit viverra felis. Pellentesque semper pretium nisl, in auctor enim interdum ut. Nullam placerat erat vel lacus vestibulum vehicula. Morbi at augue in enim luctus feugiat.
+
+Nunc aliquam auctor turpis id pretium. Donec placerat egestas tortor quis blandit. Curabitur sagittis elit eu varius gravida. Fusce eget diam eu sapien convallis pellentesque. Donec ultrices odio id leo pellentesque, eget tempus erat efficitur. Pellentesque ac ultricies purus, ut condimentum libero. Pellentesque pulvinar urna vel sollicitudin commodo. Sed tincidunt sed nulla sed auctor. \ No newline at end of file
diff --git a/model/model-api/src/test/resources/models/PolicyModel.xml b/model/model-api/src/test/resources/models/PolicyModel.xml
new file mode 100644
index 000000000..a89f73db2
--- /dev/null
+++ b/model/model-api/src/test/resources/models/PolicyModel.xml
@@ -0,0 +1,759 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<apexPolicyModel xmlns="http://www.onap.org/policy/apex-pdp">
+ <key>
+ <name>PolicyModel</name>
+ <version>0.0.1</version>
+ </key>
+ <keyInformation>
+ <key>
+ <name>KeyInfoMapKey</name>
+ <version>0.0.1</version>
+ </key>
+ <keyInfoMap>
+ <entry>
+ <key>
+ <name>ContextSchemas</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>ContextSchemas</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e000</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "ContextSchemas:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>KeyInfoMapKey</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>KeyInfoMapKey</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e001</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "KeyInfoMapKey:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>MapType</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>MapType</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e002</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "MapType:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>PolicyModel</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>PolicyModel</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e003</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "PolicyModel:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>StringType</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>StringType</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e004</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "StringType:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>context</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>context</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e005</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "context:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>contextAlbum0</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>contextAlbum0</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e006</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "contextAlbum0:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>contextAlbum1</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>contextAlbum1</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e007</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "contextAlbum1:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e008</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "eventContextItem0:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e009</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "eventContextItem1:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>events</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>events</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e010</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "events:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>inEvent</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>inEvent</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e011</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "inEvent:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>outEvent0</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>outEvent0</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e012</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "outEvent0:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>outEvent1</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>outEvent1</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e013</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "outEvent1:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>policies</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>policies</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e014</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "policies:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>policy</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>policy</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e015</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "policy:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>task</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>task</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e016</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "task:0.0.1"]]></description>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>tasks</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>tasks</name>
+ <version>0.0.1</version>
+ </key>
+ <UUID>0ce9168c-e6df-414f-9646-6da464b6e017</UUID>
+ <description><![CDATA[Generated description for concept referred to by key "tasks:0.0.1"]]></description>
+ </value>
+ </entry>
+ </keyInfoMap>
+ </keyInformation>
+ <policies>
+ <key>
+ <name>policies</name>
+ <version>0.0.1</version>
+ </key>
+ <policyMap>
+ <entry>
+ <key>
+ <name>policy</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <policyKey>
+ <name>policy</name>
+ <version>0.0.1</version>
+ </policyKey>
+ <template>FREEFORM</template>
+ <state>
+ <entry>
+ <key>state</key>
+ <value>
+ <stateKey>
+ <parentKeyName>policy</parentKeyName>
+ <parentKeyVersion>0.0.1</parentKeyVersion>
+ <parentLocalName>NULL</parentLocalName>
+ <localName>state</localName>
+ </stateKey>
+ <trigger>
+ <name>inEvent</name>
+ <version>0.0.1</version>
+ </trigger>
+ <stateOutputs>
+ <entry>
+ <key>stateOutput0</key>
+ <value>
+ <key>
+ <parentKeyName>policy</parentKeyName>
+ <parentKeyVersion>0.0.1</parentKeyVersion>
+ <parentLocalName>state</parentLocalName>
+ <localName>stateOutput0</localName>
+ </key>
+ <outgoingEvent>
+ <name>outEvent0</name>
+ <version>0.0.1</version>
+ </outgoingEvent>
+ <nextState>
+ <parentKeyName>NULL</parentKeyName>
+ <parentKeyVersion>0.0.0</parentKeyVersion>
+ <parentLocalName>NULL</parentLocalName>
+ <localName>NULL</localName>
+ </nextState>
+ </value>
+ </entry>
+ </stateOutputs>
+ <contextAlbumReference>
+ <name>contextAlbum0</name>
+ <version>0.0.1</version>
+ </contextAlbumReference>
+ <contextAlbumReference>
+ <name>contextAlbum1</name>
+ <version>0.0.1</version>
+ </contextAlbumReference>
+ <taskSelectionLogic>
+ <key>taskSelectionLogic</key>
+ <logicFlavour>MVEL</logicFlavour>
+ <logic><![CDATA[Some TS logic]]></logic>
+ </taskSelectionLogic>
+ <defaultTask>
+ <name>task</name>
+ <version>0.0.1</version>
+ </defaultTask>
+ <taskReferences>
+ <entry>
+ <key>
+ <name>task</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <parentKeyName>policy</parentKeyName>
+ <parentKeyVersion>0.0.1</parentKeyVersion>
+ <parentLocalName>state</parentLocalName>
+ <localName>task</localName>
+ </key>
+ <outputType>DIRECT</outputType>
+ <output>
+ <parentKeyName>policy</parentKeyName>
+ <parentKeyVersion>0.0.1</parentKeyVersion>
+ <parentLocalName>state</parentLocalName>
+ <localName>stateOutput0</localName>
+ </output>
+ </value>
+ </entry>
+ </taskReferences>
+ </value>
+ </entry>
+ </state>
+ <firstState>state</firstState>
+ </value>
+ </entry>
+ </policyMap>
+ </policies>
+ <tasks>
+ <key>
+ <name>tasks</name>
+ <version>0.0.1</version>
+ </key>
+ <taskMap>
+ <entry>
+ <key>
+ <name>task</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>task</name>
+ <version>0.0.1</version>
+ </key>
+ <inputFields>
+ <entry>
+ <key>IEPAR0</key>
+ <value>
+ <key>IEPAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>IEPAR1</key>
+ <value>
+ <key>IEPAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ </inputFields>
+ <outputFields>
+ <entry>
+ <key>OE0PAR0</key>
+ <value>
+ <key>OE0PAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE0PAR1</key>
+ <value>
+ <key>OE0PAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE1PAR0</key>
+ <value>
+ <key>OE1PAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE1PAR1</key>
+ <value>
+ <key>OE1PAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ </outputFields>
+ <taskParameters>
+ <entry>
+ <key>taskParameter0</key>
+ <value>
+ <key>
+ <parentKeyName>task</parentKeyName>
+ <parentKeyVersion>0.0.1</parentKeyVersion>
+ <parentLocalName>NULL</parentLocalName>
+ <localName>taskParameter0</localName>
+ </key>
+ <defaultValue>Task parameter 0 value</defaultValue>
+ </value>
+ </entry>
+ <entry>
+ <key>taskParameter1</key>
+ <value>
+ <key>
+ <parentKeyName>task</parentKeyName>
+ <parentKeyVersion>0.0.1</parentKeyVersion>
+ <parentLocalName>NULL</parentLocalName>
+ <localName>taskParameter1</localName>
+ </key>
+ <defaultValue>Task parameter 1 value</defaultValue>
+ </value>
+ </entry>
+ </taskParameters>
+ <contextAlbumReference>
+ <name>contextAlbum0</name>
+ <version>0.0.1</version>
+ </contextAlbumReference>
+ <contextAlbumReference>
+ <name>contextAlbum1</name>
+ <version>0.0.1</version>
+ </contextAlbumReference>
+ <taskLogic>
+ <key>taskLogic</key>
+ <logicFlavour>MVEL</logicFlavour>
+ <logic><![CDATA[Some task logic]]></logic>
+ </taskLogic>
+ </value>
+ </entry>
+ </taskMap>
+ </tasks>
+ <events>
+ <key>
+ <name>events</name>
+ <version>0.0.1</version>
+ </key>
+ <eventMap>
+ <entry>
+ <key>
+ <name>inEvent</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>inEvent</name>
+ <version>0.0.1</version>
+ </key>
+ <nameSpace>org.onap.policy.apex.model.policymodel.events</nameSpace>
+ <source>Source</source>
+ <target>Target</target>
+ <parameter>
+ <entry>
+ <key>IEPAR0</key>
+ <value>
+ <key>IEPAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>IEPAR1</key>
+ <value>
+ <key>IEPAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ </parameter>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>outEvent0</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>outEvent0</name>
+ <version>0.0.1</version>
+ </key>
+ <nameSpace>org.onap.policy.apex.model.policymodel.events</nameSpace>
+ <source>Source</source>
+ <target>Target</target>
+ <parameter>
+ <entry>
+ <key>OE0PAR0</key>
+ <value>
+ <key>OE0PAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE0PAR1</key>
+ <value>
+ <key>OE0PAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE1PAR0</key>
+ <value>
+ <key>OE1PAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE1PAR1</key>
+ <value>
+ <key>OE1PAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ </parameter>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name>outEvent1</name>
+ <version>0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name>outEvent1</name>
+ <version>0.0.1</version>
+ </key>
+ <nameSpace>org.onap.policy.apex.model.policymodel.events</nameSpace>
+ <source>Source</source>
+ <target>Target</target>
+ <parameter>
+ <entry>
+ <key>OE1PAR0</key>
+ <value>
+ <key>OE1PAR0</key>
+ <fieldSchemaKey>
+ <name>eventContextItem0</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ <entry>
+ <key>OE1PAR1</key>
+ <value>
+ <key>OE1PAR1</key>
+ <fieldSchemaKey>
+ <name>eventContextItem1</name>
+ <version>0.0.1</version>
+ </fieldSchemaKey>
+ </value>
+ </entry>
+ </parameter>
+ </value>
+ </entry>
+ </eventMap>
+ </events>
+ <albums>
+ <key xmlns="">
+ <name xmlns="http://www.onap.org/policy/apex-pdp">context</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <albums xmlns="">
+ <entry>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">contextAlbum0</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">contextAlbum0</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <scope>APPLICATION</scope>
+ <isWritable>true</isWritable>
+ <itemSchema>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">MapType</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </itemSchema>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">contextAlbum1</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">contextAlbum1</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <scope>GLOBAL</scope>
+ <isWritable>false</isWritable>
+ <itemSchema>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">StringType</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </itemSchema>
+ </value>
+ </entry>
+ </albums>
+ </albums>
+ <schemas>
+ <key xmlns="">
+ <name xmlns="http://www.onap.org/policy/apex-pdp">ContextSchemas</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <schemas xmlns="">
+ <entry>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">MapType</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">MapType</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <schemaFlavour>Java</schemaFlavour>
+ <schemaDefinition>org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A</schemaDefinition>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">StringType</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">StringType</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <schemaFlavour>Java</schemaFlavour>
+ <schemaDefinition>org.onap.policy.apex.model.policymodel.concepts.TestContextItem000</schemaDefinition>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">eventContextItem0</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">eventContextItem0</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <schemaFlavour>Java</schemaFlavour>
+ <schemaDefinition>java.lang.String</schemaDefinition>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">eventContextItem1</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <value>
+ <key>
+ <name xmlns="http://www.onap.org/policy/apex-pdp">eventContextItem1</name>
+ <version xmlns="http://www.onap.org/policy/apex-pdp">0.0.1</version>
+ </key>
+ <schemaFlavour>Java</schemaFlavour>
+ <schemaDefinition>java.lang.Long</schemaDefinition>
+ </value>
+ </entry>
+ </schemas>
+ </schemas>
+</apexPolicyModel>
diff --git a/model/policy-model/pom.xml b/model/policy-model/pom.xml
new file mode 100644
index 000000000..e6e4d4858
--- /dev/null
+++ b/model/policy-model/pom.xml
@@ -0,0 +1,72 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.model</groupId>
+ <artifactId>model</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>policy-model</artifactId>
+ <name>${project.artifactId}</name>
+ <description>Policy Models used in Apex</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.apex-pdp.model</groupId>
+ <artifactId>context-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.apex-pdp.model</groupId>
+ <artifactId>event-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-xml-schema</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ <configuration>
+ <mainClass>org.onap.policy.apex.model.basicmodel.handling.ApexSchemaGenerator</mainClass>
+ <classpathScope>compile</classpathScope>
+ <arguments>
+ <argument>org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel</argument>
+ <argument>${project.build.directory}/model/xml/apex-policy-model.xsd</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project> \ No newline at end of file
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
new file mode 100644
index 000000000..a537d90b9
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java
@@ -0,0 +1,419 @@
+/*-
+ * ============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 java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Convert;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.basicmodel.dao.converters.CDATAConditioner;
+import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
+import org.onap.policy.apex.model.utilities.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.
+ */
+
+@Entity
+@Table(name = "AxLogic")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxLogic", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "logicFlavour", "logic"})
+
+public class AxLogic extends AxConcept {
+ private static final long serialVersionUID = -4260562004005697328L;
+
+ 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
+
+ @EmbeddedId()
+ @XmlElement(name = "key", required = true)
+ @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
+ private AxReferenceKey key;
+
+ @Column(name = LOGIC_FLAVOUR_TOKEN)
+ @XmlElement(required = true)
+ private String logicFlavour;
+
+ @Column(name = "logic", length = MAX_LOGIC_SIZE)
+ @Convert(converter = CDATAConditioner.class)
+ @XmlJavaTypeAdapter(value = CDATAConditioner.class)
+ @XmlElement(required = true)
+ 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @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, "");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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"));
+ }
+
+ try {
+ Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP);
+ } catch (final IllegalArgumentException e) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "logic flavour invalid-" + e.getMessage()));
+ }
+
+ 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ if (key != null) {
+ key.clean();
+ }
+ logicFlavour = Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP);
+ logic = logic.replaceAll(WHITESPACE_REGEXP, "");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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;
+ }
+ final String thislogic = CDATAConditioner.clean(logic).replaceAll("\n", "");
+ final String otherlogic = CDATAConditioner.clean(other.logic).replaceAll("\n", "");
+ return thislogic.equals(otherlogic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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
new file mode 100644
index 000000000..7532f9f34
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogicReader.java
@@ -0,0 +1,74 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..248e4fdae
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java
@@ -0,0 +1,429 @@
+/*-
+ * ============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 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 javax.persistence.CascadeType;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter;
+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.apex.model.utilities.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.
+ */
+@Entity
+@Table(name = "AxPolicies")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxPolicies", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = {"key", "policyMap"})
+
+public class AxPolicies extends AxConcept implements AxConceptGetter<AxPolicy> {
+ private static final long serialVersionUID = 4290442590545820316L;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxArtifactKey key;
+
+ // @formatter:off
+ @ManyToMany(cascade = CascadeType.ALL)
+ @JoinTable(
+ joinColumns = {@JoinColumn(name = "policyMapName", referencedColumnName = "name"),
+ @JoinColumn(name = "policyMapVersion", referencedColumnName = "version")},
+ inverseJoinColumns = {@JoinColumn(name = "policyName", referencedColumnName = "name"),
+ @JoinColumn(name = "policyVersion", referencedColumnName = "version")})
+ @XmlElement(required = true)
+ private Map<AxArtifactKey, AxPolicy> policyMap;
+ // @formatter:on
+
+ /**
+ * 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<AxArtifactKey, AxPolicy>());
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * When a model is unmarshalled from disk or from the database, the policy map is returned as a
+ * raw hash map. This method is called by JAXB after unmarshaling and is used to convert the
+ * hash map to a {@link NavigableMap} so that it will work with the {@link AxConceptGetter}
+ * interface.
+ *
+ * @param u the unmarshaler that is unmarshaling the model
+ * @param parent the parent object of this object in the unmarshaler
+ */
+ public void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ // The map must be navigable to allow name and version searching, unmarshaling returns a
+ // hash map
+ final NavigableMap<AxArtifactKey, AxPolicy> navigablePolicyMap = new TreeMap<>();
+ navigablePolicyMap.putAll(policyMap);
+ policyMap = navigablePolicyMap;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+
+ for (final AxPolicy policy : policyMap.values()) {
+ keyList.addAll(policy.getKeys());
+ }
+
+ return keyList;
+ }
+
+ /**
+ * 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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()) {
+ if (policyEntry.getKey().equals(AxArtifactKey.getNullKey())) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "key on policy entry " + policyEntry.getKey() + " may not be the null key"));
+ } else if (policyEntry.getValue() == null) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "value on policy entry " + policyEntry.getKey() + " may not be null"));
+ } else {
+ if (!policyEntry.getKey().equals(policyEntry.getValue().getKey())) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(),
+ ValidationResult.INVALID, "key on policy entry key " + policyEntry.getKey()
+ + " does not equal policy value key " + policyEntry.getValue().getKey()));
+ }
+
+ result = policyEntry.getValue().validate(result);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ for (final Entry<AxArtifactKey, AxPolicy> policyEntry : policyMap.entrySet()) {
+ policyEntry.getKey().clean();
+ policyEntry.getValue().clean();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + policyMap.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(org.onap.policy.apex.model
+ * .basicmodel.concepts.AxArtifactKey)
+ */
+ @Override
+ public AxPolicy get(final AxArtifactKey conceptKey) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(java.lang.String)
+ */
+ @Override
+ public AxPolicy get(final String conceptKeyName) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKeyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public AxPolicy get(final String conceptKeyName, final String conceptKeyVersion) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).get(conceptKeyName,
+ conceptKeyVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#getAll(java.lang.String)
+ */
+ @Override
+ public Set<AxPolicy> getAll(final String conceptKeyName) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxPolicy>) policyMap).getAll(conceptKeyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#getAll(java.lang.String,
+ * java.lang.String)
+ */
+ @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
new file mode 100644
index 000000000..ff7e4a23f
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java
@@ -0,0 +1,536 @@
+/*-
+ * ============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 java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.utilities.Assertions;
+
+/**
+ * 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>
+ */
+
+@Entity
+@Table(name = "AxPolicy")
+@XmlRootElement(name = "apexPolicy", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxPolicy", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "template", "stateMap", "firstState"})
+
+public class AxPolicy extends AxConcept {
+ private static final long serialVersionUID = -1775614096390365941L;
+
+ @EmbeddedId
+ @XmlElement(name = "policyKey", required = true)
+ private AxArtifactKey key;
+
+ @Column(name = "template")
+ @XmlElement(required = true)
+ private String template;
+
+ // @formatter:off
+ @OneToMany(cascade = CascadeType.ALL)
+ @JoinTable(joinColumns = {@JoinColumn(name = "parentKeyName", referencedColumnName = "name"),
+ @JoinColumn(name = "parentKeyVersion", referencedColumnName = "version")})
+ @XmlElement(name = "state", required = true)
+ private Map<String, AxState> stateMap;
+ // @formatter:on
+
+ @Column(name = "firstState")
+ @XmlElement(required = true)
+ 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<String, AxState>(), "");
+ }
+
+ /**
+ * 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+ for (final AxState state : stateMap.values()) {
+ keyList.addAll(state.getKeys());
+ }
+ return keyList;
+ }
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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 {
+ // Cpnstructor 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) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
+ "state tree in policy is invalid"));
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ firstState = firstState.trim();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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
new file mode 100644
index 000000000..f6000b1f3
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java
@@ -0,0 +1,737 @@
+/*-
+ * ============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 java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.basicmodel.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.apex.model.utilities.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>
+ */
+@Entity
+@Table(name = "AxPolicyModel")
+
+@XmlRootElement(name = "apexPolicyModel", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxPolicyModel", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"policies", "tasks", "events", "albums", "schemas"})
+
+public class AxPolicyModel extends AxModel {
+ private static final String DOES_NOT_EXIST = " does not exist";
+
+ private static final long serialVersionUID = 8800599637708309945L;
+
+ // @formatter:off
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({@JoinColumn(name = "policiesName", referencedColumnName = "name"),
+ @JoinColumn(name = "policiesVersion", referencedColumnName = "version")})
+ @XmlElement(name = "policies", required = true)
+ private AxPolicies policies;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({@JoinColumn(name = "tasksName", referencedColumnName = "name"),
+ @JoinColumn(name = "tasksVersion", referencedColumnName = "version")})
+ @XmlElement(name = "tasks", required = true)
+ private AxTasks tasks;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({@JoinColumn(name = "eventsName", referencedColumnName = "name"),
+ @JoinColumn(name = "eventsVersion", referencedColumnName = "version")})
+ @XmlElement(name = "events", required = true)
+ private AxEvents events;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({@JoinColumn(name = "albumsName", referencedColumnName = "name"),
+ @JoinColumn(name = "albumsVersion", referencedColumnName = "version")})
+ @XmlElement(name = "albums", required = true)
+ private AxContextAlbums albums;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({@JoinColumn(name = "schemasName", referencedColumnName = "name"),
+ @JoinColumn(name = "schemasVersion", referencedColumnName = "version")})
+ @XmlElement(name = "schemas", required = true)
+ private AxContextSchemas schemas;
+ // @formatter:on
+
+ /**
+ * 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", key.getVersion())),
+ new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion())),
+ new AxEvents(new AxArtifactKey(key.getName() + "_Events", key.getVersion())),
+ new AxContextAlbums(new AxArtifactKey(key.getName() + "_Albums", key.getVersion())),
+ new AxTasks(new AxArtifactKey(key.getName() + "_Tasks", key.getVersion())),
+ new AxPolicies(new AxArtifactKey(key.getName() + "_Policies", key.getVersion())));
+ }
+
+ /**
+ * This 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#register()
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#getKeys()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxModel#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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);
+ 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)) {
+ result = 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 AxField field : task.getInputFieldSet()) {
+ if (getSchemas().get(field.getSchema()) == null) {
+ result.addValidationMessage(
+ new AxValidationMessage(task.getKey(), this.getClass(), ValidationResult.INVALID,
+ "task input field schema " + field.getSchema().getID() + DOES_NOT_EXIST));
+ }
+ }
+ for (final AxField field : task.getOutputFieldSet()) {
+ if (getSchemas().get(field.getSchema()) == null) {
+ result.addValidationMessage(
+ new AxValidationMessage(task.getKey(), this.getClass(), ValidationResult.INVALID,
+ "task output field schema " + field.getSchema().getID() + DOES_NOT_EXIST));
+ }
+ }
+ 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));
+ }
+
+ // Check task input fields and event fields are compatible for default tasks with no task
+ // selection logic
+ if (state.getTaskSelectionLogic().getKey().equals(AxReferenceKey.getNullKey()) && triggerEvent != null
+ && defaultTask != null) {
+ final Set<AxField> unhandledTaskInputFields = new TreeSet<>(defaultTask.getInputFieldSet());
+ unhandledTaskInputFields.removeAll(triggerEvent.getFields());
+ for (final AxField unhandledTaskInputField : unhandledTaskInputFields) {
+ result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(),
+ ValidationResult.INVALID, "task input field " + unhandledTaskInputField + " for task "
+ + defaultTask.getID() + " not in trigger event " + triggerEvent.getID()));
+ }
+ }
+
+ for (final AxStateOutput stateOutput : state.getStateOutputs().values()) {
+ if (events.getEventMap().get(stateOutput.getOutgingEvent()) == null) {
+ result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(),
+ ValidationResult.INVALID, "output event " + stateOutput.getOutgingEvent().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.getOutgingEvent());
+ if (usedEvent == null) {
+ result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(),
+ ValidationResult.INVALID, "output event " + stateOutput.getOutgingEvent().getID()
+ + " for state output " + stateOutput.getID() + DOES_NOT_EXIST));
+ }
+
+ if (task != null && usedEvent != null) {
+ final Set<AxField> unhandledTaskOutputFields = new TreeSet<>(task.getOutputFieldSet());
+ unhandledTaskOutputFields.removeAll(usedEvent.getFields());
+ for (final AxField unhandledTaskOutputField : unhandledTaskOutputFields) {
+ result.addValidationMessage(new AxValidationMessage(state.getKey(), this.getClass(),
+ ValidationResult.INVALID, "task output field " + unhandledTaskOutputField + " for task "
+ + task.getID() + " not in output event " + usedEvent.getID()));
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#clean()
+ */
+ @Override
+ public void clean() {
+ super.clean();
+ policies.clean();
+ tasks.clean();
+ events.clean();
+ albums.clean();
+ schemas.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#hashCode()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxModel#compareTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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
new file mode 100644
index 000000000..895232e1c
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxState.java
@@ -0,0 +1,1020 @@
+/*-
+ * ============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 java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.CascadeType;
+import javax.persistence.CollectionTable;
+import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.Embedded;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.utilities.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>
+ */
+
+@Entity
+@Table(name = "AxState")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexState", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxState", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "trigger", "stateOutputs", "contextAlbumReferenceSet", "taskSelectionLogic",
+ "stateFinalizerLogicMap", "defaultTask", "taskReferenceMap"})
+
+public class AxState extends AxConcept {
+ private static final String DOES_NOT_EQUAL_STATE_KEY = " does not equal state key";
+
+ private static final long serialVersionUID = 8041771382337655535L;
+
+ @EmbeddedId
+ @XmlElement(name = "stateKey", required = true)
+ private AxReferenceKey key;
+
+ // @formatter:off
+ @Embedded
+ @AttributeOverrides({@AttributeOverride(name = "name", column = @Column(name = "inTriggerName")),
+ @AttributeOverride(name = "version", column = @Column(name = "inTriggerVersion"))})
+ @Column(name = "trigger")
+ @XmlElement(required = true)
+ private AxArtifactKey trigger;
+
+ @ManyToMany(cascade = CascadeType.ALL)
+ @JoinTable(
+ joinColumns = {@JoinColumn(name = "soParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "soParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "soParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "soLocalName", referencedColumnName = "localName")},
+ inverseJoinColumns = {@JoinColumn(name = "stateParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "stateParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "stateParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "stateLocalName", referencedColumnName = "localName")})
+ @XmlElement(name = "stateOutputs", required = true)
+ private Map<String, AxStateOutput> stateOutputs;
+
+ @ElementCollection
+ @CollectionTable(joinColumns = {@JoinColumn(name = "stateParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "stateParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "stateParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "stateLocalName", referencedColumnName = "localName")})
+ @XmlElement(name = "contextAlbumReference")
+ private Set<AxArtifactKey> contextAlbumReferenceSet;
+
+ @OneToOne
+ @JoinTable(name = "STATE_TSL_JT",
+ joinColumns = {
+ @JoinColumn(name = "tslParentKeyName", referencedColumnName = "parentKeyName", updatable = false,
+ insertable = false),
+ @JoinColumn(name = "tslParentKeyVersion", referencedColumnName = "parentKeyVersion",
+ updatable = false, insertable = false),
+ @JoinColumn(name = "tslParentLocalName ", referencedColumnName = "parentLocalName",
+ updatable = false, insertable = false),
+ @JoinColumn(name = "tslLocalName", referencedColumnName = "localName", updatable = false,
+ insertable = false)})
+ @XmlElement(required = true)
+ private AxTaskSelectionLogic taskSelectionLogic;
+
+ @ManyToMany(cascade = CascadeType.ALL)
+ @JoinTable(
+ joinColumns = {@JoinColumn(name = "sflParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "sflParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "sflParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "sflLocalName", referencedColumnName = "localName")},
+ inverseJoinColumns = {@JoinColumn(name = "stateParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "stateParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "stateParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "stateLocalName", referencedColumnName = "localName")})
+ @XmlElement(name = "stateFinalizerLogicMap", required = true)
+ private Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap;
+
+ @Embedded
+ @AttributeOverrides({@AttributeOverride(name = "name", column = @Column(name = "defaultTaskName")),
+ @AttributeOverride(name = "version", column = @Column(name = "defaultTaskVersion"))})
+ @Column(name = "defaultTask")
+ @XmlElement(required = true)
+ private AxArtifactKey defaultTask;
+
+ @ManyToMany(cascade = CascadeType.ALL)
+ @JoinTable(
+ joinColumns = {@JoinColumn(name = "trmParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "trmParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "trmParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "trmLocalName", referencedColumnName = "localName")},
+ inverseJoinColumns = {@JoinColumn(name = "stateParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "stateParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "stateParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "stateLocalName", referencedColumnName = "localName")})
+ @XmlElement(name = "taskReferences", required = true)
+ private Map<AxArtifactKey, AxStateTaskReference> taskReferenceMap;
+ // @formatter:on
+
+ /**
+ * 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) {
+ this(key, // Key
+ AxArtifactKey.getNullKey(), // Trigger Reference
+ new TreeMap<String, AxStateOutput>(), // State Outputs
+ new TreeSet<AxArtifactKey>(), // Context Album References
+ new AxTaskSelectionLogic(), // Task Selection Logic
+ new TreeMap<String, AxStateFinalizerLogic>(), // State Finalizer Logics
+ AxArtifactKey.getNullKey(), // Default Task
+ new TreeMap<AxArtifactKey, AxStateTaskReference>() // Task References
+ );
+ }
+
+ /**
+ * This Constructor creates a state with all its fields defined.
+ *
+ * @param key the reference key of the state
+ * @param trigger the event that triggers the state
+ * @param stateOutputs the possible state outputs for the state
+ * @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
+ * @param taskSelectionLogic the task selection logic that selects the task a state executes in
+ * an 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
+ * @param defaultTask the default task that will execute in a state if Task Selection Logic is
+ * not specified
+ * @param taskReferenceMap the task reference map that defines the tasks for the state and how
+ * the task outputs are handled
+ */
+ // CHECKSTYLE:OFF: checkstyle:parameterNumber
+ public AxState(final AxReferenceKey key, final AxArtifactKey trigger, final Map<String, AxStateOutput> stateOutputs,
+ final Set<AxArtifactKey> contextAlbumReferenceSet, final AxTaskSelectionLogic taskSelectionLogic,
+ final Map<String, AxStateFinalizerLogic> stateFinalizerLogicMap, final AxArtifactKey defaultTask,
+ final Map<AxArtifactKey, AxStateTaskReference> taskReferenceMap) {
+ super();
+ Assertions.argumentNotNull(key, "key may not be null");
+ Assertions.argumentNotNull(trigger, "trigger may not be null");
+ Assertions.argumentNotNull(stateOutputs, "stateOutputs may not be null");
+ Assertions.argumentNotNull(contextAlbumReferenceSet, "contextAlbumReferenceSet may not be null");
+ Assertions.argumentNotNull(taskSelectionLogic, "taskSelectionLogic may not be null");
+ Assertions.argumentNotNull(stateFinalizerLogicMap, "stateFinalizerLogicMap may not be null");
+ Assertions.argumentNotNull(defaultTask, "defaultTask may not be null");
+ Assertions.argumentNotNull(taskReferenceMap, "taskReferenceMap may not be null");
+
+ this.key = key;
+ this.trigger = trigger;
+ this.stateOutputs = stateOutputs;
+ this.contextAlbumReferenceSet = contextAlbumReferenceSet;
+ this.taskSelectionLogic = taskSelectionLogic;
+ this.stateFinalizerLogicMap = stateFinalizerLogicMap;
+ this.defaultTask = defaultTask;
+ this.taskReferenceMap = taskReferenceMap;
+ }
+ // CHECKSTYLE:ON: checkstyle:parameterNumber
+
+ /**
+ * When a state is unmarshalled from disk or from the database, the parent of contained objects
+ * is not defined. This method is called by JAXB after unmarshaling and is used to set the
+ * parent keys of all {@link AxTaskSelectionLogic}, {@link AxStateOutput}, and
+ * {@link AxStateFinalizerLogic} instance in the state.
+ *
+ * @param u the unmarshaler that is unmarshaling the model
+ * @param parent the parent object of this object in the unmarshaler
+ */
+ public void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ if (!taskSelectionLogic.getKey().getLocalName().equals(AxKey.NULL_KEY_NAME)) {
+ taskSelectionLogic.getKey().setParentReferenceKey(key);
+ }
+
+ for (final Entry<String, AxStateOutput> soEntry : stateOutputs.entrySet()) {
+ soEntry.getValue().getKey().setParentReferenceKey(key);
+ }
+
+ for (final Entry<String, AxStateFinalizerLogic> sflEntry : stateFinalizerLogicMap.entrySet()) {
+ sflEntry.getValue().getKey().setParentReferenceKey(key);
+ }
+
+ for (final Entry<AxArtifactKey, AxStateTaskReference> trEntry : taskReferenceMap.entrySet()) {
+ trEntry.getValue().getKey().setParentReferenceKey(key);
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @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();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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 AxState other = (AxState) otherObj;
+ 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
new file mode 100644
index 000000000..76704b051
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateFinalizerLogic.java
@@ -0,0 +1,137 @@
+/*-
+ * ============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 javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+/**
+ * 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}.
+ */
+@Entity
+@Table(name = "AxStateFinalizerLogic")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexStateFinalizerLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxStateFinalizerLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+
+public class AxStateFinalizerLogic extends AxLogic {
+ private static final long serialVersionUID = 2090324845463750391L;
+
+ /**
+ * 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
new file mode 100644
index 000000000..a0c73c260
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java
@@ -0,0 +1,389 @@
+/*-
+ * ============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 java.util.List;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.utilities.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>
+ */
+
+@Entity
+@Table(name = "AxStateOutput")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexStateOutput", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxStateOutput", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "outgoingEvent", "nextState"})
+
+public class AxStateOutput extends AxConcept {
+ private static final long serialVersionUID = 8041771382337655535L;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxReferenceKey key;
+
+ // @formatter:off
+ @Embedded
+ @AttributeOverrides({@AttributeOverride(name = "name", column = @Column(name = "outgoingEventName")),
+ @AttributeOverride(name = "version", column = @Column(name = "outgoingEventVersion"))})
+ @Column(name = "outgoingEvent")
+ @XmlElement(required = true)
+ private AxArtifactKey outgoingEvent;
+
+ @Embedded
+ @AttributeOverrides({@AttributeOverride(name = "parentKeyName", column = @Column(name = "nextStateParentKeyName")),
+ @AttributeOverride(name = "parentKeyVersion", column = @Column(name = "nextStateParentKeyVersion")),
+ @AttributeOverride(name = "parentLocalName", column = @Column(name = "nextStateParentLocalName")),
+ @AttributeOverride(name = "localName", column = @Column(name = "nextStateLocalName"))})
+ @Column(name = "nextState")
+ @XmlElement(required = true)
+ 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @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;
+ }
+
+ /**
+ * Sets the reference key for the state output.
+ *
+ * @param key the reference key for the state output
+ */
+ public void setKey(final AxReferenceKey key) {
+ Assertions.argumentNotNull(key, "key may not be null");
+ this.key = key;
+ }
+
+ /**
+ * Gets the outgoing event emitted on use of this state output.
+ *
+ * @return the outgoing event emitted on use of this state output
+ */
+ public AxArtifactKey getOutgingEvent() {
+ return outgoingEvent;
+ }
+
+ /**
+ * Sets the outgoing event emitted on use of this state output.
+ *
+ * @param outgoingEvent the outgoing event emitted on use of this state output
+ */
+ public void setOutgoingEvent(final AxArtifactKey outgoingEvent) {
+ Assertions.argumentNotNull(outgoingEvent, "outgoingEvent may not be null");
+ this.outgoingEvent = outgoingEvent;
+ }
+
+ /**
+ * Gets the next state to which execution will pass on use of this state output.
+ *
+ * @return the next state to which execution will pass on use of this state output
+ */
+ public AxReferenceKey getNextState() {
+ return nextState;
+ }
+
+ /**
+ * Sets the next state to which execution will pass on use of this state output.
+ *
+ * @param nextState the next state to which execution will pass on use of this state output
+ */
+ public void setNextState(final AxReferenceKey nextState) {
+ Assertions.argumentNotNull(nextState, "nextState may not be null");
+ this.nextState = nextState;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ outgoingEvent.clean();
+ nextState.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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/AxStateTaskOutputType.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java
new file mode 100644
index 000000000..741eb8833
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskOutputType.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * This enumeration defines the type of state output selection that is defined for a task in a
+ * state. The {@link AxStateTaskReference} instance for each task uses this enumeration to decide
+ * what type of output selection to use when a task has completed execution.
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxStateTaskOutputType", namespace = "http://www.onap.org/policy/apex-pdp")
+
+public enum AxStateTaskOutputType {
+ /** The state output selection for the task has not been defined. */
+ UNDEFINED,
+ /**
+ * 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
new file mode 100644
index 000000000..011af6cbb
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTaskReference.java
@@ -0,0 +1,400 @@
+/*-
+ * ============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 java.util.List;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Enumerated;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.utilities.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>
+ */
+
+@Entity
+@Table(name = "AxStateTaskReference")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexStateTaskReference", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxStateTaskReference", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "outputType", "output"})
+
+public class AxStateTaskReference extends AxConcept {
+ private static final long serialVersionUID = 8041771382337655535L;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxReferenceKey key;
+
+ @Enumerated
+ @Column(name = "outputType")
+ @XmlElement(required = true)
+ private AxStateTaskOutputType outputType;
+
+ // @formatter:off
+ @Embedded
+ @AttributeOverrides({@AttributeOverride(name = "parentKeyName", column = @Column(name = "outputParentKeyName")),
+ @AttributeOverride(name = "parentKeyVersion", column = @Column(name = "outputParentKeyVersion")),
+ @AttributeOverride(name = "parentLocalName", column = @Column(name = "outputParentLocalName")),
+ @AttributeOverride(name = "localName", column = @Column(name = "outputLocalName"))})
+ @Column(name = "output")
+ @XmlElement(required = true)
+ private AxReferenceKey output;
+ // @formatter:on
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ output.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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
new file mode 100644
index 000000000..30076ca0b
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateTree.java
@@ -0,0 +1,157 @@
+/*-
+ * ============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 java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.utilities.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.
+ */
+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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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;
+ if (!thisState.equals(other.thisState)) {
+ return thisState.compareTo(other.thisState);
+ }
+ if (!nextStates.equals(other.nextStates)) {
+ return (nextStates.hashCode() - other.nextStates.hashCode());
+ }
+ 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
new file mode 100644
index 000000000..b1f26f6c0
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java
@@ -0,0 +1,745 @@
+/*-
+ * ============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 java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.persistence.CascadeType;
+import javax.persistence.CollectionTable;
+import javax.persistence.ElementCollection;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.AxField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
+import org.onap.policy.apex.model.utilities.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 task must have at least one input field
+ * <li>The parent of each input field of a task must be that task
+ * <li>Each input field must be valid, see validation in {@link AxInputField}
+ * <li>The task must have at least one output field
+ * <li>The parent of each output field of a task must be that task
+ * <li>Each output field must be valid, see validation in {@link AxOutputField}
+ * <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>
+ */
+
+@Entity
+@Table(name = "AxTask")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexTask", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxTask", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "inputFields", "outputFields", "taskParameters", "contextAlbumReferenceSet", "taskLogic"})
+
+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;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxArtifactKey key;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ @XmlElement(name = "inputFields", required = true)
+ private Map<String, AxInputField> inputFields;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ @XmlElement(name = "outputFields", required = true)
+ private Map<String, AxOutputField> outputFields;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ @XmlElement(name = "taskParameters", required = true)
+ private Map<String, AxTaskParameter> taskParameters;
+
+ // @formatter:off
+ @ElementCollection
+ @CollectionTable(joinColumns = {@JoinColumn(name = "contextAlbumName", referencedColumnName = "name"),
+ @JoinColumn(name = "contextAlbumVersion", referencedColumnName = "version")})
+ @XmlElement(name = "contextAlbumReference")
+ private Set<AxArtifactKey> contextAlbumReferenceSet;
+ // @formatter:on
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @XmlElement(required = true)
+ 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<String, AxInputField>(), // Input fields
+ new TreeMap<String, AxOutputField>(), // Output Fields
+ new TreeMap<String, AxTaskParameter>(), // Task Parameters
+ new TreeSet<AxArtifactKey>(), // 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 inputFields the input fields that the task expects
+ * @param outputFields the output fields that the task emits
+ * @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, AxInputField> inputFields,
+ final Map<String, AxOutputField> outputFields, final Map<String, AxTaskParameter> taskParameters,
+ final Set<AxArtifactKey> contextAlbumReferenceSet, final AxTaskLogic taskLogic) {
+ super();
+ Assertions.argumentNotNull(key, "key may not be null");
+ Assertions.argumentNotNull(inputFields, "inputFields may not be null");
+ Assertions.argumentNotNull(outputFields, "outputFields 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.inputFields = inputFields;
+ this.outputFields = outputFields;
+ this.taskParameters = taskParameters;
+ this.contextAlbumReferenceSet = contextAlbumReferenceSet;
+ this.taskLogic = taskLogic;
+ }
+
+ /**
+ * When a task is unmarshalled from disk or from the database, the parent of contained objects
+ * is not defined. This method is called by JAXB after unmarshaling and is used to set the
+ * parent keys of all {@link AxInputField}, {@link AxOutputField}, and {@link AxTaskParameter}
+ * instance in the task.
+ *
+ * @param u the unmarshaler that is unmarshaling the model
+ * @param parent the parent object of this object in the unmarshaler
+ */
+ public void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ taskLogic.getKey().setParentArtifactKey(key);
+
+ for (final AxInputField inputField : inputFields.values()) {
+ inputField.getKey().setParentArtifactKey(key);
+ inputField.getKey().setParentLocalName("InField");
+ }
+ for (final AxOutputField outputField : outputFields.values()) {
+ outputField.getKey().setParentArtifactKey(key);
+ outputField.getKey().setParentLocalName("OutField");
+ }
+ for (final AxTaskParameter parameter : taskParameters.values()) {
+ parameter.getKey().setParentArtifactKey(key);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+ for (final AxInputField inputField : inputFields.values()) {
+ keyList.addAll(inputField.getKeys());
+ }
+ for (final AxOutputField outputField : outputFields.values()) {
+ keyList.addAll(outputField.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;
+ }
+
+ /**
+ * Sets the key of the task.
+ *
+ * @param key the key of the task
+ */
+ public void setKey(final AxArtifactKey key) {
+ Assertions.argumentNotNull(key, "key may not be null");
+ this.key = key;
+ }
+
+ /**
+ * Gets the input fields that the task expects.
+ *
+ * @return the input fields that the task expects
+ */
+ public Map<String, AxInputField> getInputFields() {
+ return inputFields;
+ }
+
+ /**
+ * Gets the raw input fields that the task expects as a tree map.
+ *
+ * @return the raw input fields that the task expects
+ */
+ public Map<String, AxField> getRawInputFields() {
+ return new TreeMap<>(inputFields);
+ }
+
+ /**
+ * Convenience method to get the input fields as a set.
+ *
+ * @return the input fields as a set
+ */
+ public Set<AxField> getInputFieldSet() {
+ final Set<AxField> inputFieldSet = new TreeSet<>();
+ for (final AxInputField field : inputFields.values()) {
+ inputFieldSet.add(field);
+ }
+ return inputFieldSet;
+ }
+
+ /**
+ * Sets the input fields that the task expects.
+ *
+ * @param inputFields the input fields that the task expects
+ */
+ public void setInputFields(final Map<String, AxInputField> inputFields) {
+ Assertions.argumentNotNull(inputFields, "inputFields may not be null");
+ this.inputFields = inputFields;
+ }
+
+ /**
+ * Copy the input fields from the given map into the task. This method is used to get a copy of
+ * the input fields, which can be useful for unit testing of policies and tasks.
+ *
+ * @param fields the fields to copy into the task
+ */
+ public void duplicateInputFields(final Map<String, AxField> fields) {
+ Assertions.argumentNotNull(fields, "fields may not be null");
+
+ for (final AxField field : fields.values()) {
+ final AxReferenceKey fieldKey = new AxReferenceKey(this.getKey().getName(), this.getKey().getVersion(),
+ "inputFields", field.getKey().getLocalName());
+ final AxInputField inputField = new AxInputField(fieldKey, field.getSchema());
+ inputFields.put(inputField.getKey().getLocalName(), inputField);
+ }
+ }
+
+ /**
+ * Gets the output fields that the task emits.
+ *
+ * @return the output fields that the task emits
+ */
+ public Map<String, AxOutputField> getOutputFields() {
+ return outputFields;
+ }
+
+ /**
+ * Gets the raw output fields that the task emits as a tree map.
+ *
+ * @return the raw output fields as a tree map
+ */
+ public Map<String, AxField> getRawOutputFields() {
+ return new TreeMap<>(outputFields);
+ }
+
+ /**
+ * Gets the output fields that the task emits as a set.
+ *
+ * @return the output fields as a set
+ */
+ public Set<AxField> getOutputFieldSet() {
+ final Set<AxField> outputFieldSet = new TreeSet<>();
+ for (final AxOutputField field : outputFields.values()) {
+ outputFieldSet.add(field);
+ }
+ return outputFieldSet;
+ }
+
+ /**
+ * Sets the output fields that the task emits.
+ *
+ * @param outputFields the output fields that the task emits
+ */
+ public void setOutputFields(final Map<String, AxOutputField> outputFields) {
+ Assertions.argumentNotNull(outputFields, "outputFields may not be null");
+ this.outputFields = outputFields;
+ }
+
+ /**
+ * Copy the output fields from the given map into the task. This method is used to get a copy of
+ * the output fields, which can be useful for unit testing of policies and tasks.
+ *
+ * @param fields the fields to copy into the task
+ */
+ public void duplicateOutputFields(final Map<String, AxField> fields) {
+ Assertions.argumentNotNull(fields, "fields may not be null");
+
+ for (final AxField field : fields.values()) {
+ final AxReferenceKey fieldKey = new AxReferenceKey(this.getKey().getName(), this.getKey().getVersion(),
+ "outputFields", field.getKey().getLocalName());
+ final AxOutputField outputField = new AxOutputField(fieldKey, field.getSchema());
+ outputFields.put(outputField.getKey().getLocalName(), outputField);
+ }
+ }
+
+ /**
+ * Gets the task parameters that are used to initialize tasks of this type.
+ *
+ * @return the task parameters that are used to initialize tasks of this type
+ */
+ public Map<String, AxTaskParameter> getTaskParameters() {
+ return taskParameters;
+ }
+
+ /**
+ * Sets the task parameters that are used to initialize tasks of this type.
+ *
+ * @param taskParameters the task parameters that are used to initialize tasks of this type
+ */
+ public void setTaskParameters(final Map<String, AxTaskParameter> taskParameters) {
+ Assertions.argumentNotNull(taskParameters, "taskParameters may not be null");
+ this.taskParameters = taskParameters;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Gets the task logic that performs the domain specific work of the task.
+ *
+ * @return the task logic that performs the domain specific work of the task
+ */
+ public AxTaskLogic getTaskLogic() {
+ return taskLogic;
+ }
+
+ /**
+ * Sets the task logic that performs the domain specific work of the task.
+ *
+ * @param taskLogic the task logic that performs the domain specific work of the task
+ */
+ public void setTaskLogic(final AxTaskLogic taskLogic) {
+ Assertions.argumentNotNull(taskLogic, "taskLogic may not be null");
+ this.taskLogic = taskLogic;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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 (inputFields.size() == 0) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "inputFields may not be empty"));
+ } else {
+ for (final Entry<String, AxInputField> inputFieldEntry : inputFields.entrySet()) {
+ result = validateField(inputFieldEntry.getKey(), inputFieldEntry.getValue(), "input", result);
+ }
+ }
+
+ if (outputFields.size() == 0) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "outputFields may not be empty"));
+ } else {
+ for (final Entry<String, AxOutputField> outputFieldEntry : outputFields.entrySet()) {
+ result = validateField(outputFieldEntry.getKey(), outputFieldEntry.getValue(), "input", result);
+ }
+ }
+
+ for (final Entry<String, AxTaskParameter> taskParameterEntry : taskParameters.entrySet()) {
+ result = vaildateTaskParameterEntry(taskParameterEntry, result);
+ }
+
+ for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) {
+ result = vaildateContextAlbumReference(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 field
+ *
+ * @param key the key of the field to validate
+ * @param field the field to validate
+ * @param direction The direction of the field
+ * @param result The validation result to append to
+ * @return The result of the validation
+ */
+ private AxValidationResult validateField(final String fieldKey, final AxField field, final String direction,
+ AxValidationResult result) {
+ if (field == null) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "null " + direction + " field value found on " + direction + " field " + fieldKey));
+ } else {
+ if (!field.getKey().getParentArtifactKey().equals(key)) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "parent key on " + direction + " field " + fieldKey + DOES_NOT_EQUAL_TASK_KEY));
+ }
+
+ result = field.validate(result);
+ }
+
+ return 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 vaildateTaskParameterEntry(final Entry<String, AxTaskParameter> taskParameterEntry,
+ AxValidationResult result) {
+ if (taskParameterEntry.getValue() == null) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "null input task parameer 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 taskParameterEntry the context album reference entry to validate
+ * @param result The validation result to append to
+ * @return The result of the validation
+ */
+ private AxValidationResult vaildateContextAlbumReference(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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ for (final AxInputField inputField : inputFields.values()) {
+ inputField.clean();
+ }
+ for (final AxOutputField outputField : outputFields.values()) {
+ outputField.clean();
+ }
+ for (final AxTaskParameter parameter : taskParameters.values()) {
+ parameter.clean();
+ }
+ for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) {
+ contextAlbumReference.clean();
+ }
+ taskLogic.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append("key=");
+ builder.append(key);
+ builder.append(",inputFields=");
+ builder.append(inputFields);
+ builder.append(",outputFields=");
+ builder.append(outputFields);
+ builder.append(",taskParameters=");
+ builder.append(taskParameters);
+ builder.append(",contextAlbumReferenceSet=");
+ builder.append(contextAlbumReferenceSet);
+ builder.append(",taskLogic=");
+ builder.append(taskLogic);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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, AxInputField> newInputFields = new TreeMap<>();
+ for (final Entry<String, AxInputField> inputFieldEntry : inputFields.entrySet()) {
+ newInputFields.put(inputFieldEntry.getKey(), new AxInputField(inputFieldEntry.getValue()));
+ }
+ copy.setInputFields(newInputFields);
+
+ final Map<String, AxOutputField> newOutputFields = new TreeMap<>();
+ for (final Entry<String, AxOutputField> outputFieldEntry : outputFields.entrySet()) {
+ newOutputFields.put(outputFieldEntry.getKey(), new AxOutputField(outputFieldEntry.getValue()));
+ }
+ copy.setOutputFields(newOutputFields);
+
+ 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((AxLogic) taskLogic));
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + inputFields.hashCode();
+ result = prime * result + outputFields.hashCode();
+ result = prime * result + taskParameters.hashCode();
+ result = prime * result + contextAlbumReferenceSet.hashCode();
+ result = prime * result + taskLogic.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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 (!inputFields.equals(other.inputFields)) {
+ return false;
+ }
+ if (!outputFields.equals(other.outputFields)) {
+ return false;
+ }
+ if (!taskParameters.equals(other.taskParameters)) {
+ return false;
+ }
+ if (!contextAlbumReferenceSet.equals(other.contextAlbumReferenceSet)) {
+ return false;
+ }
+ return taskLogic.equals(other.taskLogic);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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 (!inputFields.equals(other.inputFields)) {
+ return (inputFields.hashCode() - other.inputFields.hashCode());
+ }
+ if (!outputFields.equals(other.outputFields)) {
+ return (outputFields.hashCode() - other.outputFields.hashCode());
+ }
+ 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
new file mode 100644
index 000000000..00513e8f7
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskLogic.java
@@ -0,0 +1,136 @@
+/*-
+ * ============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 javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+/**
+ * This class 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}.
+ */
+@Entity
+@Table(name = "AxTaskLogic")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxTaskLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+
+public class AxTaskLogic extends AxLogic {
+ private static final long serialVersionUID = 2090324845463750391L;
+
+ /**
+ * 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
new file mode 100644
index 000000000..5ae3bfa42
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskParameter.java
@@ -0,0 +1,299 @@
+/*-
+ * ============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 java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.utilities.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.
+ */
+
+@Entity
+@Table(name = "AxTaskParameter")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxTaskParameter", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = {"key", "defaultValue"})
+
+public class AxTaskParameter extends AxConcept {
+ private static final long serialVersionUID = 7351688156934099977L;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxReferenceKey key;
+
+ @Column(name = "defaultValue")
+ @XmlElement
+ 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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ defaultValue = defaultValue.trim();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + defaultValue.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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
new file mode 100644
index 000000000..89c9418a4
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTaskSelectionLogic.java
@@ -0,0 +1,135 @@
+/*-
+ * ============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 javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+/**
+ * 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}.
+ */
+@Entity
+@Table(name = "AxTaskSelectionLogic")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexTaskSelectionLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxTaskSelectionLogic", namespace = "http://www.onap.org/policy/apex-pdp")
+
+public class AxTaskSelectionLogic extends AxLogic {
+ private static final long serialVersionUID = 2090324845463750391L;
+
+ /**
+ * 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
new file mode 100644
index 000000000..532d7d017
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTasks.java
@@ -0,0 +1,425 @@
+/*-
+ * ============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 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 javax.persistence.CascadeType;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter;
+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.apex.model.utilities.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.
+ */
+@Entity
+@Table(name = "AxTasks")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxTasks", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = {"key", "taskMap"})
+public class AxTasks extends AxConcept implements AxConceptGetter<AxTask> {
+ private static final long serialVersionUID = 4290442590545820316L;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxArtifactKey key;
+
+ // @formatter:off
+ @ManyToMany(cascade = CascadeType.ALL)
+ @JoinTable(
+ joinColumns = {@JoinColumn(name = "taskMapName", referencedColumnName = "name"),
+ @JoinColumn(name = "taskMapVersion", referencedColumnName = "version")},
+ inverseJoinColumns = {@JoinColumn(name = "taskName", referencedColumnName = "name"),
+ @JoinColumn(name = "taskVersion", referencedColumnName = "version")})
+ @XmlElement(required = true)
+ private Map<AxArtifactKey, AxTask> taskMap;
+ // @formatter:on
+
+ /**
+ * 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<AxArtifactKey, AxTask>());
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * When a model is unmarshalled from disk or from the database, the task map is returned as a
+ * raw hash map. This method is called by JAXB after unmarshaling and is used to convert the
+ * hash map to a {@link NavigableMap} so that it will work with the {@link AxConceptGetter}
+ * interface.
+ *
+ * @param u the unmarshaler that is unmarshaling the model
+ * @param parent the parent object of this object in the unmarshaler
+ */
+ public void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ // The map must be navigable to allow name and version searching, unmarshaling returns a
+ // hash map
+ final NavigableMap<AxArtifactKey, AxTask> navigableTaskMap = new TreeMap<>();
+ navigableTaskMap.putAll(taskMap);
+ taskMap = navigableTaskMap;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+
+ for (final AxTask task : taskMap.values()) {
+ keyList.addAll(task.getKeys());
+ }
+
+ return keyList;
+ }
+
+ /**
+ * 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxValidationResult)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ for (final Entry<AxArtifactKey, AxTask> taskEntry : taskMap.entrySet()) {
+ taskEntry.getKey().clean();
+ taskEntry.getValue().clean();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @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();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.
+ * basicmodel.concepts.AxConcept)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + taskMap.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(org.onap.policy.apex.
+ * model. basicmodel.concepts.AxArtifactKey)
+ */
+ @Override
+ public AxTask get(final AxArtifactKey conceptKey) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(java.lang.String)
+ */
+ @Override
+ public AxTask get(final String conceptKeyName) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKeyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(java.lang.String,
+ * java.lang.String)
+ */
+ @Override
+ public AxTask get(final String conceptKeyName, final String conceptKeyVersion) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).get(conceptKeyName,
+ conceptKeyVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#getAll(java.lang.String)
+ */
+ @Override
+ public Set<AxTask> getAll(final String conceptKeyName) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxTask>) taskMap).getAll(conceptKeyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#getAll(java.lang.String,
+ * java.lang.String)
+ */
+ @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
new file mode 100644
index 000000000..3b0d53f9c
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyException.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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 e the exception that caused this exception to be thrown
+ */
+ public PolicyException(final String message, final Exception e) {
+ super(message, e);
+ }
+}
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
new file mode 100644
index 000000000..dbd2fb64f
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/PolicyRuntimeException.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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 e the exception that caused this exception to be thrown
+ */
+ public PolicyRuntimeException(final String message, final Exception e) {
+ super(message, e);
+ }
+}
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
new file mode 100644
index 000000000..cc15a6af5
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/package-info.java
@@ -0,0 +1,35 @@
+/*-
+ * ============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 the concepts required to specify policies and tasks in APEX. It defines the main Apex
+ * concepts of policies and tasks.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
+ xmlns = {@XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "")})
+
+package org.onap.policy.apex.model.policymodel.concepts;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java
new file mode 100644
index 000000000..99058484b
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java
@@ -0,0 +1,186 @@
+/*-
+ * ============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.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.eventmodel.concepts.AxInputField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
+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.apex.model.utilities.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.getOutgingEvent()).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());
+ }
+
+ // Task data type usage
+ for (final AxInputField inputField : task.getInputFields().values()) {
+ result.getContextSchemaUsage().get(inputField.getSchema()).add(task.getKey());
+ }
+ for (final AxOutputField outputField : task.getOutputFields().values()) {
+ result.getContextSchemaUsage().get(outputField.getSchema()).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
new file mode 100644
index 000000000..d59af7cba
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalysisResult.java
@@ -0,0 +1,266 @@
+/*-
+ * ============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.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<AxKey>());
+ }
+
+ for (final Entry<AxArtifactKey, AxContextAlbum> contextAlbumEntry : policyModel.getAlbums().getAlbumsMap().entrySet()) {
+ contextAlbumUsage.put(contextAlbumEntry.getKey(), new TreeSet<AxKey>());
+ }
+
+ for (final AxArtifactKey eventKey : policyModel.getEvents().getEventMap().keySet()) {
+ eventUsage.put(eventKey, new TreeSet<AxKey>());
+ }
+
+ for (final AxArtifactKey taskKey : policyModel.getTasks().getTaskMap().keySet()) {
+ taskUsage.put(taskKey, new TreeSet<AxKey>());
+ }
+ }
+
+ /**
+ * 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @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
new file mode 100644
index 000000000..5a947c596
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyComparer.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..3e5571242
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReader.java
@@ -0,0 +1,153 @@
+/*-
+ * ============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.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.apex.model.utilities.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;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#getLogicPackage()
+ */
+ @Override
+ public String getLogicPackage() {
+ return logicPackage;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#setLogicPackage(java.lang.
+ * String)
+ */
+ @Override
+ public AxLogicReader setLogicPackage(final String incomingLogicPackage) {
+ this.logicPackage = incomingLogicPackage;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#getDefaultLogic()
+ */
+ @Override
+ public String getDefaultLogic() {
+ return defaultLogic;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#setDefaultLogic(boolean)
+ */
+ @Override
+ public AxLogicReader setDefaultLogic(final String incomingDefaultLogic) {
+ this.defaultLogic = incomingDefaultLogic;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#readLogic(.policymodel.concepts
+ * .AxLogic)
+ */
+ @Override
+ public String readLogic(final AxLogic axLogic) {
+ // Java uses compiled logic, other executor types run scripts
+ if (axLogic.getLogicFlavour().equals("JAVA")) {
+ // 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.replaceAll("\\.", "/");
+
+ // 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) {
+ LOGGER.warn("logic not found for logic \"" + fullLogicFilePath + "\"");
+ throw new PolicyRuntimeException("logic not found for logic \"" + fullLogicFilePath + "\"");
+ }
+
+ // 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
new file mode 100644
index 000000000..545a02e89
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparer.java
@@ -0,0 +1,271 @@
+/*-
+ * ============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> contextSchemaComparisonResult =
+ 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());
+
+ contextSchemaComparisonResult = 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 contextSchemaComparisonResult;
+ }
+
+ /**
+ * 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;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()
+ */
+ @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(contextSchemaComparisonResult.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
new file mode 100644
index 000000000..091f20462
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
@@ -0,0 +1,155 @@
+/*-
+ * ============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.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.AxPolicyModel;
+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
+ * @return the new Destination Model
+ * @throws ApexModelException on model transfer errors
+ */
+ public static AxPolicyModel getMergedPolicyModel(final AxPolicyModel leftPolicyModel,
+ final AxPolicyModel rightPolicyModel, final boolean useLeftOnMatches) throws ApexModelException {
+ return getMergedPolicyModel(leftPolicyModel, rightPolicyModel, useLeftOnMatches, false);
+ }
+
+ /**
+ * 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
+ * @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)
+ throws ApexModelException {
+ // Validate the left model
+ if (!ignoreInvalidSource) {
+ final AxValidationResult leftValidationResult = new AxValidationResult();
+ leftPolicyModel.validate(leftValidationResult);
+ if (!leftValidationResult.isValid()) {
+ LOGGER.warn("left model is invalid: " + leftValidationResult.toString());
+ throw new ApexModelException("left model is invalid: " + leftValidationResult.toString());
+ }
+ }
+
+ // Validate the right model
+ if (!ignoreInvalidSource) {
+ final AxValidationResult rightValidationResult = new AxValidationResult();
+ rightPolicyModel.validate(rightValidationResult);
+ if (!rightValidationResult.isValid()) {
+ LOGGER.warn("right model is invalid: " + rightValidationResult.toString());
+ throw new ApexModelException("right model is invalid: " + rightValidationResult.toString());
+ }
+ }
+
+ // The new policy model uses the favoured copy side as its base
+ final AxPolicyModel mergedPolicyModel = (AxPolicyModel) (useLeftOnMatches ? new AxPolicyModel(leftPolicyModel)
+ : new AxPolicyModel(rightPolicyModel));
+
+ // The Compared to policy model is the unfavoured side
+ final AxPolicyModel copyFromPolicyModel = (useLeftOnMatches ? rightPolicyModel : leftPolicyModel);
+
+ //  Get the keys to copy over
+ final Set<AxArtifactKey> copyOverKeyInfoKeys =
+ new TreeSet<>(copyFromPolicyModel.getKeyInformation().getKeyInfoMap().keySet());
+ final Set<AxArtifactKey> copyOverContextSchemaKeys =
+ new TreeSet<>(copyFromPolicyModel.getSchemas().getSchemasMap().keySet());
+ final Set<AxArtifactKey> copyOverEventKeys =
+ new TreeSet<>(copyFromPolicyModel.getEvents().getEventMap().keySet());
+ final Set<AxArtifactKey> copyOverContextAlbumKeys =
+ new TreeSet<>(copyFromPolicyModel.getAlbums().getAlbumsMap().keySet());
+ final Set<AxArtifactKey> copyOverTaskKeys = new TreeSet<>(copyFromPolicyModel.getTasks().getTaskMap().keySet());
+ final Set<AxArtifactKey> copyOverPolicyKeys =
+ new TreeSet<>(copyFromPolicyModel.getPolicies().getPolicyMap().keySet());
+
+ //  Remove keys that already exist
+ copyOverKeyInfoKeys.removeAll(mergedPolicyModel.getKeyInformation().getKeyInfoMap().keySet());
+ copyOverContextSchemaKeys.removeAll(mergedPolicyModel.getSchemas().getSchemasMap().keySet());
+ copyOverEventKeys.removeAll(mergedPolicyModel.getEvents().getEventMap().keySet());
+ copyOverContextAlbumKeys.removeAll(mergedPolicyModel.getAlbums().getAlbumsMap().keySet());
+ copyOverTaskKeys.removeAll(mergedPolicyModel.getTasks().getTaskMap().keySet());
+ copyOverPolicyKeys.removeAll(mergedPolicyModel.getPolicies().getPolicyMap().keySet());
+
+ // Now add all the concepts that must be copied over
+ for (final AxArtifactKey keyInfoKey : copyOverKeyInfoKeys) {
+ mergedPolicyModel.getKeyInformation().getKeyInfoMap().put(keyInfoKey,
+ copyFromPolicyModel.getKeyInformation().getKeyInfoMap().get(keyInfoKey));
+ }
+ for (final AxArtifactKey contextSchemaKey : copyOverContextSchemaKeys) {
+ mergedPolicyModel.getSchemas().getSchemasMap().put(contextSchemaKey,
+ copyFromPolicyModel.getSchemas().getSchemasMap().get(contextSchemaKey));
+ }
+ for (final AxArtifactKey eventKey : copyOverEventKeys) {
+ mergedPolicyModel.getEvents().getEventMap().put(eventKey,
+ copyFromPolicyModel.getEvents().getEventMap().get(eventKey));
+ }
+ for (final AxArtifactKey contextAlbumKey : copyOverContextAlbumKeys) {
+ mergedPolicyModel.getAlbums().getAlbumsMap().put(contextAlbumKey,
+ copyFromPolicyModel.getAlbums().getAlbumsMap().get(contextAlbumKey));
+ }
+ for (final AxArtifactKey taskKey : copyOverTaskKeys) {
+ mergedPolicyModel.getTasks().getTaskMap().put(taskKey,
+ copyFromPolicyModel.getTasks().getTaskMap().get(taskKey));
+ }
+ for (final AxArtifactKey policyKey : copyOverPolicyKeys) {
+ mergedPolicyModel.getPolicies().getPolicyMap().put(policyKey,
+ copyFromPolicyModel.getPolicies().getPolicyMap().get(policyKey));
+ }
+
+ // That's it, return the model
+ return mergedPolicyModel;
+ }
+}
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
new file mode 100644
index 000000000..586d0706e
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitter.java
@@ -0,0 +1,165 @@
+/*-
+ * ============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() {}
+
+ /**
+ * 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()) {
+ LOGGER.warn("source model is invalid: " + sourceValidationResult.toString());
+ throw new ApexModelException("source model is invalid: " + sourceValidationResult.toString());
+ }
+ }
+
+ // 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
new file mode 100644
index 000000000..f84befd26
--- /dev/null
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/package-info.java
@@ -0,0 +1,26 @@
+/*-
+ * ============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;
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java
new file mode 100644
index 000000000..28f70f48b
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java
@@ -0,0 +1,84 @@
+/*-
+ * ============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.policymodel.concepts.AxLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxLogicReader;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class DummyLogicReader implements AxLogicReader {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#getLogicPackage()
+ */
+ @Override
+ public String getLogicPackage() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#setLogicPackage(java.lang.
+ * String)
+ */
+ @Override
+ public AxLogicReader setLogicPackage(final String logicPackage) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#getDefaultLogic()
+ */
+ @Override
+ public String getDefaultLogic() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#setDefaultLogic(java.lang.
+ * String)
+ */
+ @Override
+ public AxLogicReader setDefaultLogic(final String defaultLogic) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.policymodel.concepts.AxLogicReader#readLogic(org.onap.policy.apex.
+ * model.policymodel.concepts.AxLogic)
+ */
+ @Override
+ public String readLogic(final AxLogic axLogic) {
+ return "Dummy Logic";
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestExceptions.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestExceptions.java
new file mode 100644
index 000000000..9c7405b97
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestExceptions.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.policymodel.concepts.PolicyException;
+import org.onap.policy.apex.model.policymodel.concepts.PolicyRuntimeException;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestExceptions {
+
+ @Test
+ public void test() {
+ assertNotNull(new PolicyException("Message"));
+ assertNotNull(new PolicyException("Message", new IOException()));
+
+ final PolicyException ae = new PolicyException("Message", new IOException("IO exception message"));
+ assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage());
+
+ assertNotNull(new PolicyRuntimeException("Message"));
+ assertNotNull(new PolicyRuntimeException("Message", new IOException()));
+
+ final PolicyRuntimeException re =
+ new PolicyRuntimeException("Runtime Message", new IOException("IO runtime exception message"));
+ assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message",
+ re.getCascadedMessage());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestLogic.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestLogic.java
new file mode 100644
index 000000000..a415a1c69
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestLogic.java
@@ -0,0 +1,181 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.policymodel.concepts.AxLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestLogic {
+
+ @Test
+ public void testLogic() {
+ final DummyLogicReader logicReader = new DummyLogicReader();
+
+ assertNotNull(new AxLogic());
+ assertNotNull(new AxLogic(new AxReferenceKey()));
+ assertNotNull(new AxLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+
+ assertNotNull(new AxTaskLogic());
+ assertNotNull(new AxTaskLogic(new AxReferenceKey()));
+ assertNotNull(new AxTaskLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskLogic(new AxLogic()));
+ assertNotNull(new AxTaskLogic(new AxArtifactKey(), "LogicName", "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskLogic(new AxArtifactKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+
+ assertNotNull(new AxTaskSelectionLogic());
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey()));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskSelectionLogic(new AxLogic()));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", logicReader));
+
+ assertNotNull(new AxStateFinalizerLogic());
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey()));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxStateFinalizerLogic(new AxLogic()));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", logicReader));
+
+ final AxLogic logic = new AxLogic();
+
+ final AxReferenceKey logicKey = new AxReferenceKey("LogicParentName", "0.0.1", "PLN", "LN");
+ logic.setKey(logicKey);
+ assertEquals("LogicParentName:0.0.1:PLN:LN", logic.getKey().getID());
+ assertEquals("LogicParentName:0.0.1:PLN:LN", logic.getKeys().get(0).getID());
+
+ logic.setLogicFlavour("LogicFlavour");
+ assertEquals("LogicFlavour", logic.getLogicFlavour());
+
+ logic.setLogic("Logic");
+ assertEquals("Logic", logic.getLogic());
+
+ AxValidationResult result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ logic.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ logic.setKey(logicKey);
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ try {
+ logic.setLogicFlavour(null);
+ fail("test shold throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("parameter \"logicFlavour\" is null", e.getMessage());
+ }
+
+ try {
+ logic.setLogicFlavour("");
+ fail("test shold throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "parameter \"logicFlavour\": value \"\", does not match regular expression \"[A-Za-z0-9\\-_]+\"",
+ e.getMessage());
+ }
+
+ logic.setLogicFlavour(AxLogic.LOGIC_FLAVOUR_UNDEFINED);
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ logic.setLogicFlavour("LogicFlavour");
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ try {
+ logic.setLogic(null);
+ fail("test shold throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("logic may not be null", e.getMessage());
+ }
+
+ logic.setLogic("");
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ logic.setLogic("Logic");
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ logic.clean();
+
+ final AxLogic clonedLogic = new AxLogic(logic);
+ assertEquals(
+ "AxLogic:(key=AxReferenceKey:(parentKeyName=LogicParentName,parentKeyVersion=0.0.1,parentLocalName=PLN,localName=LN),logicFlavour=LogicFlavour,logic=Logic)",
+ clonedLogic.toString());
+
+ assertFalse(logic.hashCode() == 0);
+
+ assertTrue(logic.equals(logic));
+ assertTrue(logic.equals(clonedLogic));
+ assertFalse(logic.equals(null));
+ assertFalse(logic.equals("Hello"));
+ assertFalse(logic.equals(new AxLogic(AxReferenceKey.getNullKey(), "LogicFlavour", "Logic")));
+ assertFalse(logic.equals(new AxLogic(logicKey, "AnotherLogicFlavour", "Logic")));
+ assertFalse(logic.equals(new AxLogic(logicKey, "LogicFlavour", "AnotherLogic")));
+ assertTrue(logic.equals(new AxLogic(logicKey, "LogicFlavour", "Logic")));
+
+ assertEquals(0, logic.compareTo(logic));
+ assertEquals(0, logic.compareTo(clonedLogic));
+ assertNotEquals(0, logic.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, logic.compareTo(null));
+ assertNotEquals(0, logic.compareTo(new AxLogic(AxReferenceKey.getNullKey(), "LogicFlavour", "Logic")));
+ assertNotEquals(0, logic.compareTo(new AxLogic(logicKey, "AnotherLogicFlavour", "Logic")));
+ assertNotEquals(0, logic.compareTo(new AxLogic(logicKey, "LogicFlavour", "AnotherLogic")));
+ assertEquals(0, logic.compareTo(new AxLogic(logicKey, "LogicFlavour", "Logic")));
+
+ assertNotNull(logic.getKeys());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicies.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicies.java
new file mode 100644
index 000000000..9da944b60
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicies.java
@@ -0,0 +1,433 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicies;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
+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.AxStateTree;
+import org.onap.policy.apex.model.policymodel.handling.TestApexPolicyModelCreator;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestPolicies {
+
+ @Test
+ public void testPolicies() {
+ final TreeMap<String, AxState> stateMap = new TreeMap<>();
+ final TreeMap<String, AxState> stateMapEmpty = new TreeMap<>();
+
+ assertNotNull(new AxPolicy());
+ assertNotNull(new AxPolicy(new AxArtifactKey()));
+ assertNotNull(new AxPolicy(new AxArtifactKey(), "PolicyTemplate", stateMapEmpty, "FirstState"));
+
+ AxPolicy policy = new AxPolicy();
+
+ final AxArtifactKey policyKey = new AxArtifactKey("PolicyName", "0.0.1");
+
+ final AxState firstState = new AxState(new AxReferenceKey(policy.getKey(), "FirstState"));
+ final AxState badState = new AxState(new AxReferenceKey(policy.getKey(), "BadState"));
+ final AxStateOutput badSO = new AxStateOutput(badState.getKey(), AxArtifactKey.getNullKey(),
+ new AxReferenceKey(policyKey, "BadNextState"));
+ badState.getStateOutputs().put(badSO.getKey().getLocalName(), badSO);
+ stateMap.put(firstState.getKey().getLocalName(), firstState);
+
+ try {
+ policy.setKey(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("key may not be null", e.getMessage());
+ }
+
+ policy.setKey(policyKey);
+ assertEquals("PolicyName:0.0.1", policy.getKey().getID());
+ assertEquals("PolicyName:0.0.1", policy.getKeys().get(0).getID());
+
+ try {
+ policy.setTemplate(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("template may not be null", e.getMessage());
+ }
+
+ policy.setTemplate("PolicyTemplate");
+ assertEquals("PolicyTemplate", policy.getTemplate());
+
+ try {
+ policy.setStateMap(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("stateMap may not be null", e.getMessage());
+ }
+
+ policy.setStateMap(stateMap);
+ assertEquals(stateMap, policy.getStateMap());
+
+ try {
+ policy.setFirstState(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("firstState may not be null", e.getMessage());
+ }
+
+ policy.setFirstState("FirstState");
+ assertEquals("FirstState", policy.getFirstState());
+
+ assertEquals("PolicyName:0.0.1", policy.getKeys().get(0).getID());
+
+ policy = new TestApexPolicyModelCreator().getModel().getPolicies().get("policy");
+
+ AxValidationResult result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedPolicyKey = policy.getKey();
+ policy.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policy.setKey(savedPolicyKey);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final String savedTemplate = policy.getTemplate();
+ policy.setTemplate("");
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ policy.setTemplate(savedTemplate);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final Map<String, AxState> savedStateMap = policy.getStateMap();
+
+ policy.setStateMap(stateMapEmpty);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policy.setStateMap(savedStateMap);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put(AxKey.NULL_KEY_NAME, firstState);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove(AxKey.NULL_KEY_NAME);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put("NullState", null);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove("NullState");
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put("BadStateKey", firstState);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove("BadStateKey");
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put(badState.getKey().getLocalName(), badState);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove(badState.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final String savedFirstState = policy.getFirstState();
+
+ policy.setFirstState("");
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policy.setFirstState(savedFirstState);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policy.setFirstState("NonExistantFirstState");
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policy.setFirstState(savedFirstState);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxState clonedState = new AxState(policy.getStateMap().get("state"));
+ clonedState.getKey().setLocalName("ClonedState");
+ clonedState.afterUnmarshal(null, null);
+
+ savedStateMap.put(clonedState.getKey().getLocalName(), clonedState);
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.WARNING, result.getValidationResult());
+
+ savedStateMap.remove(clonedState.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = policy.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policy.clean();
+
+ final AxPolicy clonedPolicy = new AxPolicy(policy);
+ assertEquals("AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,sta",
+ clonedPolicy.toString().substring(0, 77));
+
+ assertFalse(policy.hashCode() == 0);
+
+ assertTrue(policy.equals(policy));
+ assertTrue(policy.equals(clonedPolicy));
+ assertFalse(policy.equals(null));
+ assertFalse(policy.equals("Hello"));
+ assertFalse(
+ policy.equals(new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState)));
+ assertFalse(policy.equals(new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState)));
+ assertFalse(policy.equals(new AxPolicy(savedPolicyKey, savedTemplate, stateMapEmpty, savedFirstState)));
+ assertFalse(policy.equals(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, "SomeFirstState")));
+ assertTrue(policy.equals(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, savedFirstState)));
+
+ assertEquals(0, policy.compareTo(policy));
+ assertEquals(0, policy.compareTo(clonedPolicy));
+ assertNotEquals(0, policy.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, policy.compareTo(null));
+ assertNotEquals(0, policy
+ .compareTo(new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState)));
+ assertNotEquals(0,
+ policy.compareTo(new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState)));
+ assertNotEquals(0,
+ policy.compareTo(new AxPolicy(savedPolicyKey, savedTemplate, stateMapEmpty, savedFirstState)));
+ assertNotEquals(0,
+ policy.compareTo(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, "SomeFirstState")));
+ assertEquals(0, policy.compareTo(new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, savedFirstState)));
+
+ assertNotNull(policy.getKeys());
+
+ final AxPolicies policies = new AxPolicies();
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Invalid, no events in event map
+ policies.setKey(new AxArtifactKey("PoliciesKey", "0.0.1"));
+ assertEquals("PoliciesKey:0.0.1", policies.getKey().getID());
+
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(savedPolicyKey, policy);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), policy);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().remove(new AxArtifactKey("BadEventKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.clean();
+ policies.afterUnmarshal(null, null);
+
+ final AxPolicies clonedPolicies = new AxPolicies(policies);
+ assertEquals("AxPolicies:(key=AxArtifactKey:(name=PoliciesKey,version=0.0.",
+ clonedPolicies.toString().substring(0, 60));
+
+ assertFalse(policies.hashCode() == 0);
+
+ assertTrue(policies.equals(policies));
+ assertTrue(policies.equals(clonedPolicies));
+ assertFalse(policies.equals(null));
+ assertFalse(policies.equals("Hello"));
+ assertFalse(policies.equals(new AxPolicies(new AxArtifactKey())));
+
+ assertEquals(0, policies.compareTo(policies));
+ assertEquals(0, policies.compareTo(clonedPolicies));
+ assertNotEquals(0, policies.compareTo(null));
+ assertNotEquals(0, policies.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, policies.compareTo(new AxPolicies(new AxArtifactKey())));
+
+ clonedPolicies.get(savedPolicyKey).setTemplate("AnotherTemplate");
+ assertNotEquals(0, policies.compareTo(clonedPolicies));
+
+ assertEquals(policies.getKey(), policies.getKeys().get(0));
+
+ assertEquals("policy", policies.get("policy").getKey().getName());
+ assertEquals("policy", policies.get("policy", "0.0.1").getKey().getName());
+ assertEquals(1, policies.getAll("policy", "0.0.1").size());
+ assertEquals(0, policies.getAll("NonExistantPolicy").size());
+
+ AxStateTree stateTree = policy.getStateTree();
+ assertNotNull(stateTree);
+ assertNotNull(stateTree.getReferencedStateList());
+ assertNotNull(stateTree.getReferencedStateSet());
+
+ final AxState secondState = new AxState(policy.getStateMap().get("state"));
+ secondState.getKey().setLocalName("SecondState");
+ secondState.afterUnmarshal(null, null);
+ policy.getStateMap().put("SecondState", secondState);
+ policy.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+
+ stateTree = policy.getStateTree();
+ assertNotNull(stateTree);
+ assertNotNull(stateTree.getReferencedStateList());
+ assertNotNull(stateTree.getReferencedStateSet());
+ assertNotNull(stateTree.getNextStates());
+
+ policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(policy.getStateMap().get("state").getKey());
+ try {
+ policy.getStateTree();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "loop detected in state tree for policy policy:0.0.1 state SecondState, next state state referenced more than once",
+ e.getMessage());
+ }
+
+ policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(AxReferenceKey.getNullKey());
+
+ final AxState thirdState = new AxState(policy.getStateMap().get("state"));
+ thirdState.getKey().setLocalName("ThirdState");
+ thirdState.afterUnmarshal(null, null);
+ policy.getStateMap().put("ThirdState", thirdState);
+ policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0").setNextState(thirdState.getKey());
+ policy.getStateMap().get("ThirdState").getStateOutputs().get("stateOutput0")
+ .setNextState(AxReferenceKey.getNullKey());
+
+ stateTree = policy.getStateTree();
+
+ final AxStateOutput ssS0Clone =
+ new AxStateOutput(policy.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0"));
+ ssS0Clone.getKey().setLocalName("ssS0Clone");
+ policy.getStateMap().get("SecondState").getStateOutputs().put("ssS0Clone", ssS0Clone);
+
+ try {
+ policy.getStateTree();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "loop detected in state tree for policy policy:0.0.1 state SecondState, next state ThirdState referenced more than once",
+ e.getMessage());
+ }
+
+ policy.getStateMap().get("SecondState").getStateOutputs().remove("ssS0Clone");
+
+ policy.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+ secondState.getStateOutputs().get("stateOutput0").setNextState(thirdState.getKey());
+ thirdState.getStateOutputs().get("stateOutput0").setNextState(AxReferenceKey.getNullKey());
+
+ stateTree = policy.getStateTree();
+ assertNotNull(stateTree.getState());
+
+ thirdState.getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+
+ try {
+ policy.getStateTree();
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "loop detected in state tree for policy policy:0.0.1 state ThirdState, next state SecondState referenced more than once",
+ e.getMessage());
+ }
+
+ thirdState.getStateOutputs().get("stateOutput0").setNextState(AxReferenceKey.getNullKey());
+
+ stateTree = policy.getStateTree();
+
+ final AxStateTree otherStateTree = policy.getStateTree();
+ assertEquals(0, stateTree.compareTo(otherStateTree));
+
+ for (final AxStateTree childStateTree : stateTree.getNextStates()) {
+ assertNotEquals(0, stateTree.compareTo(childStateTree));
+ }
+
+ otherStateTree.getNextStates().clear();
+ assertNotEquals(0, stateTree.compareTo(otherStateTree));
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicyModel.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicyModel.java
new file mode 100644
index 000000000..db1d1ee62
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestPolicyModel.java
@@ -0,0 +1,357 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicies;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
+import org.onap.policy.apex.model.policymodel.handling.TestApexPolicyModelCreator;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestPolicyModel {
+
+ @Test
+ public void testPolicyModel() {
+ assertNotNull(new AxPolicyModel());
+ assertNotNull(new AxPolicyModel(new AxArtifactKey()));
+ assertNotNull(new AxPolicyModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
+ new AxEvents(), new AxContextAlbums(), new AxTasks(), new AxPolicies()));
+
+ final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
+ final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey eventsKey = new AxArtifactKey("EventsKey", "0.0.1");
+ final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey albumsKey = new AxArtifactKey("AlbumsKey", "0.0.1");
+ final AxArtifactKey tasksKey = new AxArtifactKey("TasksKey", "0.0.1");
+ final AxArtifactKey policiesKey = new AxArtifactKey("PoliciesKey", "0.0.1");
+
+ AxPolicyModel model = new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey));
+
+ model.register();
+
+ assertNotNull(model.getContextModel());
+ assertEquals("ModelKey:0.0.1", model.getKeys().get(0).getID());
+
+ model.clean();
+ assertNotNull(model);
+ assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", model.toString().substring(0, 50));
+
+ final AxPolicyModel clonedModel = new AxPolicyModel(model);
+
+ assertFalse(model.hashCode() == 0);
+
+ assertTrue(model.equals(model));
+ assertTrue(model.equals(clonedModel));
+ assertFalse(model.equals("Hello"));
+ assertFalse(model.equals(new AxPolicyModel(new AxArtifactKey())));
+ assertFalse(model.equals(new AxPolicyModel(AxArtifactKey.getNullKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertFalse(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
+ new AxEvents(eventsKey), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey))));
+ assertFalse(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
+ new AxEvents(eventsKey), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey))));
+ assertFalse(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey))));
+ assertFalse(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey))));
+ assertFalse(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(), new AxPolicies(policiesKey))));
+ assertFalse(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies())));
+ assertTrue(model.equals(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+
+ assertEquals(0, model.compareTo(model));
+ assertEquals(0, model.compareTo(clonedModel));
+ assertNotEquals(0, model.compareTo(new AxArtifactKey()));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(AxArtifactKey.getNullKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
+ new AxEvents(eventsKey), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
+ new AxEvents(eventsKey), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies())));
+ assertEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+
+ model = new TestApexPolicyModelCreator().getModel();
+
+ AxValidationResult result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedPolicyKey = model.getKey();
+ model.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.setKey(savedPolicyKey);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxField badField = new AxField(new AxReferenceKey(model.getEvents().get("inEvent").getKey(), "BadField"),
+ new AxArtifactKey("NonExistantSchema", "0.0.1"));
+ model.getEvents().get("inEvent").getParameterMap().put(badField.getKey().getLocalName(), badField);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getEvents().get("inEvent").getParameterMap().remove(badField.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxContextAlbum badAlbum = new AxContextAlbum(new AxArtifactKey("BadAlbum", "0.0.1"), "SomeScope", true,
+ new AxArtifactKey("NonExistantSchema", "0.0.1"));
+ model.getAlbums().getAlbumsMap().put(badAlbum.getKey(), badAlbum);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getAlbums().getAlbumsMap().remove(badAlbum.getKey());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxInputField badInField =
+ new AxInputField(new AxReferenceKey(model.getTasks().get("task").getKey(), "BadInField"),
+ new AxArtifactKey("NonExistantSchema", "0.0.1"));
+ model.getTasks().get("task").getInputFields().put(badInField.getKey().getLocalName(), badInField);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getTasks().get("task").getInputFields().remove(badInField.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxOutputField badOutField =
+ new AxOutputField(new AxReferenceKey(model.getTasks().get("task").getKey(), "BadOutField"),
+ new AxArtifactKey("NonExistantSchema", "0.0.1"));
+ model.getTasks().get("task").getOutputFields().put(badOutField.getKey().getLocalName(), badOutField);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getTasks().get("task").getOutputFields().remove(badOutField.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getTasks().get("task").getContextAlbumReferences()
+ .add(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getTasks().get("task").getContextAlbumReferences()
+ .remove(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getContextAlbumReferences()
+ .add(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getContextAlbumReferences()
+ .remove(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedTrigger = model.getPolicies().get("policy").getStateMap().get("state").getTrigger();
+ model.getPolicies().get("policy").getStateMap().get("state")
+ .setTrigger(new AxArtifactKey("NonExistantEvent", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").setTrigger(savedTrigger);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedDefaultTask =
+ model.getPolicies().get("policy").getStateMap().get("state").getDefaultTask();
+ model.getPolicies().get("policy").getStateMap().get("state")
+ .setDefaultTask(new AxArtifactKey("NonExistantTask", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").setDefaultTask(savedDefaultTask);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // It is OK not to have TSL
+ final AxTaskSelectionLogic savedTSL =
+ model.getPolicies().get("policy").getStateMap().get("state").getTaskSelectionLogic();
+ model.getPolicies().get("policy").getStateMap().get("state")
+ .setTaskSelectionLogic(new AxTaskSelectionLogic(AxReferenceKey.getNullKey()));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getTasks().get("task").getInputFields().put(badInField.getKey().getLocalName(), badInField);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getTasks().get("task").getInputFields().remove(badInField.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").setTaskSelectionLogic(savedTSL);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateOutput badStateOutput = new AxStateOutput(
+ new AxReferenceKey(model.getPolicies().get("policy").getStateMap().get("state").getKey(), "BadSO"),
+ new AxArtifactKey("NonExistantEvent", "0.0.1"), AxReferenceKey.getNullKey());
+ model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs()
+ .put(badStateOutput.getKey().getLocalName(), badStateOutput);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs()
+ .remove(badStateOutput.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateTaskReference badTR = new AxStateTaskReference(
+ new AxReferenceKey(model.getPolicies().get("policy").getStateMap().get("state").getKey(),
+ "NonExistantTask"),
+ AxStateTaskOutputType.LOGIC, badStateOutput.getKey());
+ model.getPolicies().get("policy").getStateMap().get("state").getTaskReferences()
+ .put(new AxArtifactKey("NonExistantTask", "0.0.1"), badTR);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ badTR.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getTaskReferences()
+ .remove(new AxArtifactKey("NonExistantTask", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateTaskReference tr = model.getPolicies().get("policy").getStateMap().get("state").getTaskReferences()
+ .get(new AxArtifactKey("task", "0.0.1"));
+
+ final String savedSOName = tr.getOutput().getLocalName();
+ tr.getOutput().setLocalName("NonExistantOutput");
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tr.getOutput().setLocalName(savedSOName);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateOutput so =
+ model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs().get(savedSOName);
+
+ final AxArtifactKey savedOE = so.getOutgingEvent();
+ so.setOutgoingEvent(new AxArtifactKey("NonExistantEvent", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so.setOutgoingEvent(savedOE);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestState.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestState.java
new file mode 100644
index 000000000..1d62ae63a
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestState.java
@@ -0,0 +1,475 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.policymodel.concepts.AxState;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestState {
+
+ @Test
+ public void testState() {
+ final TreeMap<String, AxStateOutput> soEmptyMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtEmptySet = new TreeSet<>();
+ final TreeMap<String, AxStateFinalizerLogic> sflEmptyMap = new TreeMap<>();
+ final TreeMap<AxArtifactKey, AxStateTaskReference> trEmptyMap = new TreeMap<>();
+
+ final TreeMap<String, AxStateOutput> soMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtSet = new TreeSet<>();
+ final TreeMap<String, AxStateFinalizerLogic> sflMap = new TreeMap<>();
+ final TreeMap<AxArtifactKey, AxStateTaskReference> trMap = new TreeMap<>();
+
+ assertNotNull(new AxState());
+ assertNotNull(new AxState(new AxReferenceKey()));
+ assertNotNull(new AxState(new AxReferenceKey(), new AxArtifactKey(), soEmptyMap, ctxtEmptySet,
+ new AxTaskSelectionLogic(), sflEmptyMap, new AxArtifactKey(), trEmptyMap));
+
+ final AxState state = new AxState();
+
+ final AxReferenceKey stateKey = new AxReferenceKey("PolicyName", "0.0.1", "StateName");
+ final AxReferenceKey stateKeyNext = new AxReferenceKey("PolicyName", "0.0.1", "StateNameNext");
+ final AxReferenceKey stateKeyBad = new AxReferenceKey("PolicyName", "0.0.1", "BadStateName");
+ final AxArtifactKey triggerKey = new AxArtifactKey("TriggerName", "0.0.1");
+ final AxTaskSelectionLogic tsl = new AxTaskSelectionLogic(stateKey, "TSL", "LogicFlavour", "Some Logic");
+ final AxArtifactKey defTaskKey = new AxArtifactKey("TaskName", "0.0.1");
+ final AxArtifactKey taskKey1 = new AxArtifactKey("Task1", "0.0.1");
+ final AxArtifactKey taskKey2 = new AxArtifactKey("Task2", "0.0.1");
+ final AxArtifactKey taskKeyBad = new AxArtifactKey("TaskBad", "0.0.1");
+
+ try {
+ state.setKey(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("key may not be null", e.getMessage());
+ }
+
+ state.setKey(stateKey);
+ assertEquals("PolicyName:0.0.1:NULL:StateName", state.getKey().getID());
+ assertEquals("PolicyName:0.0.1:NULL:StateName", state.getKeys().get(0).getID());
+
+ final AxStateOutput so0 = new AxStateOutput(new AxReferenceKey(stateKey, "SO0"), triggerKey, new AxReferenceKey());
+ final AxStateOutput soU = new AxStateOutput(new AxReferenceKey(stateKey, "SOU"), triggerKey, stateKeyNext);
+ final AxStateOutput soSame = new AxStateOutput(new AxReferenceKey(stateKey, "SOU"), triggerKey, stateKey);
+ final AxArtifactKey cr0 = new AxArtifactKey("ContextReference", "0.0.1");
+ final AxStateFinalizerLogic sfl = new AxStateFinalizerLogic(stateKey, "SFLogicName", "LogicFlavour", "Logic");
+ final AxStateFinalizerLogic sflU = new AxStateFinalizerLogic(stateKey, "UnusedSFLogicName", "LogicFlavour", "Logic");
+ final AxStateTaskReference str0 = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR0"),
+ AxStateTaskOutputType.DIRECT, so0.getKey());
+ final AxStateTaskReference str1 = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR1"),
+ AxStateTaskOutputType.DIRECT, so0.getKey());
+ final AxStateTaskReference str2 = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR2"),
+ AxStateTaskOutputType.LOGIC, sfl.getKey());
+
+ final AxStateTaskReference strBadState = new AxStateTaskReference(new AxReferenceKey(stateKeyBad, "STR2"),
+ AxStateTaskOutputType.LOGIC, sfl.getKey());
+ final AxStateTaskReference strBadSO = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR2"),
+ AxStateTaskOutputType.UNDEFINED, sfl.getKey());
+ final AxStateTaskReference strBadSFL = new AxStateTaskReference(new AxReferenceKey(stateKeyBad, "STR2"),
+ AxStateTaskOutputType.LOGIC, new AxReferenceKey(stateKey, "SomeSFL"));
+
+ soMap.put(so0.getKey().getLocalName(), so0);
+ ctxtSet.add(cr0);
+ sflMap.put(sfl.getKey().getLocalName(), sfl);
+ trMap.put(defTaskKey.getKey(), str0);
+ trMap.put(taskKey1.getKey(), str1);
+ trMap.put(taskKey2.getKey(), str2);
+
+ try {
+ state.setTrigger(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("trigger may not be null", e.getMessage());
+ }
+
+ state.setTrigger(triggerKey);
+ assertEquals(triggerKey, state.getTrigger());
+
+ try {
+ state.setStateOutputs(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("stateOutputs may not be null", e.getMessage());
+ }
+
+ state.setStateOutputs(soMap);
+ assertEquals(soMap, state.getStateOutputs());
+
+ try {
+ state.setContextAlbumReferences(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("contextAlbumReferenceSet may not be null", e.getMessage());
+ }
+
+ state.setContextAlbumReferences(ctxtSet);
+ assertEquals(ctxtSet, state.getContextAlbumReferences());
+
+ try {
+ state.setTaskSelectionLogic(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("taskSelectionLogic may not be null", e.getMessage());
+ }
+
+ assertEquals(false, state.checkSetTaskSelectionLogic());
+ state.setTaskSelectionLogic(tsl);
+ assertEquals(tsl, state.getTaskSelectionLogic());
+ assertEquals(true, state.checkSetTaskSelectionLogic());
+
+ try {
+ state.setStateFinalizerLogicMap(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("stateFinalizerLogic may not be null", e.getMessage());
+ }
+
+ state.setStateFinalizerLogicMap(sflMap);
+ assertEquals(sflMap, state.getStateFinalizerLogicMap());
+
+ try {
+ state.setDefaultTask(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("defaultTask may not be null", e.getMessage());
+ }
+
+ state.setDefaultTask(defTaskKey);
+ assertEquals(defTaskKey, state.getDefaultTask());
+
+ try {
+ state.setTaskReferences(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("taskReferenceMap may not be null", e.getMessage());
+ }
+
+ state.setTaskReferences(trMap);
+ assertEquals(trMap, state.getTaskReferences());
+
+ state.afterUnmarshal(null, null);
+ assertEquals(state.getKey(), state.getKeys().get(0));
+ state.getTaskSelectionLogic().getKey().setLocalName(AxKey.NULL_KEY_NAME);
+ state.afterUnmarshal(null, null);
+ assertEquals(state.getKey(), state.getKeys().get(0));
+
+ final Set<String> stateSet = state.getNextStateSet();
+ assertEquals(1, stateSet.size());
+
+ AxValidationResult result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setKey(stateKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setTrigger(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setTrigger(triggerKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setStateOutputs(soEmptyMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ so0.getKey().setParentLocalName("Zooby");
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so0.getKey().setParentLocalName("StateName");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("NullOutput", null);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ soMap.remove("NullOutput");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("DupOutput", so0);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ soMap.remove("DupOutput");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("UnusedOutput", soU);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ soMap.remove("UnusedOutput");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("OutputToSameState", soSame);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ soMap.remove("OutputToSameState");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Empty context reference set is OK
+ state.setContextAlbumReferences(ctxtEmptySet);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setContextAlbumReferences(ctxtSet);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ ctxtSet.add(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ ctxtSet.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Null TSL is OK
+ state.getTaskSelectionLogic().setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.getTaskSelectionLogic().setKey(new AxReferenceKey(stateKey, "TSL"));
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setDefaultTask(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setDefaultTask(defTaskKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setTaskReferences(trEmptyMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setTaskReferences(trMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(AxArtifactKey.getNullKey(), str0);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(taskKeyBad, strBadSO);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(taskKeyBad);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(taskKeyBad, strBadState);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(taskKeyBad);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(taskKeyBad, strBadSFL);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(taskKeyBad);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setDefaultTask(new AxArtifactKey("NonExistantTask", "0.0.1"));
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setDefaultTask(defTaskKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ sflMap.put("NullSFL", null);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ sflMap.remove("NullSFL");
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ sflMap.put(sflU.getKey().getLocalName(), sflU);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ sflMap.remove(sflU.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.clean();
+
+ final AxState clonedState = new AxState(state);
+ assertEquals("AxState:(stateKey=AxReferenceKey:(parent", clonedState.toString().substring(0, 40));
+
+ assertFalse(state.hashCode() == 0);
+
+ assertTrue(state.equals(state));
+ assertTrue(state.equals(clonedState));
+ assertFalse(state.equals(null));
+ assertFalse(state.equals("Hello"));
+ assertFalse(state
+ .equals(new AxState(new AxReferenceKey(), triggerKey, soMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+ assertFalse(state
+ .equals(new AxState(stateKey, new AxArtifactKey(), soMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+ assertFalse(
+ state.equals(new AxState(stateKey, triggerKey, soEmptyMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+ assertFalse(
+ state.equals(new AxState(stateKey, triggerKey, soMap, ctxtEmptySet, tsl, sflMap, defTaskKey, trMap)));
+ assertFalse(state.equals(new AxState(stateKey, triggerKey, soMap, ctxtSet, new AxTaskSelectionLogic(), sflMap,
+ defTaskKey, trMap)));
+ assertFalse(
+ state.equals(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflEmptyMap, defTaskKey, trMap)));
+ assertFalse(state
+ .equals(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflMap, new AxArtifactKey(), trMap)));
+ assertFalse(
+ state.equals(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflMap, defTaskKey, trEmptyMap)));
+ assertTrue(state.equals(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+
+ assertEquals(0, state.compareTo(state));
+ assertEquals(0, state.compareTo(clonedState));
+ assertNotEquals(0, state.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, state.compareTo(null));
+ assertNotEquals(0, state.compareTo(
+ new AxState(new AxReferenceKey(), triggerKey, soMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+ assertNotEquals(0, state
+ .compareTo(new AxState(stateKey, new AxArtifactKey(), soMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+ assertNotEquals(0, state
+ .compareTo(new AxState(stateKey, triggerKey, soEmptyMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+ assertNotEquals(0, state
+ .compareTo(new AxState(stateKey, triggerKey, soMap, ctxtEmptySet, tsl, sflMap, defTaskKey, trMap)));
+ assertNotEquals(0, state.compareTo(new AxState(stateKey, triggerKey, soMap, ctxtSet, new AxTaskSelectionLogic(),
+ sflMap, defTaskKey, trMap)));
+ assertNotEquals(0, state
+ .compareTo(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflEmptyMap, defTaskKey, trMap)));
+ assertNotEquals(0, state
+ .compareTo(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflMap, new AxArtifactKey(), trMap)));
+ assertNotEquals(0, state
+ .compareTo(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflMap, defTaskKey, trEmptyMap)));
+ assertEquals(0,
+ state.compareTo(new AxState(stateKey, triggerKey, soMap, ctxtSet, tsl, sflMap, defTaskKey, trMap)));
+
+ assertNotNull(state.getKeys());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateOutput.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateOutput.java
new file mode 100644
index 000000000..5911d41be
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateOutput.java
@@ -0,0 +1,137 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.policymodel.concepts.AxStateOutput;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestStateOutput {
+
+ @Test
+ public void testStateOutput() {
+ assertNotNull(new AxStateOutput());
+ assertNotNull(new AxStateOutput(new AxReferenceKey()));
+ assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
+ assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
+
+ final AxStateOutput so = new AxStateOutput();
+
+ final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
+ final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
+ final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
+
+ try {
+ so.setKey(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("key may not be null", e.getMessage());
+ }
+
+ so.setKey(soKey);
+ assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getID());
+ assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getID());
+
+ try {
+ so.setNextState(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("nextState may not be null", e.getMessage());
+ }
+
+ so.setNextState(nsKey);
+ assertEquals(nsKey, so.getNextState());
+
+ try {
+ so.setOutgoingEvent(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("outgoingEvent may not be null", e.getMessage());
+ }
+
+ so.setOutgoingEvent(eKey);
+ assertEquals(eKey, so.getOutgingEvent());
+
+ AxValidationResult result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ so.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so.setKey(soKey);
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ so.setOutgoingEvent(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so.setOutgoingEvent(eKey);
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ so.clean();
+
+ final AxStateOutput clonedPar = new AxStateOutput(so);
+ assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
+
+ assertFalse(so.hashCode() == 0);
+
+ assertTrue(so.equals(so));
+ assertTrue(so.equals(clonedPar));
+ assertFalse(so.equals(null));
+ assertFalse(so.equals("Hello"));
+ assertFalse(so.equals(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
+ assertFalse(so.equals(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
+ assertFalse(so.equals(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
+ assertTrue(so.equals(new AxStateOutput(soKey, eKey, nsKey)));
+
+ assertEquals(0, so.compareTo(so));
+ assertEquals(0, so.compareTo(clonedPar));
+ assertNotEquals(0, so.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, so.compareTo(null));
+ assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
+ assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
+ assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
+ assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
+
+ assertNotNull(so.getKeys());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateTaskReference.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateTaskReference.java
new file mode 100644
index 000000000..c85fda4be
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestStateTaskReference.java
@@ -0,0 +1,160 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.policymodel.concepts.AxStateTaskOutputType;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestStateTaskReference {
+
+ @Test
+ public void testStateTaskReference() {
+ assertNotNull(new AxStateTaskReference());
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey()));
+ assertNotNull(
+ new AxStateTaskReference(new AxReferenceKey(), AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
+ AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
+
+ AxStateTaskReference stRef = new AxStateTaskReference();
+
+ AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
+ AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
+
+ try {
+ stRef.setKey(null);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("key may not be null", e.getMessage());
+ }
+
+ stRef.setKey(stRefKey);
+ assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKey().getID());
+ assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKeys().get(0).getID());
+
+ try {
+ stRef.setStateTaskOutputType(null);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("outputType may not be null", e.getMessage());
+ }
+
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
+ assertEquals(AxStateTaskOutputType.UNDEFINED, stRef.getStateTaskOutputType());
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
+ assertEquals(AxStateTaskOutputType.DIRECT, stRef.getStateTaskOutputType());
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
+ assertEquals(AxStateTaskOutputType.LOGIC, stRef.getStateTaskOutputType());
+
+ try {
+ stRef.setOutput(null);
+ fail("test should throw an exception here");
+ } catch (Exception e) {
+ assertEquals("output may not be null", e.getMessage());
+ }
+
+ stRef.setOutput(soKey);
+ assertEquals(soKey, stRef.getOutput());
+
+ AxValidationResult result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ stRef.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stRef.setKey(stRefKey);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stRef.setOutput(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stRef.setOutput(soKey);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stRef.clean();
+
+ AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
+ assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
+
+ assertFalse(stRef.hashCode() == 0);
+
+ assertTrue(stRef.equals(stRef));
+ assertTrue(stRef.equals(clonedStRef));
+ assertFalse(stRef.equals(null));
+ assertFalse(stRef.equals("Hello"));
+ assertFalse(stRef
+ .equals(new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
+ assertFalse(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
+ assertFalse(
+ stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
+ assertTrue(stRef.equals(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
+
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
+ AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
+
+ assertEquals(0, stRef.compareTo(stRef));
+ assertEquals(0, stRef.compareTo(clonedStRef));
+ assertNotEquals(0, stRef.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, stRef.compareTo(null));
+ assertNotEquals(0, stRef
+ .compareTo(new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
+ assertNotEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
+ assertNotEquals(0,
+ stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
+ assertEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
+
+ assertNotNull(stRef.getKeys());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTaskParameter.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTaskParameter.java
new file mode 100644
index 000000000..63906add2
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTaskParameter.java
@@ -0,0 +1,116 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.policymodel.concepts.AxTaskParameter;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestTaskParameter {
+
+ @Test
+ public void testTaskParameter() {
+ assertNotNull(new AxTaskParameter());
+ assertNotNull(new AxTaskParameter(new AxReferenceKey()));
+ assertNotNull(new AxTaskParameter(new AxReferenceKey(), "DefaultValue"));
+
+ final AxTaskParameter par = new AxTaskParameter();
+
+ final AxReferenceKey parKey = new AxReferenceKey("ParParentName", "0.0.1", "PLN", "LN");
+ par.setKey(parKey);
+ assertEquals("ParParentName:0.0.1:PLN:LN", par.getKey().getID());
+ assertEquals("ParParentName:0.0.1:PLN:LN", par.getKeys().get(0).getID());
+
+ par.setDefaultValue("DefaultValue");
+ assertEquals("DefaultValue", par.getTaskParameterValue());
+
+ AxValidationResult result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ par.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ par.setKey(parKey);
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ try {
+ par.setDefaultValue(null);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("defaultValue may not be null", e.getMessage());
+ }
+
+ par.setDefaultValue("");
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.WARNING, result.getValidationResult());
+
+ par.setDefaultValue("DefaultValue");
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ par.clean();
+
+ final AxTaskParameter clonedPar = new AxTaskParameter(par);
+ assertEquals(
+ "AxTaskParameter:(key=AxReferenceKey:(parentKeyName=ParParentName,parentKeyVersion=0.0.1,parentLocalName=PLN,localName=LN),defaultValue=DefaultValue)",
+ clonedPar.toString());
+
+ assertFalse(par.hashCode() == 0);
+
+ assertTrue(par.equals(par));
+ assertTrue(par.equals(clonedPar));
+ assertFalse(par.equals(null));
+ assertFalse(par.equals("Hello"));
+ assertFalse(par.equals(new AxTaskParameter(AxReferenceKey.getNullKey(), "DefaultValue")));
+ assertFalse(par.equals(new AxTaskParameter(parKey, "OtherDefaultValue")));
+ assertTrue(par.equals(new AxTaskParameter(parKey, "DefaultValue")));
+
+ assertEquals(0, par.compareTo(par));
+ assertEquals(0, par.compareTo(clonedPar));
+ assertNotEquals(0, par.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, par.compareTo(null));
+ assertNotEquals(0, par.compareTo(new AxTaskParameter(AxReferenceKey.getNullKey(), "DefaultValue")));
+ assertNotEquals(0, par.compareTo(new AxTaskParameter(parKey, "OtherDefaultValue")));
+ assertEquals(0, par.compareTo(new AxTaskParameter(parKey, "DefaultValue")));
+
+ assertNotNull(par.getKeys());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTasks.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTasks.java
new file mode 100644
index 000000000..967e4e0aa
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TestTasks.java
@@ -0,0 +1,331 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+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.AxField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
+import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter;
+import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestTasks {
+
+ @Test
+ public void testTasks() {
+ final TreeMap<String, AxInputField> ifEmptyMap = new TreeMap<>();
+ final TreeMap<String, AxOutputField> ofEmptyMap = new TreeMap<>();
+ final TreeMap<String, AxTaskParameter> tpEmptyMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtEmptySet = new TreeSet<>();
+
+ final TreeMap<String, AxInputField> ifMap = new TreeMap<>();
+ final TreeMap<String, AxOutputField> ofMap = new TreeMap<>();
+ final TreeMap<String, AxTaskParameter> tpMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtSet = new TreeSet<>();
+
+ assertNotNull(new AxTask());
+ assertNotNull(new AxTask(new AxArtifactKey()));
+ assertNotNull(new AxTask(new AxArtifactKey(), ifMap, ofMap, tpMap, ctxtSet, new AxTaskLogic()));
+
+ final AxTask task = new AxTask();
+
+ final AxArtifactKey taskKey = new AxArtifactKey("TaskName", "0.0.1");
+ task.setKey(taskKey);
+ assertEquals("TaskName:0.0.1", task.getKey().getID());
+ assertEquals("TaskName:0.0.1", task.getKeys().get(0).getID());
+
+ final AxArtifactKey f0SchemaKey = new AxArtifactKey("FS0", "0.0.1");
+
+ final AxInputField if0 = new AxInputField(new AxReferenceKey(taskKey, "IF0"), f0SchemaKey, false);
+ final AxInputField if1 = new AxInputField(new AxReferenceKey(taskKey, "IF1"), f0SchemaKey, false);
+ final AxOutputField of0 = new AxOutputField(new AxReferenceKey(taskKey, "OF0"), f0SchemaKey, false);
+ final AxOutputField of1 = new AxOutputField(new AxReferenceKey(taskKey, "OF1"), f0SchemaKey, false);
+ final AxTaskParameter tp0 = new AxTaskParameter(new AxReferenceKey(taskKey, "TP0"), "DefaultValue");
+ final AxArtifactKey cr0 = new AxArtifactKey("ContextReference", "0.0.1");
+ final AxTaskLogic tl = new AxTaskLogic(taskKey, "LogicName", "LogicFlavour", "Logic");
+
+ ifMap.put(if0.getKey().getLocalName(), if0);
+ ofMap.put(of0.getKey().getLocalName(), of0);
+ tpMap.put(tp0.getKey().getLocalName(), tp0);
+ ctxtSet.add(cr0);
+
+ task.setInputFields(ifMap);
+ assertEquals(ifMap, task.getInputFields());
+ assertTrue(task.getInputFieldSet().contains(if0));
+ assertTrue(task.getRawInputFields().keySet().contains(if0.getKey().getLocalName()));
+
+ task.setOutputFields(ofMap);
+ assertEquals(ofMap, task.getOutputFields());
+ assertTrue(task.getOutputFieldSet().contains(of0));
+ assertTrue(task.getRawOutputFields().keySet().contains(of0.getKey().getLocalName()));
+
+ final TreeMap<String, AxField> ifDupMap = new TreeMap<>();
+ final TreeMap<String, AxField> ofDupMap = new TreeMap<>();
+ ifDupMap.put(if1.getKey().getLocalName(), if1);
+ ofDupMap.put(of1.getKey().getLocalName(), of1);
+ task.duplicateInputFields(ifDupMap);
+ task.duplicateOutputFields(ofDupMap);
+ assertTrue(ifMap.containsKey("IF1"));
+ assertTrue(ofMap.containsKey("OF1"));
+
+ task.setTaskParameters(tpMap);
+ assertEquals(tpMap, task.getTaskParameters());
+
+ task.setContextAlbumReferences(ctxtSet);
+ assertEquals(ctxtSet, task.getContextAlbumReferences());
+
+ task.setTaskLogic(tl);
+ assertEquals(tl, task.getTaskLogic());
+
+ task.setKey(taskKey);
+ assertEquals("TaskName:0.0.1", task.getKey().getID());
+ assertEquals("TaskName:0.0.1", task.getKeys().get(0).getID());
+
+ task.afterUnmarshal(null, null);
+ assertEquals(1, task.getTaskParameters().size());
+
+ AxValidationResult result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ task.setKey(taskKey);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setInputFields(ifEmptyMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ task.setInputFields(ifMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ ifMap.put("NullField", null);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ ifMap.remove("NullField");
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setOutputFields(ofEmptyMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ task.setOutputFields(ofMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ ofMap.put("NullField", null);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ ofMap.remove("NullField");
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Empty task parameter map is OK
+ task.setTaskParameters(tpEmptyMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setTaskParameters(tpMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tpMap.put("NullField", null);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tpMap.remove("NullField");
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Empty context reference set is OK
+ task.setContextAlbumReferences(ctxtEmptySet);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setContextAlbumReferences(ctxtSet);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ ctxtSet.add(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ ctxtSet.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.clean();
+
+ final AxTask clonedTask = new AxTask(task);
+ assertEquals("AxTask:(key=AxArtifactKey:(name=TaskName", clonedTask.toString().substring(0, 40));
+
+ assertFalse(task.hashCode() == 0);
+
+ assertTrue(task.equals(task));
+ assertTrue(task.equals(clonedTask));
+ assertFalse(task.equals(null));
+ assertFalse(task.equals("Hello"));
+ assertFalse(task.equals(new AxTask(new AxArtifactKey(), ifMap, ofMap, tpMap, ctxtSet, tl)));
+ assertFalse(task.equals(new AxTask(taskKey, ifEmptyMap, ofMap, tpMap, ctxtSet, tl)));
+ assertFalse(task.equals(new AxTask(taskKey, ifMap, ofEmptyMap, tpMap, ctxtSet, tl)));
+ assertFalse(task.equals(new AxTask(taskKey, ifMap, ofMap, tpEmptyMap, ctxtSet, tl)));
+ assertFalse(task.equals(new AxTask(taskKey, ifMap, ofMap, tpMap, ctxtEmptySet, tl)));
+ assertFalse(task.equals(new AxTask(taskKey, ifMap, ofMap, tpMap, ctxtSet, new AxTaskLogic())));
+ assertTrue(task.equals(new AxTask(taskKey, ifMap, ofMap, tpMap, ctxtSet, tl)));
+
+ assertEquals(0, task.compareTo(task));
+ assertEquals(0, task.compareTo(clonedTask));
+ assertNotEquals(0, task.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, task.compareTo(null));
+ assertNotEquals(0, task.compareTo(new AxTask(new AxArtifactKey(), ifMap, ofMap, tpMap, ctxtSet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, ifEmptyMap, ofMap, tpMap, ctxtSet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, ifMap, ofEmptyMap, tpMap, ctxtSet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, ifMap, ofMap, tpEmptyMap, ctxtSet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, ifMap, ofMap, tpMap, ctxtEmptySet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, ifMap, ofMap, tpMap, ctxtSet, new AxTaskLogic())));
+ assertEquals(0, task.compareTo(new AxTask(taskKey, ifMap, ofMap, tpMap, ctxtSet, tl)));
+
+ assertNotNull(task.getKeys());
+
+ final AxTasks tasks = new AxTasks();
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Invalid, no tasks in task map
+ tasks.setKey(new AxArtifactKey("TasksKey", "0.0.1"));
+ assertEquals("TasksKey:0.0.1", tasks.getKey().getID());
+
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(taskKey, task);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(new AxArtifactKey("BadTaskKey", "0.0.1"), task);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().remove(new AxArtifactKey("BadTaskKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.clean();
+ tasks.afterUnmarshal(null, null);
+
+ final AxTasks clonedTasks = new AxTasks(tasks);
+ assertEquals("AxTasks:(key=AxArtifactKey:(name=TasksKey,version=0.0.1),tas",
+ clonedTasks.toString().substring(0, 60));
+
+ assertFalse(tasks.hashCode() == 0);
+
+ assertTrue(tasks.equals(tasks));
+ assertTrue(tasks.equals(clonedTasks));
+ assertFalse(tasks.equals(null));
+ assertFalse(tasks.equals("Hello"));
+ assertFalse(tasks.equals(new AxTasks(new AxArtifactKey())));
+
+ assertEquals(0, tasks.compareTo(tasks));
+ assertEquals(0, tasks.compareTo(clonedTasks));
+ assertNotEquals(0, tasks.compareTo(null));
+ assertNotEquals(0, tasks.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, tasks.compareTo(new AxTasks(new AxArtifactKey())));
+
+ clonedTasks.get(taskKey).getTaskLogic().setLogic("SomeChangedLogic");
+ assertNotEquals(0, tasks.compareTo(clonedTasks));
+
+ assertEquals(tasks.getKey(), tasks.getKeys().get(0));
+
+ assertEquals("TaskName", tasks.get("TaskName").getKey().getName());
+ assertEquals("TaskName", tasks.get("TaskName", "0.0.1").getKey().getName());
+ assertEquals(1, tasks.getAll("TaskName", "0.0.1").size());
+ assertEquals(0, tasks.getAll("NonExistantTaskName").size());
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModel.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModel.java
new file mode 100644
index 000000000..b3fd4a1b0
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModel.java
@@ -0,0 +1,139 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class TestApexPolicyModel {
+ private Connection connection;
+ TestApexModel<AxPolicyModel> testApexModel;
+
+ @Before
+ public void setup() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
+
+ testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new TestApexPolicyModelCreator());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ connection.close();
+ new File("derby.log").delete();
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertTrue(result.toString().equals(VALID_MODEL_STRING));
+ }
+
+ @Test
+ public void testApexModelVaidateObservation() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
+ assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING));
+ }
+
+
+ @Test
+ public void testApexModelVaidateWarning() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
+ assertTrue(result.toString().equals(WARNING_MODEL_STRING));
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertEquals(INVALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING));
+ }
+
+ @Test
+ public void testModelWriteReadXML() throws Exception {
+ testApexModel.testApexModelWriteReadXML();
+ }
+
+ @Test
+ public void testModelWriteReadJSON() throws Exception {
+ testApexModel.testApexModelWriteReadJSON();
+ }
+
+ @Test
+ public void testModelWriteReadJPA() throws Exception {
+ final DAOParameters daoParameters = new DAOParameters();
+ daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
+ daoParameters.setPersistenceUnit("DAOTest");
+
+ testApexModel.testApexModelWriteReadJPA(daoParameters);
+ }
+
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+
+ private static final String OBSERVATION_MODEL_STRING =
+ "\n" + "***observations noted during validation of model***\n"
+ + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):org.onap.policy.apex.model.policymodel.concepts.AxState:OBSERVATION:state output stateOutput0 is not used directly by any task\n"
+ + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=policy,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicy:WARNING:state AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=anotherState) is not referenced in the policy execution tree\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
+ + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
+ + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:task output field AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false) for task task:0.0.1 not in output event outEvent0:0.0.1\n"
+ + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:task output field AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false) for task task:0.0.1 not in output event outEvent0:0.0.1\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:keyInfoMap may not be empty\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Schemas,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Events,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Albums,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:key information not found for key AxArtifactKey:(name=policyModel_Policies,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel_Schemas,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:contextSchemas may not be empty\n"
+ + "AxArtifactKey:(name=policyModel_Events,version=0.0.1):org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:eventMap may not be empty\n"
+ + "AxArtifactKey:(name=policyModel_Albums,version=0.0.1):org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:OBSERVATION:albums are empty\n"
+ + "AxArtifactKey:(name=policyModel_Tasks,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxTasks:INVALID:taskMap may not be empty\n"
+ + "AxArtifactKey:(name=policyModel_Policies,version=0.0.1):org.onap.policy.apex.model.policymodel.concepts.AxPolicies:INVALID:policyMap may not be empty\n"
+ + "********************************";
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModelCreator.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModelCreator.java
new file mode 100644
index 000000000..cf2bb6524
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestApexPolicyModelCreator.java
@@ -0,0 +1,448 @@
+/*-
+ * ============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.UUID;
+
+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.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+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.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
+import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicies;
+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.AxStateFinalizerLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
+import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexPolicyModelCreator implements TestApexModelCreator<AxPolicyModel> {
+
+ @Override
+ public AxPolicyModel getModel() {
+ final AxContextSchema schema0 =
+ new AxContextSchema(new AxArtifactKey("eventContextItem0", "0.0.1"), "Java", "java.lang.String");
+ final AxContextSchema schema1 =
+ new AxContextSchema(new AxArtifactKey("eventContextItem1", "0.0.1"), "Java", "java.lang.Long");
+ final AxContextSchema schema2 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem000");
+ final AxContextSchema schema3 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A");
+
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
+ schemas.getSchemasMap().put(schema0.getKey(), schema0);
+ schemas.getSchemasMap().put(schema1.getKey(), schema1);
+ schemas.getSchemasMap().put(schema2.getKey(), schema2);
+ schemas.getSchemasMap().put(schema3.getKey(), schema3);
+
+ final AxContextAlbum album0 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema3.getKey());
+ final AxContextAlbum album1 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbum1", "0.0.1"), "GLOBAL", false, schema2.getKey());
+
+ final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
+ albums.getAlbumsMap().put(album0.getKey(), album0);
+ albums.getAlbumsMap().put(album1.getKey(), album1);
+
+ final AxEvent inEvent = new AxEvent(new AxArtifactKey("inEvent", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ inEvent.getParameterMap().put("IEPAR0",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPAR0"), schema0.getKey()));
+ inEvent.getParameterMap().put("IEPAR1",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPAR1"), schema1.getKey()));
+
+ final AxEvent outEvent0 = new AxEvent(new AxArtifactKey("outEvent0", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent0.getParameterMap().put("OE0PAR0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PAR0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE0PAR1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PAR1"), schema1.getKey()));
+ outEvent0.getParameterMap().put("OE1PAR0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PAR0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE1PAR1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PAR1"), schema1.getKey()));
+
+ final AxEvent outEvent1 = new AxEvent(new AxArtifactKey("outEvent1", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent1.getParameterMap().put("OE1PAR0",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PAR0"), schema0.getKey()));
+ outEvent1.getParameterMap().put("OE1PAR1",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PAR1"), schema1.getKey()));
+
+ final AxEvents events = new AxEvents(new AxArtifactKey("events", "0.0.1"));
+ events.getEventMap().put(inEvent.getKey(), inEvent);
+ events.getEventMap().put(outEvent0.getKey(), outEvent0);
+ events.getEventMap().put(outEvent1.getKey(), outEvent1);
+
+ final AxTask task = new AxTask(new AxArtifactKey("task", "0.0.1"));
+
+ for (final AxField field : inEvent.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(),
+ "inputFields", field.getKey().getLocalName());
+ final AxInputField inputField = new AxInputField(fieldkey, field.getSchema());
+ task.getInputFields().put(inputField.getKey().getLocalName(), inputField);
+ }
+
+ for (final AxField field : outEvent0.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(),
+ "outputFields", field.getKey().getLocalName());
+ final AxOutputField outputField = new AxOutputField(fieldkey, field.getSchema());
+ task.getOutputFields().put(outputField.getKey().getLocalName(), outputField);
+ }
+
+ for (final AxField field : outEvent1.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(),
+ "outputFields", field.getKey().getLocalName());
+ final AxOutputField outputField = new AxOutputField(fieldkey, field.getSchema());
+ task.getOutputFields().put(outputField.getKey().getLocalName(), outputField);
+ }
+
+ final AxTaskParameter taskPar0 =
+ new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameter0"), "Task parameter 0 value");
+ final AxTaskParameter taskPar1 =
+ new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameter1"), "Task parameter 1 value");
+
+ task.getTaskParameters().put(taskPar0.getKey().getLocalName(), taskPar0);
+ task.getTaskParameters().put(taskPar1.getKey().getLocalName(), taskPar1);
+ task.getContextAlbumReferences().add(album0.getKey());
+ task.getContextAlbumReferences().add(album1.getKey());
+
+ final AxTaskLogic taskLogic =
+ new AxTaskLogic(new AxReferenceKey(task.getKey(), "taskLogic"), "MVEL", "Some task logic");
+ task.setTaskLogic(taskLogic);
+
+ final AxTasks tasks = new AxTasks(new AxArtifactKey("tasks", "0.0.1"));
+ tasks.getTaskMap().put(task.getKey(), task);
+
+ final AxPolicy policy = new AxPolicy(new AxArtifactKey("policy", "0.0.1"));
+ policy.setTemplate("FREEFORM");
+
+ final AxState state = new AxState(new AxReferenceKey(policy.getKey(), "state"));
+ final AxTaskSelectionLogic taskSelectionLogic = new AxTaskSelectionLogic(
+ new AxReferenceKey(state.getKey(), "taskSelectionLogic"), "MVEL", "Some TS logic ");
+
+ state.setTrigger(inEvent.getKey());
+ state.getContextAlbumReferences().add(album0.getKey());
+ state.getContextAlbumReferences().add(album1.getKey());
+ state.setTaskSelectionLogic(taskSelectionLogic);
+ state.setDefaultTask(task.getKey());
+
+ final AxStateOutput stateOutput0 = new AxStateOutput(new AxReferenceKey(state.getKey(), "stateOutput0"),
+ outEvent0.getKey(), AxReferenceKey.getNullKey());
+ state.getStateOutputs().put(stateOutput0.getKey().getLocalName(), stateOutput0);
+
+ final AxStateTaskReference stateTaskReference =
+ new AxStateTaskReference(new AxReferenceKey(state.getKey(), task.getKey().getName()),
+ AxStateTaskOutputType.DIRECT, stateOutput0.getKey());
+
+ state.getTaskReferences().put(task.getKey(), stateTaskReference);
+
+ policy.getStateMap().put(state.getKey().getLocalName(), state);
+ policy.setFirstState(state.getKey().getLocalName());
+
+ final AxPolicies policies = new AxPolicies(new AxArtifactKey("policies", "0.0.1"));
+ policies.getPolicyMap().put(policy.getKey(), policy);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+ final AxPolicyModel policyModel = new AxPolicyModel(new AxArtifactKey("PolicyModel", "0.0.1"));
+ policyModel.setKeyInformation(keyInformation);
+ policyModel.setSchemas(schemas);
+ policyModel.setAlbums(albums);
+ policyModel.setEvents(events);
+ policyModel.setTasks(tasks);
+ policyModel.setPolicies(policies);
+ policyModel.getKeyInformation().generateKeyInfo(policyModel);
+
+ int uuidIncrementer = 0;
+ for (final AxKeyInfo keyInfo : policyModel.getKeyInformation().getKeyInfoMap().values()) {
+ final String uuidString = String.format("ce9168c-e6df-414f-9646-6da464b6e%03d", uuidIncrementer++);
+ keyInfo.setUuid(UUID.fromString(uuidString));
+ }
+
+ final AxValidationResult result = new AxValidationResult();
+ policyModel.validate(result);
+
+ return policyModel;
+ }
+
+ public AxPolicyModel getAnotherModel() {
+ final AxContextSchema schema0 =
+ new AxContextSchema(new AxArtifactKey("eventContextItemA0", "0.0.1"), "Java", "java.lang.String");
+ final AxContextSchema schema1 =
+ new AxContextSchema(new AxArtifactKey("eventContextItemA1", "0.0.1"), "Java", "java.lang.Long");
+ final AxContextSchema schema2 = new AxContextSchema(new AxArtifactKey("StringTypeA", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem000");
+ final AxContextSchema schema3 = new AxContextSchema(new AxArtifactKey("MapTypeA", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A");
+
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemasA", "0.0.1"));
+ schemas.getSchemasMap().put(schema0.getKey(), schema0);
+ schemas.getSchemasMap().put(schema1.getKey(), schema1);
+ schemas.getSchemasMap().put(schema2.getKey(), schema2);
+ schemas.getSchemasMap().put(schema3.getKey(), schema3);
+
+ final AxContextAlbum album0 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbumA0", "0.0.1"), "APPLICATION", true, schema3.getKey());
+ final AxContextAlbum album1 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbumA1", "0.0.1"), "GLOBAL", false, schema2.getKey());
+
+ final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("contextA", "0.0.1"));
+ albums.getAlbumsMap().put(album0.getKey(), album0);
+ albums.getAlbumsMap().put(album1.getKey(), album1);
+
+ final AxEvent inEvent = new AxEvent(new AxArtifactKey("inEventA", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ inEvent.getParameterMap().put("IEPARA0",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPARA0"), schema0.getKey()));
+ inEvent.getParameterMap().put("IEPARA1",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPARA1"), schema1.getKey()));
+
+ final AxEvent outEvent0 = new AxEvent(new AxArtifactKey("outEventA0", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent0.getParameterMap().put("OE0PARA0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PARA0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE0PARA1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PARA1"), schema1.getKey()));
+ outEvent0.getParameterMap().put("OE1PARA0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PARA0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE1PARA1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PARA1"), schema1.getKey()));
+
+ final AxEvent outEvent1 = new AxEvent(new AxArtifactKey("outEventA1", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent1.getParameterMap().put("OE1PARA0",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PARA0"), schema0.getKey()));
+ outEvent1.getParameterMap().put("OE1PARA1",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PARA1"), schema1.getKey()));
+
+ final AxEvents events = new AxEvents(new AxArtifactKey("eventsA", "0.0.1"));
+ events.getEventMap().put(inEvent.getKey(), inEvent);
+ events.getEventMap().put(outEvent0.getKey(), outEvent0);
+ events.getEventMap().put(outEvent1.getKey(), outEvent1);
+
+ final AxTask task = new AxTask(new AxArtifactKey("taskA", "0.0.1"));
+
+ for (final AxField field : inEvent.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(),
+ "inputFieldsA", field.getKey().getLocalName());
+ final AxInputField inputField = new AxInputField(fieldkey, field.getSchema());
+ task.getInputFields().put(inputField.getKey().getLocalName(), inputField);
+ }
+
+ for (final AxField field : outEvent0.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(),
+ "outputFieldsA", field.getKey().getLocalName());
+ final AxOutputField outputField = new AxOutputField(fieldkey, field.getSchema());
+ task.getOutputFields().put(outputField.getKey().getLocalName(), outputField);
+ }
+
+ for (final AxField field : outEvent1.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(task.getKey().getName(), task.getKey().getVersion(),
+ "outputFieldsA", field.getKey().getLocalName());
+ final AxOutputField outputField = new AxOutputField(fieldkey, field.getSchema());
+ task.getOutputFields().put(outputField.getKey().getLocalName(), outputField);
+ }
+
+ final AxTaskParameter taskPar0 =
+ new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameterA0"), "Task parameter 0 value");
+ final AxTaskParameter taskPar1 =
+ new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameterA1"), "Task parameter 1 value");
+
+ task.getTaskParameters().put(taskPar0.getKey().getLocalName(), taskPar0);
+ task.getTaskParameters().put(taskPar1.getKey().getLocalName(), taskPar1);
+ task.getContextAlbumReferences().add(album0.getKey());
+ task.getContextAlbumReferences().add(album1.getKey());
+
+ final AxTaskLogic taskLogic =
+ new AxTaskLogic(new AxReferenceKey(task.getKey(), "taskLogicA"), "MVEL", "Some task logic");
+ task.setTaskLogic(taskLogic);
+
+ final AxTasks tasks = new AxTasks(new AxArtifactKey("tasksA", "0.0.1"));
+ tasks.getTaskMap().put(task.getKey(), task);
+
+ final AxPolicy policy = new AxPolicy(new AxArtifactKey("policyA", "0.0.1"));
+ policy.setTemplate("FREEFORM");
+
+ final AxState state = new AxState(new AxReferenceKey(policy.getKey(), "stateA"));
+ final AxTaskSelectionLogic taskSelectionLogic = new AxTaskSelectionLogic(
+ new AxReferenceKey(state.getKey(), "taskSelectionLogicA"), "MVEL", "Some TS logic ");
+
+ state.setTrigger(inEvent.getKey());
+ state.getContextAlbumReferences().add(album0.getKey());
+ state.getContextAlbumReferences().add(album1.getKey());
+ state.setTaskSelectionLogic(taskSelectionLogic);
+ state.setDefaultTask(task.getKey());
+
+ final AxStateOutput stateOutput0 = new AxStateOutput(new AxReferenceKey(state.getKey(), "stateOutputA0"),
+ outEvent0.getKey(), AxReferenceKey.getNullKey());
+ state.getStateOutputs().put(stateOutput0.getKey().getLocalName(), stateOutput0);
+
+ final AxStateTaskReference stateTaskReference =
+ new AxStateTaskReference(new AxReferenceKey(state.getKey(), task.getKey().getName()),
+ AxStateTaskOutputType.DIRECT, stateOutput0.getKey());
+
+ state.getTaskReferences().put(task.getKey(), stateTaskReference);
+
+ policy.getStateMap().put(state.getKey().getLocalName(), state);
+ policy.setFirstState(state.getKey().getLocalName());
+
+ final AxPolicies policies = new AxPolicies(new AxArtifactKey("policiesA", "0.0.1"));
+ policies.getPolicyMap().put(policy.getKey(), policy);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKeyA", "0.0.1"));
+ final AxPolicyModel policyModel = new AxPolicyModel(new AxArtifactKey("PolicyModelA", "0.0.1"));
+ policyModel.setKeyInformation(keyInformation);
+ policyModel.setSchemas(schemas);
+ policyModel.setAlbums(albums);
+ policyModel.setEvents(events);
+ policyModel.setTasks(tasks);
+ policyModel.setPolicies(policies);
+ policyModel.getKeyInformation().generateKeyInfo(policyModel);
+
+ int uuidIncrementer = 0;
+ for (final AxKeyInfo keyInfo : policyModel.getKeyInformation().getKeyInfoMap().values()) {
+ final String uuidString = String.format("ce9168c-e6df-414f-9646-6da464b6e%03d", uuidIncrementer++);
+ keyInfo.setUuid(UUID.fromString(uuidString));
+ }
+
+ final AxValidationResult result = new AxValidationResult();
+ policyModel.validate(result);
+
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getMalstructuredModel() {
+ final AxPolicyModel policyModel = new AxPolicyModel(new AxArtifactKey("policyModel", "0.0.1"));
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getObservationModel() {
+ final AxPolicyModel policyModel = getModel();
+
+ final AxState state = policyModel.getPolicies().get("policy").getStateMap().get("state");
+ final AxTask task = policyModel.getTasks().get("task");
+
+ final AxStateFinalizerLogic stateFinalizerLogic =
+ new AxStateFinalizerLogic(new AxReferenceKey(state.getKey(), "SFL"), "MVEL", "Some SF logic ");
+ state.getStateFinalizerLogicMap().put(stateFinalizerLogic.getKey().getLocalName(), stateFinalizerLogic);
+ final AxStateTaskReference stateTaskReference =
+ new AxStateTaskReference(new AxReferenceKey(state.getKey(), task.getKey().getName()),
+ AxStateTaskOutputType.LOGIC, stateFinalizerLogic.getKey());
+
+ state.getTaskReferences().put(task.getKey(), stateTaskReference);
+
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getWarningModel() {
+ final AxPolicyModel policyModel = getModel();
+
+ final AxState anotherState =
+ new AxState(new AxReferenceKey(new AxArtifactKey("policy", "0.0.1"), "anotherState"));
+
+ final AxEvent inEvent = policyModel.getEvents().getEventMap().get(new AxArtifactKey("inEvent", "0.0.1"));
+ final AxEvent outEvent0 = policyModel.getEvents().getEventMap().get(new AxArtifactKey("outEvent0", "0.0.1"));
+
+ final AxTask anotherTask = new AxTask(new AxArtifactKey("anotherTask", "0.0.1"));
+
+ for (final AxField field : inEvent.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(anotherTask.getKey().getName(),
+ anotherTask.getKey().getVersion(), "inputFields", field.getKey().getLocalName());
+ final AxInputField inputField = new AxInputField(fieldkey, field.getSchema());
+ anotherTask.getInputFields().put(inputField.getKey().getLocalName(), inputField);
+ }
+
+ for (final AxField field : outEvent0.getFields()) {
+ final AxReferenceKey fieldkey = new AxReferenceKey(anotherTask.getKey().getName(),
+ anotherTask.getKey().getVersion(), "outputFields", field.getKey().getLocalName());
+ final AxOutputField outputField = new AxOutputField(fieldkey, field.getSchema());
+ anotherTask.getOutputFields().put(outputField.getKey().getLocalName(), outputField);
+ }
+
+ final AxTaskParameter taskPar0 = new AxTaskParameter(new AxReferenceKey(anotherTask.getKey(), "taskParameter0"),
+ "Task parameter 0 value");
+ final AxTaskParameter taskPar1 = new AxTaskParameter(new AxReferenceKey(anotherTask.getKey(), "taskParameter1"),
+ "Task parameter 1 value");
+
+ anotherTask.getTaskParameters().put(taskPar0.getKey().getLocalName(), taskPar0);
+ anotherTask.getTaskParameters().put(taskPar1.getKey().getLocalName(), taskPar1);
+
+ final AxTaskLogic taskLogic =
+ new AxTaskLogic(new AxReferenceKey(anotherTask.getKey(), "taskLogic"), "MVEL", "Some task logic");
+ anotherTask.setTaskLogic(taskLogic);
+ policyModel.getTasks().getTaskMap().put(anotherTask.getKey(), anotherTask);
+
+ final AxStateOutput anotherStateOutput0 =
+ new AxStateOutput(new AxReferenceKey(anotherState.getKey(), "stateOutput0"), outEvent0.getKey(),
+ AxReferenceKey.getNullKey());
+ anotherState.setTrigger(inEvent.getKey());
+ anotherState.getStateOutputs().put(anotherStateOutput0.getKey().getLocalName(), anotherStateOutput0);
+ anotherState.setDefaultTask(anotherTask.getKey());
+ final AxStateTaskReference anotherStateTaskReference =
+ new AxStateTaskReference(new AxReferenceKey(anotherState.getKey(), anotherTask.getKey().getName()),
+ AxStateTaskOutputType.DIRECT, anotherStateOutput0.getKey());
+ anotherState.getTaskReferences().put(anotherTask.getKey(), anotherStateTaskReference);
+
+ policyModel.getPolicies().getPolicyMap().get(new AxArtifactKey("policy", "0.0.1")).getStateMap()
+ .put(anotherState.getKey().getLocalName(), anotherState);
+
+ policyModel.getKeyInformation().generateKeyInfo(policyModel);
+
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getInvalidModel() {
+ final AxPolicyModel policyModel = getModel();
+
+ policyModel.getAlbums().get(new AxArtifactKey("contextAlbum0", "0.0.1")).setScope("UNDEFINED");
+ policyModel.getAlbums().get(new AxArtifactKey("contextAlbum1", "0.0.1")).setScope("UNDEFINED");
+
+ final AxEvent outEvent0 = policyModel.getEvents().get("outEvent0");
+ outEvent0.getParameterMap().remove("OE1PAR0");
+ outEvent0.getParameterMap().remove("OE1PAR1");
+
+ return policyModel;
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyAnalyser.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyAnalyser.java
new file mode 100644
index 000000000..40aa51ffe
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyAnalyser.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.handling.PolicyAnalyser;
+import org.onap.policy.apex.model.policymodel.handling.PolicyAnalysisResult;
+
+public class TestPolicyAnalyser {
+ @Test
+ public void test() {
+ final AxPolicyModel apexModel = new TestApexPolicyModelCreator().getModel();
+
+ final PolicyAnalyser policyAnalyser = new PolicyAnalyser();
+ final PolicyAnalysisResult analysisResult = policyAnalyser.analyse(apexModel);
+
+ assertTrue(analysisResult.toString().equals(EXPECTED_ANALYSIS_RESULT));
+
+ assertNotNull(analysisResult.getUsedContextAlbums());
+ assertNotNull(analysisResult.getUsedContextSchemas());
+ assertNotNull(analysisResult.getUsedEvents());
+ assertNotNull(analysisResult.getUsedTasks());
+ assertNotNull(analysisResult.getUnusedContextAlbums());
+ assertNotNull(analysisResult.getUnusedContextSchemas());
+ assertNotNull(analysisResult.getUnusedEvents());
+ assertNotNull(analysisResult.getUnusedTasks());
+ }
+
+ private static final String EXPECTED_ANALYSIS_RESULT = "" + "Context Schema usage\n" + " MapType:0.0.1\n"
+ + " contextAlbum0:0.0.1\n" + " StringType:0.0.1\n" + " contextAlbum1:0.0.1\n"
+ + " eventContextItem0:0.0.1\n" + " inEvent:0.0.1\n" + " outEvent0:0.0.1\n" + " outEvent1:0.0.1\n"
+ + " task:0.0.1\n" + " eventContextItem1:0.0.1\n" + " inEvent:0.0.1\n" + " outEvent0:0.0.1\n"
+ + " outEvent1:0.0.1\n" + " task:0.0.1\n" + "Context Album usage\n" + " contextAlbum0:0.0.1\n"
+ + " task:0.0.1\n" + " policy:0.0.1:NULL:state\n" + " contextAlbum1:0.0.1\n" + " task:0.0.1\n"
+ + " policy:0.0.1:NULL:state\n" + "Event usage\n" + " inEvent:0.0.1\n" + " policy:0.0.1:NULL:state\n"
+ + " outEvent0:0.0.1\n" + " policy:0.0.1:NULL:state\n" + " outEvent1:0.0.1 (unused)\n" + "Task usage\n"
+ + " task:0.0.1\n" + " policy:0.0.1:NULL:state\n";
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyLogicReader.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyLogicReader.java
new file mode 100644
index 000000000..446cbeed8
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyLogicReader.java
@@ -0,0 +1,114 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.policymodel.concepts.AxLogic;
+import org.onap.policy.apex.model.policymodel.handling.PolicyLogicReader;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestPolicyLogicReader {
+
+ @Test
+ public void test() {
+ final AxReferenceKey logicKey = new AxReferenceKey("LogicParent", "0.0.1", "LogicInstanceName");
+
+ final PolicyLogicReader plReader = new PolicyLogicReader();
+
+ plReader.setLogicPackage("somewhere.over.the.rainbow");
+ assertEquals("somewhere.over.the.rainbow", plReader.getLogicPackage());
+
+ plReader.setDefaultLogic("FunkyDefaultLogic");
+ assertEquals("FunkyDefaultLogic", plReader.getDefaultLogic());
+
+ try {
+ new AxLogic(logicKey, "FunkyLogic", plReader);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "logic not found for logic \"somewhere/over/the/rainbow/funkylogic/FunkyDefaultLogic.funkylogic\"",
+ e.getMessage());
+ }
+
+ plReader.setDefaultLogic(null);
+ try {
+ new AxLogic(logicKey, "FunkyLogic", plReader);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "logic not found for logic \"somewhere/over/the/rainbow/funkylogic/LogicParent_LogicInstanceName.funkylogic\"",
+ e.getMessage());
+ }
+
+ logicKey.setParentLocalName("LogicParentLocalName");
+ try {
+ new AxLogic(logicKey, "FunkyLogic", plReader);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals(
+ "logic not found for logic \"somewhere/over/the/rainbow/funkylogic/LogicParent_LogicParentLocalName_LogicInstanceName.funkylogic\"",
+ e.getMessage());
+ }
+
+ plReader.setLogicPackage("path.to.apex.logic");
+ try {
+ final AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
+ assertTrue(logic.getLogic().endsWith("Way out man, this is funky logic!"));
+ } catch (final Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ plReader.setLogicPackage("somewhere.over.the.rainbow");
+ plReader.setDefaultLogic("JavaLogic");
+
+ try {
+ final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
+ } catch (final Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ plReader.setDefaultLogic(null);
+ try {
+ final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.LogicParent_LogicParentLocalName_LogicInstanceName",
+ logic.getLogic());
+ } catch (final Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ logicKey.setParentLocalName(AxKey.NULL_KEY_NAME);
+ try {
+ final AxLogic logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.LogicParent_LogicInstanceName", logic.getLogic());
+ } catch (final Exception e) {
+ fail("test should not throw an exception");
+ }
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelComparer.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelComparer.java
new file mode 100644
index 000000000..3511b54ba
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelComparer.java
@@ -0,0 +1,129 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.handling.PolicyComparer;
+import org.onap.policy.apex.model.policymodel.handling.PolicyModelComparer;
+import org.onap.policy.apex.model.utilities.TextFileUtils;
+
+public class TestPolicyModelComparer {
+
+ @Test
+ public void testPolicyComparer() throws IOException {
+ final AxPolicyModel leftApexModel = new TestApexPolicyModelCreator().getModel();
+ final AxPolicyModel rightApexModel = new AxPolicyModel(leftApexModel);
+
+ PolicyModelComparer policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
+
+ String resultString = policyModelComparer.asString(false, false);
+ String checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt");
+ assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
+ checkString.trim().replaceAll("[\\r?\\n]+", " "));
+
+ resultString = policyModelComparer.asString(false, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt");
+ assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
+ .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
+
+ resultString = policyModelComparer.asString(true, false);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
+ assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
+ .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
+
+ resultString = policyModelComparer.asString(true, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
+ assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
+ .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
+
+ final AxKeyInfo leftOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("LeftOnlyKeyInfo", "0.0.1"),
+ UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f000"), "Left only key info");
+ final AxKeyInfo rightOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("RightOnlyKeyInfo", "0.0.1"),
+ UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f001"), "Right only key info");
+
+ leftApexModel.getKeyInformation().getKeyInfoMap().put(leftOnlyKeyInfo.getKey(), leftOnlyKeyInfo);
+ rightApexModel.getKeyInformation().getKeyInfoMap().put(rightOnlyKeyInfo.getKey(), rightOnlyKeyInfo);
+
+ leftApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
+ .setDescription("Left InEvent Description");
+ rightApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
+ .setDescription("Right InEvent Description");
+
+ policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
+
+ resultString = policyModelComparer.asString(false, false);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt");
+ assertEquals(resultString.trim().replaceAll("[\\r?\\n]+", " "),
+ checkString.trim().replaceAll("[\\r?\\n]+", " "));
+
+ resultString = policyModelComparer.asString(false, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt");
+ assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
+ .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
+
+ resultString = policyModelComparer.asString(true, false);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt");
+ assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
+ .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
+
+ resultString = policyModelComparer.asString(true, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt");
+ assertTrue(resultString.trim().replaceAll("[\\r?\\n]+", " ")
+ .equals(checkString.trim().replaceAll("[\\r?\\n]+", " ")));
+
+ assertNotNull(policyModelComparer.getContextAlbumComparisonResult());
+ assertNotNull(policyModelComparer.getContextAlbumKeyDifference());
+ assertNotNull(policyModelComparer.getContextSchemaComparisonResult());
+ assertNotNull(policyModelComparer.getContextSchemaKeyDifference());
+ assertNotNull(policyModelComparer.getEventComparisonResult());
+ assertNotNull(policyModelComparer.getEventKeyDifference());
+ assertNotNull(policyModelComparer.getKeyInfoComparisonResult());
+ assertNotNull(policyModelComparer.getKeyInformationKeyDifference());
+ assertNotNull(policyModelComparer.getPolicyComparisonResult());
+ assertNotNull(policyModelComparer.getPolicykeyDifference());
+ assertNotNull(policyModelComparer.getPolicyModelsKeyDifference());
+ assertNotNull(policyModelComparer.getTaskComparisonResult());
+ assertNotNull(policyModelComparer.getTaskKeyDifference());
+
+ assertNotNull(new PolicyComparer().compare(leftApexModel.getPolicies(), rightApexModel.getPolicies()));
+
+ assertEquals("****** policy map differences ******\n*** context s",
+ policyModelComparer.toString().substring(0, 50));
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelMerger.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelMerger.java
new file mode 100644
index 000000000..92d1dc32a
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelMerger.java
@@ -0,0 +1,109 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.handling.PolicyModelMerger;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestPolicyModelMerger {
+
+ @Test
+ public void testPolicyModelMerger() {
+ final AxPolicyModel leftPolicyModel = new TestApexPolicyModelCreator().getModel();
+ AxPolicyModel rightPolicyModel = new TestApexPolicyModelCreator().getModel();
+
+ try {
+ final AxPolicyModel mergedPolicyModel =
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false);
+ assertEquals(leftPolicyModel, mergedPolicyModel);
+ assertEquals(rightPolicyModel, mergedPolicyModel);
+ } catch (final ApexModelException e) {
+ fail("test should not throw an exception");
+ }
+
+ leftPolicyModel.setKey(new AxArtifactKey("LeftPolicyModel", "0.0.1"));
+ try {
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false);
+ fail("test should throw an exception here");
+ } catch (final ApexModelException e) {
+ assertEquals("left model is invalid: \n***validation of model fai", e.getMessage().substring(0, 50));
+ }
+
+ leftPolicyModel.setKey(new AxArtifactKey("LeftPolicyModel", "0.0.1"));
+ try {
+ assertNotNull(PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, true));
+ } catch (final ApexModelException e) {
+ fail("test should not throw an exception");
+ }
+
+ leftPolicyModel.getKeyInformation().generateKeyInfo(leftPolicyModel);
+ try {
+ final AxPolicyModel mergedPolicyModel =
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, true);
+ assertNotNull(mergedPolicyModel);
+ } catch (final ApexModelException e) {
+ fail("test should not throw an exception");
+ }
+
+ rightPolicyModel.setKey(new AxArtifactKey("RightPolicyModel", "0.0.1"));
+ try {
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false);
+ fail("test should throw an exception here");
+ } catch (final ApexModelException e) {
+ assertEquals("right model is invalid: \n***validation of model fa", e.getMessage().substring(0, 50));
+ }
+
+ rightPolicyModel.setKey(new AxArtifactKey("RightPolicyModel", "0.0.1"));
+ try {
+ assertNotNull(PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, true));
+ } catch (final ApexModelException e) {
+ fail("test should not throw an exception");
+ }
+
+ rightPolicyModel.getKeyInformation().generateKeyInfo(rightPolicyModel);
+ try {
+ final AxPolicyModel mergedPolicyModel =
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false);
+ assertNotNull(mergedPolicyModel);
+ } catch (final ApexModelException e) {
+ fail("test should not throw an exception");
+ }
+
+ rightPolicyModel = new TestApexPolicyModelCreator().getAnotherModel();
+ try {
+ final AxPolicyModel mergedPolicyModel =
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, true);
+ assertNotNull(mergedPolicyModel);
+ } catch (final ApexModelException e) {
+ fail("test should not throw an exception");
+ }
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelSplitter.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelSplitter.java
new file mode 100644
index 000000000..fde6e3712
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/TestPolicyModelSplitter.java
@@ -0,0 +1,95 @@
+/*-
+ * ============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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.handling.PolicyModelSplitter;
+
+public class TestPolicyModelSplitter {
+ @Test
+ public void test() {
+ final AxPolicyModel apexModel = new TestApexPolicyModelCreator().getModel();
+
+ final Set<AxArtifactKey> requiredPolicySet = new TreeSet<AxArtifactKey>();
+ requiredPolicySet.add(new AxArtifactKey("policy", "0.0.1"));
+
+ // There's only one policy so a split of this model on that policy should return the same
+ // model
+ AxPolicyModel splitApexModel = null;
+ try {
+ splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
+ } catch (final ApexModelException e) {
+ fail(e.getMessage());
+ }
+
+ // The only difference between the models should be that the unused event outEvent1 should
+ // not be in the split model
+ apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ assertTrue(apexModel.equals(splitApexModel));
+
+ final Set<AxArtifactKey> requiredMissingPolicySet = new TreeSet<AxArtifactKey>();
+ requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
+
+ AxPolicyModel missingSplitApexModel = null;
+ try {
+ missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
+ } catch (final ApexModelException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(missingSplitApexModel);
+
+ splitApexModel = null;
+ try {
+ splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
+ } catch (final ApexModelException e) {
+ fail(e.getMessage());
+ }
+
+ // The only difference between the models should be that the unused event outEvent1 should
+ // not be in the split model
+ apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ assertTrue(apexModel.equals(splitApexModel));
+
+ // There's only one policy so a split of this model on that policy should return the same
+ // model
+ try {
+ apexModel.getKey().setName("InvalidPolicyModelName");
+ PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
+ fail("test should throw an exception here");
+ } catch (final Exception e) {
+ assertEquals("source model is invalid: \n***validation of model f", e.getMessage().substring(0, 50));
+ }
+
+ }
+}
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/utils/PolicyModelValidator.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/utils/PolicyModelValidator.java
new file mode 100644
index 000000000..4610a827e
--- /dev/null
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/utils/PolicyModelValidator.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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.utils;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class PolicyModelValidator {
+ public static void main(final String[] args) throws ApexModelException, FileNotFoundException {
+ final ApexModelReader<AxPolicyModel> policyModelReader =
+ new ApexModelReader<AxPolicyModel>(AxPolicyModel.class);
+
+
+ final AxPolicyModel policyModel = policyModelReader.read(new FileInputStream(args[0]));
+ final AxValidationResult result = policyModel.validate(new AxValidationResult());
+ System.out.println(result);
+ }
+}
diff --git a/model/policy-model/src/test/resources/META-INF/persistence.xml b/model/policy-model/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..6131c82d1
--- /dev/null
+++ b/model/policy-model/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
+ <persistence-unit name="DAOTest" transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+
+ <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDATAConditioner</class>
+ <class>org.onap.policy.apex.model.basicmodel.dao.converters.UUID2String</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxConcept</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class>
+ <class>org.onap.policy.apex.model.basicmodel.concepts.TestEntity</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums</class>
+ <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextModel</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxInputField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxOutputField</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvent</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvents</class>
+ <class>org.onap.policy.apex.model.eventmodel.concepts.AxEventModel</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTask</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTasks</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateOutput</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxState</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicy</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicies</class>
+ <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel</class>
+
+ <properties>
+ <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:apex_test" />
+ <property name="javax.persistence.target-database" value="Derby" />
+ <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
+
+ <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
+ <property name="eclipselink.ddl-generation.output-mode" value="database" />
+ <property name="eclipselink.logging.level" value="INFO" />
+ </properties>
+ </persistence-unit>
+</persistence>
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt
new file mode 100644
index 000000000..57b790222
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt
@@ -0,0 +1,15 @@
+****** policy map differences ******
+*** context schema differences ***
+*** event differences ***
+*** context album differences ***
+*** task differences ***
+*** policy differences ***
+*** key information differences ***
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1)
+*** list of differing entries between left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+***********************************
+
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt
new file mode 100644
index 000000000..e3ba6dc7c
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt
@@ -0,0 +1,14 @@
+****** policy map differences ******
+*** context schema differences ***
+*** event differences ***
+*** context album differences ***
+*** task differences ***
+*** policy differences ***
+*** key information differences ***
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f000,description=Left only key info)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f001,description=Right only key info)
+*** list of differing entries between left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1),values={AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Left InEvent Description)AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Right InEvent Description),}
+***********************************
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt
new file mode 100644
index 000000000..926a8d764
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt
@@ -0,0 +1,71 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1)
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1)
+*** list of differing entries between left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1)
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=context,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+key=AxArtifactKey:(name=events,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+key=AxArtifactKey:(name=policies,version=0.0.1)
+key=AxArtifactKey:(name=policy,version=0.0.1)
+key=AxArtifactKey:(name=task,version=0.0.1)
+key=AxArtifactKey:(name=tasks,version=0.0.1)
+***********************************
+
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt
new file mode 100644
index 000000000..d3aad785e
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt
@@ -0,0 +1,70 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=MapType,version=0.0.1),schemaFlavour=Java,schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A)
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=StringType,version=0.0.1),schemaFlavour=Java,schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem000)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),schemaFlavour=Java,schemaDefinition=java.lang.String)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),schemaFlavour=Java,schemaDefinition=java.lang.Long)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=inEvent,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={IEPAR0=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), IEPAR1=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)})
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent0,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE0PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE0PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false), OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)})
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent1,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)})
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxContextAlbum:(key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),scope=APPLICATION,isWritable=true,itemSchema=AxArtifactKey:(name=MapType,version=0.0.1))
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxContextAlbum:(key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),scope=GLOBAL,isWritable=false,itemSchema=AxArtifactKey:(name=StringType,version=0.0.1))
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxTask:(key=AxArtifactKey:(name=task,version=0.0.1),inputFields={IEPAR0=AxInputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=inputFields,localName=IEPAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), IEPAR1=AxInputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=inputFields,localName=IEPAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},outputFields={OE0PAR0=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE0PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE0PAR1=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE0PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false), OE1PAR0=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},taskParameters={taskParameter0=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter0),defaultValue=Task parameter 0 value), taskParameter1=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter1),defaultValue=Task parameter 1 value)},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskLogic=AxTaskLogic:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskLogic),logicFlavour=MVEL,logic=Some task logic))
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,stateMap={state=AxState:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state),trigger=AxArtifactKey:(name=inEvent,version=0.0.1),stateOutputs={stateOutput0=AxStateOutput:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0),outgoingEvent=AxArtifactKey:(name=outEvent0,version=0.0.1),nextState=AxReferenceKey:(parentKeyName=NULL,parentKeyVersion=0.0.0,parentLocalName=NULL,localName=NULL))},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskSelectionLogic=AxTaskSelectionLogic:(key=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=taskSelectionLogic),logicFlavour=MVEL,logic=Some TS logic),stateFinalizerLogicSet={},defaultTask=AxArtifactKey:(name=task,version=0.0.1),taskReferenceMap={AxArtifactKey:(name=task,version=0.0.1)=AxStateTaskReference:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=task),outputType=DIRECT,output=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0))})},firstState=state)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f000,description=Left only key info)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f001,description=Right only key info)
+*** list of differing entries between left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1),values={AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Left InEvent Description)AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Right InEvent Description),}
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=ContextSchemas,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e000,description=Generated description for concept referred to by key "ContextSchemas:0.0.1")
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e001,description=Generated description for concept referred to by key "KeyInfoMapKey:0.0.1")
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=MapType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e002,description=Generated description for concept referred to by key "MapType:0.0.1")
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=PolicyModel,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e003,description=Generated description for concept referred to by key "PolicyModel:0.0.1")
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=StringType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e004,description=Generated description for concept referred to by key "StringType:0.0.1")
+key=AxArtifactKey:(name=context,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=context,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e005,description=Generated description for concept referred to by key "context:0.0.1")
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e006,description=Generated description for concept referred to by key "contextAlbum0:0.0.1")
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e007,description=Generated description for concept referred to by key "contextAlbum1:0.0.1")
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e008,description=Generated description for concept referred to by key "eventContextItem0:0.0.1")
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e009,description=Generated description for concept referred to by key "eventContextItem1:0.0.1")
+key=AxArtifactKey:(name=events,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=events,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e010,description=Generated description for concept referred to by key "events:0.0.1")
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e012,description=Generated description for concept referred to by key "outEvent0:0.0.1")
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e013,description=Generated description for concept referred to by key "outEvent1:0.0.1")
+key=AxArtifactKey:(name=policies,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policies,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e014,description=Generated description for concept referred to by key "policies:0.0.1")
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policy,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e015,description=Generated description for concept referred to by key "policy:0.0.1")
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=task,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e016,description=Generated description for concept referred to by key "task:0.0.1")
+key=AxArtifactKey:(name=tasks,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=tasks,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e017,description=Generated description for concept referred to by key "tasks:0.0.1")
+***********************************
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt
new file mode 100644
index 000000000..b9c0decdd
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt
@@ -0,0 +1,8 @@
+****** policy map differences ******
+*** context schema differences ***
+*** event differences ***
+*** context album differences ***
+*** task differences ***
+*** policy differences ***
+*** key information differences ***
+*********************************** \ No newline at end of file
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt
new file mode 100644
index 000000000..17862e1b1
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt
@@ -0,0 +1,69 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1)
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1)
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=context,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+key=AxArtifactKey:(name=events,version=0.0.1)
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+key=AxArtifactKey:(name=policies,version=0.0.1)
+key=AxArtifactKey:(name=policy,version=0.0.1)
+key=AxArtifactKey:(name=task,version=0.0.1)
+key=AxArtifactKey:(name=tasks,version=0.0.1)
+***********************************
+
diff --git a/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt
new file mode 100644
index 000000000..f566a7e5f
--- /dev/null
+++ b/model/policy-model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt
@@ -0,0 +1,69 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=MapType,version=0.0.1),schemaFlavour=Java,schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A)
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=StringType,version=0.0.1),schemaFlavour=Java,schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem000)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),schemaFlavour=Java,schemaDefinition=java.lang.String)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxContextSchema:(key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),schemaFlavour=Java,schemaDefinition=java.lang.Long)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=inEvent,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={IEPAR0=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), IEPAR1=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)})
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent0,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE0PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE0PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false), OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)})
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent1,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)})
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxContextAlbum:(key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),scope=APPLICATION,isWritable=true,itemSchema=AxArtifactKey:(name=MapType,version=0.0.1))
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxContextAlbum:(key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),scope=GLOBAL,isWritable=false,itemSchema=AxArtifactKey:(name=StringType,version=0.0.1))
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxTask:(key=AxArtifactKey:(name=task,version=0.0.1),inputFields={IEPAR0=AxInputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=inputFields,localName=IEPAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), IEPAR1=AxInputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=inputFields,localName=IEPAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},outputFields={OE0PAR0=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE0PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE0PAR1=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE0PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false), OE1PAR0=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxOutputField:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=outputFields,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},taskParameters={taskParameter0=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter0),defaultValue=Task parameter 0 value), taskParameter1=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter1),defaultValue=Task parameter 1 value)},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskLogic=AxTaskLogic:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskLogic),logicFlavour=MVEL,logic=Some task logic))
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,stateMap={state=AxState:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state),trigger=AxArtifactKey:(name=inEvent,version=0.0.1),stateOutputs={stateOutput0=AxStateOutput:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0),outgoingEvent=AxArtifactKey:(name=outEvent0,version=0.0.1),nextState=AxReferenceKey:(parentKeyName=NULL,parentKeyVersion=0.0.0,parentLocalName=NULL,localName=NULL))},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskSelectionLogic=AxTaskSelectionLogic:(key=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=taskSelectionLogic),logicFlavour=MVEL,logic=Some TS logic),stateFinalizerLogicSet={},defaultTask=AxArtifactKey:(name=task,version=0.0.1),taskReferenceMap={AxArtifactKey:(name=task,version=0.0.1)=AxStateTaskReference:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=task),outputType=DIRECT,output=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0))})},firstState=state)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=ContextSchemas,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e000,description=Generated description for concept referred to by key "ContextSchemas:0.0.1")
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e001,description=Generated description for concept referred to by key "KeyInfoMapKey:0.0.1")
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=MapType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e002,description=Generated description for concept referred to by key "MapType:0.0.1")
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=PolicyModel,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e003,description=Generated description for concept referred to by key "PolicyModel:0.0.1")
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=StringType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e004,description=Generated description for concept referred to by key "StringType:0.0.1")
+key=AxArtifactKey:(name=context,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=context,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e005,description=Generated description for concept referred to by key "context:0.0.1")
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e006,description=Generated description for concept referred to by key "contextAlbum0:0.0.1")
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e007,description=Generated description for concept referred to by key "contextAlbum1:0.0.1")
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e008,description=Generated description for concept referred to by key "eventContextItem0:0.0.1")
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e009,description=Generated description for concept referred to by key "eventContextItem1:0.0.1")
+key=AxArtifactKey:(name=events,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=events,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e010,description=Generated description for concept referred to by key "events:0.0.1")
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Generated description for concept referred to by key "inEvent:0.0.1")
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e012,description=Generated description for concept referred to by key "outEvent0:0.0.1")
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e013,description=Generated description for concept referred to by key "outEvent1:0.0.1")
+key=AxArtifactKey:(name=policies,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policies,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e014,description=Generated description for concept referred to by key "policies:0.0.1")
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policy,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e015,description=Generated description for concept referred to by key "policy:0.0.1")
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=task,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e016,description=Generated description for concept referred to by key "task:0.0.1")
+key=AxArtifactKey:(name=tasks,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=tasks,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e017,description=Generated description for concept referred to by key "tasks:0.0.1")
+***********************************
+
diff --git a/model/policy-model/src/test/resources/logback-test.xml b/model/policy-model/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..114b39c70
--- /dev/null
+++ b/model/policy-model/src/test/resources/logback-test.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+-->
+
+<configuration>
+
+ <contextName>Apex</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" />
+
+ <!-- USE FOR STD OUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <logger name="org.infinispan" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex_ctxt.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="TRACE" additivity="false">
+ <appender-ref ref="CTXT_FILE" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+</configuration>
diff --git a/model/policy-model/src/test/resources/path/to/apex/logic/funkylogic/LogicParent_LogicParentLocalName_LogicInstanceName.funkylogic b/model/policy-model/src/test/resources/path/to/apex/logic/funkylogic/LogicParent_LogicParentLocalName_LogicInstanceName.funkylogic
new file mode 100644
index 000000000..7ccf3da88
--- /dev/null
+++ b/model/policy-model/src/test/resources/path/to/apex/logic/funkylogic/LogicParent_LogicParentLocalName_LogicInstanceName.funkylogic
@@ -0,0 +1,21 @@
+#-------------------------------------------------------------------------------
+# ============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=========================================================
+#-------------------------------------------------------------------------------
+
+Way out man, this is funky logic! \ No newline at end of file
diff --git a/model/pom.xml b/model/pom.xml
index 5e6a52ad5..ec9d19fc0 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -47,5 +47,8 @@
<module>basic-model</module>
<module>context-model</module>
<module>event-model</module>
+ <module>policy-model</module>
+ <module>engine-model</module>
+ <module>model-api</module>
</modules>
</project> \ No newline at end of file