summaryrefslogtreecommitdiffstats
path: root/gui-editors/gui-editor-apex/src/main/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-07-16 10:24:08 +0100
committerliamfallon <liam.fallon@est.tech>2020-07-17 14:46:26 +0100
commit2de08a64e959788f288d82cd4410fee9424a11bc (patch)
tree93d90b4de43e6e52c7059e842cf8c5ba4d10ecca /gui-editors/gui-editor-apex/src/main/java
parentee41415476b6ea1775a2f689eecb8713abf81f0c (diff)
Move apex policy editor to policy-gui
This review moves the code for the apex policy editor from the apex repo to the GUI repo. The docker part of the build will be moved in the next review because it is intertwined with the other two legacy apex GUIs and needs to be disentangled. Subsequent reviews on the apex repo will remove this code from there. Issue-ID: POLICY-2621 Change-Id: Ib9a43f463b839201656208a48ab48869a19f963a Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'gui-editors/gui-editor-apex/src/main/java')
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java82
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorException.java74
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java212
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterException.java50
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterParser.java130
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameters.java229
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java815
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java219
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java192
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java276
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandler.java73
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java461
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java589
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommand.java65
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandHandler.java103
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandType.java57
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java131
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionHandler.java113
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java185
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java468
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanBase.java82
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextAlbum.java110
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java100
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanEvent.java136
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanField.java62
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanKeyRef.java60
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanLogic.java59
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java81
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanPolicy.java112
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanState.java134
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateOutput.java61
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateTaskRef.java70
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java133
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTaskParameter.java61
34 files changed, 5785 insertions, 0 deletions
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
new file mode 100644
index 0000000..4741346
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditor.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-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 org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class is used to launch the editor. It creates a Grizzly embedded web
+ * server and runs the editor.
+ */
+public class ApexEditor {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditor.class);
+
+ // The HTTP server exposing JAX-RS resources defined in this application.
+ private final HttpServer server;
+
+ /**
+ * Starts the HTTP server for the Apex editor on the default base URI and with
+ * the default REST packages.
+ */
+ public ApexEditor() {
+ this(new ApexEditorParameters());
+ }
+
+ /**
+ * Starts the HTTP server for the Apex editor.
+ *
+ * @param parameters the parameters
+ */
+ public ApexEditor(final ApexEditorParameters parameters) {
+ Assertions.argumentNotNull(parameters, "parameters may not be null");
+
+ LOGGER.debug("Apex RESTful editor starting . . .");
+
+ // Create a resource configuration that scans for JAX-RS resources and providers
+ final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages());
+
+ // create and start a new instance of grizzly http server
+ // exposing the Jersey application at BASE_URI
+ server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc);
+
+ // Add static content
+ server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler(
+ ApexEditorMain.class.getClassLoader(), "/webapp/"), parameters.getStaticPath());
+
+ LOGGER.debug("Apex RESTful editor started");
+ }
+
+ /**
+ * Shut down the web server.
+ */
+ public void shutdown() {
+ LOGGER.debug("Apex RESTful editor shutting down . . .");
+ server.shutdown();
+ LOGGER.debug("Apex RESTful editor shut down");
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorException.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorException.java
new file mode 100644
index 0000000..a1bd28d
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorException.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest;
+
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+
+/**
+ * Exceptions from the Apex editor.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorException extends ApexException {
+ private static final long serialVersionUID = 4867385591967018254L;
+
+ /**
+ * Instantiates a new apex editor exception.
+ *
+ * @param message the message on the exception
+ */
+ public ApexEditorException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Instantiates a new apex editor exception.
+ *
+ * @param message the message on the exception
+ * @param object the object that the exception was thrown on
+ */
+ public ApexEditorException(final String message, final Object object) {
+ super(message, object);
+ }
+
+ /**
+ * Instantiates a new apex editor exception.
+ *
+ * @param message the message on the exception
+ * @param ex the exception that caused this Apex exception
+ */
+ public ApexEditorException(final String message, final Exception ex) {
+ super(message, ex);
+ }
+
+ /**
+ * Instantiates a new apex editor exception.
+ *
+ * @param message the message on the exception
+ * @param ex the exception that caused this Apex exception
+ * @param object the object that the exception was thrown on
+ */
+ public ApexEditorException(final String message, final Exception ex, final Object object) {
+ super(message, ex, object);
+ }
+
+}
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
new file mode 100644
index 0000000..481f0af
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
@@ -0,0 +1,212 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-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.io.PrintStream;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class is the main class that is used to launch the Apex editor from the
+ * command line.
+ *
+ */
+public class ApexEditorMain {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorMain.class);
+
+ // Recurring string constants
+ private static final String REST_ENDPOINT_PREFIX = "Apex Editor REST endpoint (";
+
+ /**
+ * The Enum EditorState holds the current state of the editor.
+ */
+ // Editor state
+ public enum EditorState {
+ /** The editor is stopped. */
+ STOPPED,
+ /** The editor is ready to run. */
+ READY,
+ /** The editor is getting ready to run. */
+ INITIALIZING,
+ /** The editor is running. */
+ RUNNING
+ }
+
+ private static final int EDITOR_RNNING_CHECK_TIMEOUT = 1000;
+
+ private EditorState state = EditorState.STOPPED;
+
+ // The Apex editor this class is running
+ private ApexEditor apexEditor = null;
+
+ // The parameters for the editor
+ private ApexEditorParameters parameters = null;
+
+ // Output and error streams for messages
+ private final PrintStream outStream;
+
+ /**
+ * Constructor, kicks off the editor.
+ *
+ * @param args The command line arguments for the editor
+ * @param outStream The stream for output messages
+ */
+ public ApexEditorMain(final String[] args, final PrintStream outStream) {
+ // Save the streams for output and error
+ this.outStream = outStream;
+
+ // Editor parameter parsing
+ final ApexEditorParameterParser parser = new ApexEditorParameterParser();
+
+ try {
+ // Get and check the parameters
+ parameters = parser.parse(args);
+ } catch (final ApexEditorParameterException e) {
+ 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()));
+ }
+
+ // Validate the parameters
+ final String validationMessage = parameters.validate();
+ if (validationMessage.length() > 0) {
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, "
+ + validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getName()));
+ }
+
+ state = EditorState.READY;
+ }
+
+ /**
+ * Initialize the Apex editor.
+ */
+ public void init() {
+ outStream.println(
+ REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + " . . .");
+
+ try {
+ state = EditorState.INITIALIZING;
+
+ // Start the editor
+ apexEditor = new ApexEditor(parameters);
+
+ // Add a shutdown hook to shut down the editor when the process is exiting
+ Runtime.getRuntime().addShutdownHook(new Thread(new ApexEditorShutdownHook()));
+
+ state = EditorState.RUNNING;
+
+ if (parameters.getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) {
+ outStream.println(
+ REST_ENDPOINT_PREFIX + this.toString() + ") started at " + parameters.getBaseUri().toString());
+ } else {
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
+ }
+
+ // Find out how long is left to wait
+ long timeRemaining = parameters.getTimeToLive();
+ while (timeRemaining == ApexEditorParameters.INFINITY_TIME_TO_LIVE || timeRemaining > 0) {
+ // decrement the time to live in the non-infinity case
+ if (timeRemaining > 0) {
+ timeRemaining--;
+ }
+
+ // Wait for a second
+ Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT);
+ }
+ } catch (final Exception e) {
+ String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage();
+ outStream.println(message);
+ LOGGER.warn(message, e);
+ } finally {
+ if (apexEditor != null) {
+ apexEditor.shutdown();
+ apexEditor = null;
+ }
+ state = EditorState.STOPPED;
+ }
+ }
+
+ /**
+ * Get the editor state.
+ *
+ * @return the state
+ */
+ public EditorState getState() {
+ return state;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder ret = new StringBuilder();
+ ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=")
+ .append(this.getState());
+ return ret.toString();
+ }
+
+ /**
+ * Explicitly shut down the editor.
+ */
+ public void shutdown() {
+ if (apexEditor != null) {
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down");
+ apexEditor.shutdown();
+ }
+ state = EditorState.STOPPED;
+ outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down");
+ }
+
+ /**
+ * This class is a shutdown hook for the Apex editor command.
+ */
+ private class ApexEditorShutdownHook implements Runnable {
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void run() {
+ if (apexEditor != null) {
+ apexEditor.shutdown();
+ }
+ }
+ }
+
+ /**
+ * Main method, main entry point for command.
+ *
+ * @param args The command line arguments for the editor
+ */
+ public static void main(final String[] args) {
+ try {
+ final ApexEditorMain editorMain = new ApexEditorMain(args, System.out);
+ editorMain.init();
+ } catch (final Exception e) {
+ LOGGER.error("start failed", e);
+ }
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterException.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterException.java
new file mode 100644
index 0000000..f59a5eb
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterException.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest;
+
+/**
+ * A run time exception used to report parsing and parameter input errors.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorParameterException extends IllegalArgumentException {
+ private static final long serialVersionUID = 6520231162404452427L;
+
+ /**
+ * Create an ApexEditorParameterException with a message.
+ *
+ * @param message the message
+ */
+ public ApexEditorParameterException(final String message) {
+ super(message);
+ }
+
+ /**
+ * Create an ApexEditorParameterException with a message and an exception.
+ *
+ * @param message the message
+ * @param th the Throwable instance
+ */
+ public ApexEditorParameterException(final String message, final Throwable th) {
+ super(message, th);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterParser.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterParser.java
new file mode 100644
index 0000000..0033bcb
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameterParser.java
@@ -0,0 +1,130 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Arrays;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+/**
+ * This class reads and handles command line parameters to the Apex CLI editor.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorParameterParser {
+ // Apache Commons CLI options
+ private Options options;
+
+ private static final int COMMAND_HELP_MAX_LINE_WIDTH = 120;
+
+ /**
+ * Construct the options for the CLI editor.
+ */
+ public ApexEditorParameterParser() {
+ options = new Options();
+ options.addOption("h", "help", false, "outputs the usage of this command");
+ options
+ .addOption(Option.builder("p").longOpt("port").desc("port to use for the Apex RESTful editor REST calls.")
+ .hasArg().argName("PORT").required(false).type(Number.class).build());
+ options.addOption(Option.builder("t").longOpt("time-to-live")
+ .desc("the amount of time in seconds that the server will run for before terminating. "
+ + "Default value is " + ApexEditorParameters.INFINITY_TIME_TO_LIVE + " to run indefinitely.")
+ .hasArg().argName("TIME_TO_LIVE").required(false).type(Number.class).build());
+ options.addOption(Option.builder("l").longOpt("listen")
+ .desc("the IP address to listen on. Default value is " + ApexEditorParameters.DEFAULT_SERVER_URI_ROOT
+ + " to restrict access to the local machine only.")
+ .hasArg().argName("ADDRESS").required(false).type(String.class).build());
+ }
+
+ /**
+ * Parse the command line options.
+ *
+ * @param args The arguments
+ * @return the apex editor parameters
+ */
+ public ApexEditorParameters parse(final String[] args) {
+ CommandLine commandLine = null;
+ try {
+ commandLine = new DefaultParser().parse(options, args);
+ } catch (final ParseException e) {
+ throw new ApexEditorParameterException("invalid command line arguments specified : " + e.getMessage());
+ }
+
+ final ApexEditorParameters parameters = new ApexEditorParameters();
+ final String[] remainingArgs = commandLine.getArgs();
+
+ if (commandLine.getArgs().length > 0) {
+ throw new ApexEditorParameterException(
+ "too many command line arguments specified : " + Arrays.toString(remainingArgs));
+ }
+
+ if (commandLine.hasOption('h')) {
+ parameters.setHelp(true);
+ }
+ try {
+ if (commandLine.hasOption('p')) {
+ parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue());
+ }
+ } catch (final ParseException e) {
+ throw new ApexEditorParameterException("error parsing argument \"port\" :" + e.getMessage(), e);
+ }
+ try {
+ if (commandLine.hasOption('t')) {
+ parameters.setTimeToLive(((Number) commandLine.getParsedOptionValue("time-to-live")).longValue());
+ }
+ } catch (final ParseException e) {
+ throw new ApexEditorParameterException("error parsing argument \"time-to-live\" :" + e.getMessage(), e);
+ }
+ try {
+ if (commandLine.hasOption('l')) {
+ parameters.setListenAddress(commandLine.getParsedOptionValue("listen").toString());
+ }
+ } catch (final ParseException e) {
+ throw new ApexEditorParameterException("error parsing argument \"listen-address\" :" + e.getMessage(), e);
+ }
+
+ return parameters;
+ }
+
+ /**
+ * Get help information.
+ *
+ * @param mainClassName the main class name
+ * @return the help
+ */
+ public String getHelp(final String mainClassName) {
+ final StringWriter stringWriter = new StringWriter();
+ final PrintWriter stringPrintWriter = new PrintWriter(stringWriter);
+
+ final HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.printHelp(stringPrintWriter, COMMAND_HELP_MAX_LINE_WIDTH, mainClassName + " [options...] ", null,
+ options, 0, 1, "");
+
+ return stringWriter.toString();
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameters.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameters.java
new file mode 100644
index 0000000..c4c36ff
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorParameters.java
@@ -0,0 +1,229 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class reads and handles command line parameters to the Apex CLI editor.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorParameters {
+ // Logger for this class
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorParameters.class);
+
+ /** The default port for connecting to the Web editor on. */
+ public static final int DEFAULT_REST_PORT = 18989;
+
+ /** The connection is held up until killed on demand. */
+ public static final int INFINITY_TIME_TO_LIVE = -1;
+
+ // Base URI the HTTP server will listen on
+ private static final String DEFAULT_SERVER_URI_PREFIX = "http://";
+ /** The server listens on localhost by default. */
+ public static final String DEFAULT_SERVER_URI_ROOT = "localhost";
+ private static final String DEFAULT_REST_PATH = "/apexservices/";
+ private static final String DEFAULT_STATIC_PATH = "/";
+
+ // Constants for port checks
+ private static final int MIN_USER_PORT = 1024;
+ private static final int MAX_USER_PORT = 65535;
+
+ // Package that will field REST requests
+ private static final String[] DEFAULT_PACKAGES = new String[] { "org.onap.policy.gui.editors.apex.rest" };
+
+ // The editor parameters
+ private boolean helpSet = false;
+ private int restPort = DEFAULT_REST_PORT;
+ private long timeToLive = INFINITY_TIME_TO_LIVE;
+ private String listenAddress = DEFAULT_SERVER_URI_ROOT;
+
+ /**
+ * Validate.
+ *
+ * @return the string
+ */
+ public String validate() {
+ String validationMessage = "";
+ validationMessage += validatePort();
+ validationMessage += validateTimeToLive();
+ validationMessage += validateUrl();
+
+ return validationMessage;
+ }
+
+ /**
+ * Gets the base URI.
+ *
+ * @return the base URI
+ */
+ public URI getBaseUri() {
+ return URI.create(DEFAULT_SERVER_URI_PREFIX + listenAddress + ':' + restPort + DEFAULT_REST_PATH);
+ }
+
+ /**
+ * Gets the REST packages.
+ *
+ * @return the REST packages
+ */
+ public String[] getRestPackages() {
+ return DEFAULT_PACKAGES;
+ }
+
+ /**
+ * Gets the static path.
+ *
+ * @return the static path
+ */
+ public String getStaticPath() {
+ return DEFAULT_STATIC_PATH;
+ }
+
+ /**
+ * Validate port.
+ *
+ * @return a warning string, or an empty string
+ */
+ private String validatePort() {
+ if (restPort < MIN_USER_PORT || restPort > MAX_USER_PORT) {
+ return "port must be between " + MIN_USER_PORT + " and " + MAX_USER_PORT + "\n";
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Validate URL.
+ *
+ * @return a warning string, or an empty string
+ */
+ private String validateUrl() {
+ try {
+ new URI(getBaseUri().toString()).parseServerAuthority();
+ return "";
+ } catch (final URISyntaxException e) {
+ String message = "listen address is not valid. " + e.getMessage() + "\n";
+ LOGGER.warn(message, e);
+ return message;
+ }
+ }
+
+ /**
+ * Validate time to live.
+ *
+ * @return the string
+ */
+ private String validateTimeToLive() {
+ if (timeToLive < -1) {
+ return "time to live must be greater than -1 (set to -1 to wait forever)\n";
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Checks if is help set.
+ *
+ * @return true, if checks if is help set
+ */
+ public boolean isHelpSet() {
+ return helpSet;
+ }
+
+ /**
+ * Sets the help.
+ *
+ * @param help the help
+ */
+ public void setHelp(final boolean help) {
+ this.helpSet = help;
+ }
+
+ /**
+ * Gets the REST port.
+ *
+ * @return the REST port
+ */
+ public int getRestPort() {
+ return restPort;
+ }
+
+ /**
+ * Sets the REST port.
+ *
+ * @param incomingRestPort the REST port
+ */
+ public void setRestPort(final int incomingRestPort) {
+ this.restPort = incomingRestPort;
+ }
+
+ /**
+ * Gets the time to live.
+ *
+ * @return the time to live
+ */
+ public long getTimeToLive() {
+ return timeToLive;
+ }
+
+ /**
+ * Sets the time to live.
+ *
+ * @param timeToLive the time to live
+ */
+ public void setTimeToLive(final long timeToLive) {
+ this.timeToLive = timeToLive;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ final StringBuilder ret = new StringBuilder();
+ ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=")
+ .append(this.getTimeToLive()).append("sec");
+ return ret.toString();
+ }
+
+ /**
+ * Gets the base address to listen on.
+ *
+ * @return the listenAddress
+ */
+ public String getListenAddress() {
+ return listenAddress;
+ }
+
+ /**
+ * Sets the base address to listen on.
+ *
+ * @param listenAddress the new listenAddress
+ */
+ public void setListenAddress(final String listenAddress) {
+ this.listenAddress = listenAddress;
+ }
+}
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
new file mode 100644
index 0000000..ef5c57a
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
@@ -0,0 +1,815 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import java.io.IOException;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+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.utils.resources.TextFileUtils;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The class represents the root resource exposed at the base URL<br> The url to access this resource would be in the
+ * form {@code <baseURL>/rest/<session>/....} <br> For example: a PUT request to the following URL
+ * {@code http://localhost:8080/apex/rest/109/ContextSchema/Update}, with a JSON string payload containing the new
+ * {@code Schema} in the body, can be explained as: <ul> <li>The server or servlet is running at the base URL
+ * {@code http://localhost:8080/apex} <li>This resource {@code ApexRestEditorResource} is used because the path
+ * {@code rest/109} matches the {@code Path} filter specification for this Resource ({@code @Path("rest/{session}")}),
+ * where the {@code int} path parameter {@code session} is assigned the {@code int} value {@code 109} <li>The path
+ * {@code ContextSchema/Update} redirects this call to the method {@link #updateContextSchema(String)}, which should be
+ * a {@link javax.ws.rs.PUT}, with a single String in the body/payload which gets mapped to the single String parameter
+ * for the method. <li>So, in summary, the REST request updates a {@code ContextSchema} as specified in the payload for
+ * {@code session} number {@code 109} </ul>
+ *
+ * <b>Note:</b> An allocated {@code Session} identifier must be included in (almost) all requests. Models for different
+ * {@code Session} identifiers are completely isolated from one another.
+ *
+ * <b>Note:</b> To create a new {@code Session}, and have a new session ID allocated use {@link javax.ws.rs.GET} request
+ * to {@code <baseURL>/rest/-1/Session/Create} (for example: {@code http://localhost:8080/apex/rest/-1/Session/Create} )
+ *
+ */
+@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);
+
+ // Location of the periodi event template
+ 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";
+ private static final String OK = ": OK";
+ 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();
+
+ // 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();
+ private static final ContextAlbumHandler CONTEXT_ALBUM_HANDLER = new ContextAlbumHandler();
+ 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
+
+ // The ID of this session. This gets injected from the URL.
+ @PathParam("session")
+ private int sessionId = -1;
+
+ /**
+ * 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.
+ *
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}. This includes the session id
+ * for this session.
+ */
+ @GET
+ @Path("Session/Create")
+ public ApexApiResult createSession() {
+ if (sessionId != -1) {
+ return new ApexApiResult(Result.FAILED, "Session ID must be set to -1 to create sessions: " + sessionId);
+ }
+
+ ApexApiResult result = new ApexApiResult();
+ SESSION_HANDLER.createSession(result);
+ return result;
+ }
+
+ /**
+ * Load the model from a JSON string for this session.
+ *
+ * @param jsonString the JSON string to be parsed. The returned value(s) will be similar to {@code AxPolicyModel},
+ * with merged {@code AxKeyInfo} for the root object.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("/Model/Load")
+ public ApexApiResult loadFromString(final String jsonString) {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.LOAD, jsonString);
+ }
+
+ /**
+ * Analyse the model and return analysis results. If successful the analysis results will be available in the
+ * messages in the result.
+ *
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Model/Analyse")
+ public ApexApiResult analyse() {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.ANALYSE);
+ }
+
+ /**
+ * Validate the model and return validation results. If successful the validation results will be available in the
+ * messages in the result.
+ *
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Model/Validate")
+ public ApexApiResult validate() {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.VALIDATE);
+ }
+
+ /**
+ * Creates the new model model for this session.
+ *
+ * @param jsonString the JSON string to be parsed containing the new model. See {@code BeanModel}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @POST
+ @Path("Model/Create")
+ public ApexApiResult createModel(final String jsonString) {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.CREATE, jsonString);
+ }
+
+ /**
+ * Update the model for this session.
+ *
+ * @param jsonString the JSON string to be parsed containing the updated model. See {@code BeanModel}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("Model/Update")
+ public ApexApiResult updateModel(final String jsonString) {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.UPDATE, jsonString);
+ }
+
+ /**
+ * Gets the key for the model for this session. If successful the model key will be available in the first message
+ * in the result. See {@code AxKey}
+ *
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Model/GetKey")
+ public ApexApiResult getModelKey() {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.GET_KEY);
+ }
+
+ /**
+ * Retrieve the model for this session. If successful the model will be available in the first message in the
+ * result. The returned value will be similar to a {@code AxPolicyModel}, with merged {@code AxKeyInfo} for the root
+ * object.
+ *
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Model/Get")
+ public ApexApiResult listModel() {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.LIST);
+ }
+
+ /**
+ * Download the model for this session as a String.
+ *
+ * @return the model represented as a JSON string. See {@code AxPolicyModel}
+ */
+ @GET
+ @Path("Model/Download")
+ public String downloadModel() {
+ ApexApiResult result = processRestCommand(RestCommandType.MODEL, RestCommand.DOWNLOAD);
+ if (result != null && result.isOk()) {
+ return result.getMessage();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Delete the model for this session.
+ *
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @DELETE
+ @Path("Model/Delete")
+ public ApexApiResult deleteModel() {
+ return processRestCommand(RestCommandType.MODEL, RestCommand.DELETE);
+ }
+
+ /**
+ * List key information with the given key names/versions. If successful the result(s) will be available in the
+ * result messages. See {@code AxKeyInfo}
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("KeyInformation/Get")
+ public ApexApiResult listKeyInformation(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.KEY_INFO, RestCommand.LIST, name, version);
+ }
+
+ /**
+ * Creates a context schema with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanContextSchema}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @POST
+ @Path("ContextSchema/Create")
+ public ApexApiResult createContextSchema(final String jsonString) {
+ return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.CREATE, jsonString);
+ }
+
+ /**
+ * Update a context schema with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanContextSchema}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("ContextSchema/Update")
+ public ApexApiResult updateContextSchema(final String jsonString) {
+ return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.UPDATE, jsonString);
+ }
+
+ /**
+ * List context schemas with the given key names/versions. If successful the result(s) will be available in the
+ * result messages. The returned value(s) will be similar to {@code AxContextSchema}, with merged {@code AxKeyInfo}
+ * for the root object.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("ContextSchema/Get")
+ public ApexApiResult listContextSchemas(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.LIST, name, version);
+ }
+
+ /**
+ * Delete context schemas with the given key names/versions.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @DELETE
+ @Path("ContextSchema/Delete")
+ public ApexApiResult deleteContextSchema(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.DELETE, name, version);
+ }
+
+ /**
+ * Validate context schemas with the given key names/versions. The result(s) will be available in the result
+ * messages.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Validate/ContextSchema")
+ public ApexApiResult validateContextSchemas(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.CONTEXT_SCHEMA, RestCommand.VALIDATE, name, version);
+ }
+
+ /**
+ * Creates a context album with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanContextAlbum}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @POST
+ @Path("ContextAlbum/Create")
+ public ApexApiResult createContextAlbum(final String jsonString) {
+ return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.CREATE, jsonString);
+ }
+
+ /**
+ * Update a context album with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanContextAlbum}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("ContextAlbum/Update")
+ public ApexApiResult updateContextAlbum(final String jsonString) {
+ return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.UPDATE, jsonString);
+ }
+
+ /**
+ * List context albums with the given key names/versions. If successful the result(s) will be available in the
+ * result messages. The returned value(s) will be similar to {@code AxContextAlbum}, with merged {@code AxKeyInfo}
+ * for the root object.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("ContextAlbum/Get")
+ public ApexApiResult listContextAlbums(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.LIST, name, version);
+ }
+
+ /**
+ * Delete context albums with the given key names/versions.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @DELETE
+ @Path("ContextAlbum/Delete")
+ public ApexApiResult deleteContextAlbum(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.DELETE, name, version);
+ }
+
+ /**
+ * Validate context albums with the given key names/versions. The result(s) will be available in the result
+ * messages.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Validate/ContextAlbum")
+ public ApexApiResult validateContextAlbums(@QueryParam(NAME) final String name,
+ @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.CONTEXT_ALBUM, RestCommand.VALIDATE, name, version);
+ }
+
+ /**
+ * Creates an event with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanEvent}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @POST
+ @Path("Event/Create")
+ public ApexApiResult createEvent(final String jsonString) {
+ return processRestCommand(RestCommandType.EVENT, RestCommand.CREATE, jsonString);
+ }
+
+ /**
+ * Update an event with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanEvent}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("Event/Update")
+ public ApexApiResult updateEvent(final String jsonString) {
+ return processRestCommand(RestCommandType.EVENT, RestCommand.UPDATE, jsonString);
+ }
+
+ /**
+ * List events with the given key names/versions. If successful the result(s) will be available in the result
+ * messages. The returned value(s) will be similar to {@code AxEvent}, with merged {@code AxKeyInfo} for the root
+ * object.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Event/Get")
+ public ApexApiResult listEvent(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.EVENT, RestCommand.LIST, name, version);
+ }
+
+ /**
+ * Delete events with the given key names/versions.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @DELETE
+ @Path("Event/Delete")
+ public ApexApiResult deleteEvent(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.EVENT, RestCommand.DELETE, name, version);
+ }
+
+ /**
+ * Validate events with the given key names/versions. The result(s) will be available in the result messages.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Validate/Event")
+ public ApexApiResult validateEvent(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.EVENT, RestCommand.VALIDATE, name, version);
+ }
+
+ /**
+ * Creates a task with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanTask}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @POST
+ @Path("Task/Create")
+ public ApexApiResult createTask(final String jsonString) {
+ return processRestCommand(RestCommandType.TASK, RestCommand.CREATE, jsonString);
+ }
+
+ /**
+ * Update a task with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed. See {@code BeanTask}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("Task/Update")
+ public ApexApiResult updateTask(final String jsonString) {
+ return processRestCommand(RestCommandType.TASK, RestCommand.UPDATE, jsonString);
+ }
+
+ /**
+ * List tasks with the given key names/versions. If successful the result(s) will be available in the result
+ * messages. The returned value(s) will be similar to {@code AxTask}, with merged {@code AxKeyInfo} for the root
+ * object.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Task/Get")
+ public ApexApiResult listTask(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.TASK, RestCommand.LIST, name, version);
+ }
+
+ /**
+ * Delete tasks with the given key names/versions.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @DELETE
+ @Path("Task/Delete")
+ public ApexApiResult deleteTask(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.TASK, RestCommand.DELETE, name, version);
+ }
+
+ /**
+ * Validate tasks with the given key names/versions. The result(s) will be available in the result messages.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Validate/Task")
+ public ApexApiResult validateTask(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.TASK, RestCommand.VALIDATE, name, version);
+ }
+
+ // CHECKSTYLE:OFF: MethodLength
+ /**
+ * Creates a policy with the information in the JSON string passed.
+ *
+ * @param jsonString the JSON string to be parsed See {@code BeanPolicy}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @POST
+ @Path("Policy/Create")
+ public ApexApiResult createPolicy(final String jsonString) {
+ return processRestCommand(RestCommandType.POLICY, RestCommand.CREATE, jsonString);
+ }
+
+ /**
+ * Update a policy with the information in the JSON string passed.
+ *
+ * @param firstStatePeriodic indicates if periodic event should be created and added to model
+ * @param jsonString the JSON string to be parsed. See {@code BeanPolicy}
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @PUT
+ @Path("Policy/Update")
+ public ApexApiResult updatePolicy(@QueryParam("firstStatePeriodic") final boolean firstStatePeriodic,
+ final String jsonString) {
+
+ ApexApiResult result = processRestCommand(RestCommandType.POLICY, RestCommand.UPDATE, jsonString);
+ if (result != null && result.isOk() && firstStatePeriodic) {
+ result = createPeriodicEvent();
+ }
+ return result;
+ }
+
+ /**
+ * List policies with the given key names/versions. If successful the result(s) will be available in the result
+ * messages. The returned value(s) will be similar to {@code AxPolicy}, with merged {@code AxKeyInfo} for the root
+ * object.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @GET
+ @Path("Policy/Get")
+ public ApexApiResult listPolicy(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.POLICY, RestCommand.LIST, name, version);
+ }
+
+ /**
+ * Delete policies with the given key names/versions.
+ *
+ * @param name the name to search for. If null or empty, then all names will be queried
+ * @param version the version to search for. If null then all versions will be searched for.
+ * @return an ApexAPIResult object. If successful then {@link ApexApiResult#isOk()} will return true. Any
+ * messages/errors can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ @DELETE
+ @Path("Policy/Delete")
+ public ApexApiResult deletePolicy(@QueryParam(NAME) final String name, @QueryParam(VERSION) final String version) {
+ return processRestCommand(RestCommandType.POLICY, RestCommand.DELETE, name, version);
+ }
+
+ /**
+ * This method routes REST commands that take no parameters to their caller.
+ *
+ * @param commandType the type of REST command to process
+ * @param command the REST command to process
+ * @return the result of the REST command
+ */
+ private ApexApiResult processRestCommand(final RestCommandType commandType, final RestCommand command) {
+ LOGGER.entry(commandType);
+ try {
+ ApexApiResult result = new ApexApiResult();
+ RestSession session = SESSION_HANDLER.getSession(sessionId, result);
+ if (session == null) {
+ return result;
+ }
+ result = executeRestCommand(session, commandType, command);
+ LOGGER.exit(SESSION_CREATE + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ } catch (final Exception e) {
+ LOGGER.catching(e);
+ LOGGER.exit(SESSION_CREATE_NOT_OK);
+ throw e;
+ }
+ }
+
+ /**
+ * This method routes REST commands that take a JSON string to their caller.
+ *
+ * @param commandType the type of REST command to process
+ * @param command the REST command to process
+ * @param jsonString the JSON string received in the REST request
+ * @return the result of the REST command
+ */
+ private ApexApiResult processRestCommand(final RestCommandType commandType, final RestCommand command,
+ final String jsonString) {
+ LOGGER.entry(commandType, jsonString);
+ try {
+ ApexApiResult result = new ApexApiResult();
+ RestSession session = SESSION_HANDLER.getSession(sessionId, result);
+ if (session == null) {
+ return result;
+ }
+ result = executeRestCommand(session, commandType, command, jsonString);
+ LOGGER.exit(SESSION_CREATE + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ } catch (final Exception e) {
+ LOGGER.catching(e);
+ LOGGER.exit(SESSION_CREATE_NOT_OK);
+ throw e;
+ }
+ }
+
+ /**
+ * This method routes REST commands that take a name and version to their caller.
+ *
+ * @param commandType the type of REST command to process
+ * @param command the REST command to process
+ * @param name the name received in the REST request
+ * @param version the name received in the REST request
+ * @return the result of the REST command
+ */
+ private ApexApiResult processRestCommand(final RestCommandType commandType, final RestCommand command,
+ final String name, final String version) {
+ LOGGER.entry(commandType, name, version);
+ try {
+ ApexApiResult result = new ApexApiResult();
+ RestSession session = SESSION_HANDLER.getSession(sessionId, result);
+ if (session == null) {
+ return result;
+ }
+ result = executeRestCommand(session, commandType, command, name, version);
+ LOGGER.exit(SESSION_CREATE + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ } catch (final Exception e) {
+ LOGGER.catching(e);
+ LOGGER.exit(SESSION_CREATE_NOT_OK);
+ throw e;
+ }
+ }
+
+ /**
+ * This method invokes callers to run REST commands that take no parameters.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to process
+ * @param command the REST command to process
+ * @return the result of the REST command
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ switch (commandType) {
+ case MODEL:
+ return MODEL_HANDLER.executeRestCommand(session, commandType, command);
+ case KEY_INFO:
+ return KEY_INFO_HANDLER.executeRestCommand(session, commandType, command);
+ case CONTEXT_SCHEMA:
+ return CONTEXT_SCHEMA_HANDLER.executeRestCommand(session, commandType, command);
+ case CONTEXT_ALBUM:
+ return CONTEXT_ALBUM_HANDLER.executeRestCommand(session, commandType, command);
+ case EVENT:
+ return EVENT_HANDLER.executeRestCommand(session, commandType, command);
+ case TASK:
+ return TASK_HANDLER.executeRestCommand(session, commandType, command);
+ case POLICY:
+ return POLICY_HANDLER.executeRestCommand(session, commandType, command);
+ default:
+ return new ApexApiResult(Result.FAILED, REST_COMMAND_NOT_RECOGNISED);
+ }
+ }
+
+ /**
+ * This method invokes callers to run REST commands that take a JSON string.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to process
+ * @param command the REST command to process
+ * @param jsonString the JSON string received in the REST request
+ * @return the result of the REST command
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ switch (commandType) {
+ case MODEL:
+ return MODEL_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ case KEY_INFO:
+ return KEY_INFO_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ case CONTEXT_SCHEMA:
+ return CONTEXT_SCHEMA_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ case CONTEXT_ALBUM:
+ return CONTEXT_ALBUM_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ case EVENT:
+ return EVENT_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ case TASK:
+ return TASK_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ case POLICY:
+ return POLICY_HANDLER.executeRestCommand(session, commandType, command, jsonString);
+ default:
+ return new ApexApiResult(Result.FAILED, REST_COMMAND_NOT_RECOGNISED);
+ }
+ }
+
+ /**
+ * This method invokes callers to run REST commands that take a name and version.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to process
+ * @param command the REST command to process
+ * @param name the name received in the REST request
+ * @param version the name received in the REST request
+ * @return the result of the REST command
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ switch (commandType) {
+ case MODEL:
+ return MODEL_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ case KEY_INFO:
+ return KEY_INFO_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ case CONTEXT_SCHEMA:
+ return CONTEXT_SCHEMA_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ case CONTEXT_ALBUM:
+ return CONTEXT_ALBUM_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ case EVENT:
+ return EVENT_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ case TASK:
+ return TASK_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ case POLICY:
+ return POLICY_HANDLER.executeRestCommand(session, commandType, command, name, version);
+ default:
+ return new ApexApiResult(Result.FAILED, REST_COMMAND_NOT_RECOGNISED);
+ }
+ }
+
+ /**
+ * Create a periodic event from the periodic event template.
+ */
+ private ApexApiResult createPeriodicEvent() {
+ String periodicEventJsonString;
+ try {
+ periodicEventJsonString = TextFileUtils.getTextFileAsString(PERIODIC_EVENT_TEMPLATE);
+ } catch (IOException ioException) {
+ String message = "read of periodic event tempalte from " + PERIODIC_EVENT_TEMPLATE + "failed: "
+ + ioException.getMessage();
+ LOGGER.debug(message, ioException);
+ return new ApexApiResult(Result.FAILED, message);
+ }
+
+ return processRestCommand(RestCommandType.EVENT, RestCommand.CREATE, periodicEventJsonString);
+ }
+
+ /*
+ * This method is used only for testing and is used to cause an exception on calls from unit test to test exception
+ * handling.
+ */
+ protected static int createCorruptSession() {
+ final ApexEditorRestResource apexEditorRestResource = new ApexEditorRestResource();
+ final ApexApiResult result = apexEditorRestResource.createSession();
+ final int corruptSessionId = Integer.parseInt(result.getMessages().get(0));
+
+ SESSION_HANDLER.setCorruptSession(corruptSessionId);
+
+ return corruptSessionId;
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java
new file mode 100644
index 0000000..abf81b8
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextAlbumHandler.java
@@ -0,0 +1,219 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanContextAlbum;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class handles commands on context albums in Apex models.
+ */
+public class ContextAlbumHandler implements RestCommandHandler {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextAlbumHandler.class);
+
+ // Recurring string constants
+ private static final String OK = ": OK";
+ private static final String NOT_OK = ": Not OK";
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ if (!RestCommandType.CONTEXT_ALBUM.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case CREATE:
+ return createContextAlbum(session, jsonString);
+ case UPDATE:
+ return updateContextAlbum(session, jsonString);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ if (!RestCommandType.CONTEXT_ALBUM.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case LIST:
+ return listContextAlbums(session, name, version);
+ case DELETE:
+ return deleteContextAlbum(session, name, version);
+ case VALIDATE:
+ return validateContextAlbum(session, name, version);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * Creates a context album with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See
+ * {@linkplain BeanContextAlbum}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createContextAlbum(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ session.editModel();
+
+ final BeanContextAlbum jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextAlbum.class);
+
+ ApexApiResult result = session.getApexModelEdited().createContextAlbum(jsonbean.getName(),
+ jsonbean.getVersion(), jsonbean.getScope(), Boolean.toString(jsonbean.getWriteable()),
+ jsonbean.getItemSchema().getName(), jsonbean.getItemSchema().getVersion(), jsonbean.getUuid(),
+ jsonbean.getDescription());
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("ContextAlbum/Create" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Update a context album with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See
+ * {@linkplain BeanContextAlbum}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult updateContextAlbum(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ session.editModel();
+
+ final BeanContextAlbum jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextAlbum.class);
+
+ ApexApiResult result = session.getApexModelEdited().updateContextAlbum(jsonbean.getName(),
+ jsonbean.getVersion(), jsonbean.getScope(), Boolean.toString(jsonbean.getWriteable()),
+ jsonbean.getItemSchema().getName(), jsonbean.getItemSchema().getVersion(), jsonbean.getUuid(),
+ jsonbean.getDescription());
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("ContextAlbum/Update" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * List context albums with the given key names/versions. If successful the
+ * result(s) will be available in the result messages. The returned value(s)
+ * will be similar to {@link AxContextAlbum}, with merged {@linkplain AxKeyInfo}
+ * for the root object.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult listContextAlbums(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().listContextAlbum(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("ContextAlbum/Get" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Delete context albums with the given key names/versions.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult deleteContextAlbum(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().deleteContextAlbum(blank2Null(name), blank2Null(version));
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("ContextAlbum/Delete" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Validate context albums with the given key names/versions. The result(s) will
+ * be available in the result messages.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult validateContextAlbum(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().validateContextAlbum(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Validate/ContextAlbum" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java
new file mode 100644
index 0000000..65aa2fd
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ContextSchemaHandler.java
@@ -0,0 +1,192 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanContextSchema;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class handles commands on context schemas in Apex models.
+ */
+public class ContextSchemaHandler implements RestCommandHandler {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ContextSchemaHandler.class);
+
+ // Recurring string constants
+ private static final String OK = ": OK";
+ private static final String NOT_OK = ": Not OK";
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ if (!RestCommandType.CONTEXT_SCHEMA.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case CREATE:
+ return createContextSchema(session, jsonString);
+ case UPDATE:
+ return updateContextSchema(session, jsonString);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ if (!RestCommandType.CONTEXT_SCHEMA.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case LIST:
+ return listContextSchemas(session, name, version);
+ case DELETE:
+ return deleteContextSchema(session, name, version);
+ case VALIDATE:
+ return validateContextSchemas(session, name, version);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * Creates a context schema.
+ *
+ * @param session the session holding the Apex model
+ * @param jsonString the JSON string with the context schema parameters
+ * @return the result of the operation
+ */
+ private ApexApiResult createContextSchema(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ session.editModel();
+
+ final BeanContextSchema jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextSchema.class);
+ ApexApiResult result = session.getApexModelEdited().createContextSchema(jsonbean.getName(),
+ jsonbean.getVersion(), jsonbean.getSchemaFlavour(), jsonbean.getSchemaDefinition(), jsonbean.getUuid(),
+ jsonbean.getDescription());
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("ContextSchema/create" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Update a context schema.
+ *
+ * @param session the session holding the Apex model
+ * @param jsonString the JSON string with the context schema parameters
+ * @return the result of the operation
+ */
+ private ApexApiResult updateContextSchema(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ session.editModel();
+
+ final BeanContextSchema jsonbean = RestUtils.getJsonParameters(jsonString, BeanContextSchema.class);
+
+ ApexApiResult result = session.getApexModelEdited().updateContextSchema(jsonbean.getName(),
+ jsonbean.getVersion(), jsonbean.getSchemaFlavour(), jsonbean.getSchemaDefinition(), jsonbean.getUuid(),
+ jsonbean.getDescription());
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("ContextSchema/Update" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * List context schemas.
+ *
+ * @param session the session holding the Apex model
+ * @param name the context schema name to operate on
+ * @param version the context schema version to operate on
+ * @return the result of the operation
+ */
+ private ApexApiResult listContextSchemas(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().listContextSchemas(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("ContextSchema/Get" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Delete a context schema.
+ *
+ * @param session the session holding the Apex model
+ * @param name the context schema name to operate on
+ * @param version the context schema version to operate on
+ * @return the result of the operation
+ */
+ private ApexApiResult deleteContextSchema(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().deleteContextSchema(blank2Null(name), blank2Null(version));
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("ContextSchema/Delete" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Validate a context schema.
+ *
+ * @param session the session holding the Apex model
+ * @param name the context schema name to operate on
+ * @param version the context schema version to operate on
+ * @return the result of the operation
+ */
+ private ApexApiResult validateContextSchemas(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().validateContextSchemas(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Validate/ContextSchema" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java
new file mode 100644
index 0000000..a1e2ff9
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/EventHandler.java
@@ -0,0 +1,276 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-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.Entry;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanEvent;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanField;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class handles commands on events in Apex models.
+ */
+public class EventHandler implements RestCommandHandler {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(EventHandler.class);
+
+ // Recurring string constants
+ private static final String OK = ": OK";
+ private static final String NOT_OK = ": Not OK";
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ if (!RestCommandType.EVENT.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case CREATE:
+ return createEvent(session, jsonString);
+ case UPDATE:
+ return updateEvent(session, jsonString);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ if (!RestCommandType.EVENT.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case LIST:
+ return listEvents(session, name, version);
+ case DELETE:
+ return deleteEvent(session, name, version);
+ case VALIDATE:
+ return validateEvent(session, name, version);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * Creates an event with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See {@linkplain BeanEvent}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createEvent(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanEvent jsonbean = RestUtils.getJsonParameters(jsonString, BeanEvent.class);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().createEvent(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getNameSpace(), jsonbean.getSource(), jsonbean.getTarget(), jsonbean.getUuid(),
+ jsonbean.getDescription());
+
+ if (result.isOk()) {
+ result = createEventParameters(session, jsonbean);
+ }
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Event/Create" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Create the parameters on an event.
+ *
+ * @param session the Apex editor session
+ * @param jsonbean the JSON bean holding the parameters
+ * @return result the result of the parameter creation operation
+ */
+ private ApexApiResult createEventParameters(final RestSession session, final BeanEvent jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getParameters() == null || jsonbean.getParameters().isEmpty()) {
+ return result;
+ }
+
+ for (final Entry<String, BeanField> parameterEntry : jsonbean.getParameters().entrySet()) {
+ if (parameterEntry.getValue() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null event parameter information for parameter \"" + parameterEntry.getKey()
+ + "\" in event " + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The event was created, but there was an error adding the event parameters."
+ + " The event has only been partially defined.");
+ continue;
+ }
+
+ final ApexApiResult createParResult = session.getApexModelEdited().createEventPar(jsonbean.getName(),
+ jsonbean.getVersion(), parameterEntry.getKey(), parameterEntry.getValue().getName(),
+ parameterEntry.getValue().getVersion(), parameterEntry.getValue().getOptional());
+ if (createParResult.isNok()) {
+ result.setResult(createParResult.getResult());
+ result.addMessage("Failed to add event parameter information for parameter \"" + parameterEntry.getKey()
+ + "\" in event " + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The event was created, but there was an error adding the event parameters."
+ + " The event has only been partially defined.");
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Update an event with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See {@linkplain BeanEvent}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult updateEvent(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanEvent jsonbean = RestUtils.getJsonParameters(jsonString, BeanEvent.class);
+
+ if (blank2Null(jsonbean.getName()) == null || blank2Null(jsonbean.getVersion()) == null) {
+ LOGGER.exit("Event/Update" + NOT_OK);
+ return new ApexApiResult(Result.FAILED, "Null/Empty event name/version (\"" + jsonbean.getName() + ":"
+ + jsonbean.getVersion() + "\" passed to UpdateEvent");
+ }
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().deleteEvent(blank2Null(jsonbean.getName()),
+ blank2Null(jsonbean.getVersion()));
+
+ if (result.isOk()) {
+ result = session.getApexModelEdited().createEvent(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getNameSpace(), jsonbean.getSource(), jsonbean.getTarget(), jsonbean.getUuid(),
+ jsonbean.getDescription());
+
+ if (result.isOk() && jsonbean.getParameters() != null) {
+ result = createEventParameters(session, jsonbean);
+ }
+ }
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Event/Update" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * List events with the given key names/versions. If successful the result(s)
+ * will be available in the result messages. The returned value(s) will be
+ * similar to {@link AxEvent}, with merged {@linkplain AxKeyInfo} for the root
+ * object.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult listEvents(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().listEvent(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Event/Get" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Delete events with the given key names/versions.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult deleteEvent(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().deleteEvent(blank2Null(name), blank2Null(version));
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Event/Delete" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Validate events with the given key names/versions. The result(s) will be
+ * available in the result messages.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult validateEvent(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().validateEvent(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Validate/Event" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandler.java
new file mode 100644
index 0000000..eec8e6c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/KeyInfoHandler.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+
+/**
+ * This class handles commands on key information in Apex models.
+ */
+public class KeyInfoHandler implements RestCommandHandler {
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+
+ if (RestCommandType.KEY_INFO.equals(commandType) && RestCommand.LIST.equals(command)) {
+ return listKeyInformation(session, name, version);
+ } else {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * Get the key information for a concept with the given name and version.
+ *
+ * @param session the editor session containing the Apex model
+ * @param name the name for the search
+ * @param version the version for the search
+ * @return the key information
+ */
+ private ApexApiResult listKeyInformation(final RestSession session, final String name, final String version) {
+ return session.getApexModel().listKeyInformation(blank2Null(name), blank2Null(version));
+ }
+}
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
new file mode 100644
index 0000000..667d771
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ModelHandler.java
@@ -0,0 +1,461 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-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 com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanModel;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class handles commands on Apex models.
+ */
+public class ModelHandler implements RestCommandHandler {
+
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(ModelHandler.class);
+
+ // Recurring string constants
+ private static final String OK = ": OK";
+ private static final String NOT_OK = ": Not OK";
+ private static final String KEY = "key";
+ private static final String NAME = "name";
+ private static final String VERSION = "version";
+ private static final String UUID = "uuid";
+ private static final String DESCRIPTION = "description";
+ private static final String POLICY_KEY = "policyKey";
+ private static final String APEX_KEY_INFO = "apexKeyInfo";
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ if (!RestCommandType.MODEL.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case ANALYSE:
+ return analyse(session);
+ case VALIDATE:
+ return validate(session);
+ case GET_KEY:
+ return getModelKey(session);
+ case LIST:
+ return listModel(session);
+ case DOWNLOAD:
+ return downloadModel(session);
+ case DELETE:
+ return deleteModel(session);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ if (!RestCommandType.MODEL.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case LOAD:
+ return loadFromString(session, jsonString);
+ case CREATE:
+ return createModel(session, jsonString);
+ case UPDATE:
+ return updateModel(session, jsonString);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * Load the model from a JSON string for this session.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. The returned value(s) will be
+ * similar to {@link AxPolicyModel}, with merged
+ * {@linkplain AxKeyInfo} for the root object.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult loadFromString(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().loadFromString(jsonString);
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Model/Load" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Analyse the model and return analysis results. If successful the analysis
+ * results will be available in the messages in the result.
+ *
+ * @param session the Apex model editing session
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult analyse(final RestSession session) {
+ LOGGER.entry();
+
+ ApexApiResult result = session.getApexModel().analyse();
+
+ LOGGER.exit("Model/Analyse" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Validate the model and return validation results. If successful the
+ * validation results will be available in the messages in the result.
+ *
+ * @param session the Apex model editing session
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult validate(final RestSession session) {
+ LOGGER.entry();
+
+ ApexApiResult result = session.getApexModel().validate();
+
+ LOGGER.exit("Model/Validate" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Creates the new model model for this session.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed containing the new model. See
+ * {@linkplain BeanModel}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createModel(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanModel jsonbean = RestUtils.getJsonParameters(jsonString, BeanModel.class);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().createModel(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getUuid(), jsonbean.getDescription());
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Model/Create" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Update the model for this session.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed containing the updated model.
+ * See {@linkplain BeanModel}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult updateModel(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanModel jsonbean = RestUtils.getJsonParameters(jsonString, BeanModel.class);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().updateModel(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getUuid(), jsonbean.getDescription());
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Model/Update" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Gets the key for the model for this session. If successful the model key will
+ * be available in the first message in the result. See {@linkplain AxKey}
+ *
+ * @param session the Apex model editing session
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult getModelKey(final RestSession session) {
+ LOGGER.entry();
+
+ ApexApiResult result = session.getApexModel().getModelKey();
+
+ LOGGER.exit("Model/GetKey" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Retrieve the model for this session. If successful the model will be
+ * available in the first message in the result. The returned value will be
+ * similar to a {@link AxPolicyModel}, with merged {@linkplain AxKeyInfo} for
+ * the root object.
+ *
+ * @param session the Apex model editing session
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult listModel(final RestSession session) {
+ LOGGER.entry();
+
+ ApexApiResult result = session.getApexModel().listModel();
+
+ result = addKeyInfo2Messages(session, result);
+
+ LOGGER.exit("Model/Get" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Download the model for this session as a String.
+ *
+ * @param session the Apex model editing session
+ * @return the model represented as a JSON string. See
+ * {@linkplain AxPolicyModel}
+ */
+ private ApexApiResult downloadModel(final RestSession session) {
+ LOGGER.entry();
+
+ ApexApiResult result = session.getApexModel().listModel();
+
+ LOGGER.exit("Model/Download" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Delete the model for this session.
+ *
+ * @param session the Apex model editing session
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult deleteModel(final RestSession session) {
+ LOGGER.entry();
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModel().deleteModel();
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Model/Delete" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * The json strings representing the objects listed, stored in
+ * result.messages[], does not contain the AxKeyInformation for that object.
+ * This utility method retrieves the AxKeyInfo for each object and adds it to
+ * the json for the object.
+ *
+ * @param session the Apex model editing session
+ * @param incomingResult The list result, containing JSON representations of
+ * objects stored in its "messages" array
+ * @return The list result, containing JSON augmented representations of objects
+ * stored in its "messages" array
+ */
+ private ApexApiResult addKeyInfo2Messages(final RestSession session, final ApexApiResult incomingResult) {
+ final ApexApiResult result = new ApexApiResult(incomingResult.getResult());
+ result.setMessages(incomingResult.getMessages());
+
+ final List<String> messages = incomingResult.getMessages();
+ final List<String> augmentedMessages = new ArrayList<>(messages.size());
+
+ for (final String message : messages) {
+ augmentedMessages.add(addKeyInfo2Message(session, message));
+ }
+ result.setMessages(augmentedMessages);
+
+ if (messages.size() != augmentedMessages.size()) {
+ result.setResult(Result.OTHER_ERROR);
+ result.addMessage("Failed to add KeyInfo to all results. Results are not complete");
+ }
+
+ return result;
+ }
+
+ /**
+ * Augment a message with key information.
+ *
+ * @param session the Apex model editing session
+ * @param message The message to augment
+ * @return the augmented message
+ */
+ private String addKeyInfo2Message(final RestSession session, final String message) {
+ final Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create();
+
+ JsonObject jsonObject = gson.fromJson(message, JsonObject.class);
+ if (jsonObject == null) {
+ return message;
+ }
+
+ String name = readFieldFromJsonObject(jsonObject, NAME, null);
+ String version = readFieldFromJsonObject(jsonObject, VERSION, null);
+
+ if (name == null && version == null) {
+ JsonObject newJsonObject = getSubJsonObject(jsonObject);
+
+ if (newJsonObject != null) {
+ jsonObject = newJsonObject;
+ name = readFieldFromJsonObject(jsonObject, NAME, name);
+ version = readFieldFromJsonObject(jsonObject, VERSION, version);
+ }
+ }
+
+ if (name == null || version == null || !setUuidAndDescription(session, jsonObject, name, version)) {
+ jsonObject.addProperty(UUID, (String) null);
+ jsonObject.addProperty(DESCRIPTION, (String) null);
+ }
+
+ return gson.toJson(jsonObject);
+ }
+
+ /**
+ * Get an embedded JSON object for the given JSON object.
+ *
+ * @param jsonObject the input JSON object
+ * @return the embedded JSON object
+ */
+ private JsonObject getSubJsonObject(JsonObject jsonObject) {
+ if (jsonObject.entrySet() != null && !jsonObject.entrySet().isEmpty()) {
+ return (JsonObject) jsonObject.entrySet().iterator().next().getValue();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Condition a field so its key information can be looked up.
+ *
+ * @param jsonObject the object to query
+ * @param fieldTag the tag of the field to condition
+ * @param fieldValue the value of the field to condition
+ * @return field read from the json
+ */
+ private String readFieldFromJsonObject(final JsonObject jsonObject, final String fieldTag, final String value) {
+ String lookedupValue = value;
+
+ if (jsonObject != null && jsonObject.get(KEY) != null && jsonObject.get(KEY).isJsonObject()
+ && jsonObject.getAsJsonObject(KEY).get(fieldTag) != null) {
+ lookedupValue = jsonObject.getAsJsonObject(KEY).get(fieldTag).getAsString();
+ } else if (jsonObject != null && jsonObject.get(POLICY_KEY) != null && jsonObject.get(POLICY_KEY).isJsonObject()
+ && jsonObject.getAsJsonObject(POLICY_KEY).get(fieldTag) != null) {
+ lookedupValue = jsonObject.getAsJsonObject(POLICY_KEY).get(fieldTag).getAsString();
+ }
+ return lookedupValue;
+ }
+
+ /**
+ * Look up the UUID and description in the key information for a concept.
+ *
+ * @param session the Apex editor session
+ * @param jsonObject the JSON object to place the fields in
+ * @param name the concept name to look up
+ * @param version the concept version to look up
+ */
+ private boolean setUuidAndDescription(final RestSession session, JsonObject jsonObject, String name,
+ String version) {
+ // Look up the key information for the name and version
+ JsonObject keyInfoJsonObject = lookupKeyInfo(session, name, version);
+ if (keyInfoJsonObject == null || keyInfoJsonObject.get(APEX_KEY_INFO) != null) {
+ return false;
+ }
+
+ if (keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get("UUID") != null) {
+ jsonObject.addProperty(UUID,
+ keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get("UUID").getAsString());
+ } else {
+ jsonObject.addProperty(UUID, (String) null);
+ }
+
+ if (keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get(DESCRIPTION) != null) {
+ jsonObject.addProperty(DESCRIPTION,
+ keyInfoJsonObject.get(APEX_KEY_INFO).getAsJsonObject().get(DESCRIPTION).getAsString());
+ } else {
+ jsonObject.addProperty(DESCRIPTION, (String) null);
+ }
+
+ return true;
+ }
+
+ /**
+ * Look up the key information for the given concept name and value.
+ *
+ * @param session the Apex editor session
+ * @param name the concept name to look up
+ * @param version the concept version to look up
+ * @return a JSON version of the concept key information
+ */
+ private JsonObject lookupKeyInfo(final RestSession session, final String name, final String version) {
+ final ApexApiResult keyInfoResult = session.getApexModel().listKeyInformation(name, version);
+ final List<String> keyInfoMessages = keyInfoResult.getMessages();
+
+ if (keyInfoResult.isNok() || keyInfoMessages == null || keyInfoMessages.isEmpty()) {
+ return null;
+ }
+
+ final Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().create();
+ final String keyInfoJson = keyInfoMessages.get(0);
+ return gson.fromJson(keyInfoJson, JsonObject.class);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java
new file mode 100644
index 0000000..19130aa
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyHandler.java
@@ -0,0 +1,589 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import java.util.Map;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanKeyRef;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanLogic;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanPolicy;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanState;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanStateOutput;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanStateTaskRef;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class handles commands on policies in Apex models.
+ */
+public class PolicyHandler implements RestCommandHandler {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(PolicyHandler.class);
+
+ // Recurring string constants
+ private static final String OK = ": OK";
+ private static final String NOT_OK = ": Not OK";
+ private static final String POLICY_WAS_CREATED = "\". The policy was created, ";
+ private static final String POLICY_STATE_CREATED = "\". The policy and state were created, ";
+ private static final String POLICY_PARTIALLY_DEFINED = " The policy has only been partially defined.";
+ private static final String FOR_POLICY = "\" for policy \"";
+ private static final String IN_STATE = "\" in state \"";
+ private static final String POLICY_CREATED_STATE_ERROR = POLICY_WAS_CREATED
+ + "but there was an error adding the state.";
+ private static final String POLICY_STATE_CREATED_OTHER_ERROR = POLICY_STATE_CREATED
+ + "but there was an error adding the";
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+
+ if (!RestCommandType.POLICY.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case CREATE:
+ return createPolicy(session, jsonString);
+ case UPDATE:
+ return updatePolicy(session, jsonString);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ if (!RestCommandType.POLICY.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case LIST:
+ return listPolicies(session, name, version);
+ case DELETE:
+ return deletePolicy(session, name, version);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * Creates a policy with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed See {@linkplain BeanPolicy}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ public ApexApiResult createPolicy(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanPolicy jsonbean = RestUtils.getJsonParameters(jsonString, BeanPolicy.class);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().createPolicy(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getTemplate(), jsonbean.getFirstState(), jsonbean.getUuid(), jsonbean.getDescription());
+
+ if (result.isOk()) {
+ result = createPolicyContent(session, jsonbean);
+ }
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Policy/Create" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Create the content of the policy.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed See {@linkplain BeanPolicy}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createPolicyContent(RestSession session, BeanPolicy jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getStates() == null || jsonbean.getStates().isEmpty()) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null or empty state map; no states defined for policy \"" + jsonbean.getName() + ":"
+ + jsonbean.getVersion() + "\". The policy was created, but there was an error adding states."
+ + POLICY_PARTIALLY_DEFINED);
+ return result;
+ }
+
+ // States reference each other so all states must be created before they are
+ // populated
+ for (final Map.Entry<String, BeanState> stateEntry : jsonbean.getStates().entrySet()) {
+ ApexApiResult stateCreateResult = createState(session, jsonbean.getName(), jsonbean.getVersion(),
+ stateEntry.getKey(), stateEntry.getValue());
+
+ if (stateCreateResult.isNok()) {
+ result.setResult(stateCreateResult.getResult());
+ result.addMessage(stateCreateResult.getMessage());
+ }
+ }
+
+ // Bale out if the state creation did not work
+ if (result.isNok()) {
+ return result;
+ }
+
+ // Now create the content of each state
+ for (final Map.Entry<String, BeanState> stateEntry : jsonbean.getStates().entrySet()) {
+ ApexApiResult stateContentCreateResult = createStateContent(session, jsonbean.getName(),
+ jsonbean.getVersion(), stateEntry.getKey(), stateEntry.getValue());
+
+ if (stateContentCreateResult.isNok()) {
+ result.setResult(stateContentCreateResult.getResult());
+ result.addMessage(stateContentCreateResult.getMessage());
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create a state on the policy.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createState(final RestSession session, final String policyName, final String policyVersion,
+ final String stateName, final BeanState stateBean) {
+
+ if (stateBean == null) {
+ return new ApexApiResult(Result.FAILED,
+ "Null or invalid state information for state \"" + stateName + FOR_POLICY + policyName + ":"
+ + policyVersion + POLICY_CREATED_STATE_ERROR + POLICY_PARTIALLY_DEFINED);
+ }
+
+ if (stateBean.getTrigger() == null) {
+ return new ApexApiResult(Result.FAILED,
+ "Null or invalid state trigger for state \"" + stateName + FOR_POLICY + policyName + ":" + policyVersion
+ + POLICY_CREATED_STATE_ERROR + POLICY_PARTIALLY_DEFINED);
+ }
+
+ if (stateBean.getDefaultTask() == null) {
+ return new ApexApiResult(Result.FAILED, "Null or invalid default task for state \"" + stateName + FOR_POLICY
+ + policyName + ":" + policyVersion + POLICY_CREATED_STATE_ERROR + POLICY_PARTIALLY_DEFINED);
+ }
+
+ return session.getApexModelEdited().createPolicyState(policyName, policyVersion, stateName,
+ stateBean.getTrigger().getName(), stateBean.getTrigger().getVersion(), stateBean.getDefaultTask().getName(),
+ stateBean.getDefaultTask().getVersion());
+ }
+
+ /**
+ * Create the content of a state on the policy.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createStateContent(final RestSession session, final String policyName,
+ final String policyVersion, final String stateName, final BeanState stateBean) {
+
+ ApexApiResult ret = createStateTaskSelectionLogic(session, policyName, policyVersion, stateName, stateBean);
+
+ if (ret.isOk()) {
+ ret = createStateContextReferences(session, policyName, policyVersion, stateName, stateBean);
+ }
+
+ if (ret.isOk()) {
+ ret = createStateFinalizers(session, policyName, policyVersion, stateName, stateBean);
+ }
+
+ if (ret.isOk()) {
+ ret = createStateOutputs(session, policyName, policyVersion, stateName, stateBean);
+ }
+
+ if (ret.isOk()) {
+ ret = createStateTaskReferences(session, policyName, policyVersion, stateName, stateBean);
+ }
+
+ return ret;
+ }
+
+ /**
+ * Create the task selection logic for the state.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createStateTaskSelectionLogic(final RestSession session, final String policyName,
+ final String policyVersion, final String stateName, final BeanState stateBean) {
+
+ final BeanLogic tsl = stateBean.getTaskSelectionLogic();
+ if (tsl == null) {
+ return new ApexApiResult();
+ }
+
+ ApexApiResult result = session.getApexModelEdited().createPolicyStateTaskSelectionLogic(policyName,
+ policyVersion, stateName, tsl.getLogicFlavour(), tsl.getLogic());
+
+ if (result.isNok()) {
+ result.addMessage("Failed to add task selection logic for state \"" + stateName + "\" for" + " policy \""
+ + policyName + ":" + policyVersion + POLICY_WAS_CREATED
+ + "but there was an error adding the task selection logic "
+ + "for the state. The policy has only been partially defined.");
+ }
+ return result;
+ }
+
+ /**
+ * Create the context references for the state.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createStateContextReferences(final RestSession session, final String policyName,
+ final String policyVersion, final String stateName, final BeanState stateBean) {
+
+ ApexApiResult result = new ApexApiResult();
+
+ final BeanKeyRef[] contextReferences = stateBean.getContexts();
+ if (contextReferences == null || contextReferences.length == 0) {
+ return result;
+ }
+
+ for (final BeanKeyRef contextReference : contextReferences) {
+ if (contextReference == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null or invalid context reference \"" + contextReference + "\" for" + " state \""
+ + stateName + FOR_POLICY + policyName + ":" + policyVersion
+ + "\". The policy was created, but there was an error adding the context "
+ + "reference for the state. The policy has only been partially defined.");
+ continue;
+ }
+
+ ApexApiResult contextRefResult = session.getApexModelEdited().createPolicyStateContextRef(policyName,
+ policyVersion, stateName, contextReference.getName(), contextReference.getVersion());
+
+ if (contextRefResult.isNok()) {
+ result.setResult(contextRefResult.getResult());
+ result.addMessage("Failed to add context reference \"" + contextReference + "\" for state \""
+ + stateName + FOR_POLICY + policyName + ":" + policyVersion + POLICY_WAS_CREATED
+ + "but there was an error adding the context reference "
+ + "for the state. The policy has only been partially defined.");
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the state finalizers for the state.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createStateFinalizers(final RestSession session, final String policyName,
+ final String policyVersion, final String stateName, final BeanState stateBean) {
+
+ ApexApiResult result = new ApexApiResult();
+
+ final Map<String, BeanLogic> finalizers = stateBean.getFinalizers();
+ if (finalizers == null || finalizers.isEmpty()) {
+ return result;
+ }
+
+ for (final Map.Entry<String, BeanLogic> finalizerEntry : finalizers.entrySet()) {
+ if (finalizerEntry.getKey() == null || finalizerEntry.getValue() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null or invalid finalizer information for finalizer " + "named \""
+ + finalizerEntry.getKey() + IN_STATE + stateName + FOR_POLICY + policyName + ":" + policyVersion
+ + POLICY_STATE_CREATED_OTHER_ERROR + " finalizer. The policy has only "
+ + "been partially defined.");
+ continue;
+ }
+
+ ApexApiResult finalizerResult = session.getApexModelEdited().createPolicyStateFinalizerLogic(policyName,
+ policyVersion, stateName, finalizerEntry.getKey(), finalizerEntry.getValue().getLogicFlavour(),
+ finalizerEntry.getValue().getLogic());
+
+ if (finalizerResult.isNok()) {
+ result.setResult(finalizerResult.getResult());
+ result.addMessage("Failed to add finalizer information for finalizer named \"" + finalizerEntry.getKey()
+ + "\" in" + " state \"" + stateName + FOR_POLICY + policyName + ":" + policyVersion
+ + POLICY_STATE_CREATED_OTHER_ERROR + " finalizer. The policy has only been partially defined.");
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the state outputs for the state.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createStateOutputs(final RestSession session, final String policyName,
+ final String policyVersion, final String stateName, final BeanState stateBean) {
+
+ ApexApiResult result = new ApexApiResult();
+
+ final Map<String, BeanStateOutput> stateOutputs = stateBean.getStateOutputs();
+ if (stateOutputs == null || stateOutputs.isEmpty()) {
+ result.setResult(Result.FAILED);
+ result.addMessage("No state outputs have been defined in state \"" + stateName + FOR_POLICY + policyName
+ + ":" + policyVersion + "\". The policy and state were created, but there was an error adding state"
+ + " outputs. The policy has only been partially defined.");
+ return result;
+ }
+
+ for (final Map.Entry<String, BeanStateOutput> stateOutput : stateOutputs.entrySet()) {
+ final String outputName = stateOutput.getKey();
+ final BeanStateOutput output = stateOutput.getValue();
+
+ if (outputName == null || output == null || output.getEvent() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null or invalid output information for output named \"" + outputName + IN_STATE
+ + stateName + FOR_POLICY + policyName + ":" + policyVersion + POLICY_STATE_CREATED_OTHER_ERROR
+ + " output. The policy has only been partially defined.");
+ continue;
+ }
+
+ ApexApiResult outputResult = session.getApexModelEdited().createPolicyStateOutput(policyName, policyVersion,
+ stateName, outputName, output.getEvent().getName(), output.getEvent().getVersion(),
+ output.getNextState());
+
+ if (outputResult.isNok()) {
+ result.setResult(outputResult.getResult());
+ result.addMessage("Failed to add output information for output named \"" + outputName + IN_STATE
+ + stateName + FOR_POLICY + policyName + ":" + policyVersion + POLICY_STATE_CREATED
+ + "but there was an error adding the output." + POLICY_PARTIALLY_DEFINED);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the task references for the state.
+ *
+ * @param session the Apex model editing session
+ * @param policyName the policy name
+ * @param policVersion the policy version
+ * @param stateName the name of the state
+ * @param stateBean the information on the state to create
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createStateTaskReferences(final RestSession session, final String policyName,
+ final String policyVersion, final String stateName, final BeanState stateBean) {
+
+ ApexApiResult result = new ApexApiResult();
+
+ final Map<String, BeanStateTaskRef> taskMap = stateBean.getTasks();
+ if (taskMap == null || taskMap.isEmpty()) {
+ result.setResult(Result.FAILED);
+ result.addMessage("No tasks have been defined in state \"" + stateName + FOR_POLICY + policyName + ":"
+ + policyVersion + "\". The policy and state were created, but there was an error adding tasks."
+ + POLICY_PARTIALLY_DEFINED);
+ return result;
+ }
+
+ for (final Map.Entry<String, BeanStateTaskRef> taskEntry : taskMap.entrySet()) {
+ final String taskLocalName = taskEntry.getKey();
+ final BeanStateTaskRef taskReference = taskEntry.getValue();
+
+ if (taskLocalName == null || taskReference == null || taskReference.getTask() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null or invalid task information for task named \"" + taskLocalName + IN_STATE
+ + stateName + "\" for for policy \"" + policyName + ":" + policyVersion
+ + "\". The policy and state were created, but there was an error adding the "
+ + "task. The policy has only been partially defined.");
+ continue;
+ }
+
+ ApexApiResult taskRefResult = session.getApexModelEdited().createPolicyStateTaskRef(policyName,
+ policyVersion, stateName, taskLocalName, taskReference.getTask().getName(),
+ taskReference.getTask().getVersion(), taskReference.getOutputType(), taskReference.getOutputName());
+
+ if (taskRefResult.isNok()) {
+ result.setResult(taskRefResult.getResult());
+ result.addMessage("Failed to add task reference \"" + taskEntry + "\" for state \"" + stateName
+ + FOR_POLICY + policyName + ":" + policyVersion + POLICY_WAS_CREATED
+ + "but there was an error adding the task reference for"
+ + " the state. The policy has only been partially defined.");
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Update a policy with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See {@linkplain BeanPolicy}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult updatePolicy(final RestSession session, final String jsonString) {
+
+ LOGGER.entry(jsonString);
+
+ final BeanPolicy jsonbean = RestUtils.getJsonParameters(jsonString, BeanPolicy.class);
+
+ if (blank2Null(jsonbean.getName()) == null || blank2Null(jsonbean.getVersion()) == null) {
+ LOGGER.exit("Task/Update" + NOT_OK);
+ return new ApexApiResult(Result.FAILED, "Null/Empty Policy name/version (\"" + jsonbean.getName() + ":"
+ + jsonbean.getVersion() + "\" passed to UpdatePolicy");
+ }
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().deletePolicy(jsonbean.getName(), jsonbean.getVersion());
+
+ if (result.isOk()) {
+ result = session.getApexModelEdited().createPolicy(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getTemplate(), jsonbean.getFirstState(), jsonbean.getUuid(), jsonbean.getDescription());
+
+ if (result.isOk()) {
+ result = createPolicyContent(session, jsonbean);
+ }
+ }
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Policy/Update" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+
+ }
+
+ /**
+ * List policies with the given key names/versions. If successful the result(s)
+ * will be available in the result messages. The returned value(s) will be
+ * similar to {@link AxPolicy}, with merged {@linkplain AxKey Info} for the root
+ * object.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult listPolicies(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().listPolicy(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Policy/Get" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Delete policies with the given key names/versions.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult deletePolicy(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ session.editModel();
+
+ // all input/output fields, parameters, logic, context references is
+ // "owned"/contained
+ // in the task, so
+ // deleting the task removes all of these
+ ApexApiResult result = session.getApexModelEdited().deletePolicy(blank2Null(name), blank2Null(version));
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Policy/Delete" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommand.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommand.java
new file mode 100644
index 0000000..0b6a012
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommand.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+/**
+ * This enum maps REST calls to the handlers that process them.
+ *
+ */
+public enum RestCommand {
+ /**
+ * Create the target.
+ */
+ CREATE,
+ /**
+ * Update the target.
+ */
+ UPDATE,
+ /**
+ * List the target.
+ */
+ LIST,
+ /**
+ * Delete the target.
+ */
+ DELETE,
+ /**
+ * Validate the target.
+ */
+ VALIDATE,
+ /**
+ * Load the target.
+ */
+ LOAD,
+ /**
+ * Analyse the target.
+ */
+ ANALYSE,
+ /**
+ * Get the key of the currently loaded apex model.
+ */
+ GET_KEY,
+ /**
+ * Download the currently loaded apex model.
+ */
+ DOWNLOAD
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandHandler.java
new file mode 100644
index 0000000..4086298
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandHandler.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+
+/**
+ * This interface defines the methods that a REST handler must implement to
+ * handle REST editor commands.
+ *
+ */
+public interface RestCommandHandler {
+
+ /**
+ * Process a REST command.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to execute
+ * @param command the REST command to execute
+ * @return the apex api result the result of the execution
+ */
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command);
+
+ /**
+ * Process a REST command.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to execute
+ * @param command the REST command to execute
+ * @param jsonString the json string to use to execute the command
+ * @return the apex api result the result of the execution
+ */
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString);
+
+ /**
+ * Process a REST command.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to execute
+ * @param command the REST command to execute
+ * @param name the concept name on which to execute
+ * @param version the concept version the version on which to execute
+ * @return the apex api result the result of the execution
+ */
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version);
+
+ /**
+ * Get an unsupported command result message.
+ *
+ * @param session the Apex editor session
+ * @param commandType the type of REST command to execute
+ * @param command the REST command to execute
+ * @return the apex api result the result of the execution
+ */
+ public default ApexApiResult getUnsupportedCommandResultMessage(final RestSession session,
+ final RestCommandType commandType, final RestCommand command) {
+ return new ApexApiResult(Result.FAILED,
+ "session " + session.getSessionId() + ", command type " + commandType + ", command" + command + " invalid");
+ }
+
+ /**
+ * Convert blank incoming fields to nulls.
+ *
+ * @param incomingField the field to check
+ * @return null if the field is blank, otherwise, the field trimmed
+ */
+ public default String blank2Null(final String incomingField) {
+ if (incomingField == null) {
+ return null;
+ }
+
+ final String trimmedField = incomingField.trim();
+
+ if (trimmedField.isEmpty()) {
+ return null;
+ } else {
+ return trimmedField;
+ }
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandType.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandType.java
new file mode 100644
index 0000000..a521f69
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestCommandType.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+/**
+ * This enum maps REST calls to the handlers that process them.
+ *
+ */
+public enum RestCommandType {
+ /**
+ * Model commands.
+ */
+ MODEL,
+ /**
+ * Key Information commands.
+ */
+ KEY_INFO,
+ /**
+ * Context schema commands.
+ */
+ CONTEXT_SCHEMA,
+ /**
+ * Context album commands.
+ */
+ CONTEXT_ALBUM,
+ /**
+ * Event Commands.
+ */
+ EVENT,
+ /**
+ * Task commands.
+ */
+ TASK,
+ /**
+ * Policy commands.
+ */
+ POLICY
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java
new file mode 100644
index 0000000..6e12648
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSession.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+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.modelapi.ApexModelFactory;
+
+/**
+ * This class represents an ongoing editor session in the Apex editor and holds
+ * the information for the session.
+ *
+ */
+public class RestSession {
+ // The ID of the session
+ private int sessionId;
+
+ // The Apex policy model of the session
+ private ApexModel apexModel;
+
+ // The Apex policy model being edited
+ private ApexModel apexModelEdited;
+
+ public RestSession(final int sessionId) {
+ this.sessionId = sessionId;
+ this.apexModel = new ApexModelFactory().createApexModel(null, true);
+ }
+
+ /**
+ * Commence making changes to the Apex model.
+ *
+ * @return the result of the edit commencement operation
+ */
+ public synchronized ApexApiResult editModel() {
+ if (apexModelEdited != null) {
+ return new ApexApiResult(Result.FAILED, "model is already being edited");
+ }
+
+ apexModelEdited = apexModel.clone();
+ return new ApexApiResult();
+ }
+
+ /**
+ * Commit the changes to the Apex model.
+ *
+ * @return the result of the commit operation
+ */
+ public synchronized ApexApiResult commitChanges() {
+ if (apexModelEdited == null) {
+ return new ApexApiResult(Result.FAILED, "model is not being edited");
+ }
+
+ apexModel = apexModelEdited;
+ apexModelEdited = null;
+ return new ApexApiResult();
+ }
+
+ /**
+ * Discard the changes to the Apex model.
+ *
+ * @return the result of the discard operation
+ */
+ public synchronized ApexApiResult discardChanges() {
+ if (apexModelEdited == null) {
+ return new ApexApiResult(Result.FAILED, "model is not being edited");
+ }
+
+ apexModelEdited = null;
+ return new ApexApiResult();
+ }
+
+ /**
+ * Finish a session by committing or discarding the changes.
+ *
+ * @param commitFlag if ture, commit changes otherwise discard them
+ */
+ public void finishSession(boolean commitFlag) {
+ if (commitFlag) {
+ commitChanges();
+ } else {
+ discardChanges();
+ }
+ }
+
+ /**
+ * Get the session ID of the session.
+ *
+ * @return the sessionId
+ */
+ public int getSessionId() {
+ return sessionId;
+ }
+
+ /**
+ * Get the Apex model of the session.
+ *
+ * @return the apexModel
+ */
+ public ApexModel getApexModel() {
+ return apexModel;
+ }
+
+ /**
+ * Get the edited Apex model of the session.
+ *
+ * @return the apexModel
+ */
+ public ApexModel getApexModelEdited() {
+ return apexModelEdited;
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionHandler.java
new file mode 100644
index 0000000..2afd5bd
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestSessionHandler.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class carries out session handling for Apex REST editor sessions.
+ */
+public class RestSessionHandler {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(RestSessionHandler.class);
+
+ // The next session will have this number, stating at 0
+ private AtomicInteger nextSessionId = new AtomicInteger();
+
+ // All REST editor sessions being handled by this handler
+ private final Map<Integer, RestSession> sessionMap = new TreeMap<>();
+
+ /**
+ * Create a new session.
+ *
+ * @param result the result of session creation
+ * @return the new session object
+ */
+ public RestSession createSession(ApexApiResult result) {
+ LOGGER.entry("creating session");
+
+ // Create the session with the next session ID
+ final int newSessionId = nextSessionId.getAndIncrement();
+ sessionMap.put(newSessionId, new RestSession(newSessionId));
+
+ result.addMessage(Integer.toString(newSessionId));
+
+ LOGGER.exit("created session with ID: " + newSessionId);
+ return sessionMap.get(newSessionId);
+ }
+
+ /**
+ * Get a session for the given session ID.
+ *
+ * @param sessionId the session ID of the session we require
+ * @param result the result of the session get
+ * @return the session
+ */
+ public RestSession getSession(final int sessionId, ApexApiResult result) {
+ LOGGER.entry("finding session: " + sessionId);
+
+ // Check for valid session IDs
+ if (sessionId < 0) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Session ID \"" + sessionId + "\" is negative");
+ LOGGER.exit(result.getMessage());
+ return null;
+ }
+
+ // Check if session exits
+ if (!sessionMap.containsKey(sessionId)) {
+ result.setResult(Result.FAILED);
+ result.addMessage("A session with session ID \"" + sessionId + "\" does not exist");
+ LOGGER.exit(result.getMessage());
+ return null;
+ }
+
+ RestSession session = sessionMap.get(sessionId);
+
+ // Check if session is valid
+ if (session == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("The session with session ID \"" + sessionId + "\" is corrupt");
+ LOGGER.exit(result.getMessage());
+ return null;
+ }
+
+ // Return the session
+ LOGGER.exit("session found: " + sessionId);
+ return session;
+ }
+
+ /*
+ * This is a test method to set a corrupt session ID in the session map
+ *
+ * @param corruptSessionId the ID of the corrupt session
+ */
+ protected void setCorruptSession(int corruptSessionId) {
+ sessionMap.put(corruptSessionId, null);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java
new file mode 100644
index 0000000..819657f
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/RestUtils.java
@@ -0,0 +1,185 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
+import java.io.StringReader;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import javax.ws.rs.core.MediaType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import org.eclipse.persistence.jaxb.MarshallerProperties;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanBase;
+
+/**
+ * Utilities for handling RESTful communication for Apex.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public abstract class RestUtils {
+ // Regular expressions for checking input types
+ private static final String XML_INPUT_TYPE_REGEXP = "^\\s*<\\?xml.*>\\s*"; // starts with <?xml...>
+ /**
+ * starts with some kind of bracket [ or ( or {, then has something, then has
+ * bracket.
+ */
+ private static final String JSON_INPUT_TYPE_REGEXP = "^\\s*[\\(\\{\\[][\\s+\\S]*[\\)\\}\\]]";
+
+ /**
+ * Constructor, block inheritance.
+ */
+ private RestUtils() {
+ // Private constructor to block subclassing
+ }
+
+ /**
+ * HTTP POST requests can't send nulls so we interpret blanks as nulls.
+ *
+ * @param parameter the parameter to convert from blank to null
+ * @return null if the parameter us blank, otherwise the original parameter
+ */
+ private static String blank2null(final String parameter) {
+ return (parameter.length() == 0 ? null : parameter);
+ }
+
+ /**
+ * HTTP POST requests can't send nulls so we interpret blanks as nulls.
+ *
+ * @param val the val
+ * @return null if the parameter us blank, otherwise the original parameter
+ */
+ private static JsonElement blank2null(final JsonElement val) {
+ if (val == null) {
+ return JsonNull.INSTANCE;
+ }
+ if (val.isJsonPrimitive() && ((JsonPrimitive) val).isString()) {
+ final String v = ((JsonPrimitive) val).getAsString();
+ if (v == null || "".equals(v)) {
+ return JsonNull.INSTANCE;
+ }
+ }
+ if (val.isJsonArray()) {
+ final JsonArray arr = val.getAsJsonArray();
+ for (int i = 0; i < arr.size(); i++) {
+ arr.set(i, blank2null(arr.get(i)));
+ }
+ }
+ if (val.isJsonObject()) {
+ final JsonObject o = val.getAsJsonObject();
+ for (final Entry<String, JsonElement> e : o.entrySet()) {
+ e.setValue(blank2null(e.getValue()));
+ }
+ }
+ return val;
+ }
+
+ /**
+ * Apex HTTP PUT requests send simple single level JSON strings, this method
+ * reads those strings into a map.
+ *
+ * @param jsonString the incoming JSON string
+ * @return a map of the JSON strings
+ */
+ public static Map<String, String> getJsonParameters(final String jsonString) {
+ final GsonBuilder gb = new GsonBuilder();
+ gb.serializeNulls().enableComplexMapKeySerialization();
+ final JsonObject jsonObject = gb.create().fromJson(jsonString, JsonObject.class);
+
+ final Map<String, String> jsonMap = new TreeMap<>();
+ for (final Entry<String, JsonElement> jsonEntry : jsonObject.entrySet()) {
+ jsonMap.put(jsonEntry.getKey(),
+ (jsonEntry.getValue() == JsonNull.INSTANCE ? null : blank2null(jsonEntry.getValue().getAsString())));
+ }
+ return jsonMap;
+ }
+
+ /**
+ * Apex HTTP PUT requests send simple single level JSON strings, this method
+ * reads those strings into a map.
+ *
+ * @param <C> the generic type
+ * @param jsonString the incoming JSON string
+ * @param clz the clz
+ * @return a map of the JSON strings
+ */
+ public static <C extends BeanBase> C getJsonParameters(final String jsonString, final Class<C> clz) {
+ final GsonBuilder gb = new GsonBuilder();
+ gb.serializeNulls().enableComplexMapKeySerialization();
+ final JsonObject jsonObject = gb.create().fromJson(jsonString, JsonObject.class);
+
+ for (final Entry<String, JsonElement> jsonEntry : jsonObject.entrySet()) {
+ final JsonElement val = jsonEntry.getValue();
+ jsonEntry.setValue(blank2null(val));
+ }
+ return gb.create().fromJson(jsonObject, clz);
+ }
+
+ /**
+ * Gets the concept from JSON.
+ *
+ * @param <C> the generic type
+ * @param jsonString the json string
+ * @param clz the clz
+ * @return the concept from JSON
+ * @throws JAXBException the JAXB exception
+ */
+ public static <C extends AxConcept> C getConceptFromJson(final String jsonString, final Class<C> clz)
+ throws JAXBException {
+ Unmarshaller unmarshaller = null;
+ final JAXBContext jaxbContext = JAXBContext.newInstance(clz);
+ unmarshaller = jaxbContext.createUnmarshaller();
+ if (jsonString.matches(JSON_INPUT_TYPE_REGEXP)) {
+ unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
+ unmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
+ } else if (jsonString.matches(XML_INPUT_TYPE_REGEXP)) {
+ unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
+ } else {
+ return null;
+ }
+ final StreamSource source = new StreamSource(new StringReader(jsonString));
+ final JAXBElement<C> rootElement = unmarshaller.unmarshal(source, clz);
+ return rootElement.getValue();
+ }
+
+ /**
+ * Gets the JSO nfrom concept.
+ *
+ * @param object the object
+ * @return the JSO nfrom concept
+ */
+ public static String getJsonfromConcept(final Object object) {
+ final GsonBuilder gb = new GsonBuilder();
+ gb.serializeNulls().enableComplexMapKeySerialization();
+ return gb.create().toJson(object);
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java
new file mode 100644
index 0000000..8a52a03
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/TaskHandler.java
@@ -0,0 +1,468 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling;
+
+import java.util.Map.Entry;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.modelapi.ApexApiResult;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanField;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanKeyRef;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanLogic;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanTask;
+import org.onap.policy.gui.editors.apex.rest.handling.bean.BeanTaskParameter;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * This class handles commands on tasks in Apex models.
+ */
+public class TaskHandler implements RestCommandHandler {
+ // Get a reference to the logger
+ private static final XLogger LOGGER = XLoggerFactory.getXLogger(TaskHandler.class);
+
+ // Recurring string constants
+ private static final String OK = ": OK";
+ private static final String NOT_OK = ": Not OK";
+ private static final String IN_TASK = "\" in task ";
+ private static final String TASK_PARTIALLY_DEFINED = " The task has only been partially defined.";
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String jsonString) {
+ if (!RestCommandType.TASK.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case CREATE:
+ return createTask(session, jsonString);
+ case UPDATE:
+ return updateTask(session, jsonString);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
+ final RestCommand command, final String name, final String version) {
+ if (!RestCommandType.TASK.equals(commandType)) {
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+
+ switch (command) {
+ case LIST:
+ return listTasks(session, name, version);
+ case DELETE:
+ return deleteTask(session, name, version);
+ case VALIDATE:
+ return validateTask(session, name, version);
+ default:
+ return getUnsupportedCommandResultMessage(session, commandType, command);
+ }
+ }
+
+ /**
+ * Creates a task with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See {@linkplain BeanTask}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createTask(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanTask jsonbean = RestUtils.getJsonParameters(jsonString, BeanTask.class);
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().createTask(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getUuid(), jsonbean.getDescription());
+
+ if (result.isOk()) {
+ result = createTaskContent(session, jsonbean);
+ }
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Task/Create" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Create the content of the task.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See {@linkplain BeanTask}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult createTaskContent(final RestSession session, final BeanTask jsonbean) {
+ ApexApiResult result = createInputFields(session, jsonbean);
+
+ if (result.isOk()) {
+ result = createOutputFields(session, jsonbean);
+ }
+
+ if (result.isOk()) {
+ result = createTaskLogic(session, jsonbean);
+ }
+
+ if (result.isOk()) {
+ result = createTaskParameters(session, jsonbean);
+ }
+
+ if (result.isOk()) {
+ result = createContextReferences(session, jsonbean);
+ }
+ return result;
+ }
+
+ /**
+ * Create the input fields for the task.
+ *
+ * @param session the Apex model editing session
+ * @param jsonbean the ban containing the fields
+ * @return the result of the operation
+ */
+ private ApexApiResult createInputFields(final RestSession session, final BeanTask jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getInputFields() == null || jsonbean.getInputFields().isEmpty()) {
+ return result;
+ }
+
+ for (final Entry<String, BeanField> fieldEntry : jsonbean.getInputFields().entrySet()) {
+ if (fieldEntry.getValue() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null task input field information for field \"" + fieldEntry.getKey() + IN_TASK
+ + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the input fields."
+ + TASK_PARTIALLY_DEFINED);
+ continue;
+ }
+
+ if (fieldEntry.getKey() == null || !fieldEntry.getKey().equals(fieldEntry.getValue().getLocalName())) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Invalid task input field information for field \"" + fieldEntry.getKey() + IN_TASK
+ + jsonbean.getName() + ":" + jsonbean.getVersion() + ". The localName of the field (\""
+ + fieldEntry.getValue().getLocalName() + "\") is not the same as the field name. "
+ + "The task was created, but there was an error adding the input fields." + TASK_PARTIALLY_DEFINED);
+ } else {
+ ApexApiResult fieldCreationResult = session.getApexModelEdited().createTaskInputField(
+ jsonbean.getName(), jsonbean.getVersion(), fieldEntry.getKey(), fieldEntry.getValue().getName(),
+ fieldEntry.getValue().getVersion(), fieldEntry.getValue().getOptional());
+
+ if (fieldCreationResult.isNok()) {
+ result.setResult(fieldCreationResult.getResult());
+ result.addMessage("Failed to add task input field information for field \"" + fieldEntry.getKey()
+ + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the input fields."
+ + TASK_PARTIALLY_DEFINED);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the output fields for the task.
+ *
+ * @param session the Apex model editing session
+ * @param jsonbean the ban containing the fields
+ * @return the result of the operation
+ */
+ private ApexApiResult createOutputFields(final RestSession session, final BeanTask jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getOutputFields() == null || jsonbean.getOutputFields().isEmpty()) {
+ return result;
+ }
+
+ for (final Entry<String, BeanField> fieldEntry : jsonbean.getOutputFields().entrySet()) {
+ if (fieldEntry.getValue() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null task output field information for field \"" + fieldEntry.getKey() + IN_TASK
+ + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the output fields."
+ + TASK_PARTIALLY_DEFINED);
+ continue;
+ }
+
+ if (fieldEntry.getKey() == null || !fieldEntry.getKey().equals(fieldEntry.getValue().getLocalName())) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Invalid task output field information for field \"" + fieldEntry.getKey() + IN_TASK
+ + jsonbean.getName() + ":" + jsonbean.getVersion() + ". The localName of the field (\""
+ + fieldEntry.getValue().getLocalName() + "\") is not the same as the field name. "
+ + "The task was created, but there was an error adding the output fields."
+ + TASK_PARTIALLY_DEFINED);
+ } else {
+ ApexApiResult fieldCreationResult = session.getApexModelEdited().createTaskOutputField(
+ jsonbean.getName(), jsonbean.getVersion(), fieldEntry.getKey(), fieldEntry.getValue().getName(),
+ fieldEntry.getValue().getVersion(), fieldEntry.getValue().getOptional());
+ if (fieldCreationResult.isNok()) {
+ result.setResult(fieldCreationResult.getResult());
+ result.addMessage("Failed to add task output field information for field \"" + fieldEntry.getKey()
+ + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the output fields."
+ + TASK_PARTIALLY_DEFINED);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the task logic for the task.
+ *
+ * @param session the Apex model editing session
+ * @param jsonbean the bean containing the logic
+ * @return the result of the operation
+ */
+ private ApexApiResult createTaskLogic(final RestSession session, final BeanTask jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getTaskLogic() == null) {
+ return result;
+ }
+
+ final BeanLogic logic = jsonbean.getTaskLogic();
+ result = session.getApexModelEdited().createTaskLogic(jsonbean.getName(), jsonbean.getVersion(),
+ logic.getLogicFlavour(), logic.getLogic());
+
+ if (result.isNok()) {
+ result.addMessage("Failed to add task logic in task " + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the logic." + TASK_PARTIALLY_DEFINED);
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the task parameters for the task.
+ *
+ * @param session the Apex model editing session
+ * @param jsonbean the bean containing the parameters
+ * @return the result of the operation
+ */
+ private ApexApiResult createTaskParameters(final RestSession session, final BeanTask jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getParameters() == null || jsonbean.getParameters().isEmpty()) {
+ return result;
+ }
+
+ for (final Entry<String, BeanTaskParameter> parameterEntry : jsonbean.getParameters().entrySet()) {
+ if (parameterEntry.getKey() == null || parameterEntry.getValue() == null
+ || !parameterEntry.getKey().equals(parameterEntry.getValue().getParameterName())) {
+ result.setResult(Result.FAILED);
+ result
+ .addMessage("Null or invalid task parameter information for parameter \"" + parameterEntry.getKey()
+ + IN_TASK + jsonbean.getName() + ":" + jsonbean.getVersion() + ". The task was created, "
+ + "but there was an error adding the parameters." + TASK_PARTIALLY_DEFINED);
+ continue;
+ }
+ ApexApiResult createParResult = session.getApexModelEdited().createTaskParameter(jsonbean.getName(),
+ jsonbean.getVersion(), parameterEntry.getValue().getParameterName(),
+ parameterEntry.getValue().getDefaultValue());
+ if (createParResult.isNok()) {
+ result.setResult(createParResult.getResult());
+ result.addMessage("Failed to add task parameter \"" + parameterEntry.getKey() + IN_TASK
+ + jsonbean.getName() + ":" + jsonbean.getVersion()
+ + ". The task was created, but there was an error adding the parameters." + TASK_PARTIALLY_DEFINED);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create the context references for the task.
+ *
+ * @param session the Apex model editing session
+ * @param jsonbean the bean containing the context references
+ * @return the result of the operation
+ */
+ private ApexApiResult createContextReferences(final RestSession session, final BeanTask jsonbean) {
+ ApexApiResult result = new ApexApiResult();
+
+ if (jsonbean.getContexts() == null || jsonbean.getContexts().length == 0) {
+ return result;
+ }
+
+ for (final BeanKeyRef contextalbum : jsonbean.getContexts()) {
+ if (contextalbum.getName() == null || contextalbum.getVersion() == null) {
+ result.setResult(Result.FAILED);
+ result.addMessage("Null or invalid context album reference information in task " + jsonbean.getName()
+ + ":" + jsonbean.getVersion() + ". The task was created, but there was an error adding the"
+ + " context album reference. " + "The task has only been partially defined.");
+ continue;
+ }
+ ApexApiResult createRefResult = session.getApexModelEdited().createTaskContextRef(jsonbean.getName(),
+ jsonbean.getVersion(), contextalbum.getName(), contextalbum.getVersion());
+ if (createRefResult.isNok()) {
+ result.setResult(createRefResult.getResult());
+ result.addMessage("Failed to add context album reference information in task " + jsonbean.getName()
+ + ":" + jsonbean.getVersion() + ". The task was created, but there was an error adding the"
+ + " context album reference. " + "The task has only been partially defined.");
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Update a task with the information in the JSON string passed.
+ *
+ * @param session the Apex model editing session
+ * @param jsonString the JSON string to be parsed. See {@linkplain BeanTask}
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult updateTask(final RestSession session, final String jsonString) {
+ LOGGER.entry(jsonString);
+
+ final BeanTask jsonbean = RestUtils.getJsonParameters(jsonString, BeanTask.class);
+
+ if (blank2Null(jsonbean.getName()) == null || blank2Null(jsonbean.getVersion()) == null) {
+ LOGGER.exit("Task/Update" + NOT_OK);
+ return new ApexApiResult(Result.FAILED, "Null/Empty task name/version (\"" + jsonbean.getName() + ":"
+ + jsonbean.getVersion() + "\" passed to UpdateTask");
+ }
+
+ session.editModel();
+
+ ApexApiResult result = session.getApexModelEdited().deleteTask(jsonbean.getName(), jsonbean.getVersion());
+
+ if (result.isOk()) {
+ result = session.getApexModelEdited().createTask(jsonbean.getName(), jsonbean.getVersion(),
+ jsonbean.getUuid(), jsonbean.getDescription());
+
+ if (result.isOk()) {
+ result = createTaskContent(session, jsonbean);
+ }
+ }
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Task/Update" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * List tasks with the given key names/versions. If successful the result(s)
+ * will be available in the result messages. The returned value(s) will be
+ * similar to {@link AxTask}, with merged {@linkplain AxKeyInfo} for the root
+ * object.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult listTasks(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().listTask(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Task/Get" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Delete tasks with the given key names/versions.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult deleteTask(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ session.editModel();
+
+ // all input/output fields, parameters, logic, context references is
+ // "owned"/contained
+ // in the task, so
+ // deleting the task removes all of these
+ ApexApiResult result = session.getApexModelEdited().deleteTask(blank2Null(name), blank2Null(version));
+
+ session.finishSession(result.isOk());
+
+ LOGGER.exit("Task/Delete" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+
+ /**
+ * Validate tasks with the given key names/versions. The result(s) will be
+ * available in the result messages.
+ *
+ * @param session the Apex model editing session
+ * @param name the name to search for. If null or empty, then all names will
+ * be queried
+ * @param version the version to search for. If null then all versions will be
+ * searched for.
+ * @return an ApexAPIResult object. If successful then
+ * {@link ApexApiResult#isOk()} will return true. Any messages/errors
+ * can be retrieved using {@link ApexApiResult#getMessages()}
+ */
+ private ApexApiResult validateTask(final RestSession session, final String name, final String version) {
+ LOGGER.entry(name, version);
+
+ ApexApiResult result = session.getApexModel().validateTask(blank2Null(name), blank2Null(version));
+
+ LOGGER.exit("Validate/Task" + (result != null && result.isOk() ? OK : NOT_OK));
+ return result;
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanBase.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanBase.java
new file mode 100644
index 0000000..261cbae
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanBase.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * The base class for Beans.
+ */
+public abstract class BeanBase {
+ // Recurring string constants
+ private static final String PROBLEM_RETRIEVING_FIELD_PREFIX = "Problem retrieving field called ('";
+ private static final String JSON_BEAN_SUFFIX = "') from JSON bean ";
+
+ // Magic numbers
+ private static final int GET_LENGTH = 3;
+
+ /**
+ * Gets a named field from the bean.
+ *
+ * @param field the field name
+ * @return the value for the field
+ */
+ public String get(final String field) {
+ // use getter preferably
+ for (final Method method : this.getClass().getMethods()) {
+ if (method.getName().startsWith("get") && method.getName().length() == (field.length() + GET_LENGTH)
+ && method.getName().toLowerCase().endsWith(field.toLowerCase())) {
+ return invokeGetterMethod(field, method);
+ }
+ }
+
+ // Use field approach
+ if (field != null) {
+ try {
+ final Field f = this.getClass().getDeclaredField(field);
+ if (f != null) {
+ f.setAccessible(true);
+ return (String) (f.get(this));
+ }
+ } catch (final Exception e) {
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this,
+ e);
+ }
+ }
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this);
+ }
+
+ /**
+ * Invoke a getter method on a bean.
+ *
+ * @param field the field that the getter gets a value for
+ * @param method the method to invoke
+ */
+ private String invokeGetterMethod(final String field, final Method method) {
+ try {
+ return (String) method.invoke(this);
+ } catch (final Exception e) {
+ throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e);
+ }
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextAlbum.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextAlbum.java
new file mode 100644
index 0000000..51ccafb
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextAlbum.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The ContextAlbum Bean.
+ */
+@XmlType
+public class BeanContextAlbum extends BeanBase {
+ private String name = null;
+ private String version = null;
+ private String scope = null;
+ private String uuid = null;
+ private String description = null;
+ private BeanKeyRef itemSchema = null;
+ private boolean writeable;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Gets the scope.
+ *
+ * @return the scope
+ */
+ public String getScope() {
+ return scope;
+ }
+
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Gets the item schema.
+ *
+ * @return the item schema
+ */
+ public BeanKeyRef getItemSchema() {
+ return itemSchema;
+ }
+
+ /**
+ * Gets the writeable.
+ *
+ * @return the writeable
+ */
+ public boolean getWriteable() {
+ return writeable;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "ContextAlbum [name=" + name + ", version=" + version + ", scope=" + scope + ", uuid=" + uuid
+ + ", description=" + description + ", itemSchema=" + itemSchema + ", writeable=" + writeable + "]";
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java
new file mode 100644
index 0000000..bec3fcd
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanContextSchema.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The ContextSchema Bean.
+ */
+@XmlType
+public class BeanContextSchema extends BeanBase {
+ private String name = null;
+ private String version = null;
+ private String schemaFlavour = null;
+ private String schemaDefinition = null;
+ private String uuid = null;
+ private String description = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Gets the schema flavour.
+ *
+ * @return the schema flavour
+ */
+ public String getSchemaFlavour() {
+ return schemaFlavour;
+ }
+
+ /**
+ * Gets the schema definition.
+ *
+ * @return the schema definition
+ */
+ public String getSchemaDefinition() {
+ return schemaDefinition;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "ContextSchema [name=" + name + ", version=" + version + ", schemaFlavour=" + schemaFlavour
+ + ", schemaDefinition=" + schemaDefinition + ", uuid=" + uuid + ", description=" + description + "]";
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanEvent.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanEvent.java
new file mode 100644
index 0000000..2e14f72
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanEvent.java
@@ -0,0 +1,136 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Event Bean.
+ */
+@XmlType
+public class BeanEvent extends BeanBase {
+ private String name = null;
+ private String version = null;
+ private String nameSpace = null;
+ private String source = null;
+ private String target = null;
+ private String uuid = null;
+ private String description = null;
+ private Map<String, BeanField> parameters = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Gets the name space.
+ *
+ * @return the name space
+ */
+ public String getNameSpace() {
+ return nameSpace;
+ }
+
+ /**
+ * Gets the source.
+ *
+ * @return the source
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * Gets the target.
+ *
+ * @return the target
+ */
+ public String getTarget() {
+ return target;
+ }
+
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Gets the parameters.
+ *
+ * @return the parameters
+ */
+ public Map<String, BeanField> getParameters() {
+ return parameters;
+ }
+
+ /**
+ * Gets the parameter.
+ *
+ * @param ps the parameter string
+ * @return the parameter
+ */
+ public BeanField getParameter(final String ps) {
+ if (parameters != null) {
+ return parameters.get(ps);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "Event [name=" + name + ", version=" + version + ", nameSpace=" + nameSpace + ", source=" + source
+ + ", target=" + target + ", uuid=" + uuid + ", description=" + description + ", parameters="
+ + getParameters() + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanField.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanField.java
new file mode 100644
index 0000000..0a9042c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanField.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Field Bean.
+ */
+@XmlType
+public class BeanField extends BeanKeyRef {
+
+ private boolean optional = true;
+ private String localName = null;
+
+ /**
+ * Gets the local name for this field.
+ *
+ * @return the local name for this field.
+ */
+ public String getLocalName() {
+ return localName;
+ }
+
+ /**
+ * Gets the optional flag.
+ *
+ * @return the optional flag
+ */
+ public boolean getOptional() {
+ return optional;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "Field [localName=" + getLocalName() + ", name=" + getName() + ", version=" + getVersion()
+ + ", optional=" + getOptional() + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanKeyRef.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanKeyRef.java
new file mode 100644
index 0000000..6238b3c
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanKeyRef.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Key Reference Bean.
+ */
+@XmlType
+public class BeanKeyRef extends BeanBase {
+ private String name = null;
+ private String version = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "KeyRef [name=" + name + ", version=" + version + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanLogic.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanLogic.java
new file mode 100644
index 0000000..a11b768
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanLogic.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Logic Bean.
+ */
+@XmlType
+public class BeanLogic extends BeanBase {
+ private String logic = null;
+ private String logicFlavour = null;
+
+ /**
+ * Gets the logic flavour.
+ *
+ * @return the logic flavour
+ */
+ public String getLogicFlavour() {
+ return logicFlavour;
+ }
+
+ /**
+ * Gets the logic.
+ *
+ * @return the logic
+ */
+ public String getLogic() {
+ return logic;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "Logic [logicFlavour=" + logicFlavour + ", logic=" + logic + "]";
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java
new file mode 100644
index 0000000..fdb3c9b
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanModel.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Model Bean.
+ */
+@XmlType
+public class BeanModel extends BeanBase {
+
+ private String name = null;
+ private String version = null;
+ private String uuid = null;
+ private String description = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "Model [name=" + name + ", version=" + version + ", uuid=" + uuid + ", description=" + description + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanPolicy.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanPolicy.java
new file mode 100644
index 0000000..be67402
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanPolicy.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Policy Bean.
+ */
+@XmlType
+public class BeanPolicy extends BeanBase {
+ private String name = null;
+ private String version = null;
+ private String uuid = null;
+ private String description = null;
+ private String firstState = null;
+ private String template = null;
+ private Map<String, BeanState> states = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Gets the first state.
+ *
+ * @return the first state
+ */
+ public String getFirstState() {
+ return firstState;
+ }
+
+ /**
+ * Gets the template.
+ *
+ * @return the template
+ */
+ public String getTemplate() {
+ return template;
+ }
+
+ /**
+ * Gets the states.
+ *
+ * @return the states
+ */
+ public Map<String, BeanState> getStates() {
+ return states;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "Policy [name=" + name + ", version=" + version + ", uuid=" + uuid + ", description=" + description
+ + ", firstState=" + firstState + ", template=" + template + ", states=" + states + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanState.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanState.java
new file mode 100644
index 0000000..e1a5c68
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanState.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import java.util.Arrays;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The State Bean.
+ */
+@XmlType
+public class BeanState extends BeanBase {
+
+ private String name = null;
+ private BeanKeyRef trigger = null;
+ private BeanKeyRef defaultTask = null;
+ private BeanKeyRef[] contexts = null;
+ private BeanLogic taskSelectionLogic = null;
+ private Map<String, BeanStateTaskRef> tasks = null;
+ private Map<String, BeanLogic> finalizers = null;
+ private Map<String, BeanStateOutput> stateOutputs = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the trigger.
+ *
+ * @return the trigger
+ */
+ public BeanKeyRef getTrigger() {
+ return trigger;
+ }
+
+ /**
+ * Gets the contexts.
+ *
+ * @return the contexts
+ */
+ public BeanKeyRef[] getContexts() {
+ return contexts;
+ }
+
+ /**
+ * Gets the task selection logic.
+ *
+ * @return the task selection logic
+ */
+ public BeanLogic getTaskSelectionLogic() {
+ return taskSelectionLogic;
+ }
+
+ /**
+ * Gets the tasks.
+ *
+ * @return the tasks
+ */
+ public Map<String, BeanStateTaskRef> getTasks() {
+ return tasks;
+ }
+
+ /**
+ * Gets the finalizers.
+ *
+ * @return the finalizers
+ */
+ public Map<String, BeanLogic> getFinalizers() {
+ return finalizers;
+ }
+
+ /**
+ * Gets the state outputs.
+ *
+ * @return the state outputs
+ */
+ public Map<String, BeanStateOutput> getStateOutputs() {
+ return stateOutputs;
+ }
+
+ /**
+ * Gets the default task.
+ *
+ * @return the default task
+ */
+ public BeanKeyRef getDefaultTask() {
+ return defaultTask;
+ }
+
+ /**
+ * Sets the default task.
+ *
+ * @param defaultTask the new default task
+ */
+ public void setDefaultTask(final BeanKeyRef defaultTask) {
+ this.defaultTask = defaultTask;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "State [name=" + name + ", trigger=" + trigger + ", defaultTask=" + defaultTask + ", contexts="
+ + Arrays.toString(contexts) + ", taskSelectionLogic=" + taskSelectionLogic + ", tasks=" + tasks
+ + ", finalizers=" + finalizers + ", stateOutputs=" + stateOutputs + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateOutput.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateOutput.java
new file mode 100644
index 0000000..ee4c3fc
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateOutput.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The StateOutput Bean.
+ */
+@XmlType
+public class BeanStateOutput extends BeanBase {
+
+ private BeanKeyRef event = null;
+ private String nextState = null;
+
+ /**
+ * Gets the event.
+ *
+ * @return the event
+ */
+ public BeanKeyRef getEvent() {
+ return event;
+ }
+
+ /**
+ * Gets the next state.
+ *
+ * @return the next state
+ */
+ public String getNextState() {
+ return nextState;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "StateOutput [event=" + event + ", nextState=" + nextState + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateTaskRef.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateTaskRef.java
new file mode 100644
index 0000000..9b31dad
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanStateTaskRef.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The State Task Reference Bean.
+ */
+@XmlType
+public class BeanStateTaskRef extends BeanBase {
+ private BeanKeyRef task = null;
+ private String outputType = null;
+ private String outputName = null;
+
+ /**
+ * Gets the task.
+ *
+ * @return the task
+ */
+ public BeanKeyRef getTask() {
+ return task;
+ }
+
+ /**
+ * Gets the output type.
+ *
+ * @return the output type
+ */
+ public String getOutputType() {
+ return outputType;
+ }
+
+ /**
+ * Gets the output name.
+ *
+ * @return the output name
+ */
+ public String getOutputName() {
+ return outputName;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "StateTaskRef [task=" + task + ", outputType=" + outputType + ", outputName=" + outputName + "]";
+ }
+
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java
new file mode 100644
index 0000000..010745e
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTask.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import java.util.Arrays;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Task Bean.
+ */
+@XmlType
+public class BeanTask extends BeanBase {
+ private String name = null;
+ private String version = null;
+ private String uuid = null;
+ private String description = null;
+ private BeanLogic taskLogic = null;
+ private Map<String, BeanField> inputFields = null;
+ private Map<String, BeanField> outputFields = null;
+ private Map<String, BeanTaskParameter> parameters = null;
+ private BeanKeyRef[] contexts = null;
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
+ public String getUuid() {
+ return uuid;
+ }
+
+ /**
+ * Gets the description.
+ *
+ * @return the description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Gets the task logic.
+ *
+ * @return the task logic
+ */
+ public BeanLogic getTaskLogic() {
+ return taskLogic;
+ }
+
+ /**
+ * Gets the input fields.
+ *
+ * @return the input fields
+ */
+ public Map<String, BeanField> getInputFields() {
+ return inputFields;
+ }
+
+ /**
+ * Gets the output fields.
+ *
+ * @return the output fields
+ */
+ public Map<String, BeanField> getOutputFields() {
+ return outputFields;
+ }
+
+ /**
+ * Gets the parameters.
+ *
+ * @return the parameters
+ */
+ public Map<String, BeanTaskParameter> getParameters() {
+ return parameters;
+ }
+
+ /**
+ * Gets the contexts.
+ *
+ * @return the contexts
+ */
+ public BeanKeyRef[] getContexts() {
+ return contexts;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "BeanTask [name=" + name + ", version=" + version + ", uuid=" + uuid + ", description=" + description
+ + ", taskLogic=" + taskLogic + ", inputFields=" + inputFields + ", outputFields=" + outputFields
+ + ", parameters=" + parameters + ", contexts=" + Arrays.toString(contexts) + "]";
+ }
+}
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTaskParameter.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTaskParameter.java
new file mode 100644
index 0000000..5210a48
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/bean/BeanTaskParameter.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.gui.editors.apex.rest.handling.bean;
+
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * The Task Parameter Bean.
+ */
+@XmlType
+public class BeanTaskParameter extends BeanBase {
+
+ private String parameterName = null;
+ private String defaultValue = null;
+
+ /**
+ * Gets the parameter name.
+ *
+ * @return the parameter name
+ */
+ public String getParameterName() {
+ return parameterName;
+ }
+
+ /**
+ * Gets the default value.
+ *
+ * @return the default value
+ */
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String toString() {
+ return "TaskParameter [parameterName=" + parameterName + ", defaultValue=" + defaultValue + "]";
+ }
+
+}