aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2019-07-24 09:35:31 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2019-07-24 09:35:31 +0000
commita86ba140b1e100a2db2b04fc5f4f55bbb8eace42 (patch)
treef969bfdca22f9777b205d441d876e29fc8aa65d3
parent9e4e4474ee079176b26ed0af7105a4b23540d585 (diff)
Extend APEX CLIEditor to generate policy in ToscaServiceTemplate format
Currently apex CLIEditor is used to generate a json policy model from apex CLI language (.apex) file. As per the new LifeCycle API, the policies are expected to be defined as ToscaServiceTemplate. Hence, the current CLIEditor is extended to generate the policies in ToscaServiceTemplate way. Change-Id: I2eb5d5b146643d40b623e329a2a63d6bb0c1fb42 Issue-ID: POLICY-1885 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
-rw-r--r--auth/cli-editor/pom.xml7
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java15
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java22
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java70
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java360
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java110
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java74
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameters.java57
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java221
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java109
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java38
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java156
-rw-r--r--auth/cli-editor/src/test/resources/tosca/ApexConfig.json46
-rw-r--r--auth/cli-editor/src/test/resources/tosca/PolicyModel.apex180
-rw-r--r--auth/cli-editor/src/test/resources/tosca/PolicyModel.json952
-rw-r--r--auth/cli-editor/src/test/resources/tosca/ToscaPolicyOutput_compare.json1
-rw-r--r--auth/cli-editor/src/test/resources/tosca/ToscaTemplate.json19
-rw-r--r--pom.xml4
18 files changed, 2056 insertions, 385 deletions
diff --git a/auth/cli-editor/pom.xml b/auth/cli-editor/pom.xml
index 8ae9d8d53..d10b9959d 100644
--- a/auth/cli-editor/pom.xml
+++ b/auth/cli-editor/pom.xml
@@ -45,6 +45,13 @@
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
+
+ <!--test dependencies -->
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
index fc9424357..9258b45b8 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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=========================================================
*/
@@ -24,7 +25,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
-
+import org.onap.policy.apex.auth.clieditor.utils.CliUtils;
import org.onap.policy.apex.model.utilities.json.JsonHandler;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -64,7 +65,7 @@ public class ApexCommandLineEditorMain {
parameters = parser.parse(args);
if (parameters.isHelpSet()) {
- parser.help(ApexCommandLineEditorMain.class.getName());
+ CliUtils.help(ApexCommandLineEditorMain.class.getName(), parser.getOptions());
return;
}
parameters.validate();
@@ -165,7 +166,7 @@ public class ApexCommandLineEditorMain {
/**
* Get the number of errors encountered in command processing.
- *
+ *
* @return the number of errors
*/
public int getErrorCount() {
@@ -174,7 +175,7 @@ public class ApexCommandLineEditorMain {
/**
* Sets the number of errors encountered in command processing.
- *
+ *
* @param errorCount the number of errors
*/
public void setErrorCount(final int errorCount) {
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
index e95acedcd..b4f31b9e8 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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=========================================================
*/
@@ -38,7 +39,6 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.TreeMap;
-
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.apex.model.modelapi.ApexApiResult;
@@ -120,7 +120,7 @@ public class CommandLineEditorLoop {
}
// Get the output model
- if (!parameters.isSuppressModelOutputSet()) {
+ if (!parameters.isSuppressModelOutput()) {
final String modelString = modelHandler.writeModelToString(writer);
if (parameters.checkSetOutputModelFileName()) {
@@ -138,7 +138,7 @@ public class CommandLineEditorLoop {
/**
* Check if the command processing loop has come to an end.
- *
+ *
* @param executionStatus a pair containing the result of the last command and the accumulated error count
* @param parameters the input parameters for command execution
* @return true if the command processing loop should exit
@@ -153,7 +153,7 @@ public class CommandLineEditorLoop {
/**
* Process the incoming commands one by one.
- *
+ *
* @param parameters the parameters to the CLI editor
* @param reader the reader to read the logic block from
* @param writer the writer to write results and error messages on
@@ -178,7 +178,7 @@ public class CommandLineEditorLoop {
line = expandMacroFile(parameters, line);
}
- if (parameters.isEchoSet()) {
+ if (parameters.isEcho()) {
writer.println(line);
}
@@ -221,7 +221,7 @@ public class CommandLineEditorLoop {
/**
* Read a logic block, a block of program logic for a policy.
- *
+ *
* @param parameters the parameters to the CLI editor
* @param reader the reader to read the logic block from
* @param writer the writer to write results and error messages on
@@ -244,7 +244,7 @@ public class CommandLineEditorLoop {
logicLine = expandMacroFile(parameters, logicLine);
}
- if (parameters.isEchoSet()) {
+ if (parameters.isEcho()) {
writer.println(logicLine);
}
@@ -549,7 +549,7 @@ public class CommandLineEditorLoop {
/**
* This method reads in the file from a file macro statement, expands the macro, and replaces the Macro tag in the
* line with the file contents.
- *
+ *
* @param parameters The parameters for the CLI editor
* @param line The line with the macro keyword in it
* @return the expanded line
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
index 3465a6dd8..d630d89a5 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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=========================================================
*/
@@ -22,10 +23,10 @@ package org.onap.policy.apex.auth.clieditor;
import java.nio.file.Paths;
import java.util.Arrays;
-
+import java.util.Properties;
+import lombok.Getter;
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;
@@ -35,17 +36,20 @@ import org.apache.commons.cli.ParseException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+@Getter
public class CommandLineParameterParser {
- private static final int MAX_HELP_LINE_LENGTH = 120;
// Apache Commons CLI options
private final Options options;
+ private Properties optionVariableMap;
/**
* Construct the options for the CLI editor.
*/
public CommandLineParameterParser() {
options = new Options();
+ optionVariableMap = new Properties();
+
options.addOption(Option.builder("h").longOpt("help").desc("outputs the usage of this command").required(false)
.type(Boolean.class).build());
options.addOption(Option.builder("m").longOpt("metadata-file").desc("name of the command metadata file to use")
@@ -92,6 +96,21 @@ public class CommandLineParameterParser {
* @return the CLI parameters
*/
public CommandLineParameters parse(final String[] args) {
+ CommandLine commandLine = parseDefault(args);
+ final CommandLineParameters parameters = new CommandLineParameters();
+ parseSingleLetterOptions(commandLine, parameters);
+ parseDoubleLetterOptions(commandLine, parameters);
+
+ return parameters;
+ }
+
+ /**
+ * Parse the command line options using default parser.
+ *
+ * @param args The arguments
+ * @return the CLI parameters
+ */
+ protected CommandLine parseDefault(final String[] args) {
CommandLine commandLine = null;
try {
commandLine = new DefaultParser().parse(options, args);
@@ -99,41 +118,40 @@ public class CommandLineParameterParser {
throw new CommandLineException("invalid command line arguments specified : " + e.getMessage());
}
- final CommandLineParameters parameters = new CommandLineParameters();
final String[] remainingArgs = commandLine.getArgs();
if (remainingArgs.length > 0) {
throw new CommandLineException(
"too many command line arguments specified : " + Arrays.toString(remainingArgs));
}
-
- parseSIngleLetterOptions(commandLine, parameters);
- parseDoubleLetterOptions(commandLine, parameters);
-
- return parameters;
+ return commandLine;
}
/**
* Parse options with just a single letter.
- *
+ *
* @param commandLine the command line
* @param parameters the parsed parameters
*/
- private void parseDoubleLetterOptions(CommandLine commandLine, final CommandLineParameters parameters) {
+ protected void parseDoubleLetterOptions(CommandLine commandLine, final CommandLineParameters parameters) {
if (commandLine.hasOption("nl")) {
parameters.setSuppressLog(true);
+ optionVariableMap.setProperty("nl", "suppressLog");
}
if (commandLine.hasOption("nm")) {
parameters.setSuppressModelOutput(true);
+ optionVariableMap.setProperty("nm", "suppressModelOutput");
}
if (commandLine.hasOption("if")) {
parameters.setIgnoreCommandFailuresSet(true);
parameters.setIgnoreCommandFailures(Boolean.valueOf(commandLine.getOptionValue("if")));
+ optionVariableMap.setProperty("if", "ignoreCommandFailures");
} else {
parameters.setIgnoreCommandFailuresSet(false);
}
if (commandLine.hasOption("wd")) {
parameters.setWorkingDirectory(commandLine.getOptionValue("wd"));
+ optionVariableMap.setProperty("wd", "workingDirectory");
} else {
parameters.setWorkingDirectory(Paths.get("").toAbsolutePath().toString());
}
@@ -141,41 +159,39 @@ public class CommandLineParameterParser {
/**
* Parse options with two letters.
- *
+ *
* @param commandLine the command line
* @param parameters the parsed parameters
*/
- private void parseSIngleLetterOptions(CommandLine commandLine, final CommandLineParameters parameters) {
+ protected void parseSingleLetterOptions(CommandLine commandLine, final CommandLineParameters parameters) {
if (commandLine.hasOption('h')) {
- parameters.setHelp(true);
+ parameters.setHelpSet(true);
+ optionVariableMap.setProperty("h", "helpSet");
}
if (commandLine.hasOption('m')) {
parameters.setMetadataFileName(commandLine.getOptionValue('m'));
+ optionVariableMap.setProperty("m", "metadataFileName");
}
if (commandLine.hasOption('a')) {
- parameters.setApexPorpertiesFileName(commandLine.getOptionValue('a'));
+ parameters.setApexPropertiesFileName(commandLine.getOptionValue('a'));
+ optionVariableMap.setProperty("a", "apexPropertiesFileName");
}
if (commandLine.hasOption('c')) {
parameters.setCommandFileName(commandLine.getOptionValue('c'));
+ optionVariableMap.setProperty("c", "commandFileName");
}
if (commandLine.hasOption('l')) {
parameters.setLogFileName(commandLine.getOptionValue('l'));
+ optionVariableMap.setProperty("l", "logFileName");
}
if (commandLine.hasOption('i')) {
parameters.setInputModelFileName(commandLine.getOptionValue('i'));
+ optionVariableMap.setProperty("i", "inputModelFileName");
}
if (commandLine.hasOption('o')) {
parameters.setOutputModelFileName(commandLine.getOptionValue('o'));
+ optionVariableMap.setProperty("o", "outputModelFileName");
}
}
- /**
- * Print help information.
- *
- * @param mainClassName the main class name
- */
- public void help(final String mainClassName) {
- final HelpFormatter helpFormatter = new HelpFormatter();
- helpFormatter.printHelp(MAX_HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, "");
- }
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
index 01eeb6162..87c7a0828 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +28,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.apex.auth.clieditor.utils.CliUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
/**
@@ -35,9 +38,9 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+@Setter
+@Getter
public class CommandLineParameters {
- // Recurring string constants
- private static final String OF_TYPE_TAG = " of type ";
// Default location of the command definition meta data in JSON
private static final String JSON_COMMAND_METADATA_RESOURCE = "etc/editor/Commands.json";
@@ -62,26 +65,26 @@ public class CommandLineParameters {
* Validates the command line parameters.
*/
public void validate() {
- validateReadableFile("Metadata File", metadataFileName);
- validateReadableFile("Properties File", apexPropertiesFileName);
- validateReadableFile("Command File", commandFileName);
- validateReadableFile("Input Model File", inputModelFileName);
- validateWritableFile("Output Model File", outputModelFileName);
- validateWritableFile("Log File", logFileName);
- validateWritableDirectory("Working Directory", workingDirectory);
-
- if (isSuppressLogSet()) {
+ CliUtils.validateReadableFile("Metadata File", metadataFileName);
+ CliUtils.validateReadableFile("Properties File", apexPropertiesFileName);
+ CliUtils.validateReadableFile("Command File", commandFileName);
+ CliUtils.validateReadableFile("Input Model File", inputModelFileName);
+ CliUtils.validateWritableFile("Output Model File", outputModelFileName);
+ CliUtils.validateWritableFile("Log File", logFileName);
+ CliUtils.validateWritableDirectory("Working Directory", workingDirectory);
+
+ if (isSuppressLog()) {
setEcho(false);
} else {
if (checkSetCommandFileName()) {
setEcho(true);
- if (!checkSetIgnoreCommandFailures()) {
- setIgnoreCommandFailures(false);
+ if (!isIgnoreCommandFailuresSet()) {
+ setIgnoreCommandFailuresSet(false);
}
} else {
setEcho(false);
- if (!checkSetIgnoreCommandFailures()) {
- setIgnoreCommandFailures(true);
+ if (!isIgnoreCommandFailuresSet()) {
+ setIgnoreCommandFailuresSet(true);
}
}
}
@@ -163,7 +166,7 @@ public class CommandLineParameters {
*/
public OutputStream getOutputStream() throws IOException {
// Check if log suppression is active, if so, consume all output on a byte array output stream
- if (isSuppressLogSet()) {
+ if (isSuppressLog()) {
return new ByteArrayOutputStream();
}
@@ -175,117 +178,6 @@ public class CommandLineParameters {
}
/**
- * Validate that a file is readable.
- *
- * @param fileTag the file tag, a tag used for information and error messages
- * @param fileName the file name to check
- */
- private void validateReadableFile(final String fileTag, final String fileName) {
- if (fileName == null) {
- return;
- }
- final File theFile = new File(fileName);
- final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag;
-
- if (!theFile.exists()) {
- throw new CommandLineException(prefixExceptionMessage + " does not exist");
- }
- if (!theFile.isFile()) {
- throw new CommandLineException(prefixExceptionMessage + " is not a normal file");
- }
- if (!theFile.canRead()) {
- throw new CommandLineException(prefixExceptionMessage + " is ureadable");
- }
- }
-
- /**
- * Validate that a file is writable.
- *
- * @param fileTag the file tag, a tag used for information and error messages
- * @param fileName the file name to check
- */
- private void validateWritableFile(final String fileTag, final String fileName) {
- if (fileName == null) {
- return;
- }
- final File theFile = new File(fileName);
- final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag;
- if (theFile.exists()) {
- if (!theFile.isFile()) {
- throw new CommandLineException(prefixExceptionMessage + " is not a normal file");
- }
- if (!theFile.canWrite()) {
- throw new CommandLineException(prefixExceptionMessage + " cannot be written");
- }
- } else {
- try {
- theFile.createNewFile();
- } catch (final IOException e) {
- throw new CommandLineException(prefixExceptionMessage + " cannot be created: ", e);
- }
- }
- }
-
- /**
- * Validate that a directory exists and is writable.
- *
- * @param directoryTag the directory tag, a tag used for information and error messages
- * @param directoryName the directory name to check
- */
- private void validateWritableDirectory(final String directoryTag, final String directoryName) {
- if (directoryName == null) {
- return;
- }
- final File theDirectory = new File(directoryName);
- final String prefixExceptionMessage = "directory " + directoryName + OF_TYPE_TAG + directoryTag;
-
- if (theDirectory.exists()) {
- if (!theDirectory.isDirectory()) {
- throw new CommandLineException(prefixExceptionMessage + " is not a directory");
- }
- if (!theDirectory.canWrite()) {
- throw new CommandLineException(prefixExceptionMessage + " cannot be written");
- }
- }
- }
-
- /**
- * Checks if help is set.
- *
- * @return true, if help is set
- */
- public boolean isHelpSet() {
- return helpSet;
- }
-
- /**
- * Sets whether the help flag is set or not.
- *
- * @param isHelpSet the value of the help flag
- */
- public void setHelp(final boolean isHelpSet) {
- this.helpSet = isHelpSet;
- }
-
- /**
- * Gets the file name of the command metadata file for the editor commands.
- *
- * @return the file name of the command metadata file for the editor commands
- */
- public String getMetadataFileName() {
- return metadataFileName;
- }
-
- /**
- * Sets the file name of the command metadata file for the editor commands.
- *
- * @param metadataFileName the file name of the command metadata file for the editor commands
- */
- public void setMetadataFileName(final String metadataFileName) {
- this.metadataFileName = metadataFileName.trim();
- }
-
- /**
* Check if the file name of the command metadata file for the editor commands is set.
*
* @return true, if the file name of the command metadata file for the editor commands is set
@@ -295,28 +187,6 @@ public class CommandLineParameters {
}
/**
- * Gets the file name of the file containing properties that are used for command default
- * values.
- *
- * @return the file name of the file containing properties that are used for command default
- * values
- */
- public String getApexPorpertiesFileName() {
- return apexPropertiesFileName;
- }
-
- /**
- * Sets the file name of the file containing properties that are used for command default
- * values.
- *
- * @param apexPorpertiesFileName the file name of the file containing properties that are used
- * for command default values
- */
- public void setApexPorpertiesFileName(final String apexPorpertiesFileName) {
- apexPropertiesFileName = apexPorpertiesFileName.trim();
- }
-
- /**
* Check if the file name of the file containing properties that are used for command default
* values is set.
*
@@ -328,25 +198,6 @@ public class CommandLineParameters {
}
/**
- * Gets the name of the file containing commands to be streamed into the CLI editor.
- *
- * @return the name of the file containing commands to be streamed into the CLI editor
- */
- public String getCommandFileName() {
- return commandFileName;
- }
-
- /**
- * Sets the name of the file containing commands to be streamed into the CLI editor.
- *
- * @param commandFileName the name of the file containing commands to be streamed into the CLI
- * editor
- */
- public void setCommandFileName(final String commandFileName) {
- this.commandFileName = commandFileName.trim();
- }
-
- /**
* Check if the name of the file containing commands to be streamed into the CLI editor is set.
*
* @return true, if the name of the file containing commands to be streamed into the CLI editor
@@ -357,28 +208,6 @@ public class CommandLineParameters {
}
/**
- * Gets the name of the file containing the Apex model that will be used to initialize the Apex
- * model in the CLI editor.
- *
- * @return the name of the file containing the Apex model that will be used to initialize the
- * Apex model in the CLI editor
- */
- public String getInputModelFileName() {
- return inputModelFileName;
- }
-
- /**
- * Sets the name of the file containing the Apex model that will be used to initialize the Apex
- * model in the CLI editor.
- *
- * @param inputModelFileName the name of the file containing the Apex model that will be used to
- * initialize the Apex model in the CLI editor
- */
- public void setInputModelFileName(final String inputModelFileName) {
- this.inputModelFileName = inputModelFileName.trim();
- }
-
- /**
* Check if the name of the file containing the Apex model that will be used to initialize the
* Apex model in the CLI editor is set.
*
@@ -390,26 +219,6 @@ public class CommandLineParameters {
}
/**
- * Gets the name of the file that the Apex CLI editor will save the Apex model to when it exits.
- *
- * @return the name of the file that the Apex CLI editor will save the Apex model to when it
- * exits
- */
- public String getOutputModelFileName() {
- return outputModelFileName;
- }
-
- /**
- * Sets the name of the file that the Apex CLI editor will save the Apex model to when it exits.
- *
- * @param outputModelFileName the name of the file that the Apex CLI editor will save the Apex
- * model to when it exits
- */
- public void setOutputModelFileName(final String outputModelFileName) {
- this.outputModelFileName = outputModelFileName.trim();
- }
-
- /**
* Check if the name of the file that the Apex CLI editor will save the Apex model to when it
* exits is set.
*
@@ -421,43 +230,6 @@ public class CommandLineParameters {
}
/**
- * Gets the working directory that is the root for CLI editor macro includes.
- *
- * @return the CLI editor working directory
- */
- public String getWorkingDirectory() {
- return workingDirectory;
- }
-
- /**
- * Sets the working directory that is the root for CLI editor macro includes.
- *
- * @param workingDirectory the CLI editor working directory
- */
- public void setWorkingDirectory(final String workingDirectory) {
- this.workingDirectory = workingDirectory.trim();
- }
-
- /**
- * Gets the name of the file to which the Apex CLI editor will log commands and responses.
- *
- * @return the name of the file to which the Apex CLI editor will log commands and responses
- */
- public String getLogFileName() {
- return logFileName;
- }
-
- /**
- * Sets the name of the file to which the Apex CLI editor will log commands and responses.
- *
- * @param logFileName the name of the file to which the Apex CLI editor will log commands and
- * responses
- */
- public void setLogFileName(final String logFileName) {
- this.logFileName = logFileName.trim();
- }
-
- /**
* Check if the name of the file to which the Apex CLI editor will log commands and responses is
* set.
*
@@ -469,98 +241,6 @@ public class CommandLineParameters {
}
/**
- * Checks if the Apex CLI editor is set to echo commands that have been entered.
- *
- * @return true, if the Apex CLI editor is set to echo commands that have been entered
- */
- public boolean isEchoSet() {
- return echo;
- }
-
- /**
- * Sets whether the Apex CLI editor should echo commands that have been entered.
- *
- * @param echo true, if the Apex CLI editor should echo commands that have been entered
- */
- public void setEcho(final boolean echo) {
- this.echo = echo;
- }
-
- /**
- * Checks whether the Apex CLI editor is set to suppress logging of command output.
- *
- * @return true, if the Apex CLI editor is set to suppress logging of command output.
- */
- public boolean isSuppressLogSet() {
- return suppressLog;
- }
-
- /**
- * Sets whether the Apex CLI editor should suppress logging of command output.
- *
- * @param suppressLog true, if the Apex CLI editor should suppress logging of command output
- */
- public void setSuppressLog(final boolean suppressLog) {
- this.suppressLog = suppressLog;
- }
-
- /**
- * Checks whether the Apex CLI editor is set to suppress output of its Apex model on exit.
- *
- * @return true, if checks if the Apex CLI editor is set to suppress output of its Apex model on
- * exit
- */
- public boolean isSuppressModelOutputSet() {
- return suppressModelOutput;
- }
-
- /**
- * Sets whether the Apex CLI editor should suppress output of its Apex model on exit.
- *
- * @param suppressModelOutput true, if the Apex CLI editor should suppress output of its Apex
- * model on exit
- */
- public void setSuppressModelOutput(final boolean suppressModelOutput) {
- this.suppressModelOutput = suppressModelOutput;
- }
-
- /**
- * Check if the command failures flag is set.
- *
- * @return true if the command failures flag has been set
- */
- public boolean checkSetIgnoreCommandFailures() {
- return ignoreCommandFailuresSet;
- }
-
- /**
- * Checks if the command failures flag is set.
- *
- * @param ignoreCommandFailuresSet true if the command failures flag has been set
- */
- public void setIgnoreCommandFailuresSet(final boolean ignoreCommandFailuresSet) {
- this.ignoreCommandFailuresSet = ignoreCommandFailuresSet;
- }
-
- /**
- * Checks if command failures should be ignored and command execution continue.
- *
- * @return true if command failures should be ignored
- */
- public boolean isIgnoreCommandFailures() {
- return ignoreCommandFailures;
- }
-
- /**
- * Sets if command errors should be ignored and command execution continue.
- *
- * @param ignoreCommandFailures true if command errors should be ignored
- */
- public void setIgnoreCommandFailures(final boolean ignoreCommandFailures) {
- this.ignoreCommandFailures = ignoreCommandFailures;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
new file mode 100644
index 000000000..8d4fd8b86
--- /dev/null
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.tosca;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import lombok.Getter;
+import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
+import org.onap.policy.apex.auth.clieditor.CommandLineParameters;
+import org.onap.policy.apex.auth.clieditor.utils.CliUtils;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class initiates an Apex CLI Tosca editor.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ApexCliToscaEditorMain {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApexCliToscaEditorMain.class);
+
+ @Getter
+ private boolean failure;
+ private ApexCliToscaParameters parameters;
+ private ApexCommandLineEditorMain apexCliEditor;
+
+ /**
+ * Instantiates the Apex CLI Tosca editor.
+ *
+ * @param args the command line arguments
+ */
+ public ApexCliToscaEditorMain(final String[] args) {
+ final String argumentString = Arrays.toString(args);
+ LOGGER.info("Starting Apex CLI Tosca editor with arguments - {}", argumentString);
+
+ final ApexCliToscaParameterParser parser = new ApexCliToscaParameterParser();
+ parameters = parser.parse(args);
+ if (parameters.isHelpSet()) {
+ CliUtils.help(ApexCliToscaEditorMain.class.getName(), parser.getOptions());
+ return;
+ }
+ parameters.validate();
+
+ String policyModelFilePath = null;
+ try {
+ final File tempModelFile = File.createTempFile("policyModel",".json");
+ policyModelFilePath = tempModelFile.getAbsolutePath();
+ } catch (IOException e) {
+ LOGGER.error("Cannot create the policy model temp file.", e);
+ }
+
+ List<String> cliArgsList = CliUtils.generateArgumentsForCliEditor(parameters, parser.getOptionVariableMap(),
+ CommandLineParameters.class);
+ cliArgsList.add("-o");
+ cliArgsList.add(policyModelFilePath);
+ String[] cliArgs = cliArgsList.toArray(new String[cliArgsList.size()]);
+
+ apexCliEditor = new ApexCommandLineEditorMain(cliArgs);
+ if (apexCliEditor.getErrorCount() == 0) {
+ LOGGER.info("Apex CLI editor completed execution. Creating the ToscaPolicy using the tosca template"
+ + "skeleton file, config file, and policy model created.");
+
+ // Create the ToscaPolicy using the tosca template skeleton file, config file, and policy model created.
+ try {
+ CliUtils.createToscaServiceTemplate(parameters, policyModelFilePath);
+ LOGGER.info("Apex CLI Tosca editor completed execution.");
+ } catch (IOException | CoderException e) {
+ failure = true;
+ LOGGER.error("Failed to create the ToscaPolicy using the generated policy model, apex config file and"
+ + " the tosca template skeleton file.");
+ }
+ } else {
+ failure = true;
+ LOGGER.error("execution of Apex command line editor failed: {} command execution failure(s) occurred",
+ apexCliEditor.getErrorCount());
+ }
+
+ }
+
+ /**
+ * The main method, kicks off the cli tosca editor.
+ *
+ * @param args the arguments
+ */
+ public static void main(final String[] args) {
+ new ApexCliToscaEditorMain(args);
+ }
+}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java
new file mode 100644
index 000000000..d5c66858f
--- /dev/null
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.tosca;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.onap.policy.apex.auth.clieditor.CommandLineParameterParser;
+
+/**
+ * This class reads and handles command line parameters to the Apex CLI Tosca editor.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ApexCliToscaParameterParser extends CommandLineParameterParser {
+
+ /**
+ * Construct the options for the CLI editor.
+ */
+ public ApexCliToscaParameterParser() {
+ getOptions().addOption(Option.builder("ac").longOpt("apex-config-file")
+ .desc("name of the file containing apex configuration details").hasArg()
+ .argName("APEX_CONFIG_FILE").required(false).type(String.class).build());
+ getOptions().addOption(Option.builder("t").longOpt("tosca-template-file")
+ .desc("name of the input file containing tosca template which needs to be updated with policy").hasArg()
+ .argName("TOSCA_TEMPLATE_FILE").required(false).type(String.class).build());
+ getOptions().addOption(Option.builder("ot").longOpt("output-tosca-file")
+ .desc("name of a file that will contain the output model for the editor").hasArg()
+ .argName("OUTPUT_TOSCA_FILE").required(false).type(String.class).build());
+ }
+
+ /**
+ * Parse the command line options.
+ *
+ * @param args The arguments
+ * @return the CLI parameters
+ */
+ @Override
+ public ApexCliToscaParameters parse(final String[] args) {
+ CommandLine commandLine = parseDefault(args);
+ final ApexCliToscaParameters parameters = new ApexCliToscaParameters();
+ parseSingleLetterOptions(commandLine, parameters);
+ parseDoubleLetterOptions(commandLine, parameters);
+
+ if (commandLine.hasOption("ac")) {
+ parameters.setApexConfigFileName(commandLine.getOptionValue("ac"));
+ }
+ if (commandLine.hasOption("t")) {
+ parameters.setInputToscaTemplateFileName(commandLine.getOptionValue("t"));
+ }
+ if (commandLine.hasOption("ot")) {
+ parameters.setOutputToscaPolicyFileName(commandLine.getOptionValue("ot"));
+ }
+ return parameters;
+ }
+
+}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameters.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameters.java
new file mode 100644
index 000000000..49f790c5d
--- /dev/null
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameters.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.tosca;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.apex.auth.clieditor.CommandLineException;
+import org.onap.policy.apex.auth.clieditor.CommandLineParameters;
+import org.onap.policy.apex.auth.clieditor.utils.CliUtils;
+
+/**
+ * This class reads and handles command line parameters to the Apex CLI Tosca editor.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+
+@Setter
+@Getter
+public class ApexCliToscaParameters extends CommandLineParameters {
+
+ // The cli tosca editor parameters
+ private String apexConfigFileName = null;
+ private String inputToscaTemplateFileName = null;
+ private String outputToscaPolicyFileName = null;
+
+ /**
+ * Validates the command line parameters.
+ */
+ @Override
+ public void validate() {
+ if ((null == apexConfigFileName) || (null == inputToscaTemplateFileName) || (null == getCommandFileName())) {
+ throw new CommandLineException("Insufficient arguments provided.");
+ }
+ super.validate();
+ CliUtils.validateReadableFile("Apex Config File", apexConfigFileName);
+ CliUtils.validateReadableFile("Input Tosca Template File", inputToscaTemplateFileName);
+ CliUtils.validateWritableFile("Output Tosca Policy File", outputToscaPolicyFileName);
+ }
+}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java
new file mode 100644
index 000000000..2454f39fa
--- /dev/null
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java
@@ -0,0 +1,221 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.utils;
+
+import com.google.gson.JsonObject;
+import java.beans.PropertyDescriptor;
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Properties;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.apex.auth.clieditor.CommandLineException;
+import org.onap.policy.apex.auth.clieditor.CommandLineParameters;
+import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaParameters;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class contains the utility methods specifically for Apex CLI Editor.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class CliUtils {
+
+ private CliUtils() {
+ // This class cannot be initialized
+ }
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CliUtils.class);
+
+ // Recurring string constants
+ private static final String OF_TYPE_TAG = " of type ";
+ private static final int MAX_HELP_LINE_LENGTH = 120;
+
+ /**
+ * Method to create apex policy in tosca service template.
+ *
+ * @param parameters containing paths to the apex config and tosca template skeleton file
+ * @param policyModelFilePath path of apex policy model
+ */
+ public static void createToscaServiceTemplate(ApexCliToscaParameters parameters, String policyModelFilePath)
+ throws IOException, CoderException {
+ final StandardCoder standardCoder = new StandardCoder();
+ String apexConfig = TextFileUtils.getTextFileAsString(parameters.getApexConfigFileName());
+ JsonObject apexConfigJson = standardCoder.decode(apexConfig, JsonObject.class);
+ String policyModel = TextFileUtils.getTextFileAsString(policyModelFilePath);
+ JsonObject policyModelJson = standardCoder.decode(policyModel, JsonObject.class);
+ String toscaTemplate = TextFileUtils.getTextFileAsString(parameters.getInputToscaTemplateFileName());
+ JsonObject toscaTemplateJson = standardCoder.decode(toscaTemplate, JsonObject.class);
+
+ JsonObject engineServiceParameters = apexConfigJson.get("engineServiceParameters").getAsJsonObject();
+ engineServiceParameters.add("policy_type_impl", policyModelJson);
+ JsonObject toscaPolicyProperties = toscaTemplateJson.get("topology_template").getAsJsonObject();
+ JsonObject toscaPolicy = toscaPolicyProperties.get("policies").getAsJsonArray().get(0).getAsJsonObject();
+ JsonObject toscaProperties = toscaPolicy.get(toscaPolicy.keySet().toArray()[0].toString()).getAsJsonObject()
+ .get("properties").getAsJsonObject();
+ toscaProperties.add("content", apexConfigJson);
+
+ final String toscaPolicyString = standardCoder.encode(toscaTemplateJson);
+ final String toscaPolicyFileName = parameters.getOutputToscaPolicyFileName();
+ if (StringUtils.isNotBlank(toscaPolicyFileName)) {
+ TextFileUtils.putStringAsTextFile(toscaPolicyString, toscaPolicyFileName);
+ } else {
+ LOGGER.debug("Output file name not specified. Resulting tosca policy is {}", toscaPolicyString);
+ }
+ }
+
+ /**
+ * Validate that a file is readable.
+ *
+ * @param fileTag the file tag, a tag used for information and error messages
+ * @param fileName the file name to check
+ */
+ public static void validateReadableFile(final String fileTag, final String fileName) {
+ if (fileName == null) {
+ return;
+ }
+ final File theFile = new File(fileName);
+ final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag;
+
+ if (!theFile.exists()) {
+ throw new CommandLineException(prefixExceptionMessage + " does not exist");
+ }
+ if (!theFile.isFile()) {
+ throw new CommandLineException(prefixExceptionMessage + " is not a normal file");
+ }
+ if (!theFile.canRead()) {
+ throw new CommandLineException(prefixExceptionMessage + " is ureadable");
+ }
+ }
+
+ /**
+ * Validate that a file is writable.
+ *
+ * @param fileTag the file tag, a tag used for information and error messages
+ * @param fileName the file name to check
+ */
+ public static void validateWritableFile(final String fileTag, final String fileName) {
+ if (fileName == null) {
+ return;
+ }
+ final File theFile = new File(fileName);
+ final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag;
+ if (theFile.exists()) {
+ if (!theFile.isFile()) {
+ throw new CommandLineException(prefixExceptionMessage + " is not a normal file");
+ }
+ if (!theFile.canWrite()) {
+ throw new CommandLineException(prefixExceptionMessage + " cannot be written");
+ }
+ } else {
+ try {
+ if (theFile.createNewFile()) {
+ LOGGER.info("File {} does not exist. New file created.", fileName);
+ }
+ } catch (final IOException e) {
+ throw new CommandLineException(prefixExceptionMessage + " cannot be created: ", e);
+ }
+ }
+ }
+
+ /**
+ * Validate that a directory exists and is writable.
+ *
+ * @param directoryTag the directory tag, a tag used for information and error messages
+ * @param directoryName the directory name to check
+ */
+ public static void validateWritableDirectory(final String directoryTag, final String directoryName) {
+ if (directoryName == null) {
+ return;
+ }
+ final File theDirectory = new File(directoryName);
+ final String prefixExceptionMessage = "directory " + directoryName + OF_TYPE_TAG + directoryTag;
+
+ if (theDirectory.exists()) {
+ if (!theDirectory.isDirectory()) {
+ throw new CommandLineException(prefixExceptionMessage + " is not a directory");
+ }
+ if (!theDirectory.canWrite()) {
+ throw new CommandLineException(prefixExceptionMessage + " cannot be written");
+ }
+ } else {
+ if (!theDirectory.mkdir()) {
+ throw new CommandLineException(prefixExceptionMessage + " doesn't exist and cannot be created.");
+ }
+ }
+ }
+
+ /**
+ * Print help information.
+ *
+ * @param mainClassName the main class name
+ * @param options the options for cli editor
+ */
+ public static void help(final String mainClassName, Options options) {
+ final HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.printHelp(MAX_HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, "");
+ }
+
+ /**
+ * Method to generate arguments required for APEX CLI editor.
+ *
+ * @param parameters the command line parameters
+ * @param optionVariableMap the properties object containing the option and corresponding variable name
+ * @param class1 the class type in which the variable names has to be looked for
+ * @return list of arguments
+ */
+ public static List<String> generateArgumentsForCliEditor(CommandLineParameters parameters,
+ Properties optionVariableMap, Class<?> class1) {
+
+ List<String> cliArgsList = new ArrayList<>();
+ PropertyDescriptor pd;
+ Method getter;
+ Object argValue;
+
+ for (Entry<Object, Object> entry : optionVariableMap.entrySet()) {
+ try {
+ pd = new PropertyDescriptor(entry.getValue().toString(), class1);
+ getter = pd.getReadMethod();
+ argValue = getter.invoke(parameters);
+ String key = entry.getKey().toString();
+
+ if (argValue instanceof String && !key.equals("o")) {
+ cliArgsList.add("-" + key);
+ cliArgsList.add(argValue.toString());
+ } else if (argValue instanceof Boolean && (Boolean)argValue) {
+ cliArgsList.add("-" + key);
+ }
+ } catch (Exception e) {
+ LOGGER.error("Invalid getter method for the argument specfied.", e);
+ }
+ }
+ return cliArgsList;
+ }
+}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
new file mode 100644
index 000000000..10bb63329
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.tosca;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+/**
+ * Class to perform unit test of Apex cli tosca editor}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ApexCliToscaEditorTest {
+
+ private File tempOutputToscaFile;
+ private File tempLogFile;
+ String[] sampleArgs;
+
+ /**
+ * Initialise args.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @Before
+ public void initialiseArgs() throws IOException {
+
+ tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json");
+ tempLogFile = File.createTempFile("ApexCliTosca", ".log");
+ sampleArgs = new String[] {
+ "-c", CommonTestData.COMMAND_FILE_NAME,
+ "-ac", CommonTestData.APEX_CONFIG_FILE_NAME,
+ "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME,
+ "-ot", tempOutputToscaFile.getAbsolutePath(),
+ "-l", tempLogFile.getAbsolutePath()
+ };
+ }
+
+ /**
+ * Removes the generated files.
+ */
+ @After
+ public void removeGeneratedFiles() {
+ tempOutputToscaFile.delete();
+ tempLogFile.delete();
+ }
+
+ @Test
+ public void testApexCliToscaParameterParser() {
+ ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
+ assertEquals(CommonTestData.APEX_CONFIG_FILE_NAME, params.getApexConfigFileName());
+ assertEquals(CommonTestData.COMMAND_FILE_NAME, params.getCommandFileName());
+ assertEquals(CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME, params.getInputToscaTemplateFileName());
+ assertEquals(tempOutputToscaFile.getAbsolutePath(), params.getOutputToscaPolicyFileName());
+ assertEquals(tempLogFile.getAbsolutePath(), params.getLogFileName());
+ }
+
+ @Test
+ public void testApexCliTosca_success() throws IOException {
+ final ApexCliToscaEditorMain cliEditor = new ApexCliToscaEditorMain(sampleArgs);
+ String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath());
+ String outputToscaCompare = TextFileUtils.getTextFileAsString(
+ "src/test/resources/tosca/ToscaPolicyOutput_compare.json");
+ assertEquals(outputToscaCompare, outputTosca);
+ assertFalse(cliEditor.isFailure());
+ }
+
+ @Test
+ public void testApexCliTosca_no_args() {
+ String[] noArgs = new String[] {};
+ assertThatThrownBy(() -> new ApexCliToscaEditorMain(noArgs)).hasMessage("Insufficient arguments provided.");
+ }
+
+ @Test
+ public void testApexCliTosca_missing_commandfile() {
+ String[] sampleArgs = new String[] {
+ "-ac", CommonTestData.APEX_CONFIG_FILE_NAME,
+ "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME,
+ "-ot", tempOutputToscaFile.getAbsolutePath(),
+ "-l", tempLogFile.getAbsolutePath()
+ };
+ assertThatThrownBy(() -> new ApexCliToscaEditorMain(sampleArgs)).hasMessage("Insufficient arguments provided.");
+ }
+}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java
new file mode 100644
index 000000000..ce88f9795
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/CommonTestData.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.tosca;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class CommonTestData {
+
+ private CommonTestData() {
+ // This class cannot be initialized
+ }
+
+ public static final String INPUT_TOSCA_TEMPLATE_FILE_NAME = "src/test/resources/tosca/ToscaTemplate.json";
+ public static final String APEX_CONFIG_FILE_NAME = "src/test/resources/tosca/ApexConfig.json";
+ public static final String COMMAND_FILE_NAME = "src/test/resources/tosca/PolicyModel.apex";
+ public static final String POLICY_MODEL_FILE_NAME = "src/test/resources/tosca/PolicyModel.json";
+}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
new file mode 100644
index 000000000..2dfd6f6c9
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
@@ -0,0 +1,156 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.auth.clieditor.utils;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaParameterParser;
+import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaParameters;
+import org.onap.policy.apex.auth.clieditor.tosca.CommonTestData;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+/**
+ * Class to perform unit test of {@link CliUtils}}.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class CliUtilsTest {
+
+ private File tempOutputToscaFile;
+ private File tempLogFile;
+ private String policyModelFilePath;
+ String[] sampleArgs;
+
+ /**
+ * Initialise args.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @Before
+ public void initialiseArgs() throws IOException {
+
+ tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json");
+ tempLogFile = File.createTempFile("ApexCliTosca", ".log");
+ policyModelFilePath = CommonTestData.POLICY_MODEL_FILE_NAME;
+ sampleArgs = new String[] {"-c", CommonTestData.COMMAND_FILE_NAME, "-ac", CommonTestData.APEX_CONFIG_FILE_NAME,
+ "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME, "-ot", tempOutputToscaFile.getAbsolutePath(), "-l",
+ tempLogFile.getAbsolutePath()};
+ }
+
+ /**
+ * Removes the generated files.
+ */
+ @After
+ public void removeGeneratedFiles() {
+ tempOutputToscaFile.delete();
+ tempLogFile.delete();
+ }
+
+ @Test
+ public void testCreateToscaServiceTemplate() throws IOException, CoderException {
+ ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
+ CliUtils.createToscaServiceTemplate(params, policyModelFilePath);
+ String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath());
+ String outputToscaCompare =
+ TextFileUtils.getTextFileAsString("src/test/resources/tosca/ToscaPolicyOutput_compare.json");
+ assertEquals(outputToscaCompare, outputTosca);
+ }
+
+ @Test
+ public void testValidateReadableFile_validfile() {
+ CliUtils.validateReadableFile("Apex Config File", CommonTestData.APEX_CONFIG_FILE_NAME);
+ }
+
+ @Test
+ public void testValidateReadableFile_invalidfile() {
+ String invalidFileName = "src/test/resources/tosca/ApexConfigxyz.json";
+ assertThatThrownBy(() -> CliUtils.validateReadableFile("Apex Config File", invalidFileName))
+ .hasMessage("File " + invalidFileName + " of type Apex Config File does not exist");
+ }
+
+ @Test
+ public void testValidateWritableFile_validfile() {
+ CliUtils.validateWritableFile("Output Tosca Policy File", tempOutputToscaFile.getAbsolutePath());
+ }
+
+ @Test
+ public void testValidateWritableFile_invalidfile() {
+ String invalidFileName = "src/test/resources/tosca";
+ assertThatThrownBy(() -> CliUtils.validateWritableFile("Output Tosca Policy File", invalidFileName))
+ .hasMessage("File " + invalidFileName + " of type Output Tosca Policy File is not a normal file");
+ }
+
+ @Test
+ public void testValidateWritableDirectory_validdirectory() {
+ CliUtils.validateWritableDirectory("Working Directory", "src/test/resources/tosca");
+ }
+
+ @Test
+ public void testValidateWritableDirectory_invaliddirectory() {
+ assertThatThrownBy(() -> CliUtils.validateWritableDirectory("Working Directory",
+ CommonTestData.APEX_CONFIG_FILE_NAME)).hasMessage("directory " + CommonTestData.APEX_CONFIG_FILE_NAME
+ + " of type Working Directory is not a directory");
+ }
+
+ @Test
+ public void testGenerateArgumentsForCliEditor_success() {
+ ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
+ Properties optionVariableMap = new Properties();
+ optionVariableMap.setProperty("c", "commandFileName");
+ optionVariableMap.setProperty("ac", "apexConfigFileName");
+ optionVariableMap.setProperty("t", "inputToscaTemplateFileName");
+ optionVariableMap.setProperty("ot", "outputToscaPolicyFileName");
+ optionVariableMap.setProperty("l", "logFileName");
+ List<String> cliArgsList =
+ CliUtils.generateArgumentsForCliEditor(params, optionVariableMap, ApexCliToscaParameters.class);
+ assertTrue(cliArgsList.containsAll(Arrays.asList(sampleArgs)));
+ }
+
+ @Test
+ public void testGenerateArgumentsForCliEditor_invalidvariable() {
+ ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
+ Properties optionVariableMap = new Properties();
+ optionVariableMap.setProperty("c", "invalidFileName");
+ List<String> cliArgsList =
+ CliUtils.generateArgumentsForCliEditor(params, optionVariableMap, ApexCliToscaParameters.class);
+ assertEquals(0, cliArgsList.size());
+ }
+
+ @Test
+ public void testGenerateArgumentsForCliEditor_missingoption() {
+ ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
+ Properties optionVariableMap = new Properties();
+ List<String> cliArgsList =
+ CliUtils.generateArgumentsForCliEditor(params, optionVariableMap, ApexCliToscaParameters.class);
+ assertEquals(0, cliArgsList.size());
+ }
+}
diff --git a/auth/cli-editor/src/test/resources/tosca/ApexConfig.json b/auth/cli-editor/src/test/resources/tosca/ApexConfig.json
new file mode 100644
index 000000000..21a159c0d
--- /dev/null
+++ b/auth/cli-editor/src/test/resources/tosca/ApexConfig.json
@@ -0,0 +1,46 @@
+{
+ "engineServiceParameters": {
+ "name": "MyFirstPolicyApexEngine",
+ "version": "0.0.1",
+ "id": 101,
+ "instanceCount": 4,
+ "deploymentPort": 12345,
+ "policyModelFileName": "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json",
+ "engineParameters": {
+ "executorParameters": {
+ "MVEL": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters"
+ },
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ }
+ }
+ },
+ "eventOutputParameters": {
+ "FirstProducer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "FILE",
+ "parameters": {
+ "standardIo": true
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ }
+ }
+ },
+ "eventInputParameters": {
+ "FirstConsumer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "FILE",
+ "parameters": {
+ "standardIo": true
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ }
+ }
+ }
+}
diff --git a/auth/cli-editor/src/test/resources/tosca/PolicyModel.apex b/auth/cli-editor/src/test/resources/tosca/PolicyModel.apex
new file mode 100644
index 000000000..2178bc67f
--- /dev/null
+++ b/auth/cli-editor/src/test/resources/tosca/PolicyModel.apex
@@ -0,0 +1,180 @@
+#-------------------------------------------------------------------------------
+# ============LICENSE_START=======================================================
+# Copyright (C) 2016-2018 Ericsson. All rights reserved.
+# Modifications Copyright (C) 2019 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=========================================================
+#-------------------------------------------------------------------------------
+
+model create name=MyFirstPolicyModel version=0.0.1 uuid=540226fb-55ee-4f0e-a444-983a0494818e description="This is my first Apex Policy Model."
+
+schema create name=assistant_ID_type version=0.0.1 uuid=36df4c71-9616-4206-8b53-976a5cd4bd87 description="A type for 'assistant_ID' values" flavour=Java schema=java.lang.Long
+
+schema create name=authorised_type version=0.0.1 uuid=d48b619e-d00d-4008-b884-02d76ea4350b description="A type for 'authorised' values" flavour=Java schema=java.lang.Boolean
+
+schema create name=branch_ID_type version=0.0.1 uuid=6468845f-4122-4128-8e49-0f52c26078b5 description="A type for 'branch_ID' values" flavour=Java schema=java.lang.Long
+
+schema create name=item_ID_type version=0.0.1 uuid=4f227ff1-aee0-453a-b6b6-9a4b2e0da932 description="A type for 'item_ID' values" flavour=Java schema=java.lang.Long
+
+schema create name=message_type version=0.0.1 uuid=ad1431bb-3155-4e73-b5a3-b89bee498749 description="A type for 'message' values" flavour=Java schema=java.lang.String
+
+schema create name=notes_type version=0.0.1 uuid=eecfde90-896c-4343-8f9c-2603ced94e2d description="A type for 'notes' values" flavour=Java schema=java.lang.String
+
+schema create name=price_type version=0.0.1 uuid=52c2fc45-fd8c-463c-bd6f-d91b0554aea7 description="A type for 'amount'/'price' values" flavour=Java schema=java.lang.Long
+
+schema create name=quantity_type version=0.0.1 uuid=ac3d9842-80af-4a98-951c-bd79a431c613 description="A type for 'quantity' values" flavour=Java schema=java.lang.Integer
+
+schema create name=sale_ID_type version=0.0.1 uuid=cca47d74-7754-4a61-b163-ca31f66b157b description="A type for 'sale_ID' values" flavour=Java schema=java.lang.Long
+
+schema create name=timestamp_type version=0.0.1 uuid=fd594e88-411d-4a94-b2be-697b3a0d7adf description="A type for 'time' values" flavour=Java schema=java.lang.Long
+
+task create name=MorningBoozeCheck version=0.0.1 uuid=3351b0f4-cf06-4fa2-8823-edf67bd30223 description=LS
+This task checks if the sales request is for an item that contains alcohol.
+If the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised.
+In this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)
+LE
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
+task inputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=amount schemaName=price_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=quantity schemaName=quantity_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorised schemaName=authorised_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1
+task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true
+task logic create name=MorningBoozeCheck version=0.0.1 logicFlavour=MVEL logic=LS
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 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=========================================================
+ */
+import java.util.Date;
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.text.SimpleDateFormat;
+
+logger.info("Task Execution: '"+subject.id+"'. Input Fields: '"+inFields+"'");
+
+outFields.put("amount" , inFields.get("amount"));
+outFields.put("assistant_ID", inFields.get("assistant_ID"));
+outFields.put("notes" , inFields.get("notes"));
+outFields.put("quantity" , inFields.get("quantity"));
+outFields.put("branch_ID" , inFields.get("branch_ID"));
+outFields.put("item_ID" , inFields.get("item_ID"));
+outFields.put("time" , inFields.get("time"));
+outFields.put("sale_ID" , inFields.get("sale_ID"));
+
+item_id = inFields.get("item_ID");
+
+//The events used later to test this task use GMT timezone!
+gmt = TimeZone.getTimeZone("GMT");
+timenow = Calendar.getInstance(gmt);
+df = new SimpleDateFormat("HH:mm:ss z");
+df.setTimeZone(gmt);
+timenow.setTimeInMillis(inFields.get("time"));
+
+midnight = timenow.clone();
+midnight.set(
+ timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
+ timenow.get(Calendar.DATE),0,0,0);
+eleven30 = timenow.clone();
+eleven30.set(
+ timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),
+ timenow.get(Calendar.DATE),11,30,0);
+
+itemisalcohol = false;
+if(item_id != null && item_id >=1000 && item_id < 2000)
+ itemisalcohol = true;
+
+if( itemisalcohol
+ && timenow.after(midnight) && timenow.before(eleven30)){
+ outFields.put("authorised", false);
+ outFields.put("message", "Sale not authorised by policy task "+subject.taskName+
+ " for time "+df.format(timenow.getTime())+
+ ". Alcohol can not be sold between "+df.format(midnight.getTime())+
+ " and "+df.format(eleven30.getTime()));
+ return true;
+}
+else{
+ outFields.put("authorised", true);
+ outFields.put("message", "Sale authorised by policy task "+subject.taskName+
+ " for time "+df.format(timenow.getTime()));
+ return true;
+}
+
+/*
+This task checks if a sale request is for an item that is an alcoholic drink.
+If the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not
+authorised. Otherwise the sale is authorised.
+In this implementation we assume that items with item_ID value between 1000 and
+2000 are all alcoholic drinks :-)
+*/
+LE
+
+event create name=SALE_AUTH version=0.0.1 uuid=c4500941-3f98-4080-a9cc-5b9753ed050b description="An event emitted by the Policy to indicate whether the sale of an item has been authorised" nameSpace=com.hyperm source="APEX" target="POS"
+event parameter create name=SALE_AUTH version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=authorised schemaName=authorised_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=message schemaName=message_type schemaVersion=0.0.1 optional=true
+event parameter create name=SALE_AUTH version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
+event parameter create name=SALE_AUTH version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_AUTH version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
+
+event create name=SALE_INPUT version=0.0.1 uuid=4f04aa98-e917-4f4a-882a-c75ba5a99374 description="An event raised by the PoS system each time an item is scanned for purchase" nameSpace=com.hyperm source="POS" target="APEX"
+event parameter create name=SALE_INPUT version=0.0.1 parName=amount schemaName=price_type schemaVersion=0.0.1
+event parameter create name=SALE_INPUT version=0.0.1 parName=assistant_ID schemaName=assistant_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_INPUT version=0.0.1 parName=branch_ID schemaName=branch_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_INPUT version=0.0.1 parName=item_ID schemaName=item_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_INPUT version=0.0.1 parName=notes schemaName=notes_type schemaVersion=0.0.1 optional=true
+event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName=quantity_type schemaVersion=0.0.1
+event parameter create name=SALE_INPUT version=0.0.1 parName=sale_ID schemaName=sale_ID_type schemaVersion=0.0.1
+event parameter create name=SALE_INPUT version=0.0.1 parName=time schemaName=timestamp_type schemaVersion=0.0.1
+
+
+policy create name=MyFirstPolicy version=0.0.1 uuid=6c5e410f-489a-46ff-964e-982ce6e8b6d0 description="This is my first Apex policy. It checks if a sale should be authorised or not." template=FREEFORM firstState=BoozeAuthDecide
+policy state create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide triggerName=SALE_INPUT triggerVersion=0.0.1 defaultTaskName=MorningBoozeCheck defaultTaskVersion=0.0.1
+policy state output create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide outputName=MorningBoozeCheck_Output_Direct eventName=SALE_AUTH eventVersion=0.0.1 nextState=NULL
+policy state taskref create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide taskLocalName=MorningBoozeCheck taskName=MorningBoozeCheck taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct
+
+
+
diff --git a/auth/cli-editor/src/test/resources/tosca/PolicyModel.json b/auth/cli-editor/src/test/resources/tosca/PolicyModel.json
new file mode 100644
index 000000000..0e9cfca11
--- /dev/null
+++ b/auth/cli-editor/src/test/resources/tosca/PolicyModel.json
@@ -0,0 +1,952 @@
+{
+ "apexPolicyModel" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel",
+ "version" : "0.0.1"
+ },
+ "keyInformation" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_KeyInfo",
+ "version" : "0.0.1"
+ },
+ "keyInfoMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "MorningBoozeCheck",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MorningBoozeCheck",
+ "version" : "0.0.1"
+ },
+ "UUID" : "3351b0f4-cf06-4fa2-8823-edf67bd30223",
+ "description" : "This task checks if the sales request is for an item that contains alcohol. \nIf the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised. \nIn this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)"
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicy",
+ "version" : "0.0.1"
+ },
+ "UUID" : "6c5e410f-489a-46ff-964e-982ce6e8b6d0",
+ "description" : "This is my first Apex policy. It checks if a sale should be authorised or not."
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicyModel",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel",
+ "version" : "0.0.1"
+ },
+ "UUID" : "540226fb-55ee-4f0e-a444-983a0494818e",
+ "description" : "This is my first Apex Policy Model."
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Events",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Events",
+ "version" : "0.0.1"
+ },
+ "UUID" : "ef281318-5ac9-3ef0-8db3-8f9c4e4a81e2",
+ "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Events:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicyModel_KeyInfo",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_KeyInfo",
+ "version" : "0.0.1"
+ },
+ "UUID" : "d9248c6f-7c00-38df-8251-611463ba4065",
+ "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_KeyInfo:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Policies",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Policies",
+ "version" : "0.0.1"
+ },
+ "UUID" : "77c01a6b-510c-3aa9-b640-b4db356aa03b",
+ "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Policies:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Schemas",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Schemas",
+ "version" : "0.0.1"
+ },
+ "UUID" : "d0cc3aa0-ea69-3a43-80ff-a0dbb0ebd885",
+ "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Schemas:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Tasks",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Tasks",
+ "version" : "0.0.1"
+ },
+ "UUID" : "b02a7e02-2cd0-39e6-b3cb-946fa83a8f08",
+ "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Tasks:0.0.1\""
+ }
+ }, {
+ "key" : {
+ "name" : "SALE_AUTH",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SALE_AUTH",
+ "version" : "0.0.1"
+ },
+ "UUID" : "c4500941-3f98-4080-a9cc-5b9753ed050b",
+ "description" : "An event emitted by the Policy to indicate whether the sale of an item has been authorised"
+ }
+ }, {
+ "key" : {
+ "name" : "SALE_INPUT",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SALE_INPUT",
+ "version" : "0.0.1"
+ },
+ "UUID" : "4f04aa98-e917-4f4a-882a-c75ba5a99374",
+ "description" : "An event raised by the PoS system each time an item is scanned for purchase"
+ }
+ }, {
+ "key" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "36df4c71-9616-4206-8b53-976a5cd4bd87",
+ "description" : "A type for 'assistant_ID' values"
+ }
+ }, {
+ "key" : {
+ "name" : "authorised_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "authorised_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "d48b619e-d00d-4008-b884-02d76ea4350b",
+ "description" : "A type for 'authorised' values"
+ }
+ }, {
+ "key" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "6468845f-4122-4128-8e49-0f52c26078b5",
+ "description" : "A type for 'branch_ID' values"
+ }
+ }, {
+ "key" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "4f227ff1-aee0-453a-b6b6-9a4b2e0da932",
+ "description" : "A type for 'item_ID' values"
+ }
+ }, {
+ "key" : {
+ "name" : "message_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "message_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "ad1431bb-3155-4e73-b5a3-b89bee498749",
+ "description" : "A type for 'message' values"
+ }
+ }, {
+ "key" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "eecfde90-896c-4343-8f9c-2603ced94e2d",
+ "description" : "A type for 'notes' values"
+ }
+ }, {
+ "key" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "52c2fc45-fd8c-463c-bd6f-d91b0554aea7",
+ "description" : "A type for 'amount'/'price' values"
+ }
+ }, {
+ "key" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "ac3d9842-80af-4a98-951c-bd79a431c613",
+ "description" : "A type for 'quantity' values"
+ }
+ }, {
+ "key" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "cca47d74-7754-4a61-b163-ca31f66b157b",
+ "description" : "A type for 'sale_ID' values"
+ }
+ }, {
+ "key" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "UUID" : "fd594e88-411d-4a94-b2be-697b3a0d7adf",
+ "description" : "A type for 'time' values"
+ }
+ } ]
+ }
+ },
+ "policies" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Policies",
+ "version" : "0.0.1"
+ },
+ "policyMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "MyFirstPolicy",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "policyKey" : {
+ "name" : "MyFirstPolicy",
+ "version" : "0.0.1"
+ },
+ "template" : "FREEFORM",
+ "state" : {
+ "entry" : [ {
+ "key" : "BoozeAuthDecide",
+ "value" : {
+ "stateKey" : {
+ "parentKeyName" : "MyFirstPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "NULL",
+ "localName" : "BoozeAuthDecide"
+ },
+ "trigger" : {
+ "name" : "SALE_INPUT",
+ "version" : "0.0.1"
+ },
+ "stateOutputs" : {
+ "entry" : [ {
+ "key" : "MorningBoozeCheck_Output_Direct",
+ "value" : {
+ "key" : {
+ "parentKeyName" : "MyFirstPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "BoozeAuthDecide",
+ "localName" : "MorningBoozeCheck_Output_Direct"
+ },
+ "outgoingEvent" : {
+ "name" : "SALE_AUTH",
+ "version" : "0.0.1"
+ },
+ "nextState" : {
+ "parentKeyName" : "NULL",
+ "parentKeyVersion" : "0.0.0",
+ "parentLocalName" : "NULL",
+ "localName" : "NULL"
+ }
+ }
+ } ]
+ },
+ "contextAlbumReference" : [ ],
+ "taskSelectionLogic" : {
+ "key" : "NULL",
+ "logicFlavour" : "UNDEFINED",
+ "logic" : ""
+ },
+ "stateFinalizerLogicMap" : {
+ "entry" : [ ]
+ },
+ "defaultTask" : {
+ "name" : "MorningBoozeCheck",
+ "version" : "0.0.1"
+ },
+ "taskReferences" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "MorningBoozeCheck",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "parentKeyName" : "MyFirstPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "BoozeAuthDecide",
+ "localName" : "MorningBoozeCheck"
+ },
+ "outputType" : "DIRECT",
+ "output" : {
+ "parentKeyName" : "MyFirstPolicy",
+ "parentKeyVersion" : "0.0.1",
+ "parentLocalName" : "BoozeAuthDecide",
+ "localName" : "MorningBoozeCheck_Output_Direct"
+ }
+ }
+ } ]
+ }
+ }
+ } ]
+ },
+ "firstState" : "BoozeAuthDecide"
+ }
+ } ]
+ }
+ },
+ "tasks" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Tasks",
+ "version" : "0.0.1"
+ },
+ "taskMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "MorningBoozeCheck",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "MorningBoozeCheck",
+ "version" : "0.0.1"
+ },
+ "inputFields" : {
+ "entry" : [ {
+ "key" : "amount",
+ "value" : {
+ "key" : "amount",
+ "fieldSchemaKey" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "assistant_ID",
+ "value" : {
+ "key" : "assistant_ID",
+ "fieldSchemaKey" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "branch_ID",
+ "value" : {
+ "key" : "branch_ID",
+ "fieldSchemaKey" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "item_ID",
+ "value" : {
+ "key" : "item_ID",
+ "fieldSchemaKey" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "notes",
+ "value" : {
+ "key" : "notes",
+ "fieldSchemaKey" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "optional" : true
+ }
+ }, {
+ "key" : "quantity",
+ "value" : {
+ "key" : "quantity",
+ "fieldSchemaKey" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "sale_ID",
+ "value" : {
+ "key" : "sale_ID",
+ "fieldSchemaKey" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "time",
+ "value" : {
+ "key" : "time",
+ "fieldSchemaKey" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "outputFields" : {
+ "entry" : [ {
+ "key" : "amount",
+ "value" : {
+ "key" : "amount",
+ "fieldSchemaKey" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "assistant_ID",
+ "value" : {
+ "key" : "assistant_ID",
+ "fieldSchemaKey" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "authorised",
+ "value" : {
+ "key" : "authorised",
+ "fieldSchemaKey" : {
+ "name" : "authorised_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "branch_ID",
+ "value" : {
+ "key" : "branch_ID",
+ "fieldSchemaKey" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "item_ID",
+ "value" : {
+ "key" : "item_ID",
+ "fieldSchemaKey" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "message",
+ "value" : {
+ "key" : "message",
+ "fieldSchemaKey" : {
+ "name" : "message_type",
+ "version" : "0.0.1"
+ },
+ "optional" : true
+ }
+ }, {
+ "key" : "notes",
+ "value" : {
+ "key" : "notes",
+ "fieldSchemaKey" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "optional" : true
+ }
+ }, {
+ "key" : "quantity",
+ "value" : {
+ "key" : "quantity",
+ "fieldSchemaKey" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "sale_ID",
+ "value" : {
+ "key" : "sale_ID",
+ "fieldSchemaKey" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "time",
+ "value" : {
+ "key" : "time",
+ "fieldSchemaKey" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ },
+ "taskParameters" : {
+ "entry" : [ ]
+ },
+ "contextAlbumReference" : [ ],
+ "taskLogic" : {
+ "key" : "TaskLogic",
+ "logicFlavour" : "MVEL",
+ "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2019 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\nimport java.util.Date;\nimport java.util.Calendar;\nimport java.util.TimeZone;\nimport java.text.SimpleDateFormat;\n\nlogger.info(\"Task Execution: '\"+subject.id+\"'. Input Fields: '\"+inFields+\"'\");\n\noutFields.put(\"amount\" , inFields.get(\"amount\"));\noutFields.put(\"assistant_ID\", inFields.get(\"assistant_ID\"));\noutFields.put(\"notes\" , inFields.get(\"notes\"));\noutFields.put(\"quantity\" , inFields.get(\"quantity\"));\noutFields.put(\"branch_ID\" , inFields.get(\"branch_ID\"));\noutFields.put(\"item_ID\" , inFields.get(\"item_ID\"));\noutFields.put(\"time\" , inFields.get(\"time\"));\noutFields.put(\"sale_ID\" , inFields.get(\"sale_ID\"));\n\nitem_id = inFields.get(\"item_ID\");\n\n//The events used later to test this task use GMT timezone!\ngmt = TimeZone.getTimeZone(\"GMT\");\ntimenow = Calendar.getInstance(gmt);\ndf = new SimpleDateFormat(\"HH:mm:ss z\");\ndf.setTimeZone(gmt);\ntimenow.setTimeInMillis(inFields.get(\"time\"));\n\nmidnight = timenow.clone();\nmidnight.set(\n timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n timenow.get(Calendar.DATE),0,0,0);\neleven30 = timenow.clone();\neleven30.set(\n timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n timenow.get(Calendar.DATE),11,30,0);\n\nitemisalcohol = false;\nif(item_id != null && item_id >=1000 && item_id < 2000)\n itemisalcohol = true;\n\nif( itemisalcohol\n && timenow.after(midnight) && timenow.before(eleven30)){\n outFields.put(\"authorised\", false);\n outFields.put(\"message\", \"Sale not authorised by policy task \"+subject.taskName+\n \" for time \"+df.format(timenow.getTime())+\n \". Alcohol can not be sold between \"+df.format(midnight.getTime())+\n \" and \"+df.format(eleven30.getTime()));\n return true;\n}\nelse{\n outFields.put(\"authorised\", true);\n outFields.put(\"message\", \"Sale authorised by policy task \"+subject.taskName+\n \" for time \"+df.format(timenow.getTime()));\n return true;\n}\n\n/*\nThis task checks if a sale request is for an item that is an alcoholic drink.\nIf the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not\nauthorised. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID value between 1000 and\n2000 are all alcoholic drinks :-)\n*/"
+ }
+ }
+ } ]
+ }
+ },
+ "events" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Events",
+ "version" : "0.0.1"
+ },
+ "eventMap" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "SALE_AUTH",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SALE_AUTH",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "com.hyperm",
+ "source" : "APEX",
+ "target" : "POS",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "amount",
+ "value" : {
+ "key" : "amount",
+ "fieldSchemaKey" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "assistant_ID",
+ "value" : {
+ "key" : "assistant_ID",
+ "fieldSchemaKey" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "authorised",
+ "value" : {
+ "key" : "authorised",
+ "fieldSchemaKey" : {
+ "name" : "authorised_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "branch_ID",
+ "value" : {
+ "key" : "branch_ID",
+ "fieldSchemaKey" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "item_ID",
+ "value" : {
+ "key" : "item_ID",
+ "fieldSchemaKey" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "message",
+ "value" : {
+ "key" : "message",
+ "fieldSchemaKey" : {
+ "name" : "message_type",
+ "version" : "0.0.1"
+ },
+ "optional" : true
+ }
+ }, {
+ "key" : "notes",
+ "value" : {
+ "key" : "notes",
+ "fieldSchemaKey" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "optional" : true
+ }
+ }, {
+ "key" : "quantity",
+ "value" : {
+ "key" : "quantity",
+ "fieldSchemaKey" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "sale_ID",
+ "value" : {
+ "key" : "sale_ID",
+ "fieldSchemaKey" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "time",
+ "value" : {
+ "key" : "time",
+ "fieldSchemaKey" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ }, {
+ "key" : {
+ "name" : "SALE_INPUT",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "SALE_INPUT",
+ "version" : "0.0.1"
+ },
+ "nameSpace" : "com.hyperm",
+ "source" : "POS",
+ "target" : "APEX",
+ "parameter" : {
+ "entry" : [ {
+ "key" : "amount",
+ "value" : {
+ "key" : "amount",
+ "fieldSchemaKey" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "assistant_ID",
+ "value" : {
+ "key" : "assistant_ID",
+ "fieldSchemaKey" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "branch_ID",
+ "value" : {
+ "key" : "branch_ID",
+ "fieldSchemaKey" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "item_ID",
+ "value" : {
+ "key" : "item_ID",
+ "fieldSchemaKey" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "notes",
+ "value" : {
+ "key" : "notes",
+ "fieldSchemaKey" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "optional" : true
+ }
+ }, {
+ "key" : "quantity",
+ "value" : {
+ "key" : "quantity",
+ "fieldSchemaKey" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "sale_ID",
+ "value" : {
+ "key" : "sale_ID",
+ "fieldSchemaKey" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ }, {
+ "key" : "time",
+ "value" : {
+ "key" : "time",
+ "fieldSchemaKey" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "optional" : false
+ }
+ } ]
+ }
+ }
+ } ]
+ }
+ },
+ "schemas" : {
+ "key" : {
+ "name" : "MyFirstPolicyModel_Schemas",
+ "version" : "0.0.1"
+ },
+ "schemas" : {
+ "entry" : [ {
+ "key" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "assistant_ID_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ }, {
+ "key" : {
+ "name" : "authorised_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "authorised_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Boolean"
+ }
+ }, {
+ "key" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "branch_ID_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ }, {
+ "key" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "item_ID_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ }, {
+ "key" : {
+ "name" : "message_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "message_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.String"
+ }
+ }, {
+ "key" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "notes_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.String"
+ }
+ }, {
+ "key" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "price_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ }, {
+ "key" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "quantity_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Integer"
+ }
+ }, {
+ "key" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "sale_ID_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ }, {
+ "key" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "value" : {
+ "key" : {
+ "name" : "timestamp_type",
+ "version" : "0.0.1"
+ },
+ "schemaFlavour" : "Java",
+ "schemaDefinition" : "java.lang.Long"
+ }
+ } ]
+ }
+ }
+ }
+}
diff --git a/auth/cli-editor/src/test/resources/tosca/ToscaPolicyOutput_compare.json b/auth/cli-editor/src/test/resources/tosca/ToscaPolicyOutput_compare.json
new file mode 100644
index 000000000..3957043b6
--- /dev/null
+++ b/auth/cli-editor/src/test/resources/tosca/ToscaPolicyOutput_compare.json
@@ -0,0 +1 @@
+{"tosca_definitions_version":"tosca_simple_yaml_1_0_0","topology_template":{"policies":[{"operational.sampledomain":{"type":"onap.policies.controlloop.Operational","typeVersion":"1.0.0","name":"onap.policies.controlloop.Operational.apex.sampledomain","version":"1.0.0","properties":{"content":{"engineServiceParameters":{"name":"MyFirstPolicyApexEngine","version":"0.0.1","id":101,"instanceCount":4,"deploymentPort":12345,"policyModelFileName":"examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json","engineParameters":{"executorParameters":{"MVEL":{"parameterClassName":"org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters"},"JAVASCRIPT":{"parameterClassName":"org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"}}},"policy_type_impl":{"apexPolicyModel":{"key":{"name":"MyFirstPolicyModel","version":"0.0.1"},"keyInformation":{"key":{"name":"MyFirstPolicyModel_KeyInfo","version":"0.0.1"},"keyInfoMap":{"entry":[{"key":{"name":"MorningBoozeCheck","version":"0.0.1"},"value":{"key":{"name":"MorningBoozeCheck","version":"0.0.1"},"UUID":"3351b0f4-cf06-4fa2-8823-edf67bd30223","description":"This task checks if the sales request is for an item that contains alcohol. \nIf the local time is between 00:00:00 and 11:30:00 then the sale is not authorised. Otherwise the sale is authorised. \nIn this implementation we assume that all items with item_ID values between 1000 and 2000 contain alcohol :-)"}},{"key":{"name":"MyFirstPolicy","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicy","version":"0.0.1"},"UUID":"6c5e410f-489a-46ff-964e-982ce6e8b6d0","description":"This is my first Apex policy. It checks if a sale should be authorised or not."}},{"key":{"name":"MyFirstPolicyModel","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicyModel","version":"0.0.1"},"UUID":"540226fb-55ee-4f0e-a444-983a0494818e","description":"This is my first Apex Policy Model."}},{"key":{"name":"MyFirstPolicyModel_Events","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicyModel_Events","version":"0.0.1"},"UUID":"ef281318-5ac9-3ef0-8db3-8f9c4e4a81e2","description":"Generated description for concept referred to by key \"MyFirstPolicyModel_Events:0.0.1\""}},{"key":{"name":"MyFirstPolicyModel_KeyInfo","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicyModel_KeyInfo","version":"0.0.1"},"UUID":"d9248c6f-7c00-38df-8251-611463ba4065","description":"Generated description for concept referred to by key \"MyFirstPolicyModel_KeyInfo:0.0.1\""}},{"key":{"name":"MyFirstPolicyModel_Policies","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicyModel_Policies","version":"0.0.1"},"UUID":"77c01a6b-510c-3aa9-b640-b4db356aa03b","description":"Generated description for concept referred to by key \"MyFirstPolicyModel_Policies:0.0.1\""}},{"key":{"name":"MyFirstPolicyModel_Schemas","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicyModel_Schemas","version":"0.0.1"},"UUID":"d0cc3aa0-ea69-3a43-80ff-a0dbb0ebd885","description":"Generated description for concept referred to by key \"MyFirstPolicyModel_Schemas:0.0.1\""}},{"key":{"name":"MyFirstPolicyModel_Tasks","version":"0.0.1"},"value":{"key":{"name":"MyFirstPolicyModel_Tasks","version":"0.0.1"},"UUID":"b02a7e02-2cd0-39e6-b3cb-946fa83a8f08","description":"Generated description for concept referred to by key \"MyFirstPolicyModel_Tasks:0.0.1\""}},{"key":{"name":"SALE_AUTH","version":"0.0.1"},"value":{"key":{"name":"SALE_AUTH","version":"0.0.1"},"UUID":"c4500941-3f98-4080-a9cc-5b9753ed050b","description":"An event emitted by the Policy to indicate whether the sale of an item has been authorised"}},{"key":{"name":"SALE_INPUT","version":"0.0.1"},"value":{"key":{"name":"SALE_INPUT","version":"0.0.1"},"UUID":"4f04aa98-e917-4f4a-882a-c75ba5a99374","description":"An event raised by the PoS system each time an item is scanned for purchase"}},{"key":{"name":"assistant_ID_type","version":"0.0.1"},"value":{"key":{"name":"assistant_ID_type","version":"0.0.1"},"UUID":"36df4c71-9616-4206-8b53-976a5cd4bd87","description":"A type for \u0027assistant_ID\u0027 values"}},{"key":{"name":"authorised_type","version":"0.0.1"},"value":{"key":{"name":"authorised_type","version":"0.0.1"},"UUID":"d48b619e-d00d-4008-b884-02d76ea4350b","description":"A type for \u0027authorised\u0027 values"}},{"key":{"name":"branch_ID_type","version":"0.0.1"},"value":{"key":{"name":"branch_ID_type","version":"0.0.1"},"UUID":"6468845f-4122-4128-8e49-0f52c26078b5","description":"A type for \u0027branch_ID\u0027 values"}},{"key":{"name":"item_ID_type","version":"0.0.1"},"value":{"key":{"name":"item_ID_type","version":"0.0.1"},"UUID":"4f227ff1-aee0-453a-b6b6-9a4b2e0da932","description":"A type for \u0027item_ID\u0027 values"}},{"key":{"name":"message_type","version":"0.0.1"},"value":{"key":{"name":"message_type","version":"0.0.1"},"UUID":"ad1431bb-3155-4e73-b5a3-b89bee498749","description":"A type for \u0027message\u0027 values"}},{"key":{"name":"notes_type","version":"0.0.1"},"value":{"key":{"name":"notes_type","version":"0.0.1"},"UUID":"eecfde90-896c-4343-8f9c-2603ced94e2d","description":"A type for \u0027notes\u0027 values"}},{"key":{"name":"price_type","version":"0.0.1"},"value":{"key":{"name":"price_type","version":"0.0.1"},"UUID":"52c2fc45-fd8c-463c-bd6f-d91b0554aea7","description":"A type for \u0027amount\u0027/\u0027price\u0027 values"}},{"key":{"name":"quantity_type","version":"0.0.1"},"value":{"key":{"name":"quantity_type","version":"0.0.1"},"UUID":"ac3d9842-80af-4a98-951c-bd79a431c613","description":"A type for \u0027quantity\u0027 values"}},{"key":{"name":"sale_ID_type","version":"0.0.1"},"value":{"key":{"name":"sale_ID_type","version":"0.0.1"},"UUID":"cca47d74-7754-4a61-b163-ca31f66b157b","description":"A type for \u0027sale_ID\u0027 values"}},{"key":{"name":"timestamp_type","version":"0.0.1"},"value":{"key":{"name":"timestamp_type","version":"0.0.1"},"UUID":"fd594e88-411d-4a94-b2be-697b3a0d7adf","description":"A type for \u0027time\u0027 values"}}]}},"policies":{"key":{"name":"MyFirstPolicyModel_Policies","version":"0.0.1"},"policyMap":{"entry":[{"key":{"name":"MyFirstPolicy","version":"0.0.1"},"value":{"policyKey":{"name":"MyFirstPolicy","version":"0.0.1"},"template":"FREEFORM","state":{"entry":[{"key":"BoozeAuthDecide","value":{"stateKey":{"parentKeyName":"MyFirstPolicy","parentKeyVersion":"0.0.1","parentLocalName":"NULL","localName":"BoozeAuthDecide"},"trigger":{"name":"SALE_INPUT","version":"0.0.1"},"stateOutputs":{"entry":[{"key":"MorningBoozeCheck_Output_Direct","value":{"key":{"parentKeyName":"MyFirstPolicy","parentKeyVersion":"0.0.1","parentLocalName":"BoozeAuthDecide","localName":"MorningBoozeCheck_Output_Direct"},"outgoingEvent":{"name":"SALE_AUTH","version":"0.0.1"},"nextState":{"parentKeyName":"NULL","parentKeyVersion":"0.0.0","parentLocalName":"NULL","localName":"NULL"}}}]},"contextAlbumReference":[],"taskSelectionLogic":{"key":"NULL","logicFlavour":"UNDEFINED","logic":""},"stateFinalizerLogicMap":{"entry":[]},"defaultTask":{"name":"MorningBoozeCheck","version":"0.0.1"},"taskReferences":{"entry":[{"key":{"name":"MorningBoozeCheck","version":"0.0.1"},"value":{"key":{"parentKeyName":"MyFirstPolicy","parentKeyVersion":"0.0.1","parentLocalName":"BoozeAuthDecide","localName":"MorningBoozeCheck"},"outputType":"DIRECT","output":{"parentKeyName":"MyFirstPolicy","parentKeyVersion":"0.0.1","parentLocalName":"BoozeAuthDecide","localName":"MorningBoozeCheck_Output_Direct"}}}]}}}]},"firstState":"BoozeAuthDecide"}}]}},"tasks":{"key":{"name":"MyFirstPolicyModel_Tasks","version":"0.0.1"},"taskMap":{"entry":[{"key":{"name":"MorningBoozeCheck","version":"0.0.1"},"value":{"key":{"name":"MorningBoozeCheck","version":"0.0.1"},"inputFields":{"entry":[{"key":"amount","value":{"key":"amount","fieldSchemaKey":{"name":"price_type","version":"0.0.1"},"optional":false}},{"key":"assistant_ID","value":{"key":"assistant_ID","fieldSchemaKey":{"name":"assistant_ID_type","version":"0.0.1"},"optional":false}},{"key":"branch_ID","value":{"key":"branch_ID","fieldSchemaKey":{"name":"branch_ID_type","version":"0.0.1"},"optional":false}},{"key":"item_ID","value":{"key":"item_ID","fieldSchemaKey":{"name":"item_ID_type","version":"0.0.1"},"optional":false}},{"key":"notes","value":{"key":"notes","fieldSchemaKey":{"name":"notes_type","version":"0.0.1"},"optional":true}},{"key":"quantity","value":{"key":"quantity","fieldSchemaKey":{"name":"quantity_type","version":"0.0.1"},"optional":false}},{"key":"sale_ID","value":{"key":"sale_ID","fieldSchemaKey":{"name":"sale_ID_type","version":"0.0.1"},"optional":false}},{"key":"time","value":{"key":"time","fieldSchemaKey":{"name":"timestamp_type","version":"0.0.1"},"optional":false}}]},"outputFields":{"entry":[{"key":"amount","value":{"key":"amount","fieldSchemaKey":{"name":"price_type","version":"0.0.1"},"optional":false}},{"key":"assistant_ID","value":{"key":"assistant_ID","fieldSchemaKey":{"name":"assistant_ID_type","version":"0.0.1"},"optional":false}},{"key":"authorised","value":{"key":"authorised","fieldSchemaKey":{"name":"authorised_type","version":"0.0.1"},"optional":false}},{"key":"branch_ID","value":{"key":"branch_ID","fieldSchemaKey":{"name":"branch_ID_type","version":"0.0.1"},"optional":false}},{"key":"item_ID","value":{"key":"item_ID","fieldSchemaKey":{"name":"item_ID_type","version":"0.0.1"},"optional":false}},{"key":"message","value":{"key":"message","fieldSchemaKey":{"name":"message_type","version":"0.0.1"},"optional":true}},{"key":"notes","value":{"key":"notes","fieldSchemaKey":{"name":"notes_type","version":"0.0.1"},"optional":true}},{"key":"quantity","value":{"key":"quantity","fieldSchemaKey":{"name":"quantity_type","version":"0.0.1"},"optional":false}},{"key":"sale_ID","value":{"key":"sale_ID","fieldSchemaKey":{"name":"sale_ID_type","version":"0.0.1"},"optional":false}},{"key":"time","value":{"key":"time","fieldSchemaKey":{"name":"timestamp_type","version":"0.0.1"},"optional":false}}]},"taskParameters":{"entry":[]},"contextAlbumReference":[],"taskLogic":{"key":"TaskLogic","logicFlavour":"MVEL","logic":"/*\n * \u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003dLICENSE_START\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2019 Nordix Foundation.\n * \u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * \u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003dLICENSE_END\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\u003d\n */\nimport java.util.Date;\nimport java.util.Calendar;\nimport java.util.TimeZone;\nimport java.text.SimpleDateFormat;\n\nlogger.info(\"Task Execution: \u0027\"+subject.id+\"\u0027. Input Fields: \u0027\"+inFields+\"\u0027\");\n\noutFields.put(\"amount\" , inFields.get(\"amount\"));\noutFields.put(\"assistant_ID\", inFields.get(\"assistant_ID\"));\noutFields.put(\"notes\" , inFields.get(\"notes\"));\noutFields.put(\"quantity\" , inFields.get(\"quantity\"));\noutFields.put(\"branch_ID\" , inFields.get(\"branch_ID\"));\noutFields.put(\"item_ID\" , inFields.get(\"item_ID\"));\noutFields.put(\"time\" , inFields.get(\"time\"));\noutFields.put(\"sale_ID\" , inFields.get(\"sale_ID\"));\n\nitem_id \u003d inFields.get(\"item_ID\");\n\n//The events used later to test this task use GMT timezone!\ngmt \u003d TimeZone.getTimeZone(\"GMT\");\ntimenow \u003d Calendar.getInstance(gmt);\ndf \u003d new SimpleDateFormat(\"HH:mm:ss z\");\ndf.setTimeZone(gmt);\ntimenow.setTimeInMillis(inFields.get(\"time\"));\n\nmidnight \u003d timenow.clone();\nmidnight.set(\n timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n timenow.get(Calendar.DATE),0,0,0);\neleven30 \u003d timenow.clone();\neleven30.set(\n timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n timenow.get(Calendar.DATE),11,30,0);\n\nitemisalcohol \u003d false;\nif(item_id !\u003d null \u0026\u0026 item_id \u003e\u003d1000 \u0026\u0026 item_id \u003c 2000)\n itemisalcohol \u003d true;\n\nif( itemisalcohol\n \u0026\u0026 timenow.after(midnight) \u0026\u0026 timenow.before(eleven30)){\n outFields.put(\"authorised\", false);\n outFields.put(\"message\", \"Sale not authorised by policy task \"+subject.taskName+\n \" for time \"+df.format(timenow.getTime())+\n \". Alcohol can not be sold between \"+df.format(midnight.getTime())+\n \" and \"+df.format(eleven30.getTime()));\n return true;\n}\nelse{\n outFields.put(\"authorised\", true);\n outFields.put(\"message\", \"Sale authorised by policy task \"+subject.taskName+\n \" for time \"+df.format(timenow.getTime()));\n return true;\n}\n\n/*\nThis task checks if a sale request is for an item that is an alcoholic drink.\nIf the local time is between 00:00:00 GMT and 11:30:00 GMT then the sale is not\nauthorised. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID value between 1000 and\n2000 are all alcoholic drinks :-)\n*/"}}}]}},"events":{"key":{"name":"MyFirstPolicyModel_Events","version":"0.0.1"},"eventMap":{"entry":[{"key":{"name":"SALE_AUTH","version":"0.0.1"},"value":{"key":{"name":"SALE_AUTH","version":"0.0.1"},"nameSpace":"com.hyperm","source":"APEX","target":"POS","parameter":{"entry":[{"key":"amount","value":{"key":"amount","fieldSchemaKey":{"name":"price_type","version":"0.0.1"},"optional":false}},{"key":"assistant_ID","value":{"key":"assistant_ID","fieldSchemaKey":{"name":"assistant_ID_type","version":"0.0.1"},"optional":false}},{"key":"authorised","value":{"key":"authorised","fieldSchemaKey":{"name":"authorised_type","version":"0.0.1"},"optional":false}},{"key":"branch_ID","value":{"key":"branch_ID","fieldSchemaKey":{"name":"branch_ID_type","version":"0.0.1"},"optional":false}},{"key":"item_ID","value":{"key":"item_ID","fieldSchemaKey":{"name":"item_ID_type","version":"0.0.1"},"optional":false}},{"key":"message","value":{"key":"message","fieldSchemaKey":{"name":"message_type","version":"0.0.1"},"optional":true}},{"key":"notes","value":{"key":"notes","fieldSchemaKey":{"name":"notes_type","version":"0.0.1"},"optional":true}},{"key":"quantity","value":{"key":"quantity","fieldSchemaKey":{"name":"quantity_type","version":"0.0.1"},"optional":false}},{"key":"sale_ID","value":{"key":"sale_ID","fieldSchemaKey":{"name":"sale_ID_type","version":"0.0.1"},"optional":false}},{"key":"time","value":{"key":"time","fieldSchemaKey":{"name":"timestamp_type","version":"0.0.1"},"optional":false}}]}}},{"key":{"name":"SALE_INPUT","version":"0.0.1"},"value":{"key":{"name":"SALE_INPUT","version":"0.0.1"},"nameSpace":"com.hyperm","source":"POS","target":"APEX","parameter":{"entry":[{"key":"amount","value":{"key":"amount","fieldSchemaKey":{"name":"price_type","version":"0.0.1"},"optional":false}},{"key":"assistant_ID","value":{"key":"assistant_ID","fieldSchemaKey":{"name":"assistant_ID_type","version":"0.0.1"},"optional":false}},{"key":"branch_ID","value":{"key":"branch_ID","fieldSchemaKey":{"name":"branch_ID_type","version":"0.0.1"},"optional":false}},{"key":"item_ID","value":{"key":"item_ID","fieldSchemaKey":{"name":"item_ID_type","version":"0.0.1"},"optional":false}},{"key":"notes","value":{"key":"notes","fieldSchemaKey":{"name":"notes_type","version":"0.0.1"},"optional":true}},{"key":"quantity","value":{"key":"quantity","fieldSchemaKey":{"name":"quantity_type","version":"0.0.1"},"optional":false}},{"key":"sale_ID","value":{"key":"sale_ID","fieldSchemaKey":{"name":"sale_ID_type","version":"0.0.1"},"optional":false}},{"key":"time","value":{"key":"time","fieldSchemaKey":{"name":"timestamp_type","version":"0.0.1"},"optional":false}}]}}}]}},"schemas":{"key":{"name":"MyFirstPolicyModel_Schemas","version":"0.0.1"},"schemas":{"entry":[{"key":{"name":"assistant_ID_type","version":"0.0.1"},"value":{"key":{"name":"assistant_ID_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Long"}},{"key":{"name":"authorised_type","version":"0.0.1"},"value":{"key":{"name":"authorised_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Boolean"}},{"key":{"name":"branch_ID_type","version":"0.0.1"},"value":{"key":{"name":"branch_ID_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Long"}},{"key":{"name":"item_ID_type","version":"0.0.1"},"value":{"key":{"name":"item_ID_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Long"}},{"key":{"name":"message_type","version":"0.0.1"},"value":{"key":{"name":"message_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.String"}},{"key":{"name":"notes_type","version":"0.0.1"},"value":{"key":{"name":"notes_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.String"}},{"key":{"name":"price_type","version":"0.0.1"},"value":{"key":{"name":"price_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Long"}},{"key":{"name":"quantity_type","version":"0.0.1"},"value":{"key":{"name":"quantity_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Integer"}},{"key":{"name":"sale_ID_type","version":"0.0.1"},"value":{"key":{"name":"sale_ID_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Long"}},{"key":{"name":"timestamp_type","version":"0.0.1"},"value":{"key":{"name":"timestamp_type","version":"0.0.1"},"schemaFlavour":"Java","schemaDefinition":"java.lang.Long"}}]}}}}},"eventOutputParameters":{"FirstProducer":{"carrierTechnologyParameters":{"carrierTechnology":"FILE","parameters":{"standardIo":true}},"eventProtocolParameters":{"eventProtocol":"JSON"}}},"eventInputParameters":{"FirstConsumer":{"carrierTechnologyParameters":{"carrierTechnology":"FILE","parameters":{"standardIo":true}},"eventProtocolParameters":{"eventProtocol":"JSON"}}}}}}}]}} \ No newline at end of file
diff --git a/auth/cli-editor/src/test/resources/tosca/ToscaTemplate.json b/auth/cli-editor/src/test/resources/tosca/ToscaTemplate.json
new file mode 100644
index 000000000..a96cbf56e
--- /dev/null
+++ b/auth/cli-editor/src/test/resources/tosca/ToscaTemplate.json
@@ -0,0 +1,19 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "topology_template": {
+ "policies": [
+ {
+ "operational.sampledomain": {
+ "type": "onap.policies.controlloop.Operational",
+ "typeVersion": "1.0.0",
+ "name": "onap.policies.controlloop.Operational.apex.sampledomain",
+ "version": "1.0.0",
+ "properties": {
+ "content": {
+ }
+ }
+ }
+ }
+ ]
+ }
+} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5f974434b..b08d8b049 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,6 +85,10 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ </dependency>
</dependencies>
<dependencyManagement>