aboutsummaryrefslogtreecommitdiffstats
path: root/gui-editors
diff options
context:
space:
mode:
authorAjith Sreekumar <ajith.sreekumar@bell.ca>2020-08-10 14:33:18 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-10 14:33:18 +0000
commit864811238d7d44933df2c4f59f31947a83310587 (patch)
tree9e6bbf6894e040c20c5d5840fd1582a46ed73aae /gui-editors
parent6b61be2310929f155dcd38478df13fe1a0d81fad (diff)
parentd4dd779aa66be0e046ecb1938fb532312cfe7680 (diff)
Merge "Upload policy feature"
Diffstat (limited to 'gui-editors')
-rw-r--r--gui-editors/gui-editor-apex/pom.xml19
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java2
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java5
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParameters.java81
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java58
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResource.java83
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java2
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java182
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKey.java40
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessor.java117
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverter.java168
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ProcessedTemplate.java60
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessor.java179
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/exception/PolicyToscaConverterException.java27
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClient.java69
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDto.java40
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/css/upload/dialog.css56
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/index.html9
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js58
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js4
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js2
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js61
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js4
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html64
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java2
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java2
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParametersTest.java85
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java3
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResourceTest.java64
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessorTest.java113
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverterTest.java187
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java200
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessorTest.java216
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClientTest.java71
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/converter/APEXgRPCPolicy.json1968
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig-engineServiceParameters-notAnObject.json7
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig.json112
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/converter/ToscaTemplate.json17
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid-engineServiceParameters.json3
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid.json1
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-missing-engineServiceParameters.json6
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig.json37
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid-toscaDefinitions.json4
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid.json1
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-policies.json6
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-properties.json12
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-topologyTemplate.json4
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy1.json10
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy2.json8
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policies.json5
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policy.json6
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-properties.json15
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-topology-template.json3
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-tosca-definitions-version.json16
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-more-than-one-policy.json20
-rw-r--r--gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate.json17
56 files changed, 4595 insertions, 16 deletions
diff --git a/gui-editors/gui-editor-apex/pom.xml b/gui-editors/gui-editor-apex/pom.xml
index a065411..c209f99 100644
--- a/gui-editors/gui-editor-apex/pom.xml
+++ b/gui-editors/gui-editor-apex/pom.xml
@@ -94,11 +94,6 @@
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.onap.policy.apex-pdp.client</groupId>
<artifactId>apex-client-common</artifactId>
<version>${policy.apex-pdp.version}</version>
@@ -106,6 +101,20 @@
<type>zip</type>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-multipart</artifactId>
+ <version>${version.jersey}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
</dependencies>
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java
index 4741346..d21e305 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java
@@ -23,6 +23,7 @@ package org.onap.policy.gui.editors.apex.rest;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.onap.policy.common.utils.validation.Assertions;
import org.slf4j.ext.XLogger;
@@ -59,6 +60,7 @@ public class ApexEditor {
// Create a resource configuration that scans for JAX-RS resources and providers
final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
+ rc.register(MultiPartFeature.class);
// create and start a new instance of grizzly http server
// exposing the Jersey application at BASE_URI
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
index 481f0af..9d88a2d 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
@@ -22,6 +22,7 @@
package org.onap.policy.gui.editors.apex.rest;
import java.io.PrintStream;
+import org.onap.policy.common.parameters.ParameterService;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -85,7 +86,6 @@ public class ApexEditorMain {
throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, "
+ e.getMessage() + '\n' + parser.getHelp(ApexEditorMain.class.getName()), e);
}
-
if (parameters.isHelpSet()) {
throw new ApexEditorParameterException(parser.getHelp(ApexEditorMain.class.getName()));
}
@@ -97,6 +97,8 @@ public class ApexEditorMain {
+ validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getName()));
}
+ ParameterService.register(new UploadPluginConfigParameters());
+
state = EditorState.READY;
}
@@ -210,3 +212,4 @@ public class ApexEditorMain {
}
}
}
+
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParameters.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParameters.java
new file mode 100644
index 0000000..e330af7
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParameters.java
@@ -0,0 +1,81 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest;
+
+import java.util.Optional;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.gui.editors.apex.rest.handling.config.PolicyUploadPluginConfigKey;
+
+@Getter
+public class UploadPluginConfigParameters implements ParameterGroup {
+
+ public static final String GROUP_NAME = "UploadParameters";
+ @Setter
+ private String name;
+ private boolean isEnabled;
+ private String url;
+
+ public UploadPluginConfigParameters() {
+ this.name = GROUP_NAME;
+ initProperties();
+ }
+
+ private void initProperties() {
+ final String isEnabledProperty = System.getProperty(PolicyUploadPluginConfigKey.ENABLE.getKey());
+ isEnabled = Boolean.parseBoolean(isEnabledProperty);
+ url = System.getProperty(PolicyUploadPluginConfigKey.URL.getKey());
+ }
+
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult result = new GroupValidationResult(this);
+ if (isEnabled && StringUtils.isEmpty(url)) {
+ result.setResult("url", ValidationStatus.INVALID,
+ String.format("The URL for the upload endpoint must be provided as the java property '%s'",
+ PolicyUploadPluginConfigKey.URL.getKey()));
+ }
+
+ return result;
+ }
+
+ /**
+ * Gets a property value based on the key and type.
+ *
+ * @param <T> represents the class type
+ * @param key the property key
+ * @return the property value if it exists
+ */
+ public <T> Optional<T> getValue(final PolicyUploadPluginConfigKey key) {
+ final Class<?> type = key.getType();
+ if (key == PolicyUploadPluginConfigKey.URL && type.isInstance(url)) {
+ return (Optional<T>) Optional.of(type.cast(url));
+ }
+ if (key == PolicyUploadPluginConfigKey.ENABLE && type.isInstance(isEnabled)) {
+ return (Optional<T>) Optional.of(type.cast(isEnabled));
+ }
+ return Optional.empty();
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
index ef5c57a..33aa04d 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
@@ -22,6 +22,7 @@
package org.onap.policy.gui.editors.apex.rest.handling;
import java.io.IOException;
+import java.io.InputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -32,9 +33,18 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
+import org.glassfish.jersey.media.multipart.FormDataParam;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor;
+import org.onap.policy.gui.editors.apex.rest.handling.plugin.upload.UploadPluginClient;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -61,15 +71,16 @@ import org.slf4j.ext.XLoggerFactory;
@Path("editor/{session}")
@Produces({MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_JSON})
-
public class ApexEditorRestResource implements RestCommandHandler {
+
// Get a reference to the logger
- private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorRestResource.class);
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorRestResource.class);
// Location of the periodi event template
- private static final String PERIODIC_EVENT_TEMPLATE = "src/main/resources/templates/PeriodicEventTemplate.json";
+ private static final String PERIODIC_EVENT_TEMPLATE = "src/main/resources/templates/PeriodicEventTemplate.json";
// Recurring string constants
+
private static final String NAME = "name";
private static final String VERSION = "version";
private static final String REST_COMMAND_NOT_RECOGNISED = "REST command not recognised";
@@ -77,12 +88,12 @@ public class ApexEditorRestResource implements RestCommandHandler {
private static final String NOT_OK = ": Not OK";
private static final String SESSION_CREATE = "Session/Create";
private static final String SESSION_CREATE_NOT_OK = "Session/Create: Not OK";
-
// The session handler for sessions on the Apex editor
- private static final RestSessionHandler SESSION_HANDLER = new RestSessionHandler();
+ private static final RestSessionHandler SESSION_HANDLER = new RestSessionHandler();
// Handlers for the various parts of an Apex model
//@formatter:off
+
private static final ModelHandler MODEL_HANDLER = new ModelHandler();
private static final KeyInfoHandler KEY_INFO_HANDLER = new KeyInfoHandler();
private static final ContextSchemaHandler CONTEXT_SCHEMA_HANDLER = new ContextSchemaHandler();
@@ -90,13 +101,27 @@ public class ApexEditorRestResource implements RestCommandHandler {
private static final EventHandler EVENT_HANDLER = new EventHandler();
private static final TaskHandler TASK_HANDLER = new TaskHandler();
private static final PolicyHandler POLICY_HANDLER = new PolicyHandler();
- //@formatter:on
+ private final PolicyUploadHandler policyUploadHandler;
+ //@formatter:on
// The ID of this session. This gets injected from the URL.
+
@PathParam("session")
private int sessionId = -1;
/**
+ * Creates the ApexEditorRestResource instance.
+ */
+ public ApexEditorRestResource() {
+ final StandardCoder standardCoder = new StandardCoder();
+ policyUploadHandler = new PolicyUploadHandler(
+ new UploadPluginClient(), new PolicyToscaConverter(standardCoder, new YamlJsonTranslator()),
+ new ToscaTemplateProcessor(standardCoder), new ApexConfigProcessor(standardCoder),
+ ParameterService.get(UploadPluginConfigParameters.GROUP_NAME)
+ );
+ }
+
+ /**
* Creates a new session. Always call this method with sessionID -1, whereby a new sessionID will be allocated. If
* successful the new sessionID will be available in the first message in the result.
*
@@ -226,6 +251,27 @@ public class ApexEditorRestResource implements RestCommandHandler {
}
/**
+ * Uploads a Policy Model to a configured endpoint converting it to tosca based on the given apex config and tosca
+ * templates.
+ *
+ * @param toscaTemplateFileStream the tosca template file input stream
+ * @param apexConfigFileStream the apex config file input stream
+ * @return an ApexAPIResult that contains the operation status and success/error messages
+ */
+ @POST
+ @Path("Model/Upload")
+ @Consumes({MediaType.MULTIPART_FORM_DATA})
+ public ApexApiResult uploadModel(@FormDataParam("tosca-template-file") InputStream toscaTemplateFileStream,
+ @FormDataParam("apex-config-file") InputStream apexConfigFileStream) {
+ final ApexApiResult result = new ApexApiResult();
+ final RestSession session = SESSION_HANDLER.getSession(sessionId, result);
+ if (session == null) {
+ return result;
+ }
+ return policyUploadHandler.doUpload(session.getApexModel(), toscaTemplateFileStream, apexConfigFileStream);
+ }
+
+ /**
* Delete the model for this session.
*
* @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResource.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResource.java
new file mode 100644
index 0000000..76af06e
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResource.java
@@ -0,0 +1,83 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+import org.onap.policy.gui.editors.apex.rest.handling.config.PolicyUploadPluginConfigKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handles endpoints for the configuration properties.
+ */
+@Path("editor/config")
+@Produces({MediaType.APPLICATION_JSON})
+@Consumes({MediaType.APPLICATION_JSON})
+public class ConfigurationRestResource {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationRestResource.class);
+ private static final StandardCoder STANDARD_CODER = new StandardCoder();
+
+ private final UploadPluginConfigParameters uploadConfigParam;
+
+ public ConfigurationRestResource() {
+ uploadConfigParam = ParameterService.get(UploadPluginConfigParameters.GROUP_NAME);
+ }
+
+ /**
+ * Gets the configured properties.
+ *
+ * @return the properties as JSON in the ApexApiResult messages list.
+ */
+ @GET
+ @Path("")
+ public ApexApiResult show() {
+ final ApexApiResult result = new ApexApiResult(Result.SUCCESS);
+
+ final Map<String, Object> configMap = Stream.of(PolicyUploadPluginConfigKey.values())
+ .filter(key -> uploadConfigParam.getValue(key).isPresent())
+ .collect(Collectors.toMap(PolicyUploadPluginConfigKey::getKey,
+ configKey -> uploadConfigParam.getValue(configKey).get()));
+ try {
+ final String encode = STANDARD_CODER.encode(configMap);
+ result.addMessage(encode);
+ } catch (final CoderException e) {
+ result.setResult(Result.FAILED);
+ final String errorMsg = "Could not parse configuration parameters as JSON";
+ result.addMessage(errorMsg);
+ LOGGER.error(errorMsg, e);
+ }
+ return result;
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
index 667d771..3bedad2 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
@@ -389,7 +389,7 @@ public class ModelHandler implements RestCommandHandler {
*
* @param jsonObject the object to query
* @param fieldTag the tag of the field to condition
- * @param fieldValue the value of the field to condition
+ * @param value the default value of the field to condition
* @return field read from the json
*/
private String readFieldFromJsonObject(final JsonObject jsonObject, final String fieldTag, final String value) {
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java
new file mode 100644
index 0000000..af8d9dd
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java
@@ -0,0 +1,182 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Optional;
+import javax.ws.rs.core.Response;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+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.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ProcessedTemplate;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.exception.PolicyToscaConverterException;
+import org.onap.policy.gui.editors.apex.rest.handling.plugin.upload.UploadPluginClient;
+import org.onap.policy.gui.editors.apex.rest.handling.plugin.upload.UploadPolicyRequestDto;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * Handles the Policy Model upload.
+ */
+public class PolicyUploadHandler {
+
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(PolicyUploadHandler.class);
+ private final PolicyToscaConverter policyToscaConverter;
+ private final ToscaTemplateProcessor toscaTemplateProcessor;
+ private final ApexConfigProcessor apexConfigProcessor;
+ private final UploadPluginClient uploadPluginClient;
+ private final UploadPluginConfigParameters uploadPluginConfigParameters;
+
+ /**
+ * Creates the upload handler with its necessary dependencies.
+ *
+ * @param uploadPluginClient the UploadPluginClient instance
+ * @param policyToscaConverter the PolicyToscaConverter instance
+ * @param toscaTemplateProcessor the ToscaTemplateProcessor instance
+ * @param apexConfigProcessor the ApexConfigProcessor instance
+ * @param uploadPluginConfigParameters the Config instance
+ */
+ public PolicyUploadHandler(final UploadPluginClient uploadPluginClient,
+ final PolicyToscaConverter policyToscaConverter,
+ final ToscaTemplateProcessor toscaTemplateProcessor,
+ final ApexConfigProcessor apexConfigProcessor,
+ final UploadPluginConfigParameters uploadPluginConfigParameters) {
+ this.uploadPluginClient = uploadPluginClient;
+ this.policyToscaConverter = policyToscaConverter;
+ this.toscaTemplateProcessor = toscaTemplateProcessor;
+ this.apexConfigProcessor = apexConfigProcessor;
+ this.uploadPluginConfigParameters = uploadPluginConfigParameters;
+ }
+
+ /**
+ * Handles the policy model upload converting it to TOSCA with given template files.
+ *
+ * @param apexModel the apex model that contains the policy model
+ * @param toscaTemplateInputStream the tosca template input stream
+ * @param apexConfigInputStream the apex config input stream
+ * @return the result of the upload process
+ */
+ public ApexApiResult doUpload(final ApexModel apexModel, final InputStream toscaTemplateInputStream,
+ final InputStream apexConfigInputStream) {
+ final ProcessedTemplate processedToscaTemplate;
+ try {
+ processedToscaTemplate = toscaTemplateProcessor.process(toscaTemplateInputStream);
+ } catch (final IOException e) {
+ final ApexApiResult result = new ApexApiResult(Result.FAILED);
+ result.addThrowable(e);
+ final String errorMsg = "Could not process the tosca template file";
+ result.addMessage(errorMsg);
+ LOGGER.error(errorMsg, e);
+ return result;
+ }
+ if (!processedToscaTemplate.isValid()) {
+ return buildResponse(processedToscaTemplate);
+ }
+
+ final ProcessedTemplate processedApexConfig;
+ try {
+ processedApexConfig = apexConfigProcessor.process(apexConfigInputStream);
+ } catch (final IOException e) {
+ final ApexApiResult result = new ApexApiResult(Result.FAILED);
+ result.addThrowable(e);
+ final String errorMsg = "Could not process the apex config file";
+ result.addMessage(errorMsg);
+ LOGGER.error(errorMsg, e);
+ return result;
+ }
+ if (!processedApexConfig.isValid()) {
+ return buildResponse(processedApexConfig);
+ }
+ return doUpload(apexModel, processedToscaTemplate.getContent(), processedApexConfig.getContent());
+ }
+
+ private ApexApiResult doUpload(final ApexModel apexModel, final String toscaTemplate, final String apexConfig) {
+ LOGGER.entry();
+ if (!isUploadPluginEnabled()) {
+ final ApexApiResult apexApiResult = new ApexApiResult(Result.FAILED);
+ apexApiResult.addMessage("Upload feature is disabled");
+ return apexApiResult;
+ }
+ final AxPolicyModel policyModel = apexModel.getPolicyModel();
+ final ApexApiResult result = apexModel.listModel();
+ final UploadPolicyRequestDto uploadPolicyRequestDto = new UploadPolicyRequestDto();
+ final AxArtifactKey policyKey = policyModel.getKeyInformation().getKey();
+ final java.util.UUID uuid = policyModel.getKeyInformation().get(policyKey).getUuid();
+ uploadPolicyRequestDto
+ .setFilename(String.format("%s.%s.%s", uuid, policyKey.getName(), policyKey.getVersion()));
+ final String apexPolicy = convert(result.getMessage(), toscaTemplate, apexConfig).orElse(null);
+ if (apexPolicy == null) {
+ final ApexApiResult apexApiResult = new ApexApiResult(Result.FAILED);
+ apexApiResult.addMessage(
+ String.format("An error has occurred while uploading the converting the Policy '%s' to YAML.",
+ policyModel.getId()));
+ LOGGER.exit("Model/Upload: NOT OK");
+ return apexApiResult;
+ }
+ uploadPolicyRequestDto.setFileData(
+ Base64.getEncoder().encodeToString(apexPolicy.getBytes(StandardCharsets.UTF_8)));
+ final Response response = uploadPluginClient.upload(uploadPolicyRequestDto);
+ if (response.getStatus() == 201) {
+ final ApexApiResult apexApiResult = new ApexApiResult(Result.SUCCESS);
+ apexApiResult.addMessage(String.format("Policy '%s' uploaded successfully", policyModel.getId()));
+ LOGGER.exit("Model/Upload: OK");
+ return apexApiResult;
+ } else {
+ final ApexApiResult apexApiResult = new ApexApiResult(Result.FAILED);
+ apexApiResult.addMessage(
+ String.format("An error has occurred while uploading the Policy '%s'. Status was %s",
+ policyModel.getId(), response.getStatus()));
+ LOGGER.exit("Model/Upload: NOT OK");
+ return apexApiResult;
+ }
+ }
+
+ private ApexApiResult buildResponse(final ProcessedTemplate processedTemplate) {
+ final ApexApiResult result = new ApexApiResult(Result.SUCCESS);
+ if (!processedTemplate.isValid()) {
+ result.setResult(Result.OTHER_ERROR);
+ processedTemplate.getErrorSet().forEach(result::addMessage);
+ }
+ return result;
+ }
+
+ private boolean isUploadPluginEnabled() {
+ return uploadPluginConfigParameters.isEnabled();
+ }
+
+ private Optional<String> convert(final String apexPolicy, final String toscaTemplate, final String apexConfig) {
+ try {
+ return policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate);
+ } catch (final PolicyToscaConverterException e) {
+ LOGGER.error("Could not convert policy to TOSCA", e);
+ }
+
+ return Optional.empty();
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKey.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKey.java
new file mode 100644
index 0000000..02e23ff
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/config/PolicyUploadPluginConfigKey.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.config;
+
+import lombok.Getter;
+
+/**
+ * Represents properties related to the upload plugin.
+ */
+@Getter
+public enum PolicyUploadPluginConfigKey {
+ URL("plugin.policy.upload.url", String.class),
+ ENABLE("plugin.policy.upload.enable", Boolean.class);
+
+ private final String key;
+ private final Class<?> type;
+
+ PolicyUploadPluginConfigKey(final String key, final Class<?> type) {
+ this.key = key;
+ this.type = type;
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessor.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessor.java
new file mode 100644
index 0000000..e05b833
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessor.java
@@ -0,0 +1,117 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor.ErrorMessage.INVALID_APEX_CONFIG;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor.ErrorMessage.INVALID_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor.ErrorMessage.MISSING_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.ENGINE_SERVICE_PARAMETERS;
+
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
+import java.util.Set;
+import lombok.AllArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Process the Apex Config JSON template file.
+ */
+public class ApexConfigProcessor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApexConfigProcessor.class);
+
+ private final StandardCoder standardCoder;
+
+ public ApexConfigProcessor(final StandardCoder standardCoder) {
+ this.standardCoder = standardCoder;
+ }
+
+ /**
+ * Process the Apex Config JSON template file.
+ *
+ * @param apexConfigInputStream the input stream for the Apex Config JSON template
+ * @return the result of the processing with the read JSON and its errors.
+ */
+ public ProcessedTemplate process(final InputStream apexConfigInputStream) throws IOException {
+ final ProcessedTemplate processedTemplate = new ProcessedTemplate();
+ final String templateAsString;
+ try (final InputStream inputStream = apexConfigInputStream) {
+ templateAsString = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
+ }
+ final Set<String> errorSet = validate(templateAsString);
+ processedTemplate.setContent(templateAsString);
+ processedTemplate.addToErrors(errorSet);
+
+ return processedTemplate;
+ }
+
+ private Set<String> validate(final String apexConfig) {
+ final Set<String> errorSet = new HashSet<>();
+ final JsonObject apexConfigJson;
+ try {
+ apexConfigJson = standardCoder.decode(apexConfig, JsonObject.class);
+ } catch (final CoderException e) {
+ LOGGER.debug(INVALID_APEX_CONFIG.getMessage(), e);
+ errorSet.add(INVALID_APEX_CONFIG.getMessage());
+ return errorSet;
+ }
+
+ final JsonObject topologyTemplate;
+ try {
+ topologyTemplate = apexConfigJson.getAsJsonObject(ENGINE_SERVICE_PARAMETERS.getKey());
+ } catch (final Exception e) {
+ final String errorMsg = INVALID_ENTRY.getMessage(ENGINE_SERVICE_PARAMETERS.getKey());
+ LOGGER.debug(errorMsg, e);
+ errorSet.add(errorMsg);
+ return errorSet;
+ }
+
+ if (topologyTemplate == null) {
+ errorSet.add(MISSING_ENTRY.getMessage(ENGINE_SERVICE_PARAMETERS.getKey()));
+ return errorSet;
+ }
+
+ return errorSet;
+ }
+
+ /**
+ * Stores the possible error messages for the Apex Config template validation process.
+ */
+ @AllArgsConstructor
+ public enum ErrorMessage {
+ MISSING_ENTRY("Missing '%s' entry"),
+ INVALID_ENTRY("Invalid entry '%s' provided"),
+ INVALID_APEX_CONFIG("Invalid apex config provided");
+
+ private final String messageFormat;
+
+ public String getMessage(final String... params) {
+ return String.format(this.messageFormat, params);
+ }
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverter.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverter.java
new file mode 100644
index 0000000..0bacb24
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverter.java
@@ -0,0 +1,168 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.ENGINE_SERVICE_PARAMETERS;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.POLICIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.POLICY_TYPE_IMPL;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.PROPERTIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOPOLOGY_TEMPLATE;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import java.util.Map.Entry;
+import java.util.Optional;
+import lombok.Getter;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.exception.PolicyToscaConverterException;
+
+/**
+ * Handles the conversion from policy JSON to policy YAML.
+ */
+public class PolicyToscaConverter {
+
+ private final StandardCoder standardCoder;
+ private final YamlJsonTranslator yamlJsonTranslator;
+
+ /**
+ * Creates a policy tosca converter.
+ *
+ * @param standardCoder the encoder that will handle JSON conversions
+ * @param yamlJsonTranslator the translator that will handle YAML conversions
+ */
+ public PolicyToscaConverter(final StandardCoder standardCoder, final YamlJsonTranslator yamlJsonTranslator) {
+ this.standardCoder = standardCoder;
+ this.yamlJsonTranslator = yamlJsonTranslator;
+ }
+
+ /**
+ * Converts the policy model to TOSCA, by merging the 3 given JSON models.
+ *
+ * @param policyModelJsonString the policy model JSON
+ * @param apexConfigJsonString the apex config JSON
+ * @param toscaTemplateJsonString the base TOSCA template in JSON format
+ * @return the merged policy model in YAML format
+ * @throws PolicyToscaConverterException when a JSON string could not be parsed to JsonObject or the resulting JSON
+ * could not be parsed to YAML.
+ */
+ public Optional<String> convert(final String policyModelJsonString, final String apexConfigJsonString,
+ final String toscaTemplateJsonString) throws PolicyToscaConverterException {
+ final JsonObject apexConfigJson = decodeToJson(apexConfigJsonString);
+ final JsonObject policyModelJson = decodeToJson(policyModelJsonString);
+ final JsonObject toscaTemplateJson = decodeToJson(toscaTemplateJsonString);
+
+ final JsonObject toscaPolicyProperties = readTopologyTemplateAsJsonObject(toscaTemplateJson);
+ final JsonObject toscaPolicy = readToscaPolicyAsJsonObject(toscaPolicyProperties);
+ final JsonObject toscaProperties = readPolicyPropertiesAsJsonObject(toscaPolicy);
+
+ for (final Entry<String, JsonElement> entry : apexConfigJson.entrySet()) {
+ if (ENGINE_SERVICE_PARAMETERS.getKey().equals(entry.getKey())) {
+ final JsonObject engineServiceParameters = readEngineServiceParametersAsJsonObject(entry.getValue());
+ engineServiceParameters.add(POLICY_TYPE_IMPL.getKey(), policyModelJson);
+ }
+ toscaProperties.add(entry.getKey(), entry.getValue());
+ }
+ return Optional.ofNullable(convertToYaml(toscaTemplateJson));
+ }
+
+ private JsonObject readTopologyTemplateAsJsonObject(final JsonObject toscaTemplateJson)
+ throws PolicyToscaConverterException {
+
+ try {
+ return toscaTemplateJson.get(TOPOLOGY_TEMPLATE.getKey()).getAsJsonObject();
+ } catch (final Exception e) {
+ throw new PolicyToscaConverterException(
+ String.format("Could not read the '%s' entry in the Tosca Template", TOPOLOGY_TEMPLATE.getKey()), e);
+ }
+ }
+
+ private JsonObject readEngineServiceParametersAsJsonObject(final JsonElement engineServiceParametersEntry)
+ throws PolicyToscaConverterException {
+
+ try {
+ return engineServiceParametersEntry.getAsJsonObject();
+ } catch (final Exception e) {
+ throw new PolicyToscaConverterException(
+ String.format("Could not read the '%s' in the Apex Config", ENGINE_SERVICE_PARAMETERS.getKey()), e);
+ }
+ }
+
+ private JsonObject readToscaPolicyAsJsonObject(final JsonObject toscaPolicyProperties)
+ throws PolicyToscaConverterException {
+
+ try {
+ return toscaPolicyProperties.get(POLICIES.getKey()).getAsJsonArray().get(0).getAsJsonObject();
+ } catch (final Exception e) {
+ throw new PolicyToscaConverterException(
+ String.format("Could not read the first policy in the '%s' entry under '%s'",
+ POLICIES.getKey(), TOPOLOGY_TEMPLATE.getKey()), e);
+ }
+ }
+
+ private JsonObject readPolicyPropertiesAsJsonObject(final JsonObject toscaPolicy)
+ throws PolicyToscaConverterException {
+
+ try {
+ final String policyObjectKey = toscaPolicy.keySet().iterator().next();
+ final JsonObject policyEntry = toscaPolicy.get(policyObjectKey).getAsJsonObject();
+ return policyEntry.get(PROPERTIES.getKey()).getAsJsonObject();
+ } catch (final Exception e) {
+ throw new PolicyToscaConverterException(
+ String.format("Could not read the policy '%s' entry", PROPERTIES.getKey()), e);
+ }
+ }
+
+ private String convertToYaml(final JsonObject jsonObject) throws PolicyToscaConverterException {
+ try {
+ return yamlJsonTranslator.toYaml(jsonObject);
+ } catch (final Exception e) {
+ throw new PolicyToscaConverterException(
+ String.format("Could not convert JSON Object to YAML:%n%s", jsonObject.toString()), e);
+ }
+ }
+
+ private JsonObject decodeToJson(final String jsonString) throws PolicyToscaConverterException {
+ try {
+ return standardCoder.decode(jsonString, JsonObject.class);
+ } catch (final CoderException e) {
+ throw new PolicyToscaConverterException(
+ String.format("Could not convert JSON string to JSON:%n%s", jsonString), e);
+ }
+ }
+
+ @Getter
+ public enum ToscaKey {
+ TOPOLOGY_TEMPLATE("topology_template"),
+ TOSCA_DEFINITIONS_VERSION("tosca_definitions_version"),
+ PROPERTIES("properties"),
+ ENGINE_SERVICE_PARAMETERS("engineServiceParameters"),
+ POLICY_TYPE_IMPL("policy_type_impl"),
+ POLICIES("policies");
+
+ private final String key;
+
+ ToscaKey(final String key) {
+ this.key = key;
+ }
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ProcessedTemplate.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ProcessedTemplate.java
new file mode 100644
index 0000000..1b4bb97
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ProcessedTemplate.java
@@ -0,0 +1,60 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import java.util.HashSet;
+import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.collections4.CollectionUtils;
+
+@Getter
+@Setter
+public class ProcessedTemplate {
+
+ private String content;
+ private final Set<String> errorSet;
+
+ public ProcessedTemplate() {
+ errorSet = new HashSet<>();
+ }
+
+ /**
+ * Adds the given error messages to the errors collection.
+ *
+ * @param errorSet a set of error messages
+ */
+ public void addToErrors(final Set<String> errorSet) {
+ if (CollectionUtils.isEmpty(errorSet)) {
+ return;
+ }
+
+ this.errorSet.addAll(errorSet);
+ }
+
+ /**
+ * Checks if the processed template is valid.
+ *
+ * @return {@code true} if the content is valid, {@code false} otherwise
+ */
+ public boolean isValid() {
+ return CollectionUtils.isEmpty(errorSet);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessor.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessor.java
new file mode 100644
index 0000000..5539617
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessor.java
@@ -0,0 +1,179 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.POLICIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.PROPERTIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOPOLOGY_TEMPLATE;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOSCA_DEFINITIONS_VERSION;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.INVALID_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.INVALID_POLICY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.INVALID_TOSCA_TEMPLATE;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.MISSING_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.MISSING_POLICY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.ONLY_ONE_POLICY_ALLOWED;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
+import lombok.AllArgsConstructor;
+import org.apache.commons.io.IOUtils;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Process the TOSCA JSON template file, base for the Policy Model TOSCA conversion.
+ */
+public class ToscaTemplateProcessor {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ToscaTemplateProcessor.class);
+
+ private final StandardCoder jsonCoder;
+
+ public ToscaTemplateProcessor(final StandardCoder jsonCoder) {
+ this.jsonCoder = jsonCoder;
+ }
+
+ /**
+ * Process the TOSCA JSON template file.
+ *
+ * @param toscaTemplateInputStream the input stream for the TOSCA JSON template file
+ * @return the result of the processing with the read JSON and its errors.
+ */
+ public ProcessedTemplate process(final InputStream toscaTemplateInputStream) throws IOException {
+ final ProcessedTemplate processedTemplate = new ProcessedTemplate();
+
+ final String templateAsString;
+ try (final InputStream inputStream = toscaTemplateInputStream) {
+ templateAsString = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
+ }
+
+ final Set<String> errorSet = validate(templateAsString);
+ processedTemplate.setContent(templateAsString);
+ processedTemplate.addToErrors(errorSet);
+
+ return processedTemplate;
+ }
+
+ private Set<String> validate(final String toscaTemplate) {
+ final Set<String> errorSet = new HashSet<>();
+ final JsonObject toscaTemplateJson;
+ try {
+ toscaTemplateJson = jsonCoder.decode(toscaTemplate, JsonObject.class);
+ } catch (final CoderException e) {
+ LOGGER.debug(INVALID_TOSCA_TEMPLATE.getMessage(), e);
+ errorSet.add(INVALID_TOSCA_TEMPLATE.getMessage());
+ return errorSet;
+ }
+
+ final Optional<JsonPrimitive> toscaDefinitionVersionOpt =
+ readJsonEntry(TOSCA_DEFINITIONS_VERSION, toscaTemplateJson::getAsJsonPrimitive, errorSet);
+ if (toscaDefinitionVersionOpt.isEmpty()) {
+ return errorSet;
+ }
+
+ final Optional<JsonObject> topologyTemplate =
+ readJsonEntry(TOPOLOGY_TEMPLATE, toscaTemplateJson::getAsJsonObject, errorSet);
+ if (topologyTemplate.isEmpty()) {
+ return errorSet;
+ }
+
+ final Optional<JsonArray> policiesOpt =
+ readJsonEntry(POLICIES, topologyTemplate.get()::getAsJsonArray, errorSet);
+ if (policiesOpt.isEmpty()) {
+ return errorSet;
+ }
+ final JsonArray policies = policiesOpt.get();
+
+ if (policies.size() == 0) {
+ errorSet.add(MISSING_POLICY.getMessage());
+ return errorSet;
+ }
+
+ if (policies.size() > 1) {
+ errorSet.add(ONLY_ONE_POLICY_ALLOWED.getMessage());
+ return errorSet;
+ }
+
+ final JsonObject firstPolicy;
+ try {
+ final JsonObject firstPolicyObj = policies.get(0).getAsJsonObject();
+ firstPolicy = firstPolicyObj.entrySet().iterator().next().getValue().getAsJsonObject();
+ } catch (final Exception e) {
+ final String errorMsg = INVALID_POLICY.getMessage();
+ LOGGER.debug(errorMsg, e);
+ errorSet.add(errorMsg);
+ return errorSet;
+ }
+
+ readJsonEntry(PROPERTIES, firstPolicy::getAsJsonObject, errorSet);
+
+ return errorSet;
+ }
+
+ private <T> Optional<T> readJsonEntry(final ToscaKey toscaKey,
+ final Function<String, T> jsonFunction, final Set<String> errorSet) {
+ try {
+ final T json = jsonFunction.apply(toscaKey.getKey());
+ if (json == null) {
+ errorSet.add(MISSING_ENTRY.getMessage(toscaKey.getKey()));
+ }
+ return Optional.ofNullable(json);
+ } catch (final Exception e) {
+ final String errorMsg = INVALID_ENTRY.getMessage(toscaKey.getKey());
+ LOGGER.debug(errorMsg, e);
+ errorSet.add(errorMsg);
+ return Optional.empty();
+ }
+
+ }
+
+ /**
+ * Stores the possible error messages for the Tosca template validation process.
+ */
+ @AllArgsConstructor
+ public enum ErrorMessage {
+ MISSING_ENTRY("Missing '%s' entry"),
+ MISSING_POLICY("No policy was provided in the 'policies' list"),
+ INVALID_POLICY("Invalid policy was provided in the 'policies' list"),
+ ONLY_ONE_POLICY_ALLOWED("Only one policy entry is allowed in the 'policies' list"),
+ INVALID_TOSCA_TEMPLATE("Invalid tosca template provided"),
+ INVALID_ENTRY("Invalid entry '%s' provided"),
+ MISSING_PROPERTIES_ENTRY("Missing properties entry in '%s'");
+
+ private final String messageFormat;
+
+ public String getMessage(final String... params) {
+ return String.format(this.messageFormat, params);
+ }
+ }
+
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/exception/PolicyToscaConverterException.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/exception/PolicyToscaConverterException.java
new file mode 100644
index 0000000..a24c393
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/exception/PolicyToscaConverterException.java
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.exception;
+
+public class PolicyToscaConverterException extends Exception {
+
+ public PolicyToscaConverterException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClient.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClient.java
new file mode 100644
index 0000000..d0c97c9
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClient.java
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+
+/**
+ * Client for the Policy Model upload endpoint.
+ */
+public class UploadPluginClient {
+
+ private final Client client;
+ private final UploadPluginConfigParameters uploadConfigParam;
+
+ /**
+ * Create a upload plugin client.
+ */
+ public UploadPluginClient() {
+ this(ClientBuilder.newClient(), ParameterService.get(UploadPluginConfigParameters.GROUP_NAME));
+ }
+
+ /**
+ * Create a upload plugin client.
+ * @param client the http client
+ * @param uploadConfigParam the upload configuration parameters
+ */
+ UploadPluginClient(final Client client,
+ final UploadPluginConfigParameters uploadConfigParam) {
+ this.client = client;
+ this.uploadConfigParam = uploadConfigParam;
+ }
+
+ /**
+ * Uploads the policy to the configured endpoint.
+ *
+ * @param uploadPolicyRequestDto the policy DTO to upload
+ * @return the request response
+ */
+ public Response upload(final UploadPolicyRequestDto uploadPolicyRequestDto) {
+ return client
+ .target(uploadConfigParam.getUrl())
+ .request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(uploadPolicyRequestDto, MediaType.APPLICATION_JSON));
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDto.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDto.java
new file mode 100644
index 0000000..dbd15a0
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPolicyRequestDto.java
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import lombok.Data;
+
+/**
+ * DTO to a policy upload endpoint.
+ */
+@XmlRootElement(name = "policy")
+@XmlAccessorType(XmlAccessType.FIELD)
+@Data
+public class UploadPolicyRequestDto {
+
+ private Long id;
+ private String userId;
+ private String filename;
+ private String fileData;
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/css/upload/dialog.css b/gui-editors/gui-editor-apex/src/main/resources/webapp/css/upload/dialog.css
new file mode 100644
index 0000000..95f29b1
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/css/upload/dialog.css
@@ -0,0 +1,56 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+.upload-dialog {
+ font-size: 16px;
+ line-height: 19px;
+}
+
+.upload-dialog .ui-button {
+ position: relative;
+ display: inline-block;
+ vertical-align: middle;
+ color: #333333;
+ background-color: #ffffff;
+ border: none;
+ min-width: 60px;
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
+ border-radius: 3px;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ background-image: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.1) 100%);
+ padding: 0 8px;
+ height: 2.4rem;
+ font-size: 1.2rem;
+ white-space: nowrap;
+ text-decoration: none;
+ text-align: center;
+ cursor: pointer;
+}
+
+.upload-dialog #upload-form {
+ width: 100%;
+ font-size: 16px;
+ line-height: 19px;
+}
+
+.upload-dialog #upload-form input {
+ width: 100%;
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html b/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html
index 20a15ff..53e205e 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html
@@ -43,6 +43,8 @@
<!-- interface style -->
<link rel="stylesheet" type="text/css" href="css/interfaceAssets.css">
+<link rel="stylesheet" type="text/css" href="css/upload/dialog.css" />
+
<!-- JQuery style -->
<link rel="stylesheet" href="js/jquery-ui-1.12.1/jquery-ui.css">
@@ -82,6 +84,7 @@
<li id="menuFileNew">New <kbd>Ctrl+N</kbd></li>
<li id="menuFileOpen">Open... <kbd>Ctrl+O</kbd></li>
<li id="menuFileDownload">Download <kbd>Ctrl+S</kbd></li>
+ <li id="menuFileUpload">Upload <kbd>Ctrl+U</kbd></li>
<li id="menuFileClear">Clear<kbd>Ctrl+D</kbd></li>
<li class="divider"></li>
<li id="menuFileNewSession">New Session<kbd>Ctrl+R</kbd></li>
@@ -172,6 +175,7 @@
<!-- Dynamically created form goes here-->
</div>
</div>
+ <div id="main-dialog"></div>
</div>
<div class="placeholder">
@@ -212,7 +216,8 @@
<!-- edit area JS file -->
<script language="javascript" type="text/javascript"
src="js/edit_area/edit_area_full.js"></script>
-
+ <!-- simple jquery pub/sub library -->
+ <script type="text/javascript" src="js/lib/pubsub/ba-tiny-pubsub.min.js"></script>
<!-- Apex JS files -->
<script type="text/javascript" src="js/ApexTable.js"></script>
<script type="text/javascript" src="js/ApexContextSchemaTab.js"></script>
@@ -234,6 +239,8 @@
<script type="text/javascript" src="js/ApexNewModelForm.js"></script>
<script type="text/javascript" src="js/ApexResultForm.js"></script>
<script type="text/javascript" src="js/ApexModelHandling.js"></script>
+ <script type="text/javascript" src="js/ApexConfig.js"></script>
+ <script type="text/javascript" src="js/ApexUpload.js"></script>
<script type="text/javascript" src="js/ApexMain.js"></script>
</body>
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js
new file mode 100644
index 0000000..a7f41d2
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+const configObj = {
+ configMap: {},
+ getConfig: function (configKey) {
+ return this.configMap[configKey];
+ },
+ setConfig: function (configKey, configValue) {
+ return this.configMap[configKey] = configValue;
+ },
+ readySignal: function () {
+ $.publish("/config/ready");
+ }
+}
+
+$(document).ready(function () {
+ $("#menuFileUpload").hide();
+
+ const rootUrl = location.protocol
+ + "//"
+ + window.location.hostname
+ + (location.port ? ':' + location.port : '');
+
+ const configUrl = rootUrl + "/apexservices/editor/config";
+
+ function loadConfiguration() {
+ ajax_get(configUrl, function (data) {
+ for (let i = 0; i < data.messages.message.length; i++) {
+ const configEntry = JSON.parse(data.messages.message[i]);
+ Object.keys(configEntry).forEach(key => {
+ configObj.setConfig(key, configEntry[key]);
+ });
+ }
+ configObj.readySignal();
+ });
+ }
+
+ loadConfiguration();
+});
+
+
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js
index e8ad0de..57433d6 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js
@@ -40,10 +40,12 @@ $("#menu li").not(".emptyMessage").click(function() {
case "menuFileOpen":
files_fileOpen();
break;
-
case "menuFileDownload":
files_fileDownload();
break;
+ case "menuFileUpload":
+ uploadPlugin.openDialog();
+ break;
case "menuFileClear":
if (confirm("Clear the current model?")) {
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js
index 4904f30..c2cb45c 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexPageControl.js
@@ -27,6 +27,7 @@ function pageControl_modelMode(name, version, fileName) {
$("#menuFileNew").addClass("disabled");
$("#menuFileOpen").addClass("disabled");
$("#menuFileDownload").removeClass("disabled");
+ $("#menuFileUpload").removeClass("disabled");
$("#menuFileClear").removeClass("disabled");
$("#menuModelAnalyse").removeClass("disabled");
$("#menuModelValidate").removeClass("disabled");
@@ -77,6 +78,7 @@ function pageControl_noModelMode() {
$("#menuFileNew").removeClass("disabled");
$("#menuFileOpen").removeClass("disabled");
$("#menuFileDownload").addClass("disabled");
+ $("#menuFileUpload").addClass("disabled");
$("#menuFileClear").addClass("disabled");
$("#menuModelAnalyse").addClass("disabled");
$("#menuModelValidate").addClass("disabled");
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js
new file mode 100644
index 0000000..a71853c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js
@@ -0,0 +1,61 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+$(document).ready(function () {
+ $.subscribe("/config/ready", enableUpload);
+
+ function enableUpload() {
+ const menuFileUpload = $('#menuFileUpload');
+ const isUploadEnabled = configObj.getConfig("plugin.policy.upload.enable");
+ if (isUploadEnabled === "true" || isUploadEnabled === true) {
+ menuFileUpload.show();
+ } else {
+ menuFileUpload.hide();
+ }
+ }
+
+});
+
+const uploadPlugin = {
+ dialogDiv: $('#main-dialog'),
+ openDialog: function () {
+ this.dialogDiv.load('../upload/dialog.html');
+ },
+
+ upload: function (data, successCallback, errorCallback) {
+ const requestURL = restRootURL + "/Model/Upload";
+ $.ajax({
+ type: 'POST',
+ url: requestURL,
+ data: data,
+ contentType: false,
+ processData: false
+ }).done(function (data) {
+ pageControl_successStatus(data);
+ if (typeof successCallback === typeof Function) {
+ successCallback(data);
+ }
+ }).fail(function (jqXHR, textStatus, errorThrown) {
+ pageControl_restError(requestURL, jqXHR, textStatus, errorThrown);
+ if (typeof errorCallback === typeof Function) {
+ errorCallback(jqXHR, textStatus, errorThrown);
+ }
+ });
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js
new file mode 100644
index 0000000..635ab34
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js
@@ -0,0 +1,4 @@
+/*! Tiny Pub/Sub - v0.7.0 - 2013-01-29
+* https://github.com/cowboy/jquery-tiny-pubsub
+* Copyright (c) 2013 "Cowboy" Ben Alman; Licensed MIT */
+(function(n){var u=n({});n.subscribe=function(){u.on.apply(u,arguments)},n.unsubscribe=function(){u.off.apply(u,arguments)},n.publish=function(){u.trigger.apply(u,arguments)}})(jQuery); \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html b/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html
new file mode 100644
index 0000000..aac7762
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html
@@ -0,0 +1,64 @@
+<!--
+ ~ ============LICENSE_START=======================================================
+ ~ Copyright (C) 2020 Nordix Foundation
+ ~ ================================================================================
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ ~ SPDX-License-Identifier: Apache-2.0
+ ~ ============LICENSE_END=========================================================
+ -->
+
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Upload Policy</title>
+ <script>
+ $(document).ready(function () {
+ function upload() {
+ const data = new FormData();
+ const apexConfigFile = $('#apex-config-file')[0].files[0];
+ const toscaTemplateFile = $('#tosca-template-file')[0].files[0];
+ data.append('apex-config-file', apexConfigFile);
+ data.append('tosca-template-file', toscaTemplateFile);
+ uploadPlugin.upload(data, function () {
+ dialog.dialog("close");
+ });
+ }
+
+ const dialog = $('#inner-dialog').dialog({
+ height: 300,
+ width: 435,
+ modal: true,
+ dialogClass: 'upload-dialog',
+ buttons: {
+ "Upload": upload,
+ Cancel: function() {
+ dialog.dialog("close");
+ }
+ }
+ });
+ });
+ </script>
+</head>
+<body>
+<div id="inner-dialog" title="Upload Policy" class="upload-dialog">
+ <p>Provide the following files to compose the policy TOSCA</p>
+ <div id="upload-form">
+ <label for="apex-config-file">Apex Config</label> <br/>
+ <input id="apex-config-file" type="file" required="required" accept="application/json" class="ui-widget-content ui-corner-all"/> <br/>
+ <label for="tosca-template-file">Tosca Template</label> <br/>
+ <input id="tosca-template-file" type="file" required="required" accept="application/json" class="ui-widget-content ui-corner-all"/>
+ </div>
+</div>
+</body>
+</html> \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java
index 1dc47cd..c80b816 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/ApexEditorStartupTest.java
@@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.gui.editors.apex.rest.ApexEditorMain.EditorState;
/**
@@ -385,6 +386,7 @@ public class ApexEditorStartupTest {
* @throws InterruptedException if the test is interrupted
*/
private String runEditor(final String[] args) throws InterruptedException {
+ ParameterService.clear();
final ByteArrayOutputStream outBaStream = new ByteArrayOutputStream();
final PrintStream outStream = new PrintStream(outBaStream);
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java
index 238e3b9..60a2012 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/RestInterfaceTest.java
@@ -46,6 +46,7 @@ import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.gui.editors.apex.rest.ApexEditorMain.EditorState;
@@ -74,6 +75,7 @@ public class RestInterfaceTest {
*/
@BeforeClass
public static void setUp() throws Exception {
+ ParameterService.clear();
// Start the editor
editorMain = new ApexEditorMain(EDITOR_MAIN_ARGS, System.out);
// prevent a stray stdin value from killing the editor
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParametersTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParametersTest.java
new file mode 100644
index 0000000..3f743a7
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/UploadPluginConfigParametersTest.java
@@ -0,0 +1,85 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest;
+
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+import org.junit.Test;
+import org.onap.policy.gui.editors.apex.rest.handling.config.PolicyUploadPluginConfigKey;
+
+public class UploadPluginConfigParametersTest {
+
+ @Test
+ public void setupPropertiesTest() {
+ final String expectedUrl = "aUrl";
+ final boolean expectedEnabled = true;
+ System.setProperty(PolicyUploadPluginConfigKey.URL.getKey(), expectedUrl);
+ System.setProperty(PolicyUploadPluginConfigKey.ENABLE.getKey(), String.valueOf(expectedEnabled));
+ final UploadPluginConfigParameters uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ final String url = uploadPluginConfigParameters.getUrl();
+ final Boolean isEnabled = uploadPluginConfigParameters.isEnabled();
+ assertThat(url).isEqualTo(expectedUrl);
+ assertThat(isEnabled).isEqualTo(expectedEnabled);
+ }
+
+ @Test
+ public void testGetValue() {
+ final String expectedUrl = "aUrl";
+ final boolean expectedEnabled = true;
+ System.setProperty(PolicyUploadPluginConfigKey.URL.getKey(), expectedUrl);
+ System.setProperty(PolicyUploadPluginConfigKey.ENABLE.getKey(), String.valueOf(expectedEnabled));
+ UploadPluginConfigParameters uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ Optional<String> actualUrl = uploadPluginConfigParameters.getValue(PolicyUploadPluginConfigKey.URL);
+ assertThat(actualUrl).isPresent().contains(expectedUrl);
+ Optional<Boolean> actualEnabled = uploadPluginConfigParameters.getValue(PolicyUploadPluginConfigKey.ENABLE);
+ assertThat(actualEnabled).isPresent().contains(expectedEnabled);
+
+ System.clearProperty(PolicyUploadPluginConfigKey.URL.getKey());
+ uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ actualUrl = uploadPluginConfigParameters.getValue(PolicyUploadPluginConfigKey.URL);
+ assertThat(actualUrl).isNotPresent();
+
+ System.clearProperty(PolicyUploadPluginConfigKey.ENABLE.getKey());
+ uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ actualEnabled = uploadPluginConfigParameters.getValue(PolicyUploadPluginConfigKey.ENABLE);
+ assertThat(actualEnabled).isPresent();
+ assertThat(actualEnabled.get()).isFalse();
+ }
+
+ @Test
+ public void testValidate() {
+ final String expectedUrl = "aUrl";
+ final boolean expectedEnabled = true;
+ System.setProperty(PolicyUploadPluginConfigKey.URL.getKey(), expectedUrl);
+ System.setProperty(PolicyUploadPluginConfigKey.ENABLE.getKey(), String.valueOf(expectedEnabled));
+ UploadPluginConfigParameters uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ assertThat(uploadPluginConfigParameters.isValid()).isTrue();
+
+ System.clearProperty(PolicyUploadPluginConfigKey.URL.getKey());
+ uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ assertThat(uploadPluginConfigParameters.isValid()).isFalse();
+
+ System.clearProperty(PolicyUploadPluginConfigKey.ENABLE.getKey());
+ uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ assertThat(uploadPluginConfigParameters.isValid()).isTrue();
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java
index 934ca7e..9b0ce32 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResourceTest.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
@@ -43,7 +44,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
public class ApexEditorRestResourceTest extends JerseyTest {
@Override
protected Application configure() {
- return new ResourceConfig(ApexEditorRestResource.class);
+ return new ResourceConfig(ApexEditorRestResource.class).register(MultiPartFeature.class);
}
@Test
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResourceTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResourceTest.java
new file mode 100644
index 0000000..3820240
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/ConfigurationRestResourceTest.java
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+import org.onap.policy.gui.editors.apex.rest.handling.config.PolicyUploadPluginConfigKey;
+
+public class ConfigurationRestResourceTest extends JerseyTest {
+
+ private String anUrl;
+ private Boolean isEnabled;
+
+ @Override
+ protected Application configure() {
+ anUrl = "url";
+ isEnabled = true;
+ System.setProperty(PolicyUploadPluginConfigKey.URL.getKey(), anUrl);
+ System.setProperty(PolicyUploadPluginConfigKey.ENABLE.getKey(), String.valueOf(isEnabled));
+ final UploadPluginConfigParameters uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ ParameterService.clear();
+ ParameterService.register(uploadPluginConfigParameters);
+ return new ResourceConfig(ConfigurationRestResource.class);
+ }
+
+ @Test
+ public void testShowSuccess() {
+ final Response response = target("/editor/config").request().get();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ final ApexApiResult apexApiResult = response.readEntity(ApexApiResult.class);
+ assertEquals(Result.SUCCESS, apexApiResult.getResult());
+ final String message = apexApiResult.getMessage();
+ assertThat(message).contains(String.format("\"%s\":\"%s\"", PolicyUploadPluginConfigKey.URL.getKey(), anUrl))
+ .contains(String.format("\"%s\":%s", PolicyUploadPluginConfigKey.ENABLE.getKey(), isEnabled));
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessorTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessorTest.java
new file mode 100644
index 0000000..a12f7e1
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ApexConfigProcessorTest.java
@@ -0,0 +1,113 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.is;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor.ErrorMessage.INVALID_APEX_CONFIG;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor.ErrorMessage.INVALID_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ApexConfigProcessor.ErrorMessage.MISSING_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.ENGINE_SERVICE_PARAMETERS;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+public class ApexConfigProcessorTest {
+
+ private final ApexConfigProcessor apexConfigProcessor = new ApexConfigProcessor(new StandardCoder());
+ private final Path testResourcesPath = Paths.get("src", "test", "resources", "processor");
+
+ @Test
+ public void testProcessSuccess() throws IOException {
+ final String fileName = "ApexConfig.json";
+ final ProcessedTemplate process;
+ try (final FileInputStream fileInputStream = readFileAsStream(fileName)) {
+ process = apexConfigProcessor.process(fileInputStream);
+ }
+ assertThat("Template should be valid", process.isValid(), is(true));
+ final String expectedContent = readFileAsString(fileName);
+ assertThat("Content should be the same", process.getContent(), is(expectedContent));
+ }
+
+ @Test
+ public void testProcessMissingPoliciesEntry() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ApexConfig-missing-engineServiceParameters.json")) {
+ processedTemplate = apexConfigProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(MISSING_ENTRY.getMessage(ENGINE_SERVICE_PARAMETERS.getKey())));
+ }
+
+ @Test
+ public void testProcessInvalidToscaTemplate() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ApexConfig-invalid.json")) {
+ processedTemplate = apexConfigProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_APEX_CONFIG.getMessage()));
+ }
+
+ @Test
+ public void testProcessInvalidEngineServiceParameters() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ApexConfig-invalid-engineServiceParameters.json")) {
+ processedTemplate = apexConfigProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_ENTRY.getMessage(ENGINE_SERVICE_PARAMETERS.getKey())));
+ }
+
+ private void assertProcessedTemplate(final ProcessedTemplate process, boolean isValid,
+ final List<String> expectedErrorList) {
+
+ assertThat("Template should be valid", process.isValid(), is(isValid));
+ if (isValid || expectedErrorList == null) {
+ return;
+ }
+ assertThat("Should contains the expected quantity of errors",
+ process.getErrorSet().size(), is(expectedErrorList.size()));
+ expectedErrorList
+ .forEach(errorMsg -> assertThat("Should contains a specific error message", process.getErrorSet(),
+ contains(errorMsg)));
+ }
+
+ private FileInputStream readFileAsStream(final String fileName) throws FileNotFoundException {
+ final Path path = Paths.get(testResourcesPath.toString(), fileName);
+ return new FileInputStream(path.toFile());
+ }
+
+ private String readFileAsString(final String fileName) throws IOException {
+ final Path path = Paths.get(testResourcesPath.toString(), fileName);
+ return Files.readString(path);
+ }
+
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverterTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverterTest.java
new file mode 100644
index 0000000..ecf896e
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyToscaConverterTest.java
@@ -0,0 +1,187 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.ENGINE_SERVICE_PARAMETERS;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.POLICIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.POLICY_TYPE_IMPL;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.PROPERTIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOPOLOGY_TEMPLATE;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOSCA_DEFINITIONS_VERSION;
+
+import com.google.gson.JsonObject;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.exception.PolicyToscaConverterException;
+
+public class PolicyToscaConverterTest {
+
+ @Spy
+ private final StandardCoder standardCoder = new StandardCoder();
+ @Spy
+ private final YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
+ @InjectMocks
+ private PolicyToscaConverter policyToscaConverter;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testConvertSuccess() throws IOException, PolicyToscaConverterException, CoderException {
+ final String apexConfig = readResourceFileToString(Paths.get("converter", "ApexConfig.json"));
+ final String apexPolicy = readResourceFileToString(Paths.get("converter", "APEXgRPCPolicy.json"));
+ final String toscaTemplate = readResourceFileToString(Paths.get("converter", "ToscaTemplate.json"));
+ final Optional<String> convert = policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate);
+ assertTrue(convert.isPresent());
+ final String convertedYaml = convert.get();
+ final StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
+ @SuppressWarnings("unchecked") final Map<String, Object> yamlAsMap =
+ standardYamlCoder.decode(convertedYaml, Map.class);
+ assertThat(yamlAsMap).containsKeys(TOSCA_DEFINITIONS_VERSION.getKey(), TOPOLOGY_TEMPLATE.getKey());
+ @SuppressWarnings("unchecked") final Map<String, Object> topology_template =
+ (Map<String, Object>) yamlAsMap.get(TOPOLOGY_TEMPLATE.getKey());
+ assertThat(topology_template).containsKey(POLICIES.getKey());
+ @SuppressWarnings("unchecked") final List<Object> policies =
+ (List<Object>) topology_template.get(POLICIES.getKey());
+ assertEquals(1, policies.size());
+ @SuppressWarnings("unchecked") final Map<String, Object> firstPolicyMap = (Map<String, Object>) policies.get(0);
+ assertEquals(1, firstPolicyMap.keySet().size());
+ @SuppressWarnings("unchecked") final Map<String, Object> firstPolicy =
+ (Map<String, Object>) firstPolicyMap.get(firstPolicyMap.keySet().iterator().next());
+ assertThat(firstPolicy).containsKey(PROPERTIES.getKey());
+ @SuppressWarnings("unchecked") final Map<String, Object> propertiesMap =
+ (Map<String, Object>) firstPolicy.get(PROPERTIES.getKey());
+ assertThat(propertiesMap).containsKey(ENGINE_SERVICE_PARAMETERS.getKey());
+ @SuppressWarnings("unchecked") final Map<String, Object> engineServiceParametersProperty =
+ (Map<String, Object>) propertiesMap.get(ENGINE_SERVICE_PARAMETERS.getKey());
+ assertThat(engineServiceParametersProperty).containsKey(POLICY_TYPE_IMPL.getKey());
+ }
+
+ @Test
+ public void testConvertInvalidJsonDecode() throws CoderException {
+ final String invalidJson = "this is an invalid JSON";
+ doThrow(CoderException.class).when(standardCoder).decode(eq(invalidJson), eq(JsonObject.class));
+
+ final String expectedMsg = String.format("Could not convert JSON string to JSON:\n%s", invalidJson);
+ assertThatThrownBy(() -> policyToscaConverter.convert(invalidJson, invalidJson, invalidJson))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessage(expectedMsg);
+ }
+
+ @Test
+ public void testConvertInvalidJsonEncodeToString() throws IOException {
+ final String apexConfig = readResourceFileToString(Paths.get("converter", "ApexConfig.json"));
+ final String apexPolicy = readResourceFileToString(Paths.get("converter", "APEXgRPCPolicy.json"));
+ final String toscaTemplate = readResourceFileToString(Paths.get("converter", "ToscaTemplate.json"));
+
+ doThrow(RuntimeException.class).when(yamlJsonTranslator).toYaml(any(JsonObject.class));
+
+ assertThatThrownBy(() -> policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessageContaining("Could not convert JSON Object to YAML:");
+ }
+
+ @Test
+ public void testCouldNotReadFirstPolicy() throws IOException {
+ final String apexConfig = readResourceFileToString(Paths.get("converter", "ApexConfig.json"));
+ final String apexPolicy = readResourceFileToString(Paths.get("converter", "APEXgRPCPolicy.json"));
+ final String toscaTemplate1 =
+ readResourceFileToString(Paths.get("processor", "ToscaTemplate-missing-policies.json"));
+ final String expectedError =
+ String.format("Could not read the first policy in the '%s' entry under '%s'",
+ POLICIES.getKey(), TOPOLOGY_TEMPLATE.getKey());
+
+ assertThatThrownBy(() -> policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate1))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessage(expectedError);
+ final String toscaTemplate2 =
+ readResourceFileToString(Paths.get("processor", "ToscaTemplate-missing-policy.json"));
+
+ assertThatThrownBy(() -> policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate2))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessage(expectedError);
+ }
+
+ @Test
+ public void testCouldNotReadPolicyProperties() throws IOException {
+ final String apexConfig = readResourceFileToString(Paths.get("converter", "ApexConfig.json"));
+ final String apexPolicy = readResourceFileToString(Paths.get("converter", "APEXgRPCPolicy.json"));
+ final String toscaTemplate =
+ readResourceFileToString(Paths.get("processor", "ToscaTemplate-missing-properties.json"));
+ assertThatThrownBy(() -> policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessage(String.format("Could not read the policy '%s' entry", PROPERTIES.getKey()));
+ }
+
+ @Test
+ public void testCouldNotReadEngineServiceParameters() throws IOException {
+ final String apexConfig =
+ readResourceFileToString(Paths.get("converter", "ApexConfig-engineServiceParameters-notAnObject.json"));
+ final String apexPolicy = readResourceFileToString(Paths.get("converter", "APEXgRPCPolicy.json"));
+ final String toscaTemplate =
+ readResourceFileToString(Paths.get("converter", "ToscaTemplate.json"));
+ assertThatThrownBy(() -> policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessage(
+ String.format("Could not read the '%s' in the Apex Config", ENGINE_SERVICE_PARAMETERS.getKey()));
+ }
+
+ @Test
+ public void testCouldNotReadTopologyTemplate() throws IOException {
+ final String apexConfig = readResourceFileToString(Paths.get("converter", "ApexConfig.json"));
+ final String apexPolicy = readResourceFileToString(Paths.get("converter", "APEXgRPCPolicy.json"));
+ final String toscaTemplate =
+ readResourceFileToString(Paths.get("processor", "ToscaTemplate-missing-topology-template.json"));
+ assertThatThrownBy(() -> policyToscaConverter.convert(apexPolicy, apexConfig, toscaTemplate))
+ .isInstanceOf(PolicyToscaConverterException.class)
+ .hasMessage(
+ String.format("Could not read the '%s' entry in the Tosca Template", TOPOLOGY_TEMPLATE.getKey()));
+ }
+
+ private String readResourceFileToString(final Path filePathFromResources) throws IOException {
+ final Path resourceDirectory = Paths.get("src", "test", "resources");
+ final Path converter = Paths.get(resourceDirectory.toString(), filePathFromResources.toString());
+ return Files.readString(converter);
+ }
+
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java
new file mode 100644
index 0000000..7a6ead7
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java
@@ -0,0 +1,200 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import javax.ws.rs.core.Response;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+import org.onap.policy.gui.editors.apex.rest.handling.PolicyUploadHandler;
+import org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.exception.PolicyToscaConverterException;
+import org.onap.policy.gui.editors.apex.rest.handling.plugin.upload.UploadPluginClient;
+import org.onap.policy.gui.editors.apex.rest.handling.plugin.upload.UploadPolicyRequestDto;
+
+public class PolicyUploadHandlerTest {
+
+ @Mock
+ private PolicyToscaConverter policyToscaConverter;
+ @Mock
+ private ToscaTemplateProcessor toscaTemplateProcessor;
+ @Mock
+ private ApexConfigProcessor apexConfigProcessor;
+ @Mock
+ private UploadPluginClient uploadPluginClient;
+ @Mock
+ private UploadPluginConfigParameters config;
+
+ @InjectMocks
+ private PolicyUploadHandler policyUploadHandler;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ when(config.isEnabled()).thenReturn(true);
+ }
+
+ @Test
+ public void doUploadResponseSuccessAndFail() throws PolicyToscaConverterException, IOException {
+ final ApexModel apexModel = mockApexModel();
+ final ProcessedTemplate processedToscaTemplate = new ProcessedTemplate();
+ processedToscaTemplate.setContent("tosca");
+ final ProcessedTemplate processedApexConfig = new ProcessedTemplate();
+ processedApexConfig.setContent("apexConfig");
+ when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(processedToscaTemplate);
+ when(apexConfigProcessor.process(any(InputStream.class))).thenReturn(processedApexConfig);
+ when(policyToscaConverter.convert(eq("policy\n"), eq("apexConfig"), eq("tosca")))
+ .thenReturn(Optional.of("test"));
+ when(uploadPluginClient.upload(any(UploadPolicyRequestDto.class)))
+ .thenReturn(Response.ok().status(201).build());
+
+ ApexApiResult apexApiResult = policyUploadHandler
+ .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class));
+
+ assertThat("Response should be ok", apexApiResult.isOk(), is(true));
+ String expectedSuccessMsg =
+ String.format("Policy '%s' uploaded successfully", apexModel.getPolicyModel().getId());
+ assertThat("Response message should be as expected",
+ apexApiResult.getMessage(), is(expectedSuccessMsg + "\n"));
+
+ when(uploadPluginClient.upload(any(UploadPolicyRequestDto.class)))
+ .thenReturn(Response.serverError().build());
+
+ apexApiResult = policyUploadHandler
+ .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class));
+
+ assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
+ expectedSuccessMsg =
+ String.format("An error has occurred while uploading the Policy '%s'. Status was %s",
+ apexModel.getPolicyModel().getId(), 500);
+ assertThat("Response message should be as expected",
+ apexApiResult.getMessage(), is(expectedSuccessMsg + "\n"));
+ }
+
+ @Test
+ public void doUploadPluginDisabled() throws IOException {
+ when(config.isEnabled()).thenReturn(false);
+
+ final ProcessedTemplate processedToscaTemplate = new ProcessedTemplate();
+ final ProcessedTemplate processedApexConfig = new ProcessedTemplate();
+ when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(processedToscaTemplate);
+ when(apexConfigProcessor.process(any(InputStream.class))).thenReturn(processedApexConfig);
+ final ApexApiResult apexApiResult = policyUploadHandler
+ .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class));
+
+ assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
+ assertThat("Response message should be as expected",
+ apexApiResult.getMessage(), is("Upload feature is disabled\n"));
+ }
+
+ @Test
+ public void doUploadInvalidToscaTemplate() throws IOException {
+ when(config.isEnabled()).thenReturn(false);
+
+ final ProcessedTemplate processedToscaTemplate = new ProcessedTemplate();
+ final String errorMsg = "an error";
+ processedToscaTemplate.addToErrors(Collections.singleton(errorMsg));
+ when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(processedToscaTemplate);
+ final ApexApiResult apexApiResult = policyUploadHandler
+ .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class));
+
+ assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
+ assertThat("Response message should be as expected",
+ apexApiResult.getMessage(), is(errorMsg + "\n"));
+ }
+
+ @Test
+ public void doUploadInvalidApexConfigTemplate() throws IOException {
+ when(config.isEnabled()).thenReturn(false);
+
+ when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(new ProcessedTemplate());
+ final ProcessedTemplate processedApexConfig = new ProcessedTemplate();
+ final String errorMsg = "an error";
+ processedApexConfig.addToErrors(Collections.singleton(errorMsg));
+ when(apexConfigProcessor.process(any(InputStream.class))).thenReturn(processedApexConfig);
+ final ApexApiResult apexApiResult = policyUploadHandler
+ .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class));
+
+ assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
+ assertThat("Response message should be as expected",
+ apexApiResult.getMessage(), is(errorMsg + "\n"));
+ }
+
+ @Test
+ public void doUploadConversionFailed() throws PolicyToscaConverterException, IOException {
+ final ApexModel apexModel = mockApexModel();
+ final ProcessedTemplate processedToscaTemplate = new ProcessedTemplate();
+ processedToscaTemplate.setContent("tosca");
+ final ProcessedTemplate processedApexConfig = new ProcessedTemplate();
+ processedApexConfig.setContent("apexConfig");
+ when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(processedToscaTemplate);
+ when(apexConfigProcessor.process(any(InputStream.class))).thenReturn(processedApexConfig);
+ when(policyToscaConverter.convert(eq("policy\n"), eq("apexConfig"), eq("tosca")))
+ .thenThrow(PolicyToscaConverterException.class);
+ when(uploadPluginClient.upload(any(UploadPolicyRequestDto.class)))
+ .thenReturn(Response.ok().status(201).build());
+
+ final ApexApiResult apexApiResult = policyUploadHandler
+ .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class));
+
+ assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
+ final String expectedErrorMsg = String
+ .format("An error has occurred while uploading the converting the Policy '%s' to YAML.",
+ apexModel.getPolicyModel().getId());
+ assertThat("Response message should be as expected",
+ apexApiResult.getMessage(), is(expectedErrorMsg + "\n"));
+ }
+
+ private ApexModel mockApexModel() {
+ final ApexModel apexModel = mock(ApexModel.class);
+ final ApexApiResult listModelApexApiResult = new ApexApiResult();
+ listModelApexApiResult.addMessage("policy");
+ when(apexModel.listModel()).thenReturn(listModelApexApiResult);
+ final AxPolicyModel axPolicyModel = new AxPolicyModel();
+ final AxArtifactKey axArtifactKey = new AxArtifactKey("policyKey", "1.0.0");
+ final Map<AxArtifactKey, AxKeyInfo> keyInfoMap = new HashMap<>();
+ keyInfoMap.put(axArtifactKey, new AxKeyInfo(axArtifactKey));
+ final AxKeyInformation axKeyInformation = new AxKeyInformation(axArtifactKey, keyInfoMap);
+ axPolicyModel.setKeyInformation(axKeyInformation);
+ when(apexModel.getPolicyModel()).thenReturn(axPolicyModel);
+ return apexModel;
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessorTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessorTest.java
new file mode 100644
index 0000000..461b26e
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/ToscaTemplateProcessorTest.java
@@ -0,0 +1,216 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.converter.tosca;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.is;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.POLICIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.PROPERTIES;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOPOLOGY_TEMPLATE;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.PolicyToscaConverter.ToscaKey.TOSCA_DEFINITIONS_VERSION;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.INVALID_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.INVALID_POLICY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.INVALID_TOSCA_TEMPLATE;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.MISSING_ENTRY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.MISSING_POLICY;
+import static org.onap.policy.gui.editors.apex.rest.handling.converter.tosca.ToscaTemplateProcessor.ErrorMessage.ONLY_ONE_POLICY_ALLOWED;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.StandardCoder;
+
+public class ToscaTemplateProcessorTest {
+
+ private final ToscaTemplateProcessor toscaTemplateProcessor = new ToscaTemplateProcessor(new StandardCoder());
+ private final Path testResourcesPath = Paths.get("src", "test", "resources", "processor");
+
+ @Test
+ public void testProcessSuccess() throws IOException {
+ final String fileName = "ToscaTemplate.json";
+ final ProcessedTemplate process;
+ try (final FileInputStream fileInputStream = readFileAsStream(fileName)) {
+ process = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertThat("Template should be valid", process.isValid(), is(true));
+ final String expectedContent = readFileAsString(fileName);
+ assertThat("Content should be the same", process.getContent(), is(expectedContent));
+ }
+
+ @Test
+ public void testProcessMissingPoliciesEntry() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-missing-policies.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false, List.of(MISSING_ENTRY.getMessage(POLICIES.getKey())));
+ }
+
+ @Test
+ public void testProcessMissingTopologyTemplate() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-missing-topology-template.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(MISSING_ENTRY.getMessage(TOPOLOGY_TEMPLATE.getKey())));
+ }
+
+ @Test
+ public void testProcessMissingPolicy() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-missing-policy.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false, List.of(MISSING_POLICY.getMessage()));
+ }
+
+ @Test
+ public void testProcessMissingToscaDefinitionsVersion() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ToscaTemplate-missing-tosca-definitions-version.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(MISSING_ENTRY.getMessage(TOSCA_DEFINITIONS_VERSION.getKey())));
+ }
+
+ @Test
+ public void testProcessMissingProperties() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-missing-properties.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(MISSING_ENTRY.getMessage(PROPERTIES.getKey())));
+ }
+
+ @Test
+ public void testProcessMoreThanOnePolicy() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-more-than-one-policy.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(ONLY_ONE_POLICY_ALLOWED.getMessage()));
+ }
+
+ @Test
+ public void testProcessInvalidToscaTemplate() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-invalid.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_TOSCA_TEMPLATE.getMessage()));
+ }
+
+ @Test
+ public void testProcessInvalidEntryToscaDefinitionsVersion() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ToscaTemplate-invalid-toscaDefinitions.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_ENTRY.getMessage(TOSCA_DEFINITIONS_VERSION.getKey())));
+ }
+
+ @Test
+ public void testProcessInvalidEntryTopologyTemplate() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ToscaTemplate-invalidEntry-topologyTemplate.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_ENTRY.getMessage(TOPOLOGY_TEMPLATE.getKey())));
+ }
+
+ @Test
+ public void testProcessInvalidEntryPolicies() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ToscaTemplate-invalidEntry-policies.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_ENTRY.getMessage(POLICIES.getKey())));
+ }
+
+ @Test
+ public void testProcessInvalidPolicy() throws IOException {
+ ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-invalidPolicy1.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_POLICY.getMessage()));
+
+ try (final FileInputStream fileInputStream = readFileAsStream("ToscaTemplate-invalidPolicy2.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_POLICY.getMessage()));
+ }
+
+ @Test
+ public void testProcessInvalidEntryProperties() throws IOException {
+ final ProcessedTemplate processedTemplate;
+ try (final FileInputStream fileInputStream =
+ readFileAsStream("ToscaTemplate-invalidEntry-properties.json")) {
+ processedTemplate = toscaTemplateProcessor.process(fileInputStream);
+ }
+ assertProcessedTemplate(processedTemplate, false,
+ List.of(INVALID_ENTRY.getMessage(PROPERTIES.getKey())));
+ }
+
+
+ private void assertProcessedTemplate(final ProcessedTemplate process, boolean isValid,
+ final List<String> expectedErrorList) {
+ assertThat("Template should be valid", process.isValid(), is(isValid));
+ if (isValid || expectedErrorList == null) {
+ return;
+ }
+ assertThat("Should contains the expected quantity of errors",
+ process.getErrorSet().size(), is(expectedErrorList.size()));
+ expectedErrorList
+ .forEach(errorMsg -> assertThat("Should contains a specific error message", process.getErrorSet(),
+ contains(errorMsg)));
+ }
+
+ private FileInputStream readFileAsStream(final String fileName) throws FileNotFoundException {
+ final Path path = Paths.get(testResourcesPath.toString(), fileName);
+ return new FileInputStream(path.toFile());
+ }
+
+ private String readFileAsString(final String fileName) throws IOException {
+ final Path path = Paths.get(testResourcesPath.toString(), fileName);
+ return Files.readString(path);
+ }
+
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClientTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClientTest.java
new file mode 100644
index 0000000..ab9445e
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/UploadPluginClientTest.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.plugin.upload;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
+import org.onap.policy.gui.editors.apex.rest.handling.config.PolicyUploadPluginConfigKey;
+
+public class UploadPluginClientTest {
+
+ private UploadPluginClient uploadPluginClient;
+
+ @Mock
+ private Client client;
+
+ private static final String url = "aUrl";
+
+ /**
+ * Init the mocks and system properties.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ System.setProperty(PolicyUploadPluginConfigKey.URL.getKey(), url);
+ final UploadPluginConfigParameters uploadPluginConfigParameters = new UploadPluginConfigParameters();
+ uploadPluginClient = new UploadPluginClient(client, uploadPluginConfigParameters);
+ }
+
+ @Test
+ public void upload() {
+ final Builder mockBuilder = mock(Builder.class);
+ final WebTarget mockWebTarget = mock(WebTarget.class);
+ final Response mockResponse = mock(Response.class);
+ doReturn(mockWebTarget).when(client).target(url);
+ doReturn(mockBuilder).when(mockWebTarget).request(MediaType.APPLICATION_JSON);
+ when(mockBuilder.post(any())).thenReturn(mockResponse);
+ final Response actualResponse = uploadPluginClient.upload(new UploadPolicyRequestDto());
+ assertEquals(mockResponse, actualResponse);
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/converter/APEXgRPCPolicy.json b/gui-editors/gui-editor-apex/src/test/resources/converter/APEXgRPCPolicy.json
new file mode 100644
index 0000000..25ad71d
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/converter/APEXgRPCPolicy.json
@@ -0,0 +1,1968 @@
+{
+ "apexPolicyModel" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy",
+ "version" : "0.0.1"
+ },
+ "keyInformation" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_KeyInfo",
+ "version" : "0.0.1"
+ },
+ "keyInfoMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "APEXgRPCPolicy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy",
+ "version" : "0.0.1"
+ },
+ "UUID" : "b8424cdb-29fb-3566-b77a-f4f847d81cc9",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Albums",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Albums",
+ "version" : "0.0.1"
+ },
+ "UUID" : "9922906c-ccaa-34f7-95e2-bcc36e77821b",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy_Albums:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Events",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Events",
+ "version" : "0.0.1"
+ },
+ "UUID" : "5bf28afd-787c-3138-a3e1-b33ad94a038a",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy_Events:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "APEXgRPCPolicy_KeyInfo",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_KeyInfo",
+ "version" : "0.0.1"
+ },
+ "UUID" : "68abaa6f-8d03-3a53-9590-007115817d5c",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy_KeyInfo:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Policies",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Policies",
+ "version" : "0.0.1"
+ },
+ "UUID" : "819d06c3-33c2-3031-aa78-96281aa4270a",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy_Policies:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Schemas",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Schemas",
+ "version" : "0.0.1"
+ },
+ "UUID" : "8e67d466-f990-3a39-9fd7-4490cac342dc",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy_Schemas:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Tasks",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Tasks",
+ "version" : "0.0.1"
+ },
+ "UUID" : "4668db3d-6fe2-3885-8e47-f30cd0102f0a",
+ "description" : "Generated description for concept referred to by key \"APEXgRPCPolicy_Tasks:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "6e5fa19b-14df-37e3-a4ae-8c537e861a82",
+ "description" : "Generated description for concept referred to by key \"CDSActionIdentifiersType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "8350ac5e-c157-38b9-9614-a0f93a830e60",
+ "description" : "Generated description for concept referred to by key \"CDSCreateSubscriptionPayloadType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "12658406-9147-3c9d-a38c-5ad5e30b092b",
+ "description" : "Generated description for concept referred to by key \"CDSDeleteSubscriptionPayloadType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "35590ac0-062c-39f1-8786-b4ff716e30b1",
+ "description" : "Generated description for concept referred to by key \"CDSRequestCommonHeaderType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "dd7e1805-885a-350b-aaf9-ed541321ae3c",
+ "description" : "Generated description for concept referred to by key \"CDSResponseCommonHeaderType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "15161037-9ac8-3223-820f-4e743562a345",
+ "description" : "Generated description for concept referred to by key \"CDSResponseEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponsePayloadType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponsePayloadType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "97dc5f58-25bb-3c20-8d53-fdb70d7ca256",
+ "description" : "Generated description for concept referred to by key \"CDSResponsePayloadType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponsePolicy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponsePolicy",
+ "version" : "0.0.1"
+ },
+ "UUID" : "c28b05a8-7436-3ac0-82ca-6d5fc18c9584",
+ "description" : "Generated description for concept referred to by key \"CDSResponsePolicy:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseStatusEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseStatusEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "7986e21b-32f7-302e-9554-31f21b673493",
+ "description" : "Generated description for concept referred to by key \"CDSResponseStatusEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseStatusType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseStatusType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "92b8a2cf-344e-3ce1-8cc0-2b7d3cb695fa",
+ "description" : "Generated description for concept referred to by key \"CDSResponseStatusType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseTask",
+ "version" : "0.0.1"
+ },
+ "UUID" : "d22c78a5-272c-391d-8083-28588280caf9",
+ "description" : "Generated description for concept referred to by key \"CDSResponseTask:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "92162397-1a8e-3a3f-a469-d2af7700af4a",
+ "description" : "Generated description for concept referred to by key \"CreateSubscriptionPayloadEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "UUID" : "bc0c69f0-52ed-38ea-b468-ae4a6fd1730d",
+ "description" : "Generated description for concept referred to by key \"CreateSubscriptionPayloadTask:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "7cfcf843-337e-3f41-b755-5043cb0a08fc",
+ "description" : "Generated description for concept referred to by key \"CreateSubscriptionRequestEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "UUID" : "89cb75e9-f06c-30d3-b4ff-698d45f63869",
+ "description" : "Generated description for concept referred to by key \"CreateSubscriptionRequestTask:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "994fa441-04ab-33bb-832d-1cd12ab5d074",
+ "description" : "Generated description for concept referred to by key \"DeleteSubscriptionPayloadEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "UUID" : "0f519117-5fea-3e4b-941f-8f778100465f",
+ "description" : "Generated description for concept referred to by key \"DeleteSubscriptionPayloadTask:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "15d618d8-1689-3a05-89a5-05efa9388f65",
+ "description" : "Generated description for concept referred to by key \"DeleteSubscriptionRequestEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "UUID" : "acb772fe-d442-39e3-98f9-b1080caf4150",
+ "description" : "Generated description for concept referred to by key \"DeleteSubscriptionRequestTask:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ },
+ "UUID" : "c2bd6f0d-6854-317a-9be2-97c08338428c",
+ "description" : "Generated description for concept referred to by key \"PMSubscriptionAlbum:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "PMSubscriptionOutputEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PMSubscriptionOutputEvent",
+ "version" : "0.0.1"
+ },
+ "UUID" : "992b7819-9f69-3aa0-bb0f-6e45ea15ce05",
+ "description" : "Generated description for concept referred to by key \"PMSubscriptionOutputEvent:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "PMSubscriptionType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PMSubscriptionType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "73c1c397-4fc3-357f-93b6-a8ad707fbaae",
+ "description" : "Generated description for concept referred to by key \"PMSubscriptionType: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" : "ReceivePMSubscriptionTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "ReceivePMSubscriptionTask",
+ "version" : "0.0.1"
+ },
+ "UUID" : "6c1c6c45-26e0-3591-94bf-679d20e283f4",
+ "description" : "Generated description for concept referred to by key \"ReceivePMSubscriptionTask:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "SimpleIntType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SimpleIntType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "153791fd-ae0a-36a7-88a5-309a7936415d",
+ "description" : "Generated description for concept referred to by key \"SimpleIntType: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" : "SubscriptionStatusType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SubscriptionStatusType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "597643b1-9db1-31ce-85d0-e1c63c43b30b",
+ "description" : "Generated description for concept referred to by key \"SubscriptionStatusType:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "SubscriptionType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SubscriptionType",
+ "version" : "0.0.1"
+ },
+ "UUID" : "184547bb-7d64-3cb2-a273-d7185102c5ce",
+ "description" : "Generated description for concept referred to by key \"SubscriptionType: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" : "testPolicyB",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "testPolicyB",
+ "version" : "0.0.1"
+ },
+ "UUID" : "ead590a3-ba2e-3a01-b6e9-9329f5c8fee1",
+ "description" : "Generated description for concept referred to by key \"testPolicyB:0.0.1\""
+ }
+ } ]
+ }
+ },
+ "policies" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Policies",
+ "version" : "0.0.1"
+ },
+ "policyMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CDSResponsePolicy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "policyKey" : {
+ "name" : "CDSResponsePolicy",
+ "version" : "0.0.1"
+ },
+ "template" : "Freestyle",
+ "state" : {
+ "entry" : [ {
+ "key" : "CDSResponseState",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "CDSResponsePolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "CDSResponseState"
+ },
+ "trigger" : {
+ "name" : "CDSResponseEvent",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "ResponseOutput",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "CDSResponsePolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CDSResponseState",
+ "localName" : "ResponseOutput"
+ },
+ "outgoingEvent" : {
+ "name" : "CDSResponseStatusEvent",
+ "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" : "CDSResponseTask",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CDSResponseTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "CDSResponsePolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CDSResponseState",
+ "localName" : "CDSResponsePolicy"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "CDSResponsePolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CDSResponseState",
+ "localName" : "ResponseOutput"
+ }
+ }
+ } ]
+ }
+ }
+ } ]
+ },
+ "firstState" : "CDSResponseState"
+ }
+ }, {
+ "key" : {
+ "name" : "ReceiveEventPolicy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "policyKey" : {
+ "name" : "ReceiveEventPolicy",
+ "version" : "0.0.1"
+ },
+ "template" : "Freestyle",
+ "state" : {
+ "entry" : [ {
+ "key" : "CreateOrDeleteState",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "CreateOrDeleteState"
+ },
+ "trigger" : {
+ "name" : "PMSubscriptionOutputEvent",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "CreateSubscriptionPayload",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateOrDeleteState",
+ "localName" : "CreateSubscriptionPayload"
+ },
+ "outgoingEvent" : {
+ "name" : "CreateSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "CreateSubscription"
+ }
+ }
+ }, {
+ "key" : "DeleteSubscriptionPayload",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateOrDeleteState",
+ "localName" : "DeleteSubscriptionPayload"
+ },
+ "outgoingEvent" : {
+ "name" : "DeleteSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "DeleteSubscription"
+ }
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskSelectionLogic" : {
+ "key" : "TaskSelectionLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * 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);\n\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").get(executor.inFields.get(\"albumID\").toString())\nvar changeType = pmSubscriptionInfo.get(\"changeType\").toString()\n\nif (\"CREATE\".equals(changeType)) {\n executor.subject.getTaskKey(\"CreateSubscriptionPayloadTask\").copyTo(executor.selectedTask);\n}\nelse if (\"DELETE\".equals(changeType)) {\n executor.subject.getTaskKey(\"DeleteSubscriptionPayloadTask\").copyTo(executor.selectedTask);\n}\n\ntrue;"
+ },
+ "stateFinalizerLogicMap" : {
+ "entry" : [ ]
+ },
+ "defaultTask" : {
+ "name" : "CreateSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateOrDeleteState",
+ "localName" : "ReceiveEventPolicy"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateOrDeleteState",
+ "localName" : "CreateSubscriptionPayload"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateOrDeleteState",
+ "localName" : "ReceiveEventPolicy"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateOrDeleteState",
+ "localName" : "DeleteSubscriptionPayload"
+ }
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : "CreateSubscription",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "CreateSubscription"
+ },
+ "trigger" : {
+ "name" : "CreateSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "IssueCreateSubscriptionRequestOutput",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateSubscription",
+ "localName" : "IssueCreateSubscriptionRequestOutput"
+ },
+ "outgoingEvent" : {
+ "name" : "CreateSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "NULL",
+ "parentKeyVersion" : "0.0.0",
+ "parentLocalName" : "NULL",
+ "localName" : "NULL"
+ }
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskSelectionLogic" : {
+ "key" : "NULL",
+ "logicFlavour" : "UNDEFINED",
+ "logic" : ""
+ },
+ "stateFinalizerLogicMap" : {
+ "entry" : [ ]
+ },
+ "defaultTask" : {
+ "name" : "CreateSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CreateSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateSubscription",
+ "localName" : "ReceiveEventPolicy"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "CreateSubscription",
+ "localName" : "IssueCreateSubscriptionRequestOutput"
+ }
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : "DeleteSubscription",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "DeleteSubscription"
+ },
+ "trigger" : {
+ "name" : "DeleteSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "IssueDeleteSubscriptionRequestOutput",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "DeleteSubscription",
+ "localName" : "IssueDeleteSubscriptionRequestOutput"
+ },
+ "outgoingEvent" : {
+ "name" : "DeleteSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "NULL",
+ "parentKeyVersion" : "0.0.0",
+ "parentLocalName" : "NULL",
+ "localName" : "NULL"
+ }
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskSelectionLogic" : {
+ "key" : "NULL",
+ "logicFlavour" : "UNDEFINED",
+ "logic" : ""
+ },
+ "stateFinalizerLogicMap" : {
+ "entry" : [ ]
+ },
+ "defaultTask" : {
+ "name" : "DeleteSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "DeleteSubscription",
+ "localName" : "ReceiveEventPolicy"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "DeleteSubscription",
+ "localName" : "IssueDeleteSubscriptionRequestOutput"
+ }
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : "ReceiveSubscriptionState",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "ReceiveSubscriptionState"
+ },
+ "trigger" : {
+ "name" : "testPolicyB",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "ReceivePMSubscriptionOutput",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "ReceiveSubscriptionState",
+ "localName" : "ReceivePMSubscriptionOutput"
+ },
+ "outgoingEvent" : {
+ "name" : "PMSubscriptionOutputEvent",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "CreateOrDeleteState"
+ }
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskSelectionLogic" : {
+ "key" : "NULL",
+ "logicFlavour" : "UNDEFINED",
+ "logic" : ""
+ },
+ "stateFinalizerLogicMap" : {
+ "entry" : [ ]
+ },
+ "defaultTask" : {
+ "name" : "ReceivePMSubscriptionTask",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "ReceivePMSubscriptionTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "ReceiveSubscriptionState",
+ "localName" : "ReceiveEventPolicy"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "ReceiveEventPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "ReceiveSubscriptionState",
+ "localName" : "ReceivePMSubscriptionOutput"
+ }
+ }
+ } ]
+ }
+ }
+ } ]
+ },
+ "firstState" : "ReceiveSubscriptionState"
+ }
+ } ]
+ }
+ },
+ "tasks" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Tasks",
+ "version" : "0.0.1"
+ },
+ "taskMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CDSResponseTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseTask",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "actionIdentifiers",
+ "value" : {
+ "key" : "actionIdentifiers",
+ "fieldSchemaKey" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "commonHeader",
+ "value" : {
+ "key" : "commonHeader",
+ "fieldSchemaKey" : {
+ "name" : "CDSResponseCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSResponsePayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "status",
+ "value" : {
+ "key" : "status",
+ "fieldSchemaKey" : {
+ "name" : "CDSResponseStatusType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "status",
+ "value" : {
+ "key" : "status",
+ "fieldSchemaKey" : {
+ "name" : "SubscriptionStatusType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2020 Nordix. All rights reserved.\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\n\nvar uuidType = java.util.UUID;\n\nvar albumID = uuidType.fromString(\"d0050623-18e5-46c9-9298-9a567990cd7c\");\n\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").get(albumID.toString());\n\nvar responseStatus = executor.subject.getOutFieldSchemaHelper(\"status\").createNewInstance();\n\nresponseStatus.put(\"subscriptionName\", pmSubscriptionInfo.get(\"subscription\").get(\"subscriptionName\"))\nresponseStatus.put(\"nfName\", pmSubscriptionInfo.get(\"nfName\"))\nresponseStatus.put(\"changeType\", pmSubscriptionInfo.get(\"changeType\"))\n\nvar response = executor.inFields.get(\"payload\")\n\nif (\"failure\".equals(response.get(\"create_DasH_subscription_DasH_response\").get(\"odl_DasH_response\").get(\"status\"))) {\n responseStatus.put(\"message\", \"failed\")\n} else {\n responseStatus.put(\"message\", \"success\")\n}\n\nexecutor.outFields.put(\"status\", responseStatus)\n\ntrue;"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2020 Nordix. All rights reserved.\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);\n\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").get(executor.inFields.get(\"albumID\").toString())\n\nvar payloadProperties = executor.subject.getOutFieldSchemaHelper(\"payload\").createNewSubInstance(\"create_DasH_subscription_DasH_properties_record\");\n\npayloadProperties.put(\"nfName\", pmSubscriptionInfo.get(\"nfName\"))\npayloadProperties.put(\"subscriptionName\", pmSubscriptionInfo.get(\"subscription\").get(\"subscriptionName\"))\npayloadProperties.put(\"administrativeState\", pmSubscriptionInfo.get(\"subscription\").get(\"administrativeState\"))\npayloadProperties.put(\"fileBasedGP\", pmSubscriptionInfo.get(\"subscription\").get(\"fileBasedGP\").toString())\npayloadProperties.put(\"fileLocation\", pmSubscriptionInfo.get(\"subscription\").get(\"fileLocation\"))\npayloadProperties.put(\"measurementGroups\", pmSubscriptionInfo.get(\"subscription\").get(\"measurementGroups\"))\n\nvar payloadEntry = executor.subject.getOutFieldSchemaHelper(\"payload\").createNewSubInstance(\"CDSRequestPayloadEntry\");\npayloadEntry.put(\"create_DasH_subscription_DasH_properties\", payloadProperties)\n\nvar payload = executor.subject.getOutFieldSchemaHelper(\"payload\").createNewInstance();\npayload.put(\"create_DasH_subscription_DasH_request\", payloadEntry);\n\nexecutor.outFields.put(\"albumID\", executor.inFields.get(\"albumID\"))\nexecutor.outFields.put(\"payload\", payload);\n\nexecutor.logger.info(\"Sending Create Subscription Event to CDS\")\n\ntrue;"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "actionIdentifiers",
+ "value" : {
+ "key" : "actionIdentifiers",
+ "fieldSchemaKey" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "commonHeader",
+ "value" : {
+ "key" : "commonHeader",
+ "fieldSchemaKey" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2020 Nordix. All rights reserved.\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);\n\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").get(executor.inFields.get(\"albumID\").toString())\nvar payload = executor.inFields.get(\"payload\")\nvar actionName = \"create-subscription\"\n\nvar commonHeader = executor.subject.getOutFieldSchemaHelper(\"commonHeader\").createNewInstance();\ncommonHeader.put(\"originatorId\", \"sdnc\");\ncommonHeader.put(\"requestId\", \"123456-1000\");\ncommonHeader.put(\"subRequestId\", \"sub-123456-1000\");\n\nvar actionIdentifiers = executor.subject.getOutFieldSchemaHelper(\"actionIdentifiers\").createNewInstance();\nactionIdentifiers.put(\"actionName\", actionName);\nactionIdentifiers.put(\"blueprintName\", \"pm_control\");\nactionIdentifiers.put(\"blueprintVersion\", \"1.0.0\");\nactionIdentifiers.put(\"mode\", \"sync\");\n\nexecutor.outFields.put(\"commonHeader\", commonHeader);\nexecutor.outFields.put(\"actionIdentifiers\", actionIdentifiers);\nexecutor.outFields.put(\"payload\", payload);\n\nexecutor.logger.info(\"Sending Activate Subscription Event to CDS\")\n\ntrue;"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadTask",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2020 Nordix. All rights reserved.\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);\n\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").get(executor.inFields.get(\"albumID\").toString())\n\nvar payloadProperties = executor.subject.getOutFieldSchemaHelper(\"payload\").createNewSubInstance(\"delete_DasH_subscription_DasH_properties_record\");\n\npayloadProperties.put(\"nfName\", pmSubscriptionInfo.get(\"nfName\"))\npayloadProperties.put(\"subscriptionName\", pmSubscriptionInfo.get(\"subscription\").get(\"subscriptionName\"))\npayloadProperties.put(\"administrativeState\", pmSubscriptionInfo.get(\"subscription\").get(\"administrativeState\"))\npayloadProperties.put(\"fileBasedGP\", pmSubscriptionInfo.get(\"subscription\").get(\"fileBasedGP\").toString())\npayloadProperties.put(\"fileLocation\", pmSubscriptionInfo.get(\"subscription\").get(\"fileLocation\"))\npayloadProperties.put(\"measurementGroups\", pmSubscriptionInfo.get(\"subscription\").get(\"measurementGroups\"))\n\nvar payloadEntry = executor.subject.getOutFieldSchemaHelper(\"payload\").createNewSubInstance(\"CDSRequestPayloadEntry\");\npayloadEntry.put(\"delete_DasH_subscription_DasH_properties\", payloadProperties)\n\nvar payload = executor.subject.getOutFieldSchemaHelper(\"payload\").createNewInstance();\npayload.put(\"delete_DasH_subscription_DasH_request\", payloadEntry);\n\nexecutor.outFields.put(\"albumID\", executor.inFields.get(\"albumID\"))\nexecutor.outFields.put(\"payload\", payload);\n\nexecutor.logger.info(\"Sending delete Subscription Event to CDS\")\n\ntrue;"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestTask",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "actionIdentifiers",
+ "value" : {
+ "key" : "actionIdentifiers",
+ "fieldSchemaKey" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "commonHeader",
+ "value" : {
+ "key" : "commonHeader",
+ "fieldSchemaKey" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2020 Nordix. All rights reserved.\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);\n\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").get(executor.inFields.get(\"albumID\").toString())\nvar payload = executor.inFields.get(\"payload\")\nvar actionName = \"delete-subscription\"\n\nvar commonHeader = executor.subject.getOutFieldSchemaHelper(\"commonHeader\").createNewInstance();\ncommonHeader.put(\"originatorId\", \"sdnc\");\ncommonHeader.put(\"requestId\", \"123456-1000\");\ncommonHeader.put(\"subRequestId\", \"sub-123456-1000\");\n\nvar actionIdentifiers = executor.subject.getOutFieldSchemaHelper(\"actionIdentifiers\").createNewInstance();\nactionIdentifiers.put(\"actionName\", actionName);\nactionIdentifiers.put(\"blueprintName\", \"pm_control\");\nactionIdentifiers.put(\"blueprintVersion\", \"1.0.0\");\nactionIdentifiers.put(\"mode\", \"sync\");\n\nexecutor.outFields.put(\"commonHeader\", commonHeader);\nexecutor.outFields.put(\"actionIdentifiers\", actionIdentifiers);\nexecutor.outFields.put(\"payload\", payload);\n\nexecutor.logger.info(\"Sending Deactivate Subscription Event to CDS\")\n\ntrue;"
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "ReceivePMSubscriptionTask",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "ReceivePMSubscriptionTask",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "changeType",
+ "value" : {
+ "key" : "changeType",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "closedLoopControlName",
+ "value" : {
+ "key" : "closedLoopControlName",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "nfName",
+ "value" : {
+ "key" : "nfName",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "policyName",
+ "value" : {
+ "key" : "policyName",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "subscription",
+ "value" : {
+ "key" : "subscription",
+ "fieldSchemaKey" : {
+ "name" : "SubscriptionType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ } ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "JAVASCRIPT",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2020 Nordix. All rights reserved.\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 */\nvar uuidType = java.util.UUID;\n\n\n//albumID will be used to fetch info from our album later\nvar albumID = uuidType.fromString(\"d0050623-18e5-46c9-9298-9a567990cd7c\");\nvar pmSubscriptionInfo = executor.getContextAlbum(\"PMSubscriptionAlbum\").getSchemaHelper().createNewInstance();\nvar returnValue = true;;\n\nif(executor.inFields.get(\"policyName\") != null) {\n var changeType = executor.inFields.get(\"changeType\")\n var nfName = executor.inFields.get(\"nfName\")\n var policyName = executor.inFields.get(\"policyName\")\n var closedLoopControlName = executor.inFields.get(\"closedLoopControlName\")\n var subscription = executor.inFields.get(\"subscription\")\n\n pmSubscriptionInfo.put(\"nfName\", executor.inFields.get(\"nfName\"));\n pmSubscriptionInfo.put(\"changeType\", executor.inFields.get(\"changeType\"))\n pmSubscriptionInfo.put(\"policyName\", executor.inFields.get(\"policyName\"))\n pmSubscriptionInfo.put(\"closedLoopControlName\", executor.inFields.get(\"closedLoopControlName\"))\n pmSubscriptionInfo.put(\"subscription\", subscription)\n\n executor.getContextAlbum(\"PMSubscriptionAlbum\").put(albumID.toString(), pmSubscriptionInfo);\n\n executor.outFields.put(\"albumID\", albumID)\n} else {\n executor.message = \"Received invalid event\"\n returnValue = false;\n}\nreturnValue;"
+ }
+ }
+ } ]
+ }
+ },
+ "events" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Events",
+ "version" : "0.0.1"
+ },
+ "eventMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CDSResponseEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "CDS",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "actionIdentifiers",
+ "value" : {
+ "key" : "actionIdentifiers",
+ "fieldSchemaKey" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "commonHeader",
+ "value" : {
+ "key" : "commonHeader",
+ "fieldSchemaKey" : {
+ "name" : "CDSResponseCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSResponsePayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "status",
+ "value" : {
+ "key" : "status",
+ "fieldSchemaKey" : {
+ "name" : "CDSResponseStatusType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseStatusEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseStatusEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "APEX",
+ "target" : "DCAE",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "status",
+ "value" : {
+ "key" : "status",
+ "fieldSchemaKey" : {
+ "name" : "SubscriptionStatusType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "APEX",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "CreateSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CreateSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "APEX",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "actionIdentifiers",
+ "value" : {
+ "key" : "actionIdentifiers",
+ "fieldSchemaKey" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "commonHeader",
+ "value" : {
+ "key" : "commonHeader",
+ "fieldSchemaKey" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionPayloadEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "APEX",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "DeleteSubscriptionRequestEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "APEX",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "actionIdentifiers",
+ "value" : {
+ "key" : "actionIdentifiers",
+ "fieldSchemaKey" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "commonHeader",
+ "value" : {
+ "key" : "commonHeader",
+ "fieldSchemaKey" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "payload",
+ "value" : {
+ "key" : "payload",
+ "fieldSchemaKey" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "PMSubscriptionOutputEvent",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PMSubscriptionOutputEvent",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "APEX",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "albumID",
+ "value" : {
+ "key" : "albumID",
+ "fieldSchemaKey" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "testPolicyB",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "testPolicyB",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "org.onap.policy.apex.onap.pmcontrol",
+ "source" : "DCAE",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "changeType",
+ "value" : {
+ "key" : "changeType",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "closedLoopControlName",
+ "value" : {
+ "key" : "closedLoopControlName",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "nfName",
+ "value" : {
+ "key" : "nfName",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "policyName",
+ "value" : {
+ "key" : "policyName",
+ "fieldSchemaKey" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "subscription",
+ "value" : {
+ "key" : "subscription",
+ "fieldSchemaKey" : {
+ "name" : "SubscriptionType",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ } ]
+ }
+ },
+ "albums" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Albums",
+ "version" : "0.0.1"
+ },
+ "albums" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PMSubscriptionAlbum",
+ "version" : "0.0.1"
+ },
+ "scope" : "policy",
+ "isWritable" : true,
+ "itemSchema" : {
+ "name" : "PMSubscriptionType",
+ "version" : "0.0.1"
+ }
+ }
+ } ]
+ }
+ },
+ "schemas" : {
+ "key" : {
+ "name" : "APEXgRPCPolicy_Schemas",
+ "version" : "0.0.1"
+ },
+ "schemas" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSActionIdentifiersType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"record\",\n \"name\": \"CDSActionIdentifiers_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.helloworld\",\n \"fields\": [\n {\n \"name\": \"actionName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"blueprintName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"blueprintVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"mode\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSCreateSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"map\",\n \"values\": {\n \"type\": \"record\",\n \"name\": \"CDSRequestPayloadEntry\",\n \"fields\": [\n {\n \"name\": \"create_DasH_subscription_DasH_properties\",\n \"type\": {\n \"name\": \"create_DasH_subscription_DasH_properties_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"nfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"subscriptionName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"administrativeState\",\n \"type\": \"string\"\n },\n {\n \"name\": \"fileBasedGP\",\n \"type\": \"string\"\n },\n {\n \"name\": \"fileLocation\",\n \"type\": \"string\"\n },\n {\n \"name\": \"measurementGroups\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"measurementGroups_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementGroup\",\n \"type\": {\n \"name\": \"measurementGroup\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementTypes\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"measurementTypes_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementType\",\n \"type\": \"string\"\n }\n ]\n }\n }\n },\n {\n \"name\": \"managedObjectDNsBasic\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"managedObjectDNsBasic_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"DN\",\n \"type\": \"string\"\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n }\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSDeleteSubscriptionPayloadType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"map\",\n \"values\": {\n \"type\": \"record\",\n \"name\": \"CDSRequestPayloadEntry\",\n \"fields\": [\n {\n \"name\": \"delete_DasH_subscription_DasH_properties\",\n \"type\": {\n \"name\": \"delete_DasH_subscription_DasH_properties_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"nfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"subscriptionName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"administrativeState\",\n \"type\": \"string\"\n },\n {\n \"name\": \"fileBasedGP\",\n \"type\": \"string\"\n },\n {\n \"name\": \"fileLocation\",\n \"type\": \"string\"\n },\n {\n \"name\": \"measurementGroups\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"measurementGroups_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementGroup\",\n \"type\": {\n \"name\": \"measurementGroup\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementTypes\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"measurementTypes_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementType\",\n \"type\": \"string\"\n }\n ]\n }\n }\n },\n {\n \"name\": \"managedObjectDNsBasic\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"managedObjectDNsBasic_record\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"DN\",\n \"type\": \"string\"\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n }\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSRequestCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"record\",\n \"name\": \"CDSRequestCommonHeader_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.helloworld\",\n \"fields\": [\n {\n \"name\": \"originatorId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"requestId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"subRequestId\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseCommonHeaderType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"record\",\n \"name\": \"CDSResponseCommonHeader_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.helloworld\",\n \"fields\": [\n {\n \"name\": \"originatorId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"requestId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"subRequestId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"timestamp\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponsePayloadType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponsePayloadType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"name\": \"CDSResponsePayloadEntry\",\n \"type\": \"record\",\n \"namespace\": \"com.acme.avro\",\n \"fields\": [\n {\n \"name\": \"create_DasH_subscription_DasH_response\",\n \"type\": {\n \"name\": \"create_DasH_subscription_DasH_response\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"odl_DasH_response\",\n \"type\": {\n \"name\": \"odl_DasH_response\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"status\",\n \"type\": \"string\"\n }\n ]\n }\n }\n ]\n }\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "CDSResponseStatusType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "CDSResponseStatusType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"record\",\n \"name\": \"CDSResponseStatus_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.helloworld\",\n \"fields\": [\n {\n \"name\": \"code\",\n \"type\": \"int\"\n },\n {\n \"name\": \"eventType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"timestamp\",\n \"type\": \"string\"\n },\n {\n \"name\": \"message\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "PMSubscriptionType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "PMSubscriptionType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"name\": \"PMSubscription\",\n \"type\": \"record\",\n \"namespace\": \"org.onap.policy.apex.onap.pmcontrol\",\n \"fields\": [\n {\n \"name\": \"nfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"changeType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopControlName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"subscription\",\n \"type\": {\n \"name\": \"subscription\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"subscriptionName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"administrativeState\",\n \"type\": \"string\"\n },\n {\n \"name\": \"fileBasedGP\",\n \"type\": \"int\"\n },\n {\n \"name\": \"fileLocation\",\n \"type\": \"string\"\n },\n {\n \"name\": \"measurementGroups\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"Measurement_Groups_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementGroup\",\n \"type\": {\n \"name\": \"Measurement_Group_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementTypes\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"Measurement_Types_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementType\",\n \"type\": \"string\"\n }\n ]\n }\n }\n },\n {\n \"name\": \"managedObjectDNsBasic\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"Managed_Object_Dns_Basic_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"DN\",\n \"type\": \"string\"\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "SimpleIntType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SimpleIntType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Integer"
+ }
+ }, {
+ "key" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SimpleStringType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.String"
+ }
+ }, {
+ "key" : {
+ "name" : "SubscriptionStatusType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SubscriptionStatusType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"type\": \"record\",\n \"name\": \"ActivateSubscriptionStatus_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.helloworld\",\n \"fields\": [\n {\n \"name\": \"subscriptionName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"nfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"changeType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"message\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "SubscriptionType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SubscriptionType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Avro",
+ "schemaDefinition" : "{\n \"name\": \"subscription\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"subscriptionName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"administrativeState\",\n \"type\": \"string\"\n },\n {\n \"name\": \"fileBasedGP\",\n \"type\": \"int\"\n },\n {\n \"name\": \"fileLocation\",\n \"type\": \"string\"\n },\n {\n \"name\": \"measurementGroups\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"Measurement_Groups_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementGroup\",\n \"type\": {\n \"name\": \"Measurement_Group_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementTypes\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"Measurement_Types_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"measurementType\",\n \"type\": \"string\"\n }\n ]\n }\n }\n },\n {\n \"name\": \"managedObjectDNsBasic\",\n \"type\": {\n \"type\": \"array\",\n \"items\": {\n \"name\": \"Managed_Object_Dns_Basic_Type\",\n \"type\": \"record\",\n \"fields\": [\n {\n \"name\": \"DN\",\n \"type\": \"string\"\n }\n ]\n }\n }\n }\n ]\n }\n }\n ]\n }\n }\n }\n ]\n}"
+ }
+ }, {
+ "key" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "UUIDType",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.util.UUID"
+ }
+ } ]
+ }
+ }
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig-engineServiceParameters-notAnObject.json b/gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig-engineServiceParameters-notAnObject.json
new file mode 100644
index 0000000..cbad28f
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig-engineServiceParameters-notAnObject.json
@@ -0,0 +1,7 @@
+{
+ "engineServiceParameters": [],
+ "eventInputParameters": {
+ },
+ "eventOutputParameters": {
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig.json b/gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig.json
new file mode 100644
index 0000000..34ec305
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/converter/ApexConfig.json
@@ -0,0 +1,112 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 2,
+ "deploymentPort": 12561,
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ },
+ "contextParameters": {
+ "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters",
+ "schemaParameters": {
+ "Avro": {
+ "parameterClassName": "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
+ },
+ "Java": {
+ "parameterClassName": "org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters",
+ "jsonAdapters": {
+ "Instant": {
+ "adaptedClass": "java.time.Instant",
+ "adaptorClass": "org.onap.policy.controlloop.util.Serialization$GsonInstantAdapter"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ "DCAEConsumer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTCLIENT",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:54321/GrpcTestRestSim/sim/events/unauthenticated.DCAE_CL_OUTPUT/APEX/1?timeout=30000"
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON",
+ "parameters": {
+ "nameAlias": "testPolicyB"
+ }
+ },
+ "eventName": "testPolicyB",
+ "eventNameFilter": "testPolicyB"
+ },
+ "CDSRequestConsumer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "GRPC",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventName": "CDSResponseEvent",
+ "eventNameFilter": "CDSResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "CDSRequestProducer",
+ "requestorTimeout": 500
+ }
+ },
+ "eventOutputParameters": {
+ "logOutputter": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "FILE",
+ "parameters": {
+ "fileName": "outputevents.log"
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ }
+ },
+ "CDSRequestProducer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "GRPC",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.grpc.GrpcCarrierTechnologyParameters",
+ "parameters": {
+ "host": "localhost",
+ "port": 54322,
+ "username": "ccsdkapps",
+ "password": "ccsdkapps",
+ "timeout": 10
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "(Create|Delete)SubscriptionRequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "CDSRequestConsumer",
+ "requestorTimeout": 500
+ },
+ "CDSReplyProducer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTCLIENT",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:54321/GrpcTestRestSim/sim/events/POLICY_CL_MGT"
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "CDSResponseStatusEvent"
+ }
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/converter/ToscaTemplate.json b/gui-editors/gui-editor-apex/src/test/resources/converter/ToscaTemplate.json
new file mode 100644
index 0000000..140205c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/converter/ToscaTemplate.json
@@ -0,0 +1,17 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": {
+ "type": "onap.policies.native.Apex",
+ "type_version": "1.0.0",
+ "name": "onap.policies.native.apex.Grpc",
+ "version": "1.0.0",
+ "properties": {
+ }
+ }
+ }
+ ]
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid-engineServiceParameters.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid-engineServiceParameters.json
new file mode 100644
index 0000000..2f23055
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid-engineServiceParameters.json
@@ -0,0 +1,3 @@
+{
+ "engineServiceParameters": ""
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid.json
new file mode 100644
index 0000000..2517d8b
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-invalid.json
@@ -0,0 +1 @@
+- this is an invalid JSON \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-missing-engineServiceParameters.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-missing-engineServiceParameters.json
new file mode 100644
index 0000000..3fe89d0
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig-missing-engineServiceParameters.json
@@ -0,0 +1,6 @@
+{
+ "eventInputParameters": {
+ },
+ "eventOutputParameters": {
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig.json
new file mode 100644
index 0000000..5cd1a46
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ApexConfig.json
@@ -0,0 +1,37 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 2,
+ "deploymentPort": 12561,
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ },
+ "contextParameters": {
+ "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters",
+ "schemaParameters": {
+ "Avro": {
+ "parameterClassName": "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters"
+ },
+ "Java": {
+ "parameterClassName": "org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters",
+ "jsonAdapters": {
+ "Instant": {
+ "adaptedClass": "java.time.Instant",
+ "adaptorClass": "org.onap.policy.controlloop.util.Serialization$GsonInstantAdapter"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ },
+ "eventOutputParameters": {
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid-toscaDefinitions.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid-toscaDefinitions.json
new file mode 100644
index 0000000..e0323b8
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid-toscaDefinitions.json
@@ -0,0 +1,4 @@
+{
+ "tosca_definitions_version": {
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid.json
new file mode 100644
index 0000000..0705d6b
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalid.json
@@ -0,0 +1 @@
+- this is a invalid json \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-policies.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-policies.json
new file mode 100644
index 0000000..a9bb4e7
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-policies.json
@@ -0,0 +1,6 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": {}
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-properties.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-properties.json
new file mode 100644
index 0000000..fd06d2a
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-properties.json
@@ -0,0 +1,12 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": {
+ "properties": []
+ }
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-topologyTemplate.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-topologyTemplate.json
new file mode 100644
index 0000000..94a8148
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidEntry-topologyTemplate.json
@@ -0,0 +1,4 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": ""
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy1.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy1.json
new file mode 100644
index 0000000..194b2fd
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy1.json
@@ -0,0 +1,10 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": ""
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy2.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy2.json
new file mode 100644
index 0000000..a8741fd
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-invalidPolicy2.json
@@ -0,0 +1,8 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {}
+ ]
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policies.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policies.json
new file mode 100644
index 0000000..0d95fab
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policies.json
@@ -0,0 +1,5 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policy.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policy.json
new file mode 100644
index 0000000..88bbb6c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-policy.json
@@ -0,0 +1,6 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": []
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-properties.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-properties.json
new file mode 100644
index 0000000..7bcac74
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-properties.json
@@ -0,0 +1,15 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": {
+ "type": "onap.policies.native.Apex",
+ "type_version": "1.0.0",
+ "name": "onap.policies.native.apex.Grpc",
+ "version": "1.0.0"
+ }
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-topology-template.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-topology-template.json
new file mode 100644
index 0000000..bf8e032
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-topology-template.json
@@ -0,0 +1,3 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0"
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-tosca-definitions-version.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-tosca-definitions-version.json
new file mode 100644
index 0000000..1e0d5b8
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-missing-tosca-definitions-version.json
@@ -0,0 +1,16 @@
+{
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": {
+ "type": "onap.policies.native.Apex",
+ "type_version": "1.0.0",
+ "name": "onap.policies.native.apex.Grpc",
+ "version": "1.0.0",
+ "properties": {
+ }
+ }
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-more-than-one-policy.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-more-than-one-policy.json
new file mode 100644
index 0000000..d5801b9
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate-more-than-one-policy.json
@@ -0,0 +1,20 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": {
+ "type": "onap.policies.native.Apex",
+ "type_version": "1.0.0",
+ "name": "onap.policies.native.apex.Grpc",
+ "version": "1.0.0",
+ "properties": {
+ }
+ }
+ },
+ {
+ "onap.policies.native.apex.AnotherPolicy": {}
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate.json b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate.json
new file mode 100644
index 0000000..86ea2cf
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/test/resources/processor/ToscaTemplate.json
@@ -0,0 +1,17 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.policies.native.apex.Grpc": {
+ "type": "onap.policies.native.Apex",
+ "type_version": "1.0.0",
+ "name": "onap.policies.native.apex.Grpc",
+ "version": "1.0.0",
+ "properties": {
+ }
+ }
+ }
+ ]
+ }
+} \ No newline at end of file