From 8534756d13531ffec9c2d7b2ffe0a53ee1d3aaef Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 10 Feb 2022 12:06:25 +0000 Subject: Collapse apex-pdp maven model submodules This review collapses all the code in six podel submodules into a single model module. There are no code changes, just files moved around. This change reduces the complexity of the code structure and speeds up the build. Issue-ID: POLICY-1820 Change-Id: Ifb644e8ec85ae6d0987378f4616fbc8a8858a9a8 Signed-off-by: liamfallon --- model/model-api/pom.xml | 43 - .../policy/apex/model/modelapi/ApexApiResult.java | 264 -- .../policy/apex/model/modelapi/ApexEditorApi.java | 905 ------ .../onap/policy/apex/model/modelapi/ApexModel.java | 176 -- .../apex/model/modelapi/ApexModelFactory.java | 76 - .../apex/model/modelapi/impl/ApexModelImpl.java | 866 ------ .../apex/model/modelapi/impl/ContextAlbum.java | 39 - .../model/modelapi/impl/ContextAlbumFacade.java | 254 -- .../model/modelapi/impl/ContextSchemaFacade.java | 238 -- .../modelapi/impl/CreatePolicyStateTaskRef.java | 38 - .../apex/model/modelapi/impl/EventFacade.java | 386 --- .../model/modelapi/impl/KeyInformationFacade.java | 228 -- .../apex/model/modelapi/impl/ModelFacade.java | 202 -- .../model/modelapi/impl/ModelHandlerFacade.java | 498 ---- .../apex/model/modelapi/impl/PolicyFacade.java | 1385 --------- .../apex/model/modelapi/impl/TaskFacade.java | 597 ---- .../apex/model/modelapi/impl/package-info.java | 27 - .../policy/apex/model/modelapi/package-info.java | 27 - .../apex/model/modelapi/ApexApiResultTest.java | 80 - .../modelapi/ApexEditorApiContextAlbumTest.java | 176 -- .../modelapi/ApexEditorApiContextSchemaTest.java | 153 - .../model/modelapi/ApexEditorApiEventTest.java | 202 -- .../model/modelapi/ApexEditorApiKeyInfoTest.java | 137 - .../model/modelapi/ApexEditorApiPolicyTest.java | 1023 ------- .../apex/model/modelapi/ApexEditorApiTaskTest.java | 376 --- .../apex/model/modelapi/ApexModelApiTest.java | 208 -- .../apex/model/modelapi/ModelFacadeTest.java | 99 - .../model/modelapi/ModelHandlerFacadeTest.java | 128 - .../policy/apex/model/modelapi/RealModelTest.java | 46 - .../model-api/src/test/resources/logback-test.xml | 74 - .../src/test/resources/models/PolicyModel.json | 775 ----- .../src/test/resources/models/PolicyModel.junk | 9 - .../src/test/resources/models/RealPolicyModel.json | 3076 -------------------- 33 files changed, 12811 deletions(-) delete mode 100644 model/model-api/pom.xml delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexApiResult.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexEditorApi.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbum.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/CreatePolicyStateTaskRef.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/package-info.java delete mode 100644 model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/package-info.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java delete mode 100644 model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java delete mode 100644 model/model-api/src/test/resources/logback-test.xml delete mode 100644 model/model-api/src/test/resources/models/PolicyModel.json delete mode 100644 model/model-api/src/test/resources/models/PolicyModel.junk delete mode 100644 model/model-api/src/test/resources/models/RealPolicyModel.json (limited to 'model/model-api') diff --git a/model/model-api/pom.xml b/model/model-api/pom.xml deleted file mode 100644 index 98c727ef5..000000000 --- a/model/model-api/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - 4.0.0 - - org.onap.policy.apex-pdp.model - model - 2.7.1-SNAPSHOT - - - model-api - ${project.artifactId} - APIs for editing Apex models - - - - org.onap.policy.common - utils - - - ${project.groupId} - policy-model - ${project.version} - - - 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 deleted file mode 100644 index 83e3b5370..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexApiResult.java +++ /dev/null @@ -1,264 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; -import lombok.Setter; - -/** - * The Class ApexEditorAPIResult return the result of and messages from all model API method calls on the - * {@link ApexModel} API. - */ -@Setter -public class ApexApiResult { - - /** - * This enumeration is used to represent the result status of a call on the {@link ApexModel} API. - */ - 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; - - /** - * Check if a result is OK. - * - * @param result the result - * @return true if the result is not OK - */ - public static boolean isOk(final Result result) { - return result == Result.SUCCESS || result == Result.FINISHED; - } - - /** - * Check if a result is not OK. - * - * @param result the result - * @return true if the result is not OK - */ - public static boolean isNok(final Result result) { - return !isOk(result); - } - } - - private Result result; - private List 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 - */ - public boolean isOk() { - return Result.isOk(result); - } - - /** - * 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 Result.isNok(result); - } - - /** - * Gets the result status of an API operation. - * - * @return the result status - */ - public Result getResult() { - return result; - } - - /** - * Gets the list of messages returned by an API operation. - * - * @return the list of messages returned by an API operation - */ - public List getMessages() { - return 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 - */ - 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.replace("\"", "\\\\\"")); - builder.append("\""); - } - builder.append("]\n"); - - builder.append("}\n"); - - return builder.toString(); - } - - /** - * {@inheritDoc}. - */ - @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 deleted file mode 100644 index 8974d1fa8..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexEditorApi.java +++ /dev/null @@ -1,905 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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 - * @param toscaPolicyState specifies TOSCA policy processing status - * @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, final String toscaPolicyState); - - /** - * 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 - * @param toscaPolicyState specifies TOSCA policy processing status - * @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, final String toscaPolicyState); - - /** - * 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 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 createTaskField(final String name, final String version, final String fieldName, - final String contextSchemaName, final String contextSchemaVersion, boolean optional); - - /** - * Handle a task field. - * - * @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 handleTaskField(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); -} \ No newline at end of file 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 deleted file mode 100644 index 3c6e4c063..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModel.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -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 getCopy(); - - /** - * 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 - * @return the result of the operation - */ - ApexApiResult saveToFile(String fileName); - - /** - * 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 - * @return the result of the operation - */ - ApexApiResult writeToUrl(String urlString); - - /** - * 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 deleted file mode 100644 index 908f562d2..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/ApexModelFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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 - * @return the apex model - */ - public ApexModel createApexModel(final Properties apexProperties) { - return new ApexModelImpl(setDefaultPropertyValues(apexProperties)); - } - - /** - * 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 deleted file mode 100644 index 54b94d0e7..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java +++ /dev/null @@ -1,866 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi.impl; - -import java.util.Properties; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.onap.policy.apex.model.modelapi.ApexApiResult; -import org.onap.policy.apex.model.modelapi.ApexApiResult.Result; -import org.onap.policy.apex.model.modelapi.ApexModel; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class is an implementation of a facade on an Apex model for editors of Apex models. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ApexModelImpl implements ApexModel { - - public static final String FIELDS_DEPRECATED_WARN_MSG = - "inputFields and outputFields are deprecated from Task definition and will be removed. " - + "Instead, inputEvent and outputEvents are automatically populated to Tasks based on State definition"; - - private static final Logger LOGGER = LoggerFactory.getLogger(ApexModelImpl.class); - - // The policy model being acted upon - @Getter - @Setter - private AxPolicyModel policyModel = new AxPolicyModel(); - - // @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; - - /** - * Create an implementation of the Apex editor and model APIs. - * - * @param apexProperties The properties to use for the model - */ - public ApexModelImpl(final Properties apexProperties) { - this.apexProperties = apexProperties; - - // @formatter:off - this.modelFacade = new ModelFacade(this, apexProperties); - this.keyInformationFacade = new KeyInformationFacade(this, apexProperties); - this.contextSchemaFacade = new ContextSchemaFacade(this, apexProperties); - this.eventFacade = new EventFacade(this, apexProperties); - this.contextAlbumFacade = new ContextAlbumFacade(this, apexProperties); - this.taskFacade = new TaskFacade(this, apexProperties); - this.policyFacade = new PolicyFacade(this, apexProperties); - this.modelHandlerFacade = new ModelHandlerFacade(this, apexProperties); - // @formatter:on - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexModel getCopy() { - ApexModelImpl ret = new ApexModelImpl(); - // @formatter:off - ret.policyModel = new AxPolicyModel(policyModel); - ret.apexProperties = this.apexProperties; - ret.modelFacade = new ModelFacade(ret, this.apexProperties); - ret.keyInformationFacade = new KeyInformationFacade(ret, this.apexProperties); - ret.contextSchemaFacade = new ContextSchemaFacade(ret, this.apexProperties); - ret.eventFacade = new EventFacade(ret, this.apexProperties); - ret.contextAlbumFacade = new ContextAlbumFacade(ret, this.apexProperties); - ret.taskFacade = new TaskFacade(ret, this.apexProperties); - ret.policyFacade = new PolicyFacade(ret, this.apexProperties); - ret.modelHandlerFacade = new ModelHandlerFacade(ret, this.apexProperties); - // @formatter:on - - return ret; - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createModel(final String name, final String version, final String uuid, - final String description) { - return modelFacade.createModel(name, version, uuid, description); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult updateModel(final String name, final String version, final String uuid, - final String description) { - return modelFacade.updateModel(name, version, uuid, description); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult getModelKey() { - return modelFacade.getModelKey(); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listModel() { - return modelFacade.listModel(); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteModel() { - return modelFacade.deleteModel(); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createKeyInformation(final String name, final String version, final String uuid, - final String description) { - return keyInformationFacade.createKeyInformation(name, version, uuid, description); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult updateKeyInformation(final String name, final String version, final String uuid, - final String description) { - return keyInformationFacade.updateKeyInformation(name, version, uuid, description); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listKeyInformation(final String name, final String version) { - return keyInformationFacade.listKeyInformation(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteKeyInformation(final String name, final String version) { - return keyInformationFacade.deleteKeyInformation(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validateKeyInformation(final String name, final String version) { - return keyInformationFacade.validateKeyInformation(name, version); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listContextSchemas(final String name, final String version) { - return contextSchemaFacade.listContextSchemas(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteContextSchema(final String name, final String version) { - return contextSchemaFacade.deleteContextSchema(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validateContextSchemas(final String name, final String version) { - return contextSchemaFacade.validateContextSchemas(name, version); - } - - /** - * {@inheritDoc}. - */ - @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, - final String toscaPolicyState) { - return eventFacade.createEvent(name, version, nameSpace, source, target, uuid, description, toscaPolicyState); - } - - /** - * {@inheritDoc}. - */ - @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, - final String toscaPolicyState) { - return eventFacade.updateEvent(name, version, nameSpace, source, target, uuid, description, toscaPolicyState); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listEvent(final String name, final String version) { - return eventFacade.listEvent(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteEvent(final String name, final String version) { - return eventFacade.deleteEvent(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validateEvent(final String name, final String version) { - return eventFacade.validateEvent(name, version); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listEventPar(final String name, final String version, final String parName) { - return eventFacade.listEventPar(name, version, parName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteEventPar(final String name, final String version, final String parName) { - return eventFacade.deleteEventPar(name, version, parName); - } - - /** - * {@inheritDoc}. - */ - @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(ContextAlbum.builder().name(name).version(version) - .scope(scope).writable(writable).contextSchemaName(contextSchemaName) - .contextSchemaVersion(contextSchemaVersion).uuid(uuid).description(description).build()); - } - // CHECKSTYLE:ON: checkstyle:parameterNumber - - /** - * {@inheritDoc}. - */ - // 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(ContextAlbum.builder().name(name).version(version) - .scope(scope).writable(writable).contextSchemaName(contextSchemaName) - .contextSchemaVersion(contextSchemaVersion).uuid(uuid).description(description).build()); - } - // CHECKSTYLE:ON: checkstyle:parameterNumber - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listContextAlbum(final String name, final String version) { - return contextAlbumFacade.listContextAlbum(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteContextAlbum(final String name, final String version) { - return contextAlbumFacade.deleteContextAlbum(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validateContextAlbum(final String name, final String version) { - return contextAlbumFacade.validateContextAlbum(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createTask(final String name, final String version, final String uuid, - final String description) { - return taskFacade.createTask(name, version, uuid, description); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult updateTask(final String name, final String version, final String uuid, - final String description) { - return taskFacade.updateTask(name, version, uuid, description); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listTask(final String name, final String version) { - return taskFacade.listTask(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteTask(final String name, final String version) { - return taskFacade.deleteTask(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validateTask(final String name, final String version) { - return taskFacade.validateTask(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createTaskLogic(final String name, final String version, final String logicFlavour, - final String logic) { - return taskFacade.createTaskLogic(name, version, logicFlavour, logic); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult updateTaskLogic(final String name, final String version, final String logicFlavour, - final String logic) { - return taskFacade.updateTaskLogic(name, version, logicFlavour, logic); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listTaskLogic(final String name, final String version) { - return taskFacade.listTaskLogic(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteTaskLogic(final String name, final String version) { - return taskFacade.deleteTaskLogic(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createTaskField(final String name, final String version, final String fieldName, - final String dataTypeName, final String dataTypeVersion, final boolean optional) { - LOGGER.warn(FIELDS_DEPRECATED_WARN_MSG); - return new ApexApiResult(Result.SUCCESS, FIELDS_DEPRECATED_WARN_MSG); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult handleTaskField(final String name, final String version, final String fieldName) { - LOGGER.warn(FIELDS_DEPRECATED_WARN_MSG); - return new ApexApiResult(Result.SUCCESS, FIELDS_DEPRECATED_WARN_MSG); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createTaskParameter(final String name, final String version, final String parName, - final String defaultValue) { - return taskFacade.createTaskParameter(name, version, parName, defaultValue); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listTaskParameter(final String name, final String version, final String parName) { - return taskFacade.listTaskParameter(name, version, parName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteTaskParameter(final String name, final String version, final String parName) { - return taskFacade.deleteTaskParameter(name, version, parName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult createTaskContextRef(final String name, final String version, final String contextAlbumName, - final String contextAlbumVersion) { - return taskFacade.createTaskContextRef(name, version, contextAlbumName, contextAlbumVersion); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listTaskContextRef(final String name, final String version, final String contextAlbumName, - final String contextAlbumVersion) { - return taskFacade.listTaskContextRef(name, version, contextAlbumName, contextAlbumVersion); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deleteTaskContextRef(final String name, final String version, final String contextAlbumName, - final String contextAlbumVersion) { - return taskFacade.deleteTaskContextRef(name, version, contextAlbumName, contextAlbumVersion); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listPolicy(final String name, final String version) { - return policyFacade.listPolicy(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deletePolicy(final String name, final String version) { - return policyFacade.deletePolicy(name, version); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validatePolicy(final String name, final String version) { - return policyFacade.validatePolicy(name, version); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listPolicyState(final String name, final String version, final String stateName) { - return policyFacade.listPolicyState(name, version, stateName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deletePolicyState(final String name, final String version, final String stateName) { - return policyFacade.deletePolicyState(name, version, stateName); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listPolicyStateTaskSelectionLogic(final String name, final String version, - final String stateName) { - return policyFacade.listPolicyStateTaskSelectionLogic(name, version, stateName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deletePolicyStateTaskSelectionLogic(final String name, final String version, - final String stateName) { - return policyFacade.deletePolicyStateTaskSelectionLogic(name, version, stateName); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listPolicyStateOutput(final String name, final String version, final String stateName, - final String outputName) { - return policyFacade.listPolicyStateOutput(name, version, stateName, outputName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deletePolicyStateOutput(final String name, final String version, final String stateName, - final String outputName) { - return policyFacade.deletePolicyStateOutput(name, version, stateName, outputName); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult listPolicyStateFinalizerLogic(final String name, final String version, final String stateName, - final String finalizerLogicName) { - return policyFacade.listPolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult deletePolicyStateFinalizerLogic(final String name, final String version, - final String stateName, final String finalizerLogicName) { - return policyFacade.deletePolicyStateFinalizerLogic(name, version, stateName, finalizerLogicName); - } - - /** - * {@inheritDoc}. - */ - @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(CreatePolicyStateTaskRef.builder().name(name) - .version(version).stateName(stateName).taskLocalName(taskLocalName).taskName(taskName) - .taskVersion(taskVersion).outputType(outputType).outputName(outputName).build()); - } - // CHECKSTYLE:ON: checkstyle:parameterNumber - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @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); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult loadFromString(final String modelString) { - return modelHandlerFacade.loadFromString(modelString); - } - - /** - * {@inheritDoc}. - */ - @Override - // CHECKSTYLE:OFF: checkstyle:HiddenField - public ApexApiResult loadFromFile(final String fileName) { - return modelHandlerFacade.loadFromFile(fileName); - } - // CHECKSTYLE:ON: checkstyle:HiddenField - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult saveToFile(final String fileName) { - return modelHandlerFacade.saveToFile(fileName); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult readFromUrl(final String urlString) { - return modelHandlerFacade.readFromUrl(urlString); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult writeToUrl(final String urlString) { - return modelHandlerFacade.writeToUrl(urlString); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult analyse() { - return modelHandlerFacade.analyse(); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult validate() { - return modelHandlerFacade.validate(); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult compare(final String otherModelFileName, final boolean diffsOnly, final boolean keysOnly) { - return modelHandlerFacade.compare(otherModelFileName, diffsOnly, keysOnly); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult compareWithString(final String otherModelString, final boolean diffsOnly, - final boolean keysOnly) { - return modelHandlerFacade.compareWithString(otherModelString, diffsOnly, keysOnly); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult split(final String targetModelFileName, final String splitOutPolicies) { - return modelHandlerFacade.split(targetModelFileName, splitOutPolicies); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult split(final String splitOutPolicies) { - return modelHandlerFacade.split(splitOutPolicies); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult merge(final String mergeInModelFileName, final boolean keepOriginal) { - return modelHandlerFacade.merge(mergeInModelFileName, keepOriginal); - } - - /** - * {@inheritDoc}. - */ - @Override - public ApexApiResult mergeWithString(final String otherModelString, final boolean keepOriginal) { - return modelHandlerFacade.mergeWithString(otherModelString, keepOriginal); - } - - /** - * {@inheritDoc}. - */ - @Override - public AxPolicyModel build() { - return policyModel; - } - -} diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbum.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbum.java deleted file mode 100644 index 5a42ed14e..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbum.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi.impl; - -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -public class ContextAlbum { - private String name; - private String version; - private String scope; - private String writable; - private String contextSchemaName; - private String contextSchemaVersion; - private String uuid; - private String description; -} 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 deleted file mode 100644 index d29f32ea0..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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; - - /** - * Constructor that creates a context album facade for the Apex Model API. - * - * @param apexModel the apex model - * @param apexProperties Properties for the model - */ - public ContextAlbumFacade(final ApexModel apexModel, final Properties apexProperties) { - this.apexModel = apexModel; - this.apexProperties = apexProperties; - - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); - } - - /** - * Create a context album. - * - * @param builder the builder for the context album parameters - * @return result of the operation - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult createContextAlbum(ContextAlbum builder) { - try { - final AxArtifactKey key = new AxArtifactKey(); - key.setName(builder.getName()); - if (builder.getVersion() != null) { - key.setVersion(builder.getVersion()); - } 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(builder.getContextSchemaName(), - builder.getContextSchemaVersion()); - if (schema == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, CONCEPT - + builder.getContextSchemaName() + ':' + builder.getContextSchemaVersion() + DOES_NOT_EXIST); - } - - final AxContextAlbum contextAlbum = new AxContextAlbum(key); - contextAlbum.setScope(builder.getScope()); - contextAlbum.setItemSchema(schema.getKey()); - - contextAlbum - .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) - || "t".equalsIgnoreCase(builder.getWritable().trim()))); - - apexModel.getPolicyModel().getAlbums().getAlbumsMap().put(key, contextAlbum); - - if (apexModel.getPolicyModel().getKeyInformation().getKeyInfoMap().containsKey(key)) { - return keyInformationFacade.updateKeyInformation(builder.getName(), builder.getVersion(), - builder.getUuid(), builder.getDescription()); - } else { - return keyInformationFacade.createKeyInformation(builder.getName(), builder.getVersion(), - builder.getUuid(), builder.getDescription()); - } - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } - } - // CHECKSTYLE:ON: checkstyle:parameterNumber - - /** - * Update a context album. - * - * @param builder the builder for the context album parameters - * @return result of the operation - */ - // CHECKSTYLE:OFF: checkstyle:parameterNumber - public ApexApiResult updateContextAlbum(ContextAlbum builder) { - try { - final AxContextAlbum contextAlbum = - apexModel.getPolicyModel().getAlbums().get(builder.getName(), builder.getVersion()); - if (contextAlbum == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); - } - - if (builder.getScope() != null) { - contextAlbum.setScope(builder.getScope()); - } - - contextAlbum - .setWritable(builder.getWritable() != null && ("true".equalsIgnoreCase(builder.getWritable().trim()) - || "t".equalsIgnoreCase(builder.getWritable().trim()))); - - if (builder.getContextSchemaName() != null) { - final AxContextSchema schema = apexModel.getPolicyModel().getSchemas() - .get(builder.getContextSchemaName(), builder.getContextSchemaVersion()); - if (schema == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, CONCEPT - + builder.getContextSchemaName() + ':' + builder.getContextSchemaVersion() + DOES_NOT_EXIST); - } - contextAlbum.setItemSchema(schema.getKey()); - } - - return keyInformationFacade.updateKeyInformation(builder.getName(), builder.getVersion(), builder.getUuid(), - builder.getDescription()); - } 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 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(false).writeString(contextAlbum, AxContextAlbum.class)); - } - 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 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(false).writeString(contextAlbum, AxContextAlbum.class)); - 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 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(false).writeString(contextAlbum.getKey(), - AxArtifactKey.class)); - 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 deleted file mode 100644 index 83bca5a01..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextSchemaFacade.java +++ /dev/null @@ -1,238 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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.common.utils.validation.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; - - /** - * Constructor to create the context schema facade for the Model API. - * - * @param apexModel the apex model - * @param apexProperties Properties for the model - */ - public ContextSchemaFacade(final ApexModel apexModel, final Properties apexProperties) { - this.apexModel = apexModel; - this.apexProperties = apexProperties; - - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); - } - - /** - * 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 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(false).writeString(schema, AxContextSchema.class)); - } - 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(false).writeString(removedSchema, - AxContextSchema.class)); - } else { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); - } - } - - final Set 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(false).writeString(schema, AxContextSchema.class)); - 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 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(false).writeString(schema.getKey(), AxArtifactKey.class)); - 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/CreatePolicyStateTaskRef.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/CreatePolicyStateTaskRef.java deleted file mode 100644 index a6e4c334e..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/CreatePolicyStateTaskRef.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi.impl; - -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -public class CreatePolicyStateTaskRef { - private String name; - private String version; - private String stateName; - private String taskLocalName; - private String taskName; - private String taskVersion; - private String outputType; - private String outputName; -} 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 deleted file mode 100644 index 336f27b5d..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/EventFacade.java +++ /dev/null @@ -1,386 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2022 Bell Canada. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.common.utils.validation.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; - - /** - * Constructor to create an event facade for the Model API. - * - * @param apexModel the apex model - * @param apexProperties Properties for the model - */ - public EventFacade(final ApexModel apexModel, final Properties apexProperties) { - this.apexModel = apexModel; - this.apexProperties = apexProperties; - - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); - } - - /** - * 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 - * @param toscaPolicyState specifies TOSCA policy processing status - * @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, - final String toscaPolicyState) { - 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"))); - if (toscaPolicyState != null) { - event.setToscaPolicyState(toscaPolicyState); - } - - 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 - * @param toscaPolicyState specifies TOSCA policy processing status - * @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, - final String toscaPolicyState) { - 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); - } - if (toscaPolicyState != null) { - event.setToscaPolicyState(toscaPolicyState); - } - - 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 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(false).writeString(event, AxEvent.class)); - } - 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(false).writeString(removedEvent, AxEvent.class)); - } else { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); - } - } - - final Set 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(false).writeString(event, AxEvent.class)); - 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 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(false).writeString(event.getKey(), AxArtifactKey.class)); - 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(false).writeString(eventField, AxField.class)); - } 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(false).writeString(eventPar, AxField.class)); - } - 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(false) - .writeString(event.getParameterMap().get(parName), AxField.class)); - 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(false).writeString(eventPar, AxField.class)); - } - 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 deleted file mode 100644 index 6875a4c20..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/KeyInformationFacade.java +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi.impl; - -import java.util.Properties; -import java.util.Set; -import java.util.UUID; -import lombok.AllArgsConstructor; -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) - */ -@AllArgsConstructor -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; - - /** - * 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 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(false).writeString(keyInfo, AxKeyInfo.class)); - } - 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(false).writeString(removedKeyInfo, AxKeyInfo.class)); - } else { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); - } - } - - final Set 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(false).writeString(keyInfo, AxKeyInfo.class)); - 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 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(false).writeString(keyInfo.getKey(), AxArtifactKey.class)); - 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 deleted file mode 100644 index 1030a5bf5..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelFacade.java +++ /dev/null @@ -1,202 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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.common.utils.validation.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; - - /** - * Constructor to create a model facade for the Apex model. - * - * @param apexModel the apex model - * @param apexProperties Properties for the model - */ - public ModelFacade(final ApexModel apexModel, final Properties apexProperties) { - Assertions.argumentNotNull(apexModel, "apexModel may not be null"); - Assertions.argumentNotNull(apexProperties, "apexProperties may not be null"); - - this.apexModel = apexModel; - this.apexProperties = apexProperties; - - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); - } - - /** - * 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().buildReferences(); - 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(false).writeString(modelkey, AxArtifactKey.class)); - 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(false).writeString(apexModel.getPolicyModel(), - AxPolicyModel.class)); - 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 deleted file mode 100644 index fecf92e1f..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ModelHandlerFacade.java +++ /dev/null @@ -1,498 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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.Properties; -import java.util.Set; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -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.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.common.utils.resources.ResourceUtils; -import org.onap.policy.common.utils.resources.TextFileUtils; -import org.onap.policy.common.utils.validation.Assertions; -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 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; - - /** - * 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 - */ - public ModelHandlerFacade(final ApexModel apexModel, final Properties apexProperties) { - Assertions.argumentNotNull(apexModel, "apexModel may not be null"); - Assertions.argumentNotNull(apexProperties, "apexProperties may not be null"); - - this.apexModel = apexModel; - } - - /** - * 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 - * @return the result of the operation - */ - public ApexApiResult saveToFile(final String fileName) { - Assertions.argumentNotNull(fileName, FILE_NAME_MAY_NOT_BE_NULL); - - ApexModelFileWriter apexModelFileWriter = new ApexModelFileWriter<>(false); - - try { - apexModelFileWriter.apexModelWriteJsonFile(apexModel.getPolicyModel(), AxPolicyModel.class, fileName); - return new ApexApiResult(); - } catch (ApexException e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } - } - - /** - * 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 apexModelReader = new ApexModelReader<>(AxPolicyModel.class); - apexModelReader.setValidate(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 - * @return the result of the operation - */ - public ApexApiResult writeToUrl(final String urlString) { - 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 apexModelWriter = new ApexModelWriter<>(AxPolicyModel.class); - apexModelWriter.setValidate(false); - - // 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(false) - .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class)); - 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(false) - .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class)); - 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(false) - .writeString(apexModel.getPolicyModel().getKey(), AxArtifactKey.class)); - 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 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 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 = TextFileUtils.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, 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, 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 apexModelReader = new ApexModelReader<>(AxPolicyModel.class); - apexModelReader.setValidate(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 apexModelReader = new ApexModelReader<>(AxPolicyModel.class); - apexModelReader.setValidate(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 deleted file mode 100644 index 408f0913f..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java +++ /dev/null @@ -1,1385 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi.impl; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -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.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.common.utils.validation.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; - - /** - * Constructor that creates a policy facade for the Apex Model API. - * - * @param apexModel the apex model - * @param apexProperties Properties for the model - */ - public PolicyFacade(final ApexModel apexModel, final Properties apexProperties) { - this.apexModel = apexModel; - this.apexProperties = apexProperties; - - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); - } - - /** - * 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 templateString = template; - if (templateString == null) { - templateString = 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(templateString); - 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 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(false).writeString(policy, AxPolicy.class)); - } - 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(false).writeString(removedPolicy, AxPolicy.class)); - } else { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); - } - } - - final Set 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(false).writeString(policy, AxPolicy.class)); - 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 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(false).writeString(policy.getKey(), AxArtifactKey.class)); - 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(false).writeString(state, AxState.class)); - } 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(false).writeString(state, AxState.class)); - } - 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(false) - .writeString(policy.getStateMap().get(stateName), AxState.class)); - 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(false).writeString(state, AxState.class)); - } - 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(false).writeString(state.getTaskSelectionLogic(), - AxTaskSelectionLogic.class)); - } 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(false) - .writeString(state.getTaskSelectionLogic(), AxTaskSelectionLogic.class)); - 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); - // There can be multipe state outputs only when the current state is the final state - if (nextState != null && !AxReferenceKey.getNullKey().getLocalName().equals(nextState) - && 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); - } - } - - populateStateOuputInfo(nextState, state, refKey, event, nextStateKey); - return new ApexApiResult(); - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } - } - - private void populateStateOuputInfo(final String nextState, final AxState state, final AxReferenceKey refKey, - final AxEvent event, AxReferenceKey nextStateKey) { - // nextState is null. There could be multiple events coming out of the state - if ((nextState == null || AxReferenceKey.getNullKey().getLocalName().equals(nextState)) - && state.getStateOutputs().containsKey(refKey.getLocalName())) { - AxStateOutput existingStateOutput = state.getStateOutputs().get(refKey.getLocalName()); - if (null == existingStateOutput.getOutgoingEventSet() - || existingStateOutput.getOutgoingEventSet().isEmpty()) { - Set eventSet = new TreeSet<>(); - eventSet.add(existingStateOutput.getOutgoingEvent()); - existingStateOutput.setOutgoingEventSet(eventSet); - } - existingStateOutput.getOutgoingEventSet().add(event.getKey()); - } else { - AxStateOutput axStateOutput = new AxStateOutput(refKey, event.getKey(), nextStateKey); - Set eventSet = new TreeSet<>(); - eventSet.add(axStateOutput.getOutgoingEvent()); - axStateOutput.setOutgoingEventSet(eventSet); - state.getStateOutputs().put(refKey.getLocalName(), axStateOutput); - } - } - - /** - * 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(false).writeString(stateOutput, AxStateOutput.class)); - } 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(false).writeString(stateOutput, AxStateOutput.class)); - } - 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(false).writeString(stateOutput, AxStateOutput.class)); - 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 stateOutputEntry : state.getStateOutputs().entrySet()) { - result.addMessage(new ApexModelStringWriter(false) - .writeString(stateOutputEntry.getValue(), AxStateOutput.class)); - } - 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(false).writeString(stateFinalizerLogic, - AxStateFinalizerLogic.class)); - } 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(false) - .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class)); - } - 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(false) - .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class)); - 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(false) - .writeString(stateFinalizerLogic, AxStateFinalizerLogic.class)); - } - state.getStateFinalizerLogicMap().clear(); - return result; - } - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } - } - - /** - * Create a policy state task reference. - * - * @param builder builder for the state task reference - * @return result of the operation - */ - public ApexApiResult createPolicyStateTaskRef(CreatePolicyStateTaskRef builder) { - try { - Assertions.argumentNotNull(builder.getStateName(), STATE_NAME_MAY_NOT_BE_NULL); - Assertions.argumentNotNull(builder.getOutputName(), "outputName may not be null"); - - final AxPolicy policy = - apexModel.getPolicyModel().getPolicies().get(builder.getName(), builder.getVersion()); - if (policy == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + builder.getName() + ':' + builder.getVersion() + DOES_NOT_EXIST); - } - - final AxState state = policy.getStateMap().get(builder.getStateName()); - if (state == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + policy.getKey().getId() + ':' + builder.getStateName() + DOES_NOT_EXIST); - } - - final AxTask task = - apexModel.getPolicyModel().getTasks().get(builder.getTaskName(), builder.getTaskVersion()); - if (task == null) { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + builder.getTaskName() + ':' + builder.getTaskVersion() + 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 (builder.getTaskLocalName() == null) { - refKey = new AxReferenceKey(state.getKey(), state.getKey().getParentKeyName()); - } else { - refKey = new AxReferenceKey(state.getKey(), builder.getTaskLocalName()); - } - - // The reference to the output we're using here - final AxReferenceKey outputRefKey = new AxReferenceKey(state.getKey(), builder.getOutputName()); - - final AxStateTaskOutputType stateTaskOutputType = AxStateTaskOutputType.valueOf(builder.getOutputType()); - 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 " + builder.getOutputType() + " invalid"); - } - - String outputRefName = outputRefKey.getLocalName(); - // in case of SFL, outgoing event will be same for all state outputs that are part of SFL.So, take any entry - if (AxStateTaskOutputType.LOGIC.equals(stateTaskOutputType)) { - outputRefName = state.getStateOutputs().keySet().iterator().next(); - } - - // add input and output events to the task based on state definition - if (state.getStateOutputs().containsKey(outputRefName)) { - populateIoEventsToTask(state, task, outputRefName); - } - - state.getTaskReferences().put(task.getKey(), - new AxStateTaskReference(refKey, stateTaskOutputType, outputRefKey)); - return new ApexApiResult(); - } catch (final Exception e) { - return new ApexApiResult(ApexApiResult.Result.FAILED, e); - } - } - - private void populateIoEventsToTask(final AxState state, final AxTask task, final String outputRefName) { - AxEvent triggerEvent = apexModel.getPolicyModel().getEvents().get(state.getTrigger()); - task.setInputEvent(triggerEvent); - Map outputEvents = new TreeMap<>(); - if (state.getNextStateSet().isEmpty() - || state.getNextStateSet().contains(AxReferenceKey.getNullKey().getLocalName())) { - state.getStateOutputs().get(outputRefName).getOutgoingEventSet().forEach(outgoingEventKey -> outputEvents - .put(outgoingEventKey.getName(), apexModel.getPolicyModel().getEvents().get(outgoingEventKey))); - } else { - AxArtifactKey outgoingEventKey = state.getStateOutputs().get(outputRefName).getOutgoingEvent(); - outputEvents.put(outgoingEventKey.getName(), apexModel.getPolicyModel().getEvents().get(outgoingEventKey)); - } - task.setOutputEvents(outputEvents); - } - - /** - * 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; - final Map taskReferences = state.getTaskReferences(); - for (final Entry taskReferenceEntry : taskReferences.entrySet()) { - final AxArtifactKey key = taskReferenceEntry.getKey(); - final AxStateTaskReference value = taskReferenceEntry.getValue(); - if ((taskName != null && !key.getName().equals(taskName)) - || (taskVersion != null && !key.getVersion().equals(taskVersion))) { - continue; - } - - found = true; - result - .addMessage(new ApexModelStringWriter(false).writeString(key, AxArtifactKey.class)); - result.addMessage(new ApexModelStringWriter(false).writeString(value, - AxStateTaskReference.class)); - } - 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 deleteSet = new TreeSet<>(); - - for (final AxArtifactKey taskReferenceKey : state.getTaskReferences().keySet()) { - if ((taskName != null && !taskReferenceKey.getName().equals(taskName)) - || (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(false).writeString(keyToDelete, AxArtifactKey.class)); - } - 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 && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { - continue; - } - result.addMessage( - new ApexModelStringWriter(false).writeString(albumKey, AxArtifactKey.class)); - 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 deleteSet = new TreeSet<>(); - - for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) { - - if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { - - continue; - } - 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(false).writeString(keyToDelete, AxArtifactKey.class)); - } - 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 deleted file mode 100644 index 6a2ded3e2..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java +++ /dev/null @@ -1,597 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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.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.common.utils.validation.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; - - /** - * Constructor that creates a task facade for the Apex Model API. - * - * @param apexModel the apex model - * @param apexProperties Properties for the model - */ - public TaskFacade(final ApexModel apexModel, final Properties apexProperties) { - this.apexModel = apexModel; - this.apexProperties = apexProperties; - - keyInformationFacade = new KeyInformationFacade(apexModel, apexProperties); - } - - /** - * 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 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(false).writeString(task, AxTask.class)); - } - 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(false).writeString(removedTask, AxTask.class)); - } else { - return new ApexApiResult(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, - CONCEPT + key.getId() + DOES_NOT_EXIST); - } - } - - final Set 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(false).writeString(task, AxTask.class)); - 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 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(false).writeString(task.getKey(), AxArtifactKey.class)); - 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(false).writeString(task.getTaskLogic(), AxTaskLogic.class)); - } 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(false).writeString(task.getTaskLogic(), AxTaskLogic.class)); - task.setTaskLogic(new AxTaskLogic()); - 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(false).writeString(taskParameter, - AxTaskParameter.class)); - } 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(false).writeString(parameter, - AxTaskParameter.class)); - } - 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(false) - .writeString(task.getTaskParameters().get(parName), AxTaskParameter.class)); - 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(false).writeString(parameter, - AxTaskParameter.class)); - } - 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 && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { - continue; - } - result.addMessage( - new ApexModelStringWriter(false).writeString(albumKey, AxArtifactKey.class)); - 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 deleteSet = new TreeSet<>(); - - for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) { - if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) - || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { - continue; - } - 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(false).writeString(keyToDelete, AxArtifactKey.class)); - } - 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 deleted file mode 100644 index f31542044..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * 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 deleted file mode 100644 index 97e8db4ea..000000000 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * 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/ApexApiResultTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java deleted file mode 100644 index 3c2af18ea..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.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; - -/** - * Test API results. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexApiResultTest { - - @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/ApexEditorApiContextAlbumTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java deleted file mode 100644 index 5ce6b6760..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Context album for API tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexEditorApiContextAlbumTest { - @Test - public void testContextAlbumCrud() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createContextAlbum("MyMap002", "0.0.2", "APPLICATION", "true", "MapType", "0.0.1", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", "0.1.2", "ZOOBY", "false", "MapType", "0.0.1", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", "0.1.4", "UNDEFINED", null, "MapType", "0.0.1", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "+++", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapZooby", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "--++", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createContextAlbum("MyMap002", "0.0.2", "APPLICATION", "true", "MapType", null, - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createContextAlbum("MyMap011", "0.1.2", "APPLICATION", "true", "MapType", "0.0.1", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.deleteContextAlbum("MyMap012", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextAlbum("MyMap012", "0.1.2", "ZOOBY", "false", "MapType", "0.0.1", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - 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); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap002", "0.0.2", "ZOOBY", "true", null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap002", "0.0.2", null, null, null, null, - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, null, "true", null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", null, null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap015", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateContextAlbum("MyMap014", "0.1.5", null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "String", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", "0.0.2", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", "0.0.1", null, - null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "Hello", "StringType", "0.0.1", null, - null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listContextAlbum("@£%%$", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.listContextAlbum(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listContextAlbum("MyMap012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listContextAlbum("MyMap012", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listContextAlbum("MyMap012", "0.2.5"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listContextAlbum("MyMap014", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteContextAlbum("@£%%$", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.deleteContextAlbum("MyMap012", "0.1.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteContextAlbum("MyMap012oooo", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listContextAlbum("MyMap012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(3, result.getMessages().size()); - - result = apexModel.deleteContextAlbum("MyMap012", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listContextAlbum("MyMap012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.deleteContextAlbum("MyMap012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.listContextAlbum("MyMap012", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteContextAlbum(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - - result = apexModel.listContextAlbum(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(0, result.getMessages().size()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java deleted file mode 100644 index 20310a29e..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Context schema for API tests. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexEditorApiContextSchemaTest { - @Test - public void testContextSchemaCrud() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listContextSchemas(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createContextSchema("Hello", "0.0.2", "Java", "java.lang.String", - "1fa2e430-f2b2-11e6-bc64-92361f002671", "A description of hello"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.String", - "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String", - "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.deleteContextSchema("Hello", "0.1.4"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String", - "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createContextSchema("Hello2", null, null, "java.lang.String", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextSchema("Hello2", null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createContextSchema("Hello2", null, "Java", "java.lang.String", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.Float", - "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - result = apexModel.deleteContextSchema("Hello", "0.1.4"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String", - "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateContextSchema("Hello", "0.1.2", "Java", "java.lang.Integer", - "1fa2e430-f2b2-11e6-bc64-92361f002673", "A further updated description of hola"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updateContextSchema("Hello2", "0.0.2", null, null, null, "An updated description of hello"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listContextSchemas("@£%%$", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.listContextSchemas("Hello", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.listContextSchemas("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - - result = apexModel.listContextSchemas(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(9, result.getMessages().size()); - - result = apexModel.deleteContextSchema("@£%%$", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.deleteContextSchema("Hello", "0.1.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteContextSchema("Hellooooo", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listContextSchemas("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - - result = apexModel.deleteContextSchema("Hello", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listContextSchemas("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(3, result.getMessages().size()); - - result = apexModel.deleteContextSchema("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listContextSchemas("Hello", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listContextSchemas(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.deleteContextSchema(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(5, result.getMessages().size()); - - result = apexModel.listContextSchemas(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(0, result.getMessages().size()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java deleted file mode 100644 index ac9265e84..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java +++ /dev/null @@ -1,202 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Test events for API tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexEditorApiEventTest { - @Test - public void testEventCrud() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEvent("MyEvent012", "0.1.2", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEvent("MyEvent012", "0.1.4", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEvent("MyEvent012", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEvent("MyEvent012", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createEvent("@£$%^", "0.2.5", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.deleteEvent("MyEvent012", "0.1.4"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEvent("MyEvent012", "0.1.4", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.validateEvent(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updateEvent(null, null, 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, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateEvent("MyEvent012", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateEvent("MyEvent015", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateEvent("MyEvent014", "0.1.5", null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateEvent("@£$%^^", "0.6.9", null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.listEvent("@£$%", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listEvent(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEvent("MyEvent012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEvent("MyEvent012", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEvent("MyEvent012", "0.2.5"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listEvent("MyEvent123", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteEvent("@£$%^", "0.1.1"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deleteEvent("MyEvent012", "0.1.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteEvent("MyEvent012oooo", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listEvent("MyEvent012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(3, result.getMessages().size()); - - result = apexModel.deleteEvent("MyEvent012", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listEvent("MyEvent012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.deleteEvent("MyEvent012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listEvent("MyEvent012", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createEventPar("MyEvent123", null, "NewPar00", null, null, false); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createEventPar("MyEvent002", "4.5.6", "NewPar00", null, null, true); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createEventPar("MyEvent002", "0.1.4", "NewPar00", null, null, false); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", null, null, true); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.createContextSchema("eventContextItem0", "0.0.1", "Java", "java.lang.Integer", - "1fa2e430-f2b2-11e6-bc64-92361f002673", "A further updated description of hola"); - result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", "eventContextItem0", null, false); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", "eventContextItem0", null, true); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar01", "eventContextItem0", "0.0.1", false); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar02", "eventContextItem0", "0.0.2", true); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createEventPar("MyEvent002", null, "NewPar02", "eventContextItem0", null, false); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createEventPar("MyEvent002", null, "NewPar03", "eventContextItem0", null, true); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listEventPar("@£%%$", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listEventPar("MyEvent002", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEventPar("MyEvent002", "0.0.1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listEventPar("MyEvent002", "0.0.2", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar01"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar02"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteEventPar("@££%%%", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deleteEventPar("NonExistantEvent", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(4, apexModel.listEventPar("MyEvent002", null, null).getMessages().size()); - result = apexModel.deleteEventPar("MyEvent002", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(4, apexModel.listEventPar("MyEvent002", null, null).getMessages().size()); - result = apexModel.deleteEventPar("MyEvent002", null, "NewPar02"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(3, apexModel.listEventPar("MyEvent002", null, null).getMessages().size()); - result = apexModel.deleteEventPar("MyEvent002", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listEventPar("MyEvent002", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deleteEventPar("MyEvent002", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listEventPar("MyEvent002", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteEvent(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - - result = apexModel.listEvent(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(0, result.getMessages().size()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java deleted file mode 100644 index 2519b8cb2..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Key information for API tests. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexEditorApiKeyInfoTest { - - @Test - public void testKeyInfoCrud() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002672", - "A description of hola"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createKeyInformation("Hello", "0.1.4", "1fa2e430-f2b2-11e6-bc64-92361f002672", - "A description of connichi wa"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createKeyInformation("Hello", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createKeyInformation("Hello", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - result = apexModel.createKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002672", - "A description of hola"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateKeyInformation("Hello", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002673", - "A further updated description of hola"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updateKeyInformation("Hello2", "0.0.2", null, "An updated description of hello"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.listKeyInformation("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - - result = apexModel.deleteKeyInformation("Hello", "0.1.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteKeyInformation("Hellooooo", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listKeyInformation("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - - result = apexModel.listKeyInformation(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(22, result.getMessages().size()); - - result = apexModel.deleteKeyInformation("%%%$$", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.deleteKeyInformation("Hello", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listKeyInformation("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(3, result.getMessages().size()); - - result = apexModel.deleteKeyInformation("Hello", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listKeyInformation("Hello", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteKeyInformation(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(18, result.getMessages().size()); - - result = apexModel.listKeyInformation(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(0, result.getMessages().size()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java deleted file mode 100644 index 0a4d72214..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java +++ /dev/null @@ -1,1023 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * Test policies for API. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexEditorApiPolicyTest { - @Test - public void testMyTestPolicyCrud() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicy("MyPolicy012", null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicy("MyPolicy012", null, "SomeTemplate", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicy("MyPolicy013", null, null, "AState", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicy("MyPolicy012", null, "SomeTemplate", "AState", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicy("MyPolicy012", "0.1.2", "SomeTemplate", "AState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicy("MyTestPolicy", "0.0.1", "SomeTemplate", "TestState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.deletePolicy("MyPolicy002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.validatePolicy(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updatePolicy("@£$$", "0.0.2", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicy("MyPolicy002", "0.0.2", null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicy("MyPolicy002", "0.0.1", null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicy("MyPolicy002", "0.0.2", "SomeOtherTemplate", "BState", - "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicy("MyPolicy012", null, "SomeOtherTemplate", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicy("MyPolicy012", null, null, "CState", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicy("MyPolicy012", null, "SomeOtherTemplate", "BState", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicy("MyPolicy015", null, "SomeOtherTemplate", "DState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicy("MyPolicy014", "0.1.5", "SomeOtherTemplate", "EState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listPolicy("@£$%%", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicy(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(6, result.getMessages().size()); - result = apexModel.listPolicy("MyPolicy012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicy("MyPolicy012", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicy("MyPolicy012", "0.2.5"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicy("MyPolicy014", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deletePolicy("@£$%", "0.1.1"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.deletePolicy("MyPolicy012", "0.1.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deletePolicy("MyPolicy012oooo", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listPolicy("MyPolicy012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.deletePolicy("MyPolicy002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - - result = apexModel.listPolicy("MyPolicy012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.deletePolicy("MyPolicy012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.createPolicyState(null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyState("MyPolicy123", null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyState("MyPolicy123", null, "AState", null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", "0.0.2", "AState", null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "ATrigger", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "ATask", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "AState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "BState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "CState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "DState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updatePolicyState(null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyState("MyPolicy123", null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyState("MyPolicy123", null, "AState", null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", "0.0.2", "AState", null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", null, null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "ZState", null, null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "ATrigger", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "ATask", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "AState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "BState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "CState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "DState", "inEvent", "0.0.1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listPolicyState("MyTestPolicy", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - result = apexModel.listPolicyState(null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyState("SomeOtherPolicy", "0.0.1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyState("SomeOtherPolicy", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyState("MyTestPolicy", "0.0.2", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "CState"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyState("MyTestPolicy", null, "CState"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "AState"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "EState"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deletePolicyState("@£$$", "0.0.2", "Trigger04"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - assertEquals(4, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size()); - result = apexModel.deletePolicyState("MyTestPolicy", "0.0.2", "Trigger04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(4, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size()); - result = apexModel.deletePolicyState("MyTestPolicy", null, "CState"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyState("MyTestPolicy", null, "ZState"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(3, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size()); - result = apexModel.deletePolicyState("MyTestPolicy", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listPolicyState("MyTestPolicy", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyState("MyTestPolicy", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState1", "inEvent", "0.0.1", "task", - "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState2", "outEvent0", "0.0.1", "task", - "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState3", "outEvent1", "0.0.1", "task", - "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createPolicyStateTaskSelectionLogic(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "1.2.3", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "NewTSL00", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "UNDEFINED", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "MVEL", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "JAVA", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "JYTHON", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JAVASCRIPT", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JRUBY", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updatePolicyStateTaskSelectionLogic(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState99", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy2", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy1", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "NonExistantState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "", - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "MVEL", - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy012", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy015", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy014", "0.1.5", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listPolicyStateTaskSelectionLogic(null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, "looby"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, "TestState1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "looby"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.2", "TestState1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - - result = apexModel.deletePolicyStateTaskSelectionLogic(null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, "looby"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, "TestState1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", null, "looby"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.2", "TestState1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JRUBY", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createPolicyStateOutput(null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", null, "SomeState", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", null, "SomeState", "SomeOutput", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "1.2.3", "TestState1", "SomeOutput", null, null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", null, null, - null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", - "SomeDummyEvent", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent", - "1.2.3", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent", - "0.0.1", "SomeDummyNextState"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent", - "0.0.1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent", - "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent", - "0.0.1", "TestState2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent", - "0.0.1", "TestState2"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "AnotherOtherOutput", - "outEvent0", "0.0.1", "TestState3"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput", - "outEvent0", "0.0.1", "TestState3"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listPolicyStateOutput(null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.2", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "SomeState", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "YetAnotherOtherOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deletePolicyStateOutput(null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.2", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "SomeState", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null); - assertEquals(2, result.getMessages().size()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState1", "SomeOutput"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState2", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState2", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState2", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent", - "0.0.1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent", - "0.0.1", "TestState1"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent", - "0.0.1", "TestState2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "AnotherOtherOutput", - "outEvent0", "0.0.1", "TestState3"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput", - "outEvent0", "0.0.1", "TestState3"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createPolicyStateFinalizerLogic(null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", "SFLName01", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "1.2.3", "TestState1", "SFLName01", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName01", null, - null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName01", - "NewTSL00", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02", - "UNDEFINED", "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName04", "JAVA", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName05", "JYTHON", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", - "JAVASCRIPT", "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName07", "JRUBY", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updatePolicyStateFinalizerLogic(null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState99", "SomeSFLName", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy2", null, "TestState1", "SomeSFLName", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy1", "0.0.2", "TestState1", "SomeSFLName", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "NonEistantSFL", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", null, - null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", "", - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", "MVEL", - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy012", null, "TestState1", "SFLName06", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", null, - "Some Other Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy015", null, "TestState1", "SFLName06", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy014", "0.1.5", "TestState1", "SFLName06", null, - null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listPolicyStateFinalizerLogic(null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("zooby", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("zooby", null, "looby", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("zooby", null, "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "looby", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(6, result.getMessages().size()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - - result = apexModel.deletePolicyStateFinalizerLogic(null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, "looby", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, "looby", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(5, result.getMessages().size()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName02"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02", - "UNDEFINED", "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName04", "JAVA", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName05", "JYTHON", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", - "JAVASCRIPT", "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName07", "JRUBY", - "Some Policy Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createTask("TestTask0", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("TestTask1", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("TestTask2", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("TestTask3", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("TestTask4", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createPolicyStateTaskRef(null, null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, null, null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null, null, null, - "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "1.2.3", "SomeState", null, null, null, null, - "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("AnyOldPolicy", "1.2.3", "SomeState", null, null, null, null, - "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", null, - null, null, "DummyOutput"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", - "SomeTask", "Zooby|", null, "DummyOutput"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", - "SomeTask", "0.0.1", null, "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task", - "0.0.1", null, "DummyOutput"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "Some Policy Logic", "DummyOutput"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "DIRECT", "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "LOGIC", "DummyOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "DIRECT", "SFLName07"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "LOGIC", "SomeOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "DIRECT", "SomeOutput"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "NonExistantTask", "0.0.1", "DIRECT", "SomeOutput"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task", - "0.0.1", "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask0", "0.0.1", "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask1", "0.0.1", "DIRECT", "SomeOtherOutput"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask2", "0.0.1", "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask3", "0.0.1", "DIRECT", "SomeOtherOutput"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask4", "0.0.1", - "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask4", "0.0.1", - "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask4", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask4", "0.0.1", "FUNKY", "SFLName07"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask4", "0.0.1", "UNDEFINED", "SFLName07"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", - "TestTask4", "0.0.1", "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask0", "0.0.1", - "LOGIC", "SFLName07"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - result = apexModel.listPolicyStateTaskRef(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskRef("zooby", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateTaskRef("zooby", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("zooby", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(12, result.getMessages().size()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeOldTask", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", "1.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.deletePolicyStateTaskRef(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("zooby", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("zooby", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("zooby", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "ADummyTask", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "task", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(12, result.getMessages().size()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(10, result.getMessages().size()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask2", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(8, result.getMessages().size()); - result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(4, result.getMessages().size()); - result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createPolicyStateContextRef(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "1.2.3", "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("AnyOldPolicy", "1.2.3", "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", "Zooby|"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "task", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyPolicy123", null, null, "AContextMap00", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyPolicy123", null, "TestState1", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "4.5.6", "TestState1", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.1.4", "TestState1", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", ""); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - result = apexModel.listPolicyStateContextRef(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateContextRef("zooby", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateContextRef("zooby", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("zooby", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap04", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "1.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deletePolicyStateContextRef(null, null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateContextRef("zooby", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateContextRef("zooby", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("zooby", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "looby", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "ADummyContextMap", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap04", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", "0.1.5"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum1", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deletePolicy(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(3, result.getMessages().size()); - - result = apexModel.listPolicy(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(0, result.getMessages().size()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java deleted file mode 100644 index 15e53f925..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java +++ /dev/null @@ -1,376 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl; - -/** - * Test tasks for API tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexEditorApiTaskTest { - @Test - public void testTaskCrud() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - 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"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.createTask("@^^$^^$", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createTask("MyTask012", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("MyTask012", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.listTask(null, null); - result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createTask("MyTask012", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.deleteTask("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.validateTask(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updateTask("@$$$£", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updateTask("MyTask002", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTask("MyTask002", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700", - "A description of 002"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTask("MyTask012", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTask("MyTask012", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTask("MyTask012", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTask("MyTask015", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateTask("MyTask014", "0.1.5", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listTask("£@£@@£@£", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listTask(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTask("MyTask012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTask("MyTask012", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTask("MyTask012", "0.2.5"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listTask("MyTask014", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteTask("@£££@", "0.1.1"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deleteTask("MyTask012", "0.1.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deleteTask("MyTask012oooo", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listTask("MyTask012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.deleteTask("MyTask012", "0.1.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listTask("MyTask012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - - result = apexModel.deleteTask("MyTask012", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.listTask("MyTask012", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.updateTaskLogic("MyTask002", null, "NewLogic00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskLogic("MyTask123", null, "NewLogic00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "4.5.6", "NewLogic00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "0.1.4", "NewLogic00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "0.0.2", "NewLogic00", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "0.0.2", "UNDEFINED", "Some Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "0.0.2", "MVEL", "Some Task Logic"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "0.0.2", "JAVA", "Some Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", "0.0.2", "JYTHON", "Some Task Logic"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", null, "JAVASCRIPT", "Some Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskLogic("MyTask002", null, "JRUBY", "Some Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.updateTaskLogic("MyTask002", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTaskLogic("MyTask002", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateTaskLogic("MyTask002", "0.0.2", "", "Some Other Task Logic"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.updateTaskLogic("MyTask002", "0.0.2", "MVEL", "Some Other Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTaskLogic("MyTask012", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateTaskLogic("MyTask002", null, null, "Some Other Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTaskLogic("MyTask002", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.updateTaskLogic("MyTask015", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.updateTaskLogic("MyTask014", "0.1.5", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.listTaskLogic("MyTask002", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskLogic("MyTask002", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskLogic(null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.deleteTaskLogic("@£@£@£", "0.0.2"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deleteTaskLogic("NonExistantTask", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - assertEquals(1, apexModel.listTaskLogic("MyTask002", null).getMessages().size()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskLogic("MyTask002", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(1, apexModel.listTaskLogic("MyTask002", null).getMessages().size()); - result = apexModel.createTaskLogic("MyTask002", null, "JRUBY", "Some Task Logic"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskLogic("MyTask002", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.deleteTaskLogic("MyTask002", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskField("MyTask002", "0.0.2", "NewField00", "eventContextItem0", null, false); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(ApexModelImpl.FIELDS_DEPRECATED_WARN_MSG, result.getMessage().trim()); - result = apexModel.handleTaskField("MyTask002", "0.0.2", "NewField01"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(ApexModelImpl.FIELDS_DEPRECATED_WARN_MSG, result.getMessage().trim()); - - result = apexModel.createTaskParameter("MyTask123", null, "NewPar00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskParameter("MyTask002", "4.5.6", "NewPar00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskParameter("MyTask002", "0.1.4", "NewPar00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", "eventContextItem0"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", "eventContextItem0"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar01", "eventContextItem0"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar02", "eventContextItem0"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar02", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar03", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createTaskParameter("MyTask002", null, null, "Default value"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.listTaskParameter("@£$%", null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", "0.0.3", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", "0.0.2", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar01"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar02"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteTaskParameter("@£$%", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deleteTaskParameter("NonExistantTask", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(3, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size()); - result = apexModel.deleteTaskParameter("MyTask002", "0.0.2", "NewPar04"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(3, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size()); - result = apexModel.deleteTaskParameter("MyTask002", null, "NewPar02"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size()); - result = apexModel.deleteTaskParameter("MyTask002", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.listTaskParameter("MyTask002", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deleteTaskParameter("MyTask002", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskContextRef("@£$$", null, "AContextMap00", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "4.5.6", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.1.4", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "AContextMap00", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum2", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - result = apexModel.createTaskContextRef("MyTask002", null, "contextAlbum0", null); - assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult()); - - result = apexModel.listTaskContextRef("@£$%", null, null, null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.listTaskContextRef("MyTask002", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.1", null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "AContextMap04", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", "0.0.1"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", "0.0.2"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteTaskContextRef("@£$%", "0.0.2", "AContextMap04", null); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - result = apexModel.deleteTaskContextRef("NonExistantTask", "0.0.2", "AContextMap04", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - assertEquals(2, apexModel.listTaskContextRef("MyTask002", null, null, null).getMessages().size()); - result = apexModel.deleteTaskContextRef("MyTask002", "0.0.2", "AContextMap04", null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", "0.0.3"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", "0.1.5"); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.deleteTaskContextRef("MyTask002", null, null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(1, result.getMessages().size()); - result = apexModel.listTaskContextRef("MyTask002", null, null, null); - assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult()); - - result = apexModel.deleteTask(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(2, result.getMessages().size()); - - result = apexModel.listTask(null, null); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - assertEquals(0, result.getMessages().size()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java deleted file mode 100644 index f28d0e634..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -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.modelapi.impl.ApexModelImpl; -import org.onap.policy.common.utils.resources.TextFileUtils; - -/** - * Test the apex model API. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ApexModelApiTest { - private Connection connection; - - @Before - public void setup() throws Exception { - // Hold the h2 database up for entire tests - connection = DriverManager.getConnection("jdbc:h2:mem:testdb"); - } - - @After - public void teardown() throws Exception { - // Close the h2 database after tests - connection.close(); - } - - @Test - public void testApexModelLoadFromFile() { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - ApexApiResult result = apexModel.loadFromFile("src/main/resources/models/PolicyModel.json"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.deleteModel(); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.deleteModel(); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.junk"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - assertEquals("Unable to unmarshal Apex concept", result.getMessages().get(0).trim()); - } - - @Test - public void testApexModelSaveToFile() throws IOException { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - ApexApiResult result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - final File tempJsonModelFile = File.createTempFile("ApexModelTest", ".json"); - result = apexModel.saveToFile(tempJsonModelFile.getPath()); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - final ApexModel jsonApexModel = new ApexModelFactory().createApexModel(null); - result = jsonApexModel.loadFromFile(tempJsonModelFile.getPath()); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - tempJsonModelFile.delete(); - - final File tempModelFile = File.createTempFile("ApexModelTest", ".json"); - result = apexModel.saveToFile(tempModelFile.getPath()); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - final ApexModel testApexModel = new ApexModelFactory().createApexModel(null); - result = testApexModel.loadFromFile(tempModelFile.getPath()); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - tempModelFile.delete(); - } - - @Test - public void testApexModelUrl() throws IOException { - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - assertThatThrownBy(() -> apexModel.readFromUrl(null)).isInstanceOf(IllegalArgumentException.class); - assertThatThrownBy(() -> apexModel.writeToUrl(null)).isInstanceOf(IllegalArgumentException.class); - ApexApiResult result = null; - result = apexModel.readFromUrl("zooby/looby"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.writeToUrl("zooby/looby"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.readFromUrl("zooby://zooby/looby"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - result = apexModel.writeToUrl("zooby://zooby/looby"); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - - final File tempJsonModelFile = File.createTempFile("ApexModelTest", "json"); - - result = apexModel.saveToFile(tempJsonModelFile.getPath()); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - final String tempFileUrlString = tempJsonModelFile.toURI().toString(); - result = apexModel.readFromUrl(tempFileUrlString); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModel.writeToUrl(tempFileUrlString); - assertEquals(ApexApiResult.Result.FAILED, result.getResult()); - assertEquals("protocol doesn't support output", result.getMessages().get(0)); - - tempJsonModelFile.delete(); - } - - @Test - public void testApexModelMisc() throws IOException { - final ApexModelImpl apexModelImpl = (ApexModelImpl) new ApexModelFactory().createApexModel(null); - - 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.getPath()); - 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.getPath(), 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.getPath(), "policy"); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModelImpl.merge(tempFile.getPath(), true); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - result = apexModelImpl.mergeWithString(modelString, true); - assertEquals(ApexApiResult.Result.SUCCESS, result.getResult()); - - assertNotEquals(0, apexModelImpl.hashCode()); - assertNotNull(apexModelImpl.getCopy()); - assertNotNull(apexModelImpl.build()); - } -} diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java deleted file mode 100644 index d3b32b923..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Properties; -import java.util.UUID; -import org.junit.Test; -import org.onap.policy.apex.model.modelapi.impl.ModelFacade; - -public class ModelFacadeTest { - - @Test - public void testModelFacade() { - assertThatThrownBy(() -> new ModelFacade(null, null)) - .hasMessage("apexModel may not be null"); - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - assertThatThrownBy(() -> new ModelFacade(apexModel, null)) - .hasMessage("apexProperties may not be null"); - final Properties modelProperties = new Properties(); - final ModelFacade mf = new ModelFacade(apexModel, modelProperties); - - 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()); - - 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/ModelHandlerFacadeTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java deleted file mode 100644 index 5bbc95992..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.File; -import java.io.IOException; -import java.util.Properties; -import org.junit.Test; -import org.onap.policy.apex.model.modelapi.impl.ModelHandlerFacade; -import org.onap.policy.common.utils.resources.TextFileUtils; - -/** - * Test the model handler facade. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class ModelHandlerFacadeTest { - - @Test - public void testModelHandlerFacade() throws IOException { - assertThatThrownBy(() -> new ModelHandlerFacade(null, null)) - .hasMessage("apexModel may not be null"); - final ApexModel apexModel = new ApexModelFactory().createApexModel(null); - - assertThatThrownBy(() -> new ModelHandlerFacade(apexModel, null)) - .hasMessage("apexProperties may not be null"); - final Properties modelProperties = new Properties(); - final ModelHandlerFacade mhf = new ModelHandlerFacade(apexModel, modelProperties); - 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()); - - result = apexModel.deleteModel(); - assertEquals(ApexApiResult.Result.SUCCESS, 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()); - 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/java/org/onap/policy/apex/model/modelapi/RealModelTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java deleted file mode 100644 index 2a29f5297..000000000 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.modelapi; - -import static org.junit.Assert.assertTrue; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.util.Map; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelCustomGsonMapAdapter; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.common.utils.resources.TextFileUtils; - -public class RealModelTest { - @Test - public void testRealModel() throws Exception { - - final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json"); - - AxPolicyModel policyModel = new ApexModelReader(AxPolicyModel.class).read(modelString); - - AxValidationResult result = new AxValidationResult(); - assertTrue(policyModel.validate(result).isValid()); - } -} diff --git a/model/model-api/src/test/resources/logback-test.xml b/model/model-api/src/test/resources/logback-test.xml deleted file mode 100644 index 2aff4c2e9..000000000 --- a/model/model-api/src/test/resources/logback-test.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - Apex - - - - - - - %d %contextName [%t] %level %logger{36} - %msg%n - - - - - - - - - - - - - - - - - - - - - ${LOG_DIR}/apex.log - - %d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full} - - - - - ${LOG_DIR}/apex_ctxt.log - - %d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full} - - - - - - - - - - - diff --git a/model/model-api/src/test/resources/models/PolicyModel.json b/model/model-api/src/test/resources/models/PolicyModel.json deleted file mode 100644 index fbb91bb0b..000000000 --- a/model/model-api/src/test/resources/models/PolicyModel.json +++ /dev/null @@ -1,775 +0,0 @@ -{ - "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" - } - } - ] - } - } -} diff --git a/model/model-api/src/test/resources/models/PolicyModel.junk b/model/model-api/src/test/resources/models/PolicyModel.junk deleted file mode 100644 index 613a36ad8..000000000 --- a/model/model-api/src/test/resources/models/PolicyModel.junk +++ /dev/null @@ -1,9 +0,0 @@ -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/RealPolicyModel.json b/model/model-api/src/test/resources/models/RealPolicyModel.json deleted file mode 100644 index f084747f2..000000000 --- a/model/model-api/src/test/resources/models/RealPolicyModel.json +++ /dev/null @@ -1,3076 +0,0 @@ -{ - "key": { - "name": "ONAPvCPEPolicyModel", - "version": "0.0.1" - }, - "keyInformation": { - "key": { - "name": "ONAPvCPEPolicyModel_KeyInfo", - "version": "0.0.1" - }, - "keyInfoMap": { - "entry": [ - { - "key": { - "name": "AAILookupTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "AAILookupTask", - "version": "0.0.1" - }, - "UUID": "bc77813f-e2fa-33e0-aef0-c5b6a8832698", - "description": "Generated description for concept referred to by key \"AAILookupTask:0.0.1\"" - } - }, - { - "key": { - "name": "APPCLCMRequestType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCLCMRequestType", - "version": "0.0.1" - }, - "UUID": "ab26e475-d09d-36cd-a65c-8a8b556f0fa2", - "description": "Generated description for concept referred to by key \"APPCLCMRequestType:0.0.1\"" - } - }, - { - "key": { - "name": "APPCLCMResponseType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCLCMResponseType", - "version": "0.0.1" - }, - "UUID": "a60b42bb-c308-30ea-be59-5bc54864508b", - "description": "Generated description for concept referred to by key \"APPCLCMResponseType:0.0.1\"" - } - }, - { - "key": { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - }, - "value": { - "key": { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - }, - "UUID": "0b16f8d9-6ee9-30d7-bcd2-e4ded9fccf9b", - "description": "Generated description for concept referred to by key \"APPCRestartVNFRequestEvent:2.0.0\"" - } - }, - { - "key": { - "name": "APPCRestartVNFRequestTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCRestartVNFRequestTask", - "version": "0.0.1" - }, - "UUID": "719ae90e-ab01-322e-ace3-8c379e7c1fbf", - "description": "Generated description for concept referred to by key \"APPCRestartVNFRequestTask:0.0.1\"" - } - }, - { - "key": { - "name": "APPCRestartVNFResponseEvent", - "version": "2.0.0" - }, - "value": { - "key": { - "name": "APPCRestartVNFResponseEvent", - "version": "2.0.0" - }, - "UUID": "7034c5a9-2ea7-3e9e-9ccf-3610c3bf80d9", - "description": "Generated description for concept referred to by key \"APPCRestartVNFResponseEvent:2.0.0\"" - } - }, - { - "key": { - "name": "APPCRestartVNFResponseTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCRestartVNFResponseTask", - "version": "0.0.1" - }, - "UUID": "fe641fd9-6583-37c5-b317-2a33a3ca5ac7", - "description": "Generated description for concept referred to by key \"APPCRestartVNFResponseTask:0.0.1\"" - } - }, - { - "key": { - "name": "AbatedTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "AbatedTask", - "version": "0.0.1" - }, - "UUID": "0eb3974f-4fdc-3c90-b351-34e7e18ff1ab", - "description": "Generated description for concept referred to by key \"AbatedTask:0.0.1\"" - } - }, - { - "key": { - "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", - "version": "1.0.2" - }, - "value": { - "key": { - "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", - "version": "1.0.2" - }, - "UUID": "63ff5c25-f245-37e9-a580-6ac274ced3a7", - "description": "Generated description for concept referred to by key \"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e:1.0.2\"" - } - }, - { - "key": { - "name": "ControlLoopExecutionIDAlbum", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ControlLoopExecutionIDAlbum", - "version": "0.0.1" - }, - "UUID": "5b2bc0cf-0807-3ab1-9004-f21806d800f0", - "description": "Generated description for concept referred to by key \"ControlLoopExecutionIDAlbum:0.0.1\"" - } - }, - { - "key": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "UUID": "ed8a82ad-52c2-3d58-8c08-601606894b86", - "description": "Generated description for concept referred to by key \"ControlLoopLogEvent:0.0.1\"" - } - }, - { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "UUID": "1b175691-6b5d-31f6-bf2d-4be95a01f92e", - "description": "Generated description for concept referred to by key \"ControlLoopLogTask:0.0.1\"" - } - }, - { - "key": { - "name": "DeniedTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "DeniedTask", - "version": "0.0.1" - }, - "UUID": "00142e3c-ee3b-323f-9490-6e4b7f34b09f", - "description": "Generated description for concept referred to by key \"DeniedTask:0.0.1\"" - } - }, - { - "key": { - "name": "GetVCPEStateTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GetVCPEStateTask", - "version": "0.0.1" - }, - "UUID": "644d2a3d-0f3a-3664-8000-280c400a5cc1", - "description": "Generated description for concept referred to by key \"GetVCPEStateTask:0.0.1\"" - } - }, - { - "key": { - "name": "GuardDecisionAttributesType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardDecisionAttributesType", - "version": "0.0.1" - }, - "UUID": "5f6dff51-c183-322f-9aba-c6074aa0ece5", - "description": "Generated description for concept referred to by key \"GuardDecisionAttributesType:0.0.1\"" - } - }, - { - "key": { - "name": "GuardRequestEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardRequestEvent", - "version": "0.0.1" - }, - "UUID": "fb383a58-715b-3972-a3e6-38010a8de234", - "description": "Generated description for concept referred to by key \"GuardRequestEvent:0.0.1\"" - } - }, - { - "key": { - "name": "GuardRequestTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardRequestTask", - "version": "0.0.1" - }, - "UUID": "0427d63c-da78-334c-a5bd-95fbbb162398", - "description": "Generated description for concept referred to by key \"GuardRequestTask:0.0.1\"" - } - }, - { - "key": { - "name": "GuardResponseEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardResponseEvent", - "version": "0.0.1" - }, - "UUID": "395f6d46-cf24-3d3e-b1fd-1a189a58993d", - "description": "Generated description for concept referred to by key \"GuardResponseEvent:0.0.1\"" - } - }, - { - "key": { - "name": "GuardResponseTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardResponseTask", - "version": "0.0.1" - }, - "UUID": "1a8b3f30-a7aa-330b-8131-4aea06ad6934", - "description": "Generated description for concept referred to by key \"GuardResponseTask:0.0.1\"" - } - }, - { - "key": { - "name": "NoAAILookupTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "NoAAILookupTask", - "version": "0.0.1" - }, - "UUID": "648bc8f9-ad2b-3a1b-abe2-89401645f191", - "description": "Generated description for concept referred to by key \"NoAAILookupTask:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel", - "version": "0.0.1" - }, - "UUID": "cf1aa7f4-6fe3-3cba-90b4-49dcf46f0d57", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel_Albums", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel_Albums", - "version": "0.0.1" - }, - "UUID": "13f8471b-2b9c-32e0-940b-fe640ea442cf", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Albums:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel_Events", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel_Events", - "version": "0.0.1" - }, - "UUID": "4b8e6653-731d-38c5-a195-0cadf533a7a1", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Events:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel_KeyInfo", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel_KeyInfo", - "version": "0.0.1" - }, - "UUID": "87a9d6da-7d4b-3041-8a70-49442750d590", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_KeyInfo:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel_Policies", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel_Policies", - "version": "0.0.1" - }, - "UUID": "6220cca4-66f5-3d1b-9f19-688a9b4b70f5", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Policies:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel_Schemas", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel_Schemas", - "version": "0.0.1" - }, - "UUID": "3df4eef8-e764-3398-afe9-86730e20905a", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Schemas:0.0.1\"" - } - }, - { - "key": { - "name": "ONAPvCPEPolicyModel_Tasks", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ONAPvCPEPolicyModel_Tasks", - "version": "0.0.1" - }, - "UUID": "1781b875-a3e8-3407-98bd-ba9580cfc543", - "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Tasks:0.0.1\"" - } - }, - { - "key": { - "name": "ReceiveEventPolicy", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ReceiveEventPolicy", - "version": "0.0.1" - }, - "UUID": "568b7345-9de1-36d3-b6a3-9b857e6809a1", - "description": "Generated description for concept referred to by key \"ReceiveEventPolicy:0.0.1\"" - } - }, - { - "key": { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - "UUID": "5d8e8298-ded6-30a5-9825-48111dc17a58", - "description": "Generated description for concept referred to by key \"RequestIDVNFIDAlbum:0.0.1\"" - } - }, - { - "key": { - "name": "RestartAPPCRequestPolicy", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "RestartAPPCRequestPolicy", - "version": "0.0.1" - }, - "UUID": "33d02162-314b-352b-b8b9-2862e8883894", - "description": "Generated description for concept referred to by key \"RestartAPPCRequestPolicy:0.0.1\"" - } - }, - { - "key": { - "name": "RestartAPPCResponsePolicy", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "RestartAPPCResponsePolicy", - "version": "0.0.1" - }, - "UUID": "ef4fcbd2-1609-377c-9875-8d27f7a901df", - "description": "Generated description for concept referred to by key \"RestartAPPCResponsePolicy:0.0.1\"" - } - }, - { - "key": { - "name": "SimpleBooleanType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "SimpleBooleanType", - "version": "0.0.1" - }, - "UUID": "7218fb2f-59e3-321d-9ae1-bc97b19eb4ae", - "description": "Generated description for concept referred to by key \"SimpleBooleanType:0.0.1\"" - } - }, - { - "key": { - "name": "SimpleLongType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "SimpleLongType", - "version": "0.0.1" - }, - "UUID": "2dfcd9ec-a6f9-3f9f-958f-9b36cf4ac574", - "description": "Generated description for concept referred to by key \"SimpleLongType:0.0.1\"" - } - }, - { - "key": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "UUID": "8a4957cf-9493-3a76-8c22-a208e23259af", - "description": "Generated description for concept referred to by key \"SimpleStringType:0.0.1\"" - } - }, - { - "key": { - "name": "UUIDType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "UUIDType", - "version": "0.0.1" - }, - "UUID": "6a8cc68e-dfc8-3403-9c6d-071c886b319c", - "description": "Generated description for concept referred to by key \"UUIDType:0.0.1\"" - } - }, - { - "key": { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - }, - "UUID": "47a4403e-3074-3964-83ef-93eefaffd192", - "description": "Generated description for concept referred to by key \"VCPEClosedLoopStatusAlbum:0.0.1\"" - } - }, - { - "key": { - "name": "VCPEClosedLoopStatusType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VCPEClosedLoopStatusType", - "version": "0.0.1" - }, - "UUID": "6e7dced1-53f1-39e2-b4e6-412b75d5b9e6", - "description": "Generated description for concept referred to by key \"VCPEClosedLoopStatusType:0.0.1\"" - } - }, - { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "UUID": "5e56a3fd-f82a-3ced-821b-b9fbaf65d367", - "description": "Generated description for concept referred to by key \"VCPEStateUpdatedEvent:0.0.1\"" - } - }, - { - "key": { - "name": "VirtualControlLoopEventType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VirtualControlLoopEventType", - "version": "0.0.1" - }, - "UUID": "15aca887-8f6c-3713-8114-0f49f03adab7", - "description": "Generated description for concept referred to by key \"VirtualControlLoopEventType:0.0.1\"" - } - }, - { - "key": { - "name": "VirtualControlLoopNotificationType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VirtualControlLoopNotificationType", - "version": "0.0.1" - }, - "UUID": "283f5b0d-d8cd-31b0-91fa-89b9de2e1fda", - "description": "Generated description for concept referred to by key \"VirtualControlLoopNotificationType:0.0.1\"" - } - } - ] - } - }, - "policies": { - "key": { - "name": "ONAPvCPEPolicyModel_Policies", - "version": "0.0.1" - }, - "policyMap": { - "entry": [ - { - "key": { - "name": "ReceiveEventPolicy", - "version": "0.0.1" - }, - "value": { - "policyKey": { - "name": "ReceiveEventPolicy", - "version": "0.0.1" - }, - "template": "Freestyle", - "state": { - "entry": [ - { - "key": "AbatedState", - "value": { - "stateKey": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "AbatedState" - }, - "trigger": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "AbatedOutput", - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "AbatedState", - "localName": "AbatedOutput" - }, - "outgoingEvent": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "NULL", - "parentKeyVersion": "0.0.0", - "parentLocalName": "NULL", - "localName": "NULL" - } - } - } - ] - }, - "contextAlbumReference": [], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "AbatedState", - "localName": "ReceiveEventPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "AbatedState", - "localName": "AbatedOutput" - } - } - } - ] - } - } - }, - { - "key": "GetVCPEState", - "value": { - "stateKey": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "GetVCPEState" - }, - "trigger": { - "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", - "version": "1.0.2" - }, - "stateOutputs": { - "entry": [ - { - "key": "GetVCPEStateOutput", - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "GetVCPEState", - "localName": "GetVCPEStateOutput" - }, - "outgoingEvent": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "RequestAAIState" - } - } - } - ] - }, - "contextAlbumReference": [], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "GetVCPEStateTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "GetVCPEStateTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "GetVCPEState", - "localName": "ReceiveEventPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "GetVCPEState", - "localName": "GetVCPEStateOutput" - } - } - } - ] - } - } - }, - { - "key": "OnsetOrAbatedState", - "value": { - "stateKey": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "OnsetOrAbatedState" - }, - "trigger": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "AbatedOutput", - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "OnsetOrAbatedState", - "localName": "AbatedOutput" - }, - "outgoingEvent": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "AbatedState" - } - } - }, - { - "key": "OnsetOutput", - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "OnsetOrAbatedState", - "localName": "OnsetOutput" - }, - "outgoingEvent": { - "name": "GuardRequestEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "GuardRequestEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "NULL", - "parentKeyVersion": "0.0.0", - "parentLocalName": "NULL", - "localName": "NULL" - } - } - } - ] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskSelectionLogic": { - "key": "TaskSelectionLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar returnValue = true;\nvar status = null;\n\nif( executor.inFields.get(\"vnfID\") == null) {\n executor.logger.info(\"OnsetOrAbatedStateTSL: vnfID is null\");\n var vnfName = executor.inFields.get(\"vnfName\");\n var vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfName\"));\n status = vcpeClosedLoopStatus.get(\"closedLoopEventStatus\").toString();\n} else {\n var vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n status = vcpeClosedLoopStatus.get(\"closedLoopEventStatus\").toString();\n}\n\nif (status == \"ONSET\") {\n executor.subject.getTaskKey(\"GuardRequestTask\").copyTo(executor.selectedTask);\n} else if (status == \"ABATED\") {\n executor.subject.getTaskKey(\"AbatedTask\").copyTo(executor.selectedTask);\n onsetFlag = executor.isFalse;\n} else {\n executor.message = \"closedLoopEventStatus is \\\"\" + status + \"\\\", it must be either \\\"ONSET\\\" or \\\"ABATED\\\"\";\n returnValue = false;\n}\n\nexecutor.logger.info(\"ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:\" + executor.selectedTask);\n\nreturnValue;" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "AbatedTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "AbatedTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "OnsetOrAbatedState", - "localName": "ReceiveEventPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "OnsetOrAbatedState", - "localName": "AbatedOutput" - } - } - }, - { - "key": { - "name": "GuardRequestTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "OnsetOrAbatedState", - "localName": "ReceiveEventPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "OnsetOrAbatedState", - "localName": "OnsetOutput" - } - } - } - ] - } - } - }, - { - "key": "RequestAAIState", - "value": { - "stateKey": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "RequestAAIState" - }, - "trigger": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "RequestAAIStateOutput", - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "RequestAAIState", - "localName": "RequestAAIStateOutput" - }, - "outgoingEvent": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "OnsetOrAbatedState" - } - } - } - ] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "AAILookupTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "AAILookupTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "RequestAAIState", - "localName": "ReceiveEventPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "ReceiveEventPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "RequestAAIState", - "localName": "RequestAAIStateOutput" - } - } - } - ] - } - } - } - ] - }, - "firstState": "GetVCPEState" - } - }, - { - "key": { - "name": "RestartAPPCRequestPolicy", - "version": "0.0.1" - }, - "value": { - "policyKey": { - "name": "RestartAPPCRequestPolicy", - "version": "0.0.1" - }, - "template": "Freestyle", - "state": { - "entry": [ - { - "key": "DeniedState", - "value": { - "stateKey": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "DeniedState" - }, - "trigger": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "DeniedOutput", - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "DeniedState", - "localName": "DeniedOutput" - }, - "outgoingEvent": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "NULL", - "parentKeyVersion": "0.0.0", - "parentLocalName": "NULL", - "localName": "NULL" - } - } - } - ] - }, - "contextAlbumReference": [], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "DeniedState", - "localName": "RestartAPPCRequestPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "DeniedState", - "localName": "DeniedOutput" - } - } - } - ] - } - } - }, - { - "key": "PermitOrDenyState", - "value": { - "stateKey": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "PermitOrDenyState" - }, - "trigger": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "DenyOutput", - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PermitOrDenyState", - "localName": "DenyOutput" - }, - "outgoingEvent": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "DeniedState" - } - } - }, - { - "key": "PermitOutput", - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PermitOrDenyState", - "localName": "PermitOutput" - }, - "outgoingEvent": { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - }, - "outgoingEventReference": [ - { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - } - ], - "nextState": { - "parentKeyName": "NULL", - "parentKeyVersion": "0.0.0", - "parentLocalName": "NULL", - "localName": "NULL" - } - } - } - ] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskSelectionLogic": { - "key": "TaskSelectionLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvar guardResult = vcpeClosedLoopStatus.get(\"notification\");\n\nif (guardResult == \"OPERATION: GUARD_PERMIT\") {\n executor.subject.getTaskKey(\"APPCRestartVNFRequestTask\").copyTo(executor.selectedTask);\n} else {\n executor.subject.getTaskKey(\"DeniedTask\").copyTo(executor.selectedTask);\n}\n\nexecutor.logger.info(\"RestartAPPCRequestPolicyPermitOrDenyTSL State Selected Task:\" + executor.selectedTask);\n\ntrue;" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "DeniedTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "APPCRestartVNFRequestTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PermitOrDenyState", - "localName": "RestartAPPCRequestPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PermitOrDenyState", - "localName": "PermitOutput" - } - } - }, - { - "key": { - "name": "DeniedTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PermitOrDenyState", - "localName": "RestartAPPCRequestPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PermitOrDenyState", - "localName": "DenyOutput" - } - } - } - ] - } - } - }, - { - "key": "PolicyGuardResponseState", - "value": { - "stateKey": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "PolicyGuardResponseState" - }, - "trigger": { - "name": "GuardResponseEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "GuardResponseOutput", - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PolicyGuardResponseState", - "localName": "GuardResponseOutput" - }, - "outgoingEvent": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "PermitOrDenyState" - } - } - } - ] - }, - "contextAlbumReference": [], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "GuardResponseTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "GuardResponseTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PolicyGuardResponseState", - "localName": "RestartAPPCRequestPolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "RestartAPPCRequestPolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "PolicyGuardResponseState", - "localName": "GuardResponseOutput" - } - } - } - ] - } - } - } - ] - }, - "firstState": "PolicyGuardResponseState" - } - }, - { - "key": { - "name": "RestartAPPCResponsePolicy", - "version": "0.0.1" - }, - "value": { - "policyKey": { - "name": "RestartAPPCResponsePolicy", - "version": "0.0.1" - }, - "template": "Freestyle", - "state": { - "entry": [ - { - "key": "ResponseLogState", - "value": { - "stateKey": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "ResponseLogState" - }, - "trigger": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "stateOutputs": { - "entry": [ - { - "key": "ResponseLogOutput", - "value": { - "key": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "ResponseLogState", - "localName": "ResponseLogOutput" - }, - "outgoingEvent": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "NULL", - "parentKeyVersion": "0.0.0", - "parentLocalName": "NULL", - "localName": "NULL" - } - } - } - ] - }, - "contextAlbumReference": [], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "ResponseLogState", - "localName": "RestartAPPCResponsePolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "ResponseLogState", - "localName": "ResponseLogOutput" - } - } - } - ] - } - } - }, - { - "key": "RestartAPPCResponseState", - "value": { - "stateKey": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "RestartAPPCResponseState" - }, - "trigger": { - "name": "APPCRestartVNFResponseEvent", - "version": "2.0.0" - }, - "stateOutputs": { - "entry": [ - { - "key": "APPCRestartVNFResponseOutput", - "value": { - "key": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "RestartAPPCResponseState", - "localName": "APPCRestartVNFResponseOutput" - }, - "outgoingEvent": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "outgoingEventReference": [ - { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - } - ], - "nextState": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "NULL", - "localName": "ResponseLogState" - } - } - } - ] - }, - "contextAlbumReference": [], - "taskSelectionLogic": { - "key": "NULL", - "logicFlavour": "UNDEFINED", - "logic": "" - }, - "stateFinalizerLogicMap": { - "entry": [] - }, - "defaultTask": { - "name": "APPCRestartVNFResponseTask", - "version": "0.0.1" - }, - "taskReferences": { - "entry": [ - { - "key": { - "name": "APPCRestartVNFResponseTask", - "version": "0.0.1" - }, - "value": { - "key": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "RestartAPPCResponseState", - "localName": "RestartAPPCResponsePolicy" - }, - "outputType": "DIRECT", - "output": { - "parentKeyName": "RestartAPPCResponsePolicy", - "parentKeyVersion": "0.0.1", - "parentLocalName": "RestartAPPCResponseState", - "localName": "APPCRestartVNFResponseOutput" - } - } - } - ] - } - } - } - ] - }, - "firstState": "RestartAPPCResponseState" - } - } - ] - } - }, - "tasks": { - "key": { - "name": "ONAPvCPEPolicyModel_Tasks", - "version": "0.0.1" - }, - "taskMap": { - "entry": [ - { - "key": { - "name": "AAILookupTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "AAILookupTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "VCPEStateUpdatedEvent", - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nexecutor.logger.info(\"Executing A&AI Lookup\");\nexecutor.logger.info(vcpeClosedLoopStatus);\n\nvar aaiInfo = vcpeClosedLoopStatus.get(\"AAI\");\nvar returnValue = true;\n\nif (aaiInfo.get(\"vserverName\") == null) {\n executor.message = \"the field vserver.vserver-name must exist in the onset control loop event\";\n executor.logger.warn(executor.message);\n returnValue = false;\n}\nelse if (aaiInfo.get(\"genericVnfVnfId\") == null && aaiInfo.get(\"genericVnfVnfName\") == null) {\n executor.message = \"either the field generic-vnf.vnf-id or generic-vnf.vnf-name must exist\"\n + \" in the onset control loop event\";\n executor.logger.warn(executor.message);\n returnValue = false;\n}\nelse {\n var restManager = new org.onap.policy.rest.RestManager;\n var aaiManager = new org.onap.policy.aai.AaiManager(restManager);\n\n // We need to instantiate the type in order to trigger the static JAXB handling\n // in the AaiCqResponse class\n var aaiCqResponseType = org.onap.policy.aai.AaiCqResponse;\n\n var aaiResponse = aaiManager.getCustomQueryResponse(\n \"http://localhost:54321/OnapVCpeSim/sim\",\n \"aai.username\",\n \"aai.password\",\n executor.inFields.get(\"requestID\"),\n vcpeClosedLoopStatus.get(\"AAI\").get(\"vserverName\")\n );\n\n var genericVnf;\n\n if (aaiInfo.get(\"genericVnfVnfId\") != null) {\n genericVnf = aaiResponse.getGenericVnfByModelInvariantId(aaiInfo.get(\"genericVnfVnfId\"));\n }\n else {\n genericVnf = aaiResponse.getGenericVnfByVnfName(aaiInfo.get(\"genericVnfVnfId\"));\n }\n\n aaiInfo.put(\"genericVnfResourceVersion\", genericVnf.getResourceVersion());\n aaiInfo.put(\"genericVnfVnfName\", genericVnf.getVnfName());\n aaiInfo.put(\"genericVnfProvStatus\", genericVnf.getProvStatus());\n aaiInfo.put(\"genericVnfIsClosedLoopDisabled\", genericVnf.isIsClosedLoopDisabled().toString());\n aaiInfo.put(\"genericVnfVnfType\", genericVnf.getVnfType());\n aaiInfo.put(\"genericVnfInMaint\", genericVnf.isInMaint().toString());\n aaiInfo.put(\"genericVnfServiceId\", genericVnf.getServiceId());\n aaiInfo.put(\"genericVnfVnfId\", genericVnf.getVnfId());\n aaiInfo.put(\"genericVnfOrchestrationStatus\",\n genericVnf.getVfModules().getVfModule().get(0).getOrchestrationStatus());\n\n executor.outFields.put(\"requestID\", executor.inFields.get(\"requestID\"));\n executor.outFields.put(\"vnfID\", executor.inFields.get(\"vnfID\"));\n\n executor.logger.info(executor.outFields);\n}\n\nreturnValue;" - } - } - }, - { - "key": { - "name": "APPCRestartVNFRequestTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCRestartVNFRequestTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "APPCRestartVNFRequestEvent", - "value": { - "key": { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APPC", - "parameter": { - "entry": [ - { - "key": "APPCLCMRequestEvent", - "value": { - "key": "APPCLCMRequestEvent", - "fieldSchemaKey": { - "name": "APPCLCMRequestType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar appcRequest = new org.onap.policy.appclcm.AppcLcmDmaapWrapper;\nappcRequest.setBody(new org.onap.policy.appclcm.AppcLcmBody);\nappcRequest.getBody().setInput(new org.onap.policy.appclcm.AppcLcmInput);\nappcRequest.getBody().getInput().setCommonHeader(\n new org.onap.policy.appclcm.AppcLcmCommonHeader);\n\nappcRequest.setVersion(\"2.0.0\");\nappcRequest.setRpcName(\"restart\");\nappcRequest.setCorrelationId(executor.inFields.get(\"requestID\"));\nappcRequest.setType(\"request\");\n\nvar vcpeClosedLoopStatus = executor\n .getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nappcRequest.getBody().getInput().getCommonHeader().setTimeStamp(java.time.Instant.now());\nappcRequest.getBody().getInput().getCommonHeader().setApiVer(\"2.00\");\nappcRequest.getBody().getInput().getCommonHeader().setOriginatorId(\n executor.inFields.get(\"requestID\").toString());\nappcRequest.getBody().getInput().getCommonHeader().setRequestId(\n executor.inFields.get(\"requestID\"));\nappcRequest.getBody().getInput().getCommonHeader().setSubRequestId(\"1\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"ttl\", \"10000\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"force\", \"TRUE\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"mode\", \"EXCLUSIVE\");\n\nappcRequest.getBody().getInput().setAction(\"Restart\");\nappcRequest.getBody().getInput().setActionIdentifiers(new java.util.HashMap());\nappcRequest.getBody().getInput().getActionIdentifiers().put(\"vnf-id\",\n executor.inFields.get(\"vnfID\").toString());\n\nexecutor.getContextAlbum(\"RequestIDVNFIDAlbum\").put(\n executor.inFields.get(\"requestID\").toString(),\n executor.inFields.get(\"vnfID\"));\n\nvcpeClosedLoopStatus.put(\"notification\", \"OPERATION\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System\n .currentTimeMillis());\n\nexecutor.outFields.put(\"APPCLCMRequestEvent\", appcRequest);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" - } - } - }, - { - "key": { - "name": "APPCRestartVNFResponseTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCRestartVNFResponseTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "APPCRestartVNFResponseEvent", - "version": "2.0.0" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APPC", - "parameter": { - "entry": [ - { - "key": "APPCLCMResponseEvent", - "value": { - "key": "APPCLCMResponseEvent", - "fieldSchemaKey": { - "name": "APPCLCMResponseType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "VCPEStateUpdatedEvent", - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * APPC LCM Response code: 100 ACCEPTED\n * 200 ERROR UNEXPECTED ERROR means failure\n * 312 REJECTED DUPLICATE REQUEST\n * 400 SUCCESS\n *\n * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar appcResponse = executor.inFields.get(\"APPCLCMResponseEvent\");\n\nvar requestIDString = appcResponse.getCorrelationId().substr(0, 36);\nexecutor.logger.info(\"requestIDString = \" + requestIDString);\nvar vnfID = executor.getContextAlbum(\"RequestIDVNFIDAlbum\")\n .get(requestIDString);\nexecutor.logger.info(\"Size of RequestIDVNFIDAlbum = \"\n + executor.getContextAlbum(\"RequestIDVNFIDAlbum\").size());\nexecutor.logger.info(\"vnfID = \" + vnfID);\n\nvar returnValue = true;\n\nif (vnfID != null) {\n var vcpeClosedLoopStatus = executor.getContextAlbum(\n \"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\n var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus\n .get(\"requestID\"));\n\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System\n .currentTimeMillis());\n\n executor.logger.info(\"Got from APPC code: \"\n + org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput()\n .getStatus().getCode()));\n\n if (org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput().getStatus()\n .getCode()) == org.onap.policy.appclcm.AppcLcmResponseCode.SUCCESS) {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION_SUCCESS\");\n vcpeClosedLoopStatus.put(\"message\", \"vCPE restarted\");\n executor.getContextAlbum(\"RequestIDVNFIDAlbum\").remove(requestIDString);\n } else if (org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput().getStatus()\n .getCode()) == \"ACCEPTED\"\n || org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput()\n .getStatus().getCode()) == \"REJECT\") {\n executor.logger\n .info(\"Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: \"\n + org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody()\n .getOutput().getStatus().getCode()));\n } else {\n executor.getContextAlbum(\"RequestIDVNFIDAlbum\").remove(requestIDString);\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION_FAILURE\");\n vcpeClosedLoopStatus.put(\"message\", \"vCPE restart failed\");\n }\n\n executor.outFields.put(\"requestID\", requestId);\n executor.outFields.put(\"vnfID\", vnfID);\n} else {\n executor.message = \"VNF ID not found in context album for request ID \"\n + requestIDString;\n returnValue = false\n}\n\nexecutor.logger.info(executor.outFields);\n\nreturnValue;" - } - } - }, - { - "key": { - "name": "AbatedTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "AbatedTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "VCPEStateUpdatedEvent", - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = null;\nif( executor.inFields.get(\"vnfID\") == null) {\n executor.logger.info(\"AbatedTask: vnfID is null\");\n var vnfName = executor.inFields.get(\"vnfName\");\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfName\"));\n} else {\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n}\n\nvcpeClosedLoopStatus.put(\"notification\", \"FINAL_SUCCESS\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\nvcpeClosedLoopStatus.put(\"message\", \"situation has been abated\");\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" - } - } - }, - { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ControlLoopLogTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "ControlLoopLogEvent", - "value": { - "key": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "VirtualControlLoopNotification", - "value": { - "key": "VirtualControlLoopNotification", - "fieldSchemaKey": { - "name": "VirtualControlLoopNotificationType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vnfID = executor.inFields.get(\"vnfID\");\nif(vnfID == null) {\n vnfID = executor.inFields.get(\"vnfName\");\n}\nexecutor.logger.info(\"vnfID=\" + vnfID);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\n\nexecutor.logger.info(\"Logging context information for VNF \\\"\" + vnfID + \"\\\"\");\n\nvar clNotification = new org.onap.policy.controlloop.VirtualControlLoopNotification();\n\nclNotification.setClosedLoopControlName(vcpeClosedLoopStatus.get(\"closedLoopControlName\"));\nclNotification.setClosedLoopAlarmStart(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get(\"closedLoopAlarmStart\")));\nclNotification.setClosedLoopAlarmEnd(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get(\"closedLoopAlarmEnd\")));\nclNotification.setClosedLoopEventClient(vcpeClosedLoopStatus.get(\"closedLoopEventClient\"));\nclNotification.setVersion(vcpeClosedLoopStatus.get(\"version\"));\nclNotification.setRequestId(java.util.UUID.fromString(vcpeClosedLoopStatus.get(\"requestID\")));\nclNotification.setTargetType(vcpeClosedLoopStatus.get(\"target_type\"));\nclNotification.setTarget(vcpeClosedLoopStatus.get(\"target\"));\nclNotification.setFrom(vcpeClosedLoopStatus.get(\"from\"));\nclNotification.setPolicyScope(vcpeClosedLoopStatus.get(\"policyScope\"));\nclNotification.setPolicyName(vcpeClosedLoopStatus.get(\"policyName\"));\nclNotification.setPolicyVersion(vcpeClosedLoopStatus.get(\"policyVersion\"));\nclNotification.setNotification(org.onap.policy.controlloop.ControlLoopNotificationType.toType(vcpeClosedLoopStatus.get(\"notification\")));\nclNotification.setMessage(vcpeClosedLoopStatus.get(\"message\"));\n\nvar notificationInstant = java.time.Instant.ofEpochSecond(vcpeClosedLoopStatus.get(\"notificationTime\"));\nvar notificationTime = java.time.ZonedDateTime.ofInstant(notificationInstant, java.time.ZoneOffset.UTC);\nclNotification.setNotificationTime(notificationTime);\n\nvar aaiInfo = vcpeClosedLoopStatus.get(\"AAI\");\n\nclNotification.getAai().put(\"generic-vnf.resource-version\", aaiInfo.get(\"genericVnfResourceVersion\"));\nclNotification.getAai().put(\"generic-vnf.vnf-name\", aaiInfo.get(\"genericVnfVnfName\"));\nclNotification.getAai().put(\"generic-vnf.prov-status\", aaiInfo.get(\"genericVnfProvStatus\"));\nclNotification.getAai().put(\"generic-vnf.is-closed-loop-disabled\", aaiInfo.get(\"genericVnfIsClosedLoopDisabled\"));\nclNotification.getAai().put(\"generic-vnf.orchestration-status\", aaiInfo.get(\"genericVnfOrchestrationStatus\"));\nclNotification.getAai().put(\"generic-vnf.vnf-type\", aaiInfo.get(\"genericVnfVnfType\"));\nclNotification.getAai().put(\"generic-vnf.in-maint\", aaiInfo.get(\"genericVnfInMaint\"));\nclNotification.getAai().put(\"generic-vnf.service-id\", aaiInfo.get(\"genericVnfServiceId\"));\n\nif(vnfID != null) {\n clNotification.getAai().put(\"generic-vnf.vnf-id\", aaiInfo.get(\"genericVnfVnfId\"));\n}\nexecutor.outFields.put(\"VirtualControlLoopNotification\", clNotification);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" - } - } - }, - { - "key": { - "name": "DeniedTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "DeniedTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "VCPEStateUpdatedEvent", - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvcpeClosedLoopStatus.put(\"notification\", \"REJECTED\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" - } - } - }, - { - "key": { - "name": "GetVCPEStateTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GetVCPEStateTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", - "version": "1.0.2" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "DCAE", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "VirtualControlLoopEvent", - "value": { - "key": "VirtualControlLoopEvent", - "fieldSchemaKey": { - "name": "VirtualControlLoopEventType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "VCPEStateUpdatedEvent", - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID\n * or ABATED with only VNF-name. So need to handle differently. For ABATED case,\n * since we still keep the RequireIDVNFID context album, we can get it from there.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent;\nvar longType = java.lang.Long;\nvar uuidType = java.util.UUID;\n\nvar clEvent = executor.inFields.get(\"VirtualControlLoopEvent\");\n\nexecutor.logger.info(clEvent.toString());\nexecutor.logger.info(clEvent.getClosedLoopControlName());\n\nvar requestID = clEvent.getRequestId();\nexecutor.logger.info(\"requestID = \" + requestID);\nvar vnfID = null;\nvar vcpeClosedLoopStatus = null;\n\nif (clEvent.getAai().get(\"generic-vnf.vnf-id\") != null) {\n vnfID = uuidType.fromString(clEvent.getAai().get(\"generic-vnf.vnf-id\"));\n executor.logger.info(\"vnfID = \" + vnfID);\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID);\n\n if (vcpeClosedLoopStatus == null) {\n executor.logger.info(\"Creating context information for new vCPE VNF \\\"\" + vnfID.toString() + \"\\\"\");\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewInstance();\n\n vcpeClosedLoopStatus.put(\"closedLoopControlName\", clEvent.getClosedLoopControlName());\n vcpeClosedLoopStatus.put(\"closedLoopAlarmStart\", clEvent.getClosedLoopAlarmStart().toEpochMilli());\n vcpeClosedLoopStatus.put(\"closedLoopEventClient\", clEvent.getClosedLoopEventClient());\n vcpeClosedLoopStatus.put(\"closedLoopEventStatus\", clEvent.getClosedLoopEventStatus().toString());\n vcpeClosedLoopStatus.put(\"version\", clEvent.getVersion());\n vcpeClosedLoopStatus.put(\"requestID\", clEvent.getRequestId().toString());\n vcpeClosedLoopStatus.put(\"target_type\", clEvent.getTargetType().toString());\n vcpeClosedLoopStatus.put(\"target\", clEvent.getTarget());\n vcpeClosedLoopStatus.put(\"from\", clEvent.getFrom());\n vcpeClosedLoopStatus.put(\"policyScope\", \"vCPE\");\n vcpeClosedLoopStatus.put(\"policyName\", \"ONAPvCPEPolicyModel\");\n vcpeClosedLoopStatus.put(\"policyVersion\", \"0.0.1\");\n vcpeClosedLoopStatus.put(\"notification\", \"ACTIVE\");\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n vcpeClosedLoopStatus.put(\"message\", \"\");\n\n var aaiInfo = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewSubInstance(\"VCPE_AAI_Type\");\n\n aaiInfo.put(\"genericVnfResourceVersion\", clEvent.getAai().get(\"generic-vnf.resource-version\"));\n aaiInfo.put(\"genericVnfVnfName\", clEvent.getAai().get(\"generic-vnf.vnf-name\"));\n aaiInfo.put(\"genericVnfProvStatus\", clEvent.getAai().get(\"generic-vnf.prov-status\"));\n aaiInfo.put(\"genericVnfIsClosedLoopDisabled\", clEvent.getAai().get(\"generic-vnf.is-closed-loop-disabled\"));\n aaiInfo.put(\"genericVnfOrchestrationStatus\", clEvent.getAai().get(\"generic-vnf.orchestration-status\"));\n aaiInfo.put(\"genericVnfVnfType\", clEvent.getAai().get(\"generic-vnf.vnf-type\"));\n aaiInfo.put(\"genericVnfInMaint\", clEvent.getAai().get(\"generic-vnf.in-maint\"));\n aaiInfo.put(\"genericVnfServiceId\", clEvent.getAai().get(\"generic-vnf.service-id\"));\n aaiInfo.put(\"genericVnfVnfId\", clEvent.getAai().get(\"generic-vnf.vnf-id\"));\n aaiInfo.put(\"vserverIsClosedLoopDisabled\", clEvent.getAai().get(\"vserver.is-closed-loop-disabled\"));\n aaiInfo.put(\"vserverProvStatus\", clEvent.getAai().get(\"vserver.prov-status\"));\n aaiInfo.put(\"vserverName\", clEvent.getAai().get(\"vserver.vserver-name\"));\n\n vcpeClosedLoopStatus.put(\"AAI\", aaiInfo);\n\n if (clEvent.getClosedLoopAlarmEnd() != null) {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", clEvent.getClosedLoopAlarmEnd().toEpochMilli());\n } else {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", java.lang.Long.valueOf(0));\n }\n\n executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").put(vnfID.toString(), vcpeClosedLoopStatus);\n\n executor.logger.info(\"Created context information for new vCPE VNF \\\"\" + vnfID.toString() + \"\\\"\");\n }\n\n executor.outFields.put(\"requestID\", requestID);\n executor.outFields.put(\"vnfID\", vnfID);\n\n executor.logger.info(executor.outFields);\n}\nelse {\n executor.logger.info(\"No vnf-id in VirtualControlLoopEvent, status:\" + clEvent.getClosedLoopEventStatus().toString());\n var vnfName = clEvent.getAai().get(\"generic-vnf.vnf-name\");\n executor.logger.info(\"No vnf-id in VirtualControlLoopEvent for \" + vnfName);\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfName.toString());\n\n if (vcpeClosedLoopStatus == null) {\n executor.logger.info(\"Creating context information for new vCPE VNF \\\"\" + vnfName.toString() + \"\\\"\");\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewInstance();\n\n vcpeClosedLoopStatus.put(\"closedLoopControlName\", clEvent.getClosedLoopControlName());\n vcpeClosedLoopStatus.put(\"closedLoopAlarmStart\", clEvent.getClosedLoopAlarmStart().toEpochMilli());\n vcpeClosedLoopStatus.put(\"closedLoopEventClient\", clEvent.getClosedLoopEventClient());\n vcpeClosedLoopStatus.put(\"closedLoopEventStatus\", clEvent.getClosedLoopEventStatus().toString());\n vcpeClosedLoopStatus.put(\"version\", clEvent.getVersion());\n vcpeClosedLoopStatus.put(\"requestID\", clEvent.getRequestId().toString());\n vcpeClosedLoopStatus.put(\"target_type\", clEvent.getTargetType().toString());\n vcpeClosedLoopStatus.put(\"target\", clEvent.getTarget());\n vcpeClosedLoopStatus.put(\"from\", clEvent.getFrom());\n vcpeClosedLoopStatus.put(\"policyScope\", \"vCPE\");\n vcpeClosedLoopStatus.put(\"policyName\", \"ONAPvCPEPolicyModel\");\n vcpeClosedLoopStatus.put(\"policyVersion\", \"0.0.1\");\n vcpeClosedLoopStatus.put(\"notification\", \"ACTIVE\");\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n vcpeClosedLoopStatus.put(\"message\", \"\");\n\n var aaiInfo = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewSubInstance(\"VCPE_AAI_Type\");\n\n aaiInfo.put(\"genericVnfVnfName\", clEvent.getAai().get(\"generic-vnf.vnf-name\"));\n vcpeClosedLoopStatus.put(\"AAI\", aaiInfo);\n\n if (clEvent.getClosedLoopAlarmEnd() != null) {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", clEvent.getClosedLoopAlarmEnd().toEpochMilli());\n } else {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", java.lang.Long.valueOf(0));\n }\n\n executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").put(vnfName.toString(), vcpeClosedLoopStatus);\n\n executor.logger.info(\"Created context information for new vCPE VNF \\\"\" + vnfName.toString() + \"\\\"\");\n }\n executor.outFields.put(\"requestID\", requestID);\n executor.outFields.put(\"vnfName\", vnfName);\n executor.logger.info(executor.outFields);\n}\n\ntrue;" - } - } - }, - { - "key": { - "name": "GuardRequestTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardRequestTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "GuardRequestEvent", - "value": { - "key": { - "name": "GuardRequestEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "decisionAttributes", - "value": { - "key": "decisionAttributes", - "fieldSchemaKey": { - "name": "GuardDecisionAttributesType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "onapName", - "value": { - "key": "onapName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "ControlLoopExecutionIDAlbum", - "version": "0.0.1" - }, - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvar guardDecisionAttributes = executor.subject.getOutFieldSchemaHelper(\"decisionAttributes\").createNewInstance();\n\nguardDecisionAttributes.put(\"actor\", \"APPC\");\nguardDecisionAttributes.put(\"recipe\", \"Restart\");\nguardDecisionAttributes.put(\"target\", executor.inFields.get(\"vnfID\").toString());\nguardDecisionAttributes.put(\"clname\", \"APEXvCPEImplementation\");\n\nexecutor.logger.info(guardDecisionAttributes);\n\nexecutor.outFields.put(\"decisionAttributes\", guardDecisionAttributes);\nexecutor.outFields.put(\"onapName\", \"PDPD\");\n\nexecutor.getContextAlbum(\"ControlLoopExecutionIDAlbum\").put(executor.executionId.toString(),\n executor.inFields.get(\"vnfID\"));\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" - } - } - }, - { - "key": { - "name": "GuardResponseTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardResponseTask", - "version": "0.0.1" - }, - "inputEvent": { - "key": { - "name": "GuardResponseEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "decision", - "value": { - "key": "decision", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "details", - "value": { - "key": "details", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - }, - "outputEvents": { - "entry": [ - { - "key": "VCPEStateUpdatedEvent", - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [ - { - "name": "ControlLoopExecutionIDAlbum", - "version": "0.0.1" - }, - { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - } - ], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vnfID = executor.getContextAlbum(\"ControlLoopExecutionIDAlbum\").remove(executor.executionId.toString());\n\nexecutor.logger.info(\"Continuing execution with VNF ID: \" + vnfID);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\nexecutor.logger.info(vcpeClosedLoopStatus);\n\nvar guardResult = executor.inFields.get(\"decision\");\nvar returnValue = true;\n\nif (guardResult == \"PERMIT\") {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION: GUARD_PERMIT\");\n} else if (guardResult == \"DENY\") {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION: GUARD_DENY\");\n} else {\n executor.message = \"guard result must be either \\\"PERMIT\\\" or \\\"DENY\\\"\";\n returnValue = false;\n}\n\nvar uuidType = java.util.UUID;\nvar requestID = uuidType.fromString(vcpeClosedLoopStatus.get(\"requestID\"));\n\nexecutor.outFields.put(\"requestID\", requestID);\nexecutor.outFields.put(\"vnfID\", vnfID);\n\nexecutor.logger.info(executor.outFields);\n\n\nreturnValue;" - } - } - }, - { - "key": { - "name": "NoAAILookupTask", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "NoAAILookupTask", - "version": "0.0.1" - }, - "taskParameters": { - "entry": [] - }, - "contextAlbumReference": [], - "taskLogic": { - "key": "TaskLogic", - "logicFlavour": "JAVASCRIPT", - "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;" - } - } - } - ] - } - }, - "events": { - "key": { - "name": "ONAPvCPEPolicyModel_Events", - "version": "0.0.1" - }, - "eventMap": { - "entry": [ - { - "key": { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - }, - "value": { - "key": { - "name": "APPCRestartVNFRequestEvent", - "version": "2.0.0" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APPC", - "parameter": { - "entry": [ - { - "key": "APPCLCMRequestEvent", - "value": { - "key": "APPCLCMRequestEvent", - "fieldSchemaKey": { - "name": "APPCLCMRequestType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - }, - { - "key": { - "name": "APPCRestartVNFResponseEvent", - "version": "2.0.0" - }, - "value": { - "key": { - "name": "APPCRestartVNFResponseEvent", - "version": "2.0.0" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APPC", - "parameter": { - "entry": [ - { - "key": "APPCLCMResponseEvent", - "value": { - "key": "APPCLCMResponseEvent", - "fieldSchemaKey": { - "name": "APPCLCMResponseType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - }, - { - "key": { - "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", - "version": "1.0.2" - }, - "value": { - "key": { - "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", - "version": "1.0.2" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "DCAE", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "VirtualControlLoopEvent", - "value": { - "key": "VirtualControlLoopEvent", - "fieldSchemaKey": { - "name": "VirtualControlLoopEventType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - }, - { - "key": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ControlLoopLogEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "VirtualControlLoopNotification", - "value": { - "key": "VirtualControlLoopNotification", - "fieldSchemaKey": { - "name": "VirtualControlLoopNotificationType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - }, - { - "key": { - "name": "GuardRequestEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardRequestEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "decisionAttributes", - "value": { - "key": "decisionAttributes", - "fieldSchemaKey": { - "name": "GuardDecisionAttributesType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "onapName", - "value": { - "key": "onapName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - }, - { - "key": { - "name": "GuardResponseEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardResponseEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "decision", - "value": { - "key": "decision", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "details", - "value": { - "key": "details", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": false - } - } - ] - }, - "toscaPolicyState": "" - } - }, - { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VCPEStateUpdatedEvent", - "version": "0.0.1" - }, - "nameSpace": "org.onap.policy.apex.onap.vcpe", - "source": "APEX", - "target": "APEX", - "parameter": { - "entry": [ - { - "key": "requestID", - "value": { - "key": "requestID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfID", - "value": { - "key": "vnfID", - "fieldSchemaKey": { - "name": "UUIDType", - "version": "0.0.1" - }, - "optional": false - } - }, - { - "key": "vnfName", - "value": { - "key": "vnfName", - "fieldSchemaKey": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "optional": true - } - } - ] - }, - "toscaPolicyState": "" - } - } - ] - } - }, - "albums": { - "key": { - "name": "ONAPvCPEPolicyModel_Albums", - "version": "0.0.1" - }, - "albums": { - "entry": [ - { - "key": { - "name": "ControlLoopExecutionIDAlbum", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "ControlLoopExecutionIDAlbum", - "version": "0.0.1" - }, - "scope": "policy", - "isWritable": true, - "itemSchema": { - "name": "UUIDType", - "version": "0.0.1" - } - } - }, - { - "key": { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "RequestIDVNFIDAlbum", - "version": "0.0.1" - }, - "scope": "policy", - "isWritable": true, - "itemSchema": { - "name": "UUIDType", - "version": "0.0.1" - } - } - }, - { - "key": { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VCPEClosedLoopStatusAlbum", - "version": "0.0.1" - }, - "scope": "policy", - "isWritable": true, - "itemSchema": { - "name": "VCPEClosedLoopStatusType", - "version": "0.0.1" - } - } - } - ] - } - }, - "schemas": { - "key": { - "name": "ONAPvCPEPolicyModel_Schemas", - "version": "0.0.1" - }, - "schemas": { - "entry": [ - { - "key": { - "name": "APPCLCMRequestType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCLCMRequestType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "org.onap.policy.appclcm.AppcLcmDmaapWrapper" - } - }, - { - "key": { - "name": "APPCLCMResponseType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "APPCLCMResponseType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "org.onap.policy.appclcm.AppcLcmDmaapWrapper" - } - }, - { - "key": { - "name": "GuardDecisionAttributesType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "GuardDecisionAttributesType", - "version": "0.0.1" - }, - "schemaFlavour": "Avro", - "schemaDefinition": "{\n \"type\": \"record\",\n \"name\": \"GuardDecisionAttributes_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.vcpe\",\n \"fields\": [\n {\n \"name\": \"actor\",\n \"type\": \"string\"\n },\n {\n \"name\": \"recipe\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target\",\n \"type\": \"string\"\n },\n {\n \"name\": \"clname\",\n \"type\": \"string\"\n }\n ]\n}" - } - }, - { - "key": { - "name": "SimpleBooleanType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "SimpleBooleanType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "java.lang.Boolean" - } - }, - { - "key": { - "name": "SimpleLongType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "SimpleLongType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "java.lang.Long" - } - }, - { - "key": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "SimpleStringType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "java.lang.String" - } - }, - { - "key": { - "name": "UUIDType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "UUIDType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "java.util.UUID" - } - }, - { - "key": { - "name": "VCPEClosedLoopStatusType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VCPEClosedLoopStatusType", - "version": "0.0.1" - }, - "schemaFlavour": "Avro", - "schemaDefinition": "{\n \"type\": \"record\",\n \"name\": \"VCPEClosedLoopStatus\",\n \"fields\": [\n {\n \"name\": \"AAI\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"VCPE_AAI_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.vcpe\",\n \"fields\": [\n {\n \"name\": \"genericVnfResourceVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfProvStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfIsClosedLoopDisabled\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfOrchestrationStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfInMaint\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfServiceId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverIsClosedLoopDisabled\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverProvStatus\",\n \"type\": \"string\"\n }\n ]\n }\n },\n {\n \"name\": \"closedLoopAlarmStart\",\n \"type\": \"long\"\n },\n {\n \"name\": \"closedLoopAlarmEnd\",\n \"type\": \"long\"\n },\n {\n \"name\": \"closedLoopControlName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"version\",\n \"type\": \"string\"\n },\n {\n \"name\": \"requestID\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopEventClient\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopEventStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target_type\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target\",\n \"type\": \"string\"\n },\n {\n \"name\": \"from\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyScope\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"notification\",\n \"type\": \"string\"\n },\n {\n \"name\": \"notificationTime\",\n \"type\": \"long\"\n },\n {\n \"name\": \"message\",\n \"type\": \"string\"\n }\n ]\n}" - } - }, - { - "key": { - "name": "VirtualControlLoopEventType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VirtualControlLoopEventType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "org.onap.policy.controlloop.VirtualControlLoopEvent" - } - }, - { - "key": { - "name": "VirtualControlLoopNotificationType", - "version": "0.0.1" - }, - "value": { - "key": { - "name": "VirtualControlLoopNotificationType", - "version": "0.0.1" - }, - "schemaFlavour": "Java", - "schemaDefinition": "org.onap.policy.controlloop.VirtualControlLoopNotification" - } - } - ] - } - } -} -- cgit 1.2.3-korg