From b87ab1696010ca0bbed5db99c140cf908722df57 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 11 Mar 2020 17:17:14 +0000 Subject: Convert examples to Rhino Javascript format All examples are converted to Rhino Javascript from Nashorn Javascript. Issue-ID: POLICY-2106 Change-Id: Ia6fec5b57b1e6131799b4b069968e4766ce54c96 Signed-off-by: liamfallon --- .../src/main/resources/logic/AnswerInitTask.js | 9 +- .../main/resources/logic/DitheringAnswerTask.js | 10 +- .../src/main/resources/logic/HealthCheckTask.js | 9 +- .../main/resources/logic/MakeDecisionStateTSL.js | 11 +- .../main/resources/logic/OptimisticAnswerTask.js | 9 +- .../main/resources/logic/PessimisticAnswerTask.js | 9 +- .../src/main/resources/logic/RandomAnswerTask.js | 9 +- .../main/resources/logic/RoundRobinAnswerTask.js | 9 +- examples/examples-myfirstpolicy/pom.xml | 26 +- .../myfirstpolicy/model/MfpDomainModelFactory.java | 86 -- .../myfirstpolicy/model/MfpDomainModelSaver.java | 68 -- .../examples/myfirstpolicy/model/package-info.java | 27 - .../models/MyFirstPolicy/1/MorningBoozeCheck.js | 10 +- .../1/MyFirstPolicyModelJavascript_0.0.1.apex | 97 ++ .../1/MyFirstPolicyModelMvel_0.0.1.apex | 97 ++ .../1/MyFirstPolicyModel_0.0.1.alt.json | 974 ---------------- .../MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex | 180 --- .../MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json | 974 ---------------- .../MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex | 216 +--- .../MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json | 1191 -------------------- .../2/MyFirstPolicy_BoozeAuthDecideTSL.js | 4 +- .../myfirstpolicy/MfpDomainModelFactory.java | 90 ++ .../apex/examples/myfirstpolicy/MfpLogicTest.java | 1 - .../examples/myfirstpolicy/MfpModelCliTest.java | 2 +- .../examples/myfirstpolicy/MfpUseCaseTest.java | 57 +- .../myfirstpolicy/TestMfpModelCreator.java | 2 +- .../myfirstpolicy/TestSaleAuthListener.java | 4 +- .../main/resources/logic/AAIServiceAssignedTask.js | 15 +- .../main/resources/logic/AAIServiceCreateTask.js | 16 +- .../logic/ErrorAAIServiceAssignedLogTask.js | 4 +- .../logic/ErrorSdncResourceUpdateTaskLogTask.js | 4 +- .../resources/logic/GetBBSCloseLoopEventTask.js | 11 +- .../resources/logic/NomadicEventSuccessTask.js | 14 +- .../main/resources/logic/RUorInitStateSelect.js | 8 +- .../main/resources/logic/SU2orInitStateSelect.js | 8 +- .../main/resources/logic/SdncResourceUpdateTask.js | 18 +- .../logic/ServiceUpdateStateCpeAuthTask.js | 14 +- .../examples/pcvs/vpnsla/logic/ctxt-customer.js | 13 +- .../apex/examples/pcvs/vpnsla/logic/ctxt-edges.js | 13 +- .../apex/examples/pcvs/vpnsla/logic/ctxt-nodes.js | 13 +- .../apex/examples/pcvs/vpnsla/logic/task-act.js | 14 +- .../examples/pcvs/vpnsla/logic/task-decide-none.js | 15 +- .../pcvs/vpnsla/logic/task-decide-priority.js | 15 +- .../examples/pcvs/vpnsla/logic/task-decide-sla.js | 15 +- .../pcvs/vpnsla/logic/task-decide-solved.js | 15 +- .../examples/pcvs/vpnsla/logic/task-establish.js | 12 +- .../apex/examples/pcvs/vpnsla/logic/task-match.js | 13 +- .../apex/examples/pcvs/vpnsla/logic/tsl-decide.js | 18 +- .../src/main/resources/logic/OutputTask.js | 9 +- .../src/main/resources/logic/PeriodicTask.js | 11 +- .../test/resources/javascript/PolicyTaskLogic.js | 2 +- .../src/test/resources/javascript/TestLogic00.js | 3 +- .../model/generator/model2cli/Model2CliTest.java | 2 +- 53 files changed, 544 insertions(+), 3932 deletions(-) delete mode 100644 examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelFactory.java delete mode 100644 examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelSaver.java delete mode 100644 examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java create mode 100644 examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelJavascript_0.0.1.apex create mode 100644 examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex delete mode 100644 examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json delete mode 100644 examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex delete mode 100644 examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json delete mode 100644 examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json create mode 100644 examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java diff --git a/examples/examples-decisionmaker/src/main/resources/logic/AnswerInitTask.js b/examples/examples-decisionmaker/src/main/resources/logic/AnswerInitTask.js index 4a09705d8..f0d8c05ae 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/AnswerInitTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/AnswerInitTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -44,4 +45,4 @@ executor.outFields.put("a6", answerAlbum.get("a6")); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-decisionmaker/src/main/resources/logic/DitheringAnswerTask.js b/examples/examples-decisionmaker/src/main/resources/logic/DitheringAnswerTask.js index 7d56956cc..eaad4ab54 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/DitheringAnswerTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/DitheringAnswerTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -34,4 +35,5 @@ executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(s executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; + diff --git a/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js b/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js index ebc0e6387..7b3d5c478 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,4 +24,4 @@ executor.logger.info(executor.inFields); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-decisionmaker/src/main/resources/logic/MakeDecisionStateTSL.js b/examples/examples-decisionmaker/src/main/resources/logic/MakeDecisionStateTSL.js index 85338f682..33af49534 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/MakeDecisionStateTSL.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/MakeDecisionStateTSL.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -21,8 +22,6 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; - if (executor.inFields.get("mode").equals("random")) { executor.subject.getTaskKey("RandomAnswerTask").copyTo(executor.selectedTask); } @@ -40,3 +39,5 @@ else if (executor.inFields.get("mode").equals("dithering")) { //} executor.logger.info("Answer Selected Task:" + executor.selectedTask); + +true; diff --git a/examples/examples-decisionmaker/src/main/resources/logic/OptimisticAnswerTask.js b/examples/examples-decisionmaker/src/main/resources/logic/OptimisticAnswerTask.js index fdcca5260..918bf6241 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/OptimisticAnswerTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/OptimisticAnswerTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -34,4 +35,4 @@ executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(s executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-decisionmaker/src/main/resources/logic/PessimisticAnswerTask.js b/examples/examples-decisionmaker/src/main/resources/logic/PessimisticAnswerTask.js index 61935b3ed..62cb8fb78 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/PessimisticAnswerTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/PessimisticAnswerTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -34,4 +35,4 @@ executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(s executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-decisionmaker/src/main/resources/logic/RandomAnswerTask.js b/examples/examples-decisionmaker/src/main/resources/logic/RandomAnswerTask.js index 7a67fccc2..4b4120f34 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/RandomAnswerTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/RandomAnswerTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -34,4 +35,4 @@ executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(s executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-decisionmaker/src/main/resources/logic/RoundRobinAnswerTask.js b/examples/examples-decisionmaker/src/main/resources/logic/RoundRobinAnswerTask.js index ddfbe9254..eb63db573 100644 --- a/examples/examples-decisionmaker/src/main/resources/logic/RoundRobinAnswerTask.js +++ b/examples/examples-decisionmaker/src/main/resources/logic/RoundRobinAnswerTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -42,4 +43,4 @@ executor.outFields.put("decision", executor.getContextAlbum("AnswerAlbum").get(s executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-myfirstpolicy/pom.xml b/examples/examples-myfirstpolicy/pom.xml index ec61748f0..65349d1b3 100644 --- a/examples/examples-myfirstpolicy/pom.xml +++ b/examples/examples-myfirstpolicy/pom.xml @@ -34,7 +34,8 @@ Specific code for the Apex MyFirstPolicy Example - MyFirstPolicyModel_0.0.1 + MyFirstPolicyModelMvel_0.0.1 + MyFirstPolicyModelJavascript_0.0.1 MyFirstPolicyModel_0.0.1 @@ -81,29 +82,26 @@ org.codehaus.mojo exec-maven-plugin + - generate-models + generate-policy1m compile java - org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelSaver + org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain compile - ${project.build.directory}/classes/examples/models/MyFirstPolicy + --command-file=${project.basedir}/src/main/resources/examples/models/MyFirstPolicy/1/${policymodel1m.name}.apex + --output-model-file=${project.build.directory}/classes/examples/models/MyFirstPolicy/1/${policymodel1m.name}.json + --log-file=${project.build.directory}/${policymodel1.name}_policygeneration.log + --working-dir=${project.basedir} - - - - org.codehaus.mojo - exec-maven-plugin - - - generate-policy1 + generate-policy1j compile java @@ -112,8 +110,8 @@ org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain compile - --command-file=${project.basedir}/src/main/resources/examples/models/MyFirstPolicy/1/${policymodel1.name}.apex - --output-model-file=${project.build.directory}/classes/examples/models/MyFirstPolicy/1/${policymodel1.name}.json + --command-file=${project.basedir}/src/main/resources/examples/models/MyFirstPolicy/1/${policymodel1j.name}.apex + --output-model-file=${project.build.directory}/classes/examples/models/MyFirstPolicy/1/${policymodel1j.name}.json --log-file=${project.build.directory}/${policymodel1.name}_policygeneration.log --working-dir=${project.basedir} diff --git a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelFactory.java b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelFactory.java deleted file mode 100644 index f81a22ee9..000000000 --- a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelFactory.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.examples.myfirstpolicy.model; - -import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.common.utils.resources.ResourceUtils; - -/** - * A factory for creating MFPDomainModel objects. - * - * @author John Keeney (john.keeney@ericsson.com) - */ -public class MfpDomainModelFactory { - - private static final String MFP1PATH = "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json"; - private static final String MFP1_ALT_PATH = "examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json"; - private static final String MFP2PATH = "examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json"; - - /** - * Gets the MyFirstPolicy#1 policy model. - * - * @return the MyFirstPolicy#1 policy model - */ - public AxPolicyModel getMfp1PolicyModel() { - java.util.TimeZone.getTimeZone("gmt"); - try { - final ApexModelReader reader = new ApexModelReader<>(AxPolicyModel.class); - return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP1PATH)); - } catch (final Exception e) { - throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MfpDomainModelFactory.MFP1PATH, - e); - } - } - - /** - * Gets the MyFirstPolicy#1 policy model, with alternate JavaScript task logic. - * - * @return the MyFirstPolicy#1 policy model - */ - public AxPolicyModel getMfp1AltPolicyModel() { - java.util.TimeZone.getTimeZone("gmt"); - try { - final ApexModelReader reader = new ApexModelReader<>(AxPolicyModel.class); - return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP1_ALT_PATH)); - } catch (final Exception e) { - throw new ApexRuntimeException( - "Failed to build MyFirstPolicy_ALT from path: " + MfpDomainModelFactory.MFP1_ALT_PATH, e); - } - } - - /** - * Gets the MyFirstPolicy#1 policy model. - * - * @return the MyFirstPolicy#1 policy model - */ - public AxPolicyModel getMfp2PolicyModel() { - try { - final ApexModelReader reader = new ApexModelReader<>(AxPolicyModel.class); - return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP2PATH)); - } catch (final Exception e) { - throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MfpDomainModelFactory.MFP2PATH, - e); - } - } - -} diff --git a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelSaver.java b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelSaver.java deleted file mode 100644 index d2469f209..000000000 --- a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/MfpDomainModelSaver.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.apex.examples.myfirstpolicy.model; - -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelSaver; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class MFPDomainModelSaver. - * - * @author John Keeney (john.keeney@ericsson.com) - */ -public final class MfpDomainModelSaver { - // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(MfpDomainModelSaver.class); - - /** Private constructor to prevent instantiation. */ - private MfpDomainModelSaver() { - } - - /** - * Write the MyFirstPolicy model to args[0]. - * - * @param args uses arg[0] for directory information - * @throws ApexException the apex exception - */ - public static void main(final String[] args) throws ApexException { - if (args.length != 1) { - LOGGER.error("usage: " + MfpDomainModelSaver.class.getName() + " modelDirectory"); - return; - } - - // Save Java model - AxPolicyModel mfpPolicyModel = new MfpDomainModelFactory().getMfp1PolicyModel(); - ApexModelSaver mfpModelSaver = new ApexModelSaver<>(AxPolicyModel.class, mfpPolicyModel, - args[0] + "/1/"); - mfpModelSaver.apexModelWriteJson(); - mfpModelSaver.apexModelWriteXml(); - - mfpPolicyModel = new MfpDomainModelFactory().getMfp2PolicyModel(); - mfpModelSaver = new ApexModelSaver<>(AxPolicyModel.class, mfpPolicyModel, args[0] + "/2/"); - mfpModelSaver.apexModelWriteJson(); - mfpModelSaver.apexModelWriteXml(); - - } -} diff --git a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java b/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java deleted file mode 100644 index ed03da4ca..000000000 --- a/examples/examples-myfirstpolicy/src/main/java/org/onap/policy/apex/examples/myfirstpolicy/model/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -/** - * Contains the model for My-First-Policy. - * - * @author John Keeney (john.keeney@ericsson.com) - */ - -package org.onap.policy.apex.examples.myfirstpolicy.model; diff --git a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MorningBoozeCheck.js b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MorningBoozeCheck.js index 359bbd425..ff7cf30cb 100644 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MorningBoozeCheck.js +++ b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MorningBoozeCheck.js @@ -19,14 +19,6 @@ * ============LICENSE_END========================================================= */ -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); - -// Load compatibility script for imports etc -load("nashorn:mozilla_compat.js"); -importPackage(java.text); -importClass(java.text.SimpleDateFormat); - executor.logger.info("Task Execution: '"+executor.subject.id+"'. Input Fields: '"+executor.inFields+"'"); executor.outFields.put("amount" , executor.inFields.get("amount")); @@ -78,3 +70,5 @@ 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 :-) */ + +true; diff --git a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelJavascript_0.0.1.apex b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelJavascript_0.0.1.apex new file mode 100644 index 000000000..dfceb7ce4 --- /dev/null +++ b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelJavascript_0.0.1.apex @@ -0,0 +1,97 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# Modifications Copyright (C) 2020 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +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=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/examples/models/MyFirstPolicy/1/MorningBoozeCheck.js" +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/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex new file mode 100644 index 000000000..c820a68a5 --- /dev/null +++ b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex @@ -0,0 +1,97 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. All rights reserved. +# Modifications Copyright (C) 2020 Nordix Foundation. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +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 +#MACROFILE:"src/main/resources/examples/models/MyFirstPolicy/1/MorningBoozeCheck.mvel" +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/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json deleted file mode 100644 index 7318a4393..000000000 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.alt.json +++ /dev/null @@ -1,974 +0,0 @@ -{ - "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_Albums", - "version" : "0.0.1" - }, - "value" : { - "key" : { - "name" : "MyFirstPolicyModel_Albums", - "version" : "0.0.1" - }, - "UUID" : "3f70ec50-f896-31ba-afec-5fd47e69045b", - "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Albums:0.0.1\"" - } - }, { - "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" : "JAVASCRIPT", - "logic" : "/**============LICENSE_START=======================================================*Copyright(C)2016-2018Ericsson.Allrightsreserved.*ModificationsCopyright(C)2020NordixFoundation.*================================================================================*LicensedundertheApacheLicense,Version2.0(the\"License\");*youmaynotusethisfileexceptincompliancewiththeLicense.*YoumayobtainacopyoftheLicenseat**http://www.apache.org/licenses/LICENSE-2.0**Unlessrequiredbyapplicablelaworagreedtoinwriting,software*distributedundertheLicenseisdistributedonan\"ASIS\"BASIS,*WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.*SeetheLicenseforthespecificlanguagegoverningpermissionsand*limitationsundertheLicense.**SPDX-License-Identifier:Apache-2.0*============LICENSE_END=========================================================*/\nvar returnValueType = Java.type(\"java.lang.Boolean\");\nvar returnValue = new returnValueType(true);\n\n// Load compatibility script for imports etc\nload(\"nashorn:mozilla_compat.js\");\nimportPackage(java.text);\nimportClass(java.text.SimpleDateFormat);\n\nexecutor.logger.info(\"Task Execution: '\"+executor.subject.id+\"'. Input Fields: '\"+executor.inFields+\"'\");\n\nexecutor.outFields.put(\"amount\" , executor.inFields.get(\"amount\"));\nexecutor.outFields.put(\"assistant_ID\", executor.inFields.get(\"assistant_ID\"));\nexecutor.outFields.put(\"notes\" , executor.inFields.get(\"notes\"));\nexecutor.outFields.put(\"quantity\" , executor.inFields.get(\"quantity\"));\nexecutor.outFields.put(\"branch_ID\" , executor.inFields.get(\"branch_ID\"));\nexecutor.outFields.put(\"item_ID\" , executor.inFields.get(\"item_ID\"));\nexecutor.outFields.put(\"time\" , executor.inFields.get(\"time\"));\nexecutor.outFields.put(\"sale_ID\" , executor.inFields.get(\"sale_ID\"));\n\nitem_id = executor.inFields.get(\"item_ID\");\n\n//All times in this script are in GMT/UTC since the policy and events assume time is in GMT.\nvar timenow_gmt = new Date(Number(executor.inFields.get(\"time\")));\n\nvar midnight_gmt = new Date(Number(executor.inFields.get(\"time\")));\nmidnight_gmt.setUTCHours(0,0,0,0);\n\nvar eleven30_gmt = new Date(Number(executor.inFields.get(\"time\")));\neleven30_gmt.setUTCHours(11,30,0,0);\n\nvar timeformatter = new java.text.SimpleDateFormat(\"HH:mm:ss z\");\n\nvar itemisalcohol = false;\nif(item_id != null && item_id >=1000 && item_id < 2000)\n itemisalcohol = true;\n\nif( itemisalcohol\n && timenow_gmt.getTime() >= midnight_gmt.getTime()\n && timenow_gmt.getTime() < eleven30_gmt.getTime()) {\n\n executor.outFields.put(\"authorised\", false);\n executor.outFields.put(\"message\", \"Sale not authorised by policy task \" +\n executor.subject.taskName+ \" for time \" + timeformatter.format(timenow_gmt.getTime()) +\n \". Alcohol can not be sold between \" + timeformatter.format(midnight_gmt.getTime()) +\n \" and \" + timeformatter.format(eleven30_gmt.getTime()));\n}\nelse{\n executor.outFields.put(\"authorised\", true);\n executor.outFields.put(\"message\", \"Sale authorised by policy task \" + \n executor.subject.taskName + \" for time \"+timeformatter.format(timenow_gmt.getTime()));\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 - } - } ] - } - } - } ] - } - }, - "albums" : { - "key" : { - "name" : "MyFirstPolicyModel_Albums", - "version" : "0.0.1" - }, - "albums" : { - "entry" : [ ] - } - }, - "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/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex deleted file mode 100644 index 2c2d7ffd7..000000000 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex +++ /dev/null @@ -1,180 +0,0 @@ -#------------------------------------------------------------------------------- -# ============LICENSE_START======================================================= -# Copyright (C) 2016-2018 Ericsson. All rights reserved. -# Modifications Copyright (C) 2020 Nordix Foundation. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 -# ============LICENSE_END========================================================= -#------------------------------------------------------------------------------- - -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) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -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/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json deleted file mode 100644 index 85a60f0e5..000000000 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.json +++ /dev/null @@ -1,974 +0,0 @@ -{ - "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_Albums", - "version" : "0.0.1" - }, - "value" : { - "key" : { - "name" : "MyFirstPolicyModel_Albums", - "version" : "0.0.1" - }, - "UUID" : "3f70ec50-f896-31ba-afec-5fd47e69045b", - "description" : "Generated description for concept referred to by key \"MyFirstPolicyModel_Albums:0.0.1\"" - } - }, { - "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) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\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 - } - } ] - } - } - } ] - } - }, - "albums" : { - "key" : { - "name" : "MyFirstPolicyModel_Albums", - "version" : "0.0.1" - }, - "albums" : { - "entry" : [ ] - } - }, - "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/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex index e512a1341..6f2658810 100644 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex +++ b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.apex @@ -65,87 +65,7 @@ task outputfield create name=MorningBoozeCheck version=0.0.1 fieldName=authorise 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) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -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 :-) -*/ +#MACROFILE:"src/main/resources/examples/models/MyFirstPolicy/2/MorningBoozeCheck.mvel" LE task create name=MorningBoozeCheckAlt1 version=0.0.1 uuid=bc6d90c9-c902-4686-afd3-925b30e39990 description=LS @@ -173,89 +93,7 @@ task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=autho task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=time schemaName=timestamp_type schemaVersion=0.0.1 task outputfield create name=MorningBoozeCheckAlt1 version=0.0.1 fieldName=message schemaName=message_type schemaVersion=0.0.1 optional=true task logic create name=MorningBoozeCheckAlt1 version=0.0.1 logicFlavour=MVEL logic=LS -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -import java.util.Date; -import java.util.Calendar; -import java.util.TimeZone; -import java.text.SimpleDateFormat; - -logger.info("Task Execution: '"+subject.id+"'. Input Event: '"+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 CET timezone! -cet = TimeZone.getTimeZone("CET"); -timenow = Calendar.getInstance(cet); -df = new SimpleDateFormat("HH:mm:ss z"); -df.setTimeZone(cet); -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); -onepm = timenow.clone(); -onepm.set( - timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH), - timenow.get(Calendar.DATE),13,0,0); - -itemisalcohol = false; -if(item_id != null && item_id >=1000 && item_id < 2000) - itemisalcohol = true; - -if( itemisalcohol && - ( (timenow.after(midnight) && timenow.before(onepm)) - || - (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) - )){ - 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(onepm.getTime()) +" or on Sunday"); - 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 CET and 13:00:00 CET then the sale is not authorised. -Also alcohol sales are not allowed on Sundays. Otherwise the sale is authorised. -In this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks :-) -*/ +#MACROFILE:"src/main/resources/examples/models/MyFirstPolicy/2/MorningBoozeCheckAlt1.mvel" 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" @@ -280,59 +118,11 @@ event parameter create name=SALE_INPUT version=0.0.1 parName=quantity schemaName 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=MorningBoozeCheckAlt1 taskName=MorningBoozeCheckAlt1 taskVersion=0.0.1 outputType=DIRECT outputName=MorningBoozeCheck_Output_Direct 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 policy state selecttasklogic create name=MyFirstPolicy version=0.0.1 stateName=BoozeAuthDecide logicFlavour=JAVASCRIPT logic=LS -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -var returnValue = true; - -executor.logger.info("Task Selection Execution: '"+executor.subject.id+"'. Input Event: '"+executor.inFields+"'"); - -branchid = executor.inFields.get("branch_ID"); -taskorig = executor.subject.getTaskKey("MorningBoozeCheck"); -taskalt = executor.subject.getTaskKey("MorningBoozeCheckAlt1"); -taskdef = executor.subject.getDefaultTaskKey(); - -if(branchid >=0 && branchid <1000){ - taskorig.copyTo(executor.selectedTask); -} -else if (branchid >=1000 && branchid <2000){ - taskalt.copyTo(executor.selectedTask); -} -else{ - taskdef.copyTo(executor.selectedTask); -} - -/* -This task selection logic selects task "MorningBoozeCheck" for branches with 0<=branch_ID<1000 and selects task "MorningBoozeCheckAlt1" for branches with 1000<=branch_ID<2000. Otherwise the default task is selected. In this case the default task is also "MorningBoozeCheck" -*/ - -returnValue; +#MACROFILE:"src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicy_BoozeAuthDecideTSL.js" LE - - - diff --git a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json deleted file mode 100644 index 2ac91e4e2..000000000 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json +++ /dev/null @@ -1,1191 +0,0 @@ -{ - "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" : "MorningBoozeCheckAlt1", - "version" : "0.0.1" - }, - "value" : { - "key" : { - "name" : "MorningBoozeCheckAlt1", - "version" : "0.0.1" - }, - "UUID" : "bc6d90c9-c902-4686-afd3-925b30e39990", - "description" : "This task checks if a sale request is for an item that is an alcoholic drink.\nIf the local time is between 00:00:00 CET and 13:00:00 CET then the sale is not authorised.\nAlso alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID between 1000 and 2000 are all alcoholic drinks" - } - }, { - "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" : "TaskSelectionLogic", - "logicFlavour" : "JAVASCRIPT", - "logic" : "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nvar returnValue = true;\n\nexecutor.logger.info(\"Task Selection Execution: '\"+executor.subject.id+\"'. Input Event: '\"+executor.inFields+\"'\");\n\nbranchid = executor.inFields.get(\"branch_ID\");\ntaskorig = executor.subject.getTaskKey(\"MorningBoozeCheck\");\ntaskalt = executor.subject.getTaskKey(\"MorningBoozeCheckAlt1\");\ntaskdef = executor.subject.getDefaultTaskKey();\n\nif(branchid >=0 && branchid <1000){\n taskorig.copyTo(executor.selectedTask);\n}\nelse if (branchid >=1000 && branchid <2000){\n taskalt.copyTo(executor.selectedTask);\n}\nelse{\n taskdef.copyTo(executor.selectedTask);\n}\n\n/*\nThis task selection logic selects task \"MorningBoozeCheck\" for branches with 0<=branch_ID<1000 and selects task \"MorningBoozeCheckAlt1\" for branches with 1000<=branch_ID<2000. Otherwise the default task is selected. In this case the default task is also \"MorningBoozeCheck\"\n*/\n\nreturnValue;" - }, - "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" - } - } - }, { - "key" : { - "name" : "MorningBoozeCheckAlt1", - "version" : "0.0.1" - }, - "value" : { - "key" : { - "parentKeyName" : "MyFirstPolicy", - "parentKeyVersion" : "0.0.1", - "parentLocalName" : "BoozeAuthDecide", - "localName" : "MorningBoozeCheckAlt1" - }, - "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) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\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*/" - } - } - }, { - "key" : { - "name" : "MorningBoozeCheckAlt1", - "version" : "0.0.1" - }, - "value" : { - "key" : { - "name" : "MorningBoozeCheckAlt1", - "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) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\nimport java.util.Date;\nimport java.util.Calendar;\nimport java.util.TimeZone;\nimport java.text.SimpleDateFormat;\n\nlogger.info(\"Task Execution: '\"+subject.id+\"'. Input Event: '\"+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 CET timezone!\ncet = TimeZone.getTimeZone(\"CET\");\ntimenow = Calendar.getInstance(cet);\ndf = new SimpleDateFormat(\"HH:mm:ss z\");\ndf.setTimeZone(cet);\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);\nonepm = timenow.clone();\nonepm.set(\n timenow.get(Calendar.YEAR),timenow.get(Calendar.MONTH),\n timenow.get(Calendar.DATE),13,0,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(onepm))\n ||\n (timenow.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)\n )){\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(onepm.getTime()) +\" or on Sunday\");\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 CET and 13:00:00 CET then the sale is not authorised.\nAlso alcohol sales are not allowed on Sundays. Otherwise the sale is authorised.\nIn this implementation we assume that items with item_ID between 1000 and 2000 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/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicy_BoozeAuthDecideTSL.js b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicy_BoozeAuthDecideTSL.js index ac7464d98..18a72c1b8 100644 --- a/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicy_BoozeAuthDecideTSL.js +++ b/examples/examples-myfirstpolicy/src/main/resources/examples/models/MyFirstPolicy/2/MyFirstPolicy_BoozeAuthDecideTSL.js @@ -19,8 +19,6 @@ * ============LICENSE_END========================================================= */ -var returnValue = true; - executor.logger.info("Task Selection Execution: '"+executor.subject.id+ "'. Input Event: '"+executor.inFields+"'"); @@ -46,4 +44,4 @@ This task selection logic selects task "MorningBoozeCheck" for branches with In this case the default task is also "MorningBoozeCheck" */ -returnValue; +true; diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java new file mode 100644 index 000000000..65dad94c4 --- /dev/null +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.examples.myfirstpolicy; + +import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.common.utils.resources.ResourceUtils; + +/** + * A factory for creating MFPDomainModel objects. + * + * @author John Keeney (john.keeney@ericsson.com) + */ +public class MfpDomainModelFactory { + + private static final String MFP1PATH = + "target/classes/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.json"; + private static final String MFP1_ALT_PATH = + "target/classes/examples/models/MyFirstPolicy/1/MyFirstPolicyModelJavascript_0.0.1.json"; + private static final String MFP2PATH = + "target/classes/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json"; + + /** + * Gets the MyFirstPolicy#1 policy model. + * + * @return the MyFirstPolicy#1 policy model + */ + public AxPolicyModel getMfp1PolicyModel() { + java.util.TimeZone.getTimeZone("gmt"); + try { + final ApexModelReader reader = new ApexModelReader<>(AxPolicyModel.class); + return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP1PATH)); + } catch (final Exception e) { + throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MfpDomainModelFactory.MFP1PATH, + e); + } + } + + /** + * Gets the MyFirstPolicy#1 policy model, with alternate JavaScript task logic. + * + * @return the MyFirstPolicy#1 policy model + */ + public AxPolicyModel getMfp1AltPolicyModel() { + java.util.TimeZone.getTimeZone("gmt"); + try { + final ApexModelReader reader = new ApexModelReader<>(AxPolicyModel.class); + return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP1_ALT_PATH)); + } catch (final Exception e) { + throw new ApexRuntimeException( + "Failed to build MyFirstPolicy_ALT from path: " + MfpDomainModelFactory.MFP1_ALT_PATH, e); + } + } + + /** + * Gets the MyFirstPolicy#1 policy model. + * + * @return the MyFirstPolicy#1 policy model + */ + public AxPolicyModel getMfp2PolicyModel() { + try { + final ApexModelReader reader = new ApexModelReader<>(AxPolicyModel.class); + return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP2PATH)); + } catch (final Exception e) { + throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MfpDomainModelFactory.MFP2PATH, + e); + } + } + +} diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java index 3ebf8155e..c470e9356 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java @@ -31,7 +31,6 @@ import java.util.Map.Entry; import org.junit.BeforeClass; import org.junit.Test; -import org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java index af0e44450..90859794e 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java @@ -68,7 +68,7 @@ public class MfpModelCliTest { // @formatter:off final String[] testApexModel1CliArgs = { "-c", - "src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex", + "src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex", "-l", tempLogFile1.getAbsolutePath(), "-o", diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java index 0d6192988..fb4103c99 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,6 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineImpl; import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; @@ -169,6 +168,60 @@ public class MfpUseCaseTest { apexEngine.stop(); } + /** + * Test MyFirstPolicy#1 use case. + * + * @throws ApexException if there is an Apex error + * @throws InterruptedException if there is an Interruption. + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testMfp1AltCase() throws ApexException, InterruptedException, IOException { + final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1AltPolicyModel(); + assertNotNull(apexPolicyModel); + + final TestSaleAuthListener listener = new TestSaleAuthListener("Test"); + apexEngine.addEventListener("listener", listener); + apexEngine.updateModel(apexPolicyModel, false); + apexEngine.start(); + + final AxEvent axEventin = apexPolicyModel.getEvents().get(new AxArtifactKey("SALE_INPUT:0.0.1")); + assertNotNull(axEventin); + final AxEvent axEventout = apexPolicyModel.getEvents().get(new AxArtifactKey("SALE_AUTH:0.0.1")); + assertNotNull(axEventout); + + EnEvent event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_084106GMT.json"); + apexEngine.handleEvent(event); + EnEvent resultout = listener.getResult(); + EnEvent resulexpected = + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); + resultout.put("message", ""); + resulexpected.put("message", ""); + assertEquals(resulexpected, resultout); + + event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_201713GMT.json"); + apexEngine.handleEvent(event); + resultout = listener.getResult(); + resulexpected = + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json"); + resultout.put("message", ""); + resulexpected.put("message", ""); + assertEquals(resulexpected, resultout); + assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + + event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_NonBoozeItem_101309GMT.json"); + apexEngine.handleEvent(event); + resultout = listener.getResult(); + resulexpected = + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json"); + resultout.put("message", ""); + resulexpected.put("message", ""); + assertEquals(resulexpected, resultout); + assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + + apexEngine.stop(); + } + /** * Test MyFirstPolicy#2 use case. * diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java index 540d1e341..24f85833a 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,6 @@ package org.onap.policy.apex.examples.myfirstpolicy; -import org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelFactory; import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java index 0169d14cb..44c4306b9 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java @@ -21,6 +21,8 @@ package org.onap.policy.apex.examples.myfirstpolicy; +import static org.awaitility.Awaitility.await; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -28,8 +30,6 @@ import java.util.concurrent.TimeUnit; import org.onap.policy.apex.core.engine.engine.EnEventListener; import org.onap.policy.apex.core.engine.event.EnEvent; -import static org.awaitility.Awaitility.await; - /** * The listener interface for receiving SaleAuth events. The class that is interested in processing a SaleAuth event * implements this interface, and the object created with that class is registered with a component using the diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js index a4be3707f..9ad41b59e 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); -importClass(org.apache.avro.Schema); -importClass(java.io.BufferedReader); -importClass(java.io.IOException); -importClass(java.nio.file.Files); -importClass(java.nio.file.Paths); executor.logger.info("Begin Execution AAIServiceAssignedTask.js"); executor.logger.info(executor.subject.id); @@ -39,7 +33,7 @@ executor.logger.info(NomadicONTContext); var jsonObj; var aaiUpdateResult = true; -var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var wbClient = org.onap.policy.apex.examples.bbs.WebClient; var client = new wbClient(); /* Get AAI URL from Configuration file. */ @@ -234,7 +228,7 @@ try { } /* If Success then Fill output schema */ -if (aaiUpdateResult === true) { +if (aaiUpdateResult == true) { executor.outFields.put("result", "SUCCESS"); NomadicONTContext.put("result", "SUCCESS"); NomadicONTContext.put("aai_message", JSON.stringify(service_instance)); @@ -248,10 +242,11 @@ executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); -var returnValue = executor.isTrue; executor.logger.info(executor.outFields); executor.logger.info("End Execution AAIServiceAssignedTask.js"); +true; + /* Utility functions Begin */ function IsValidJSONString(str) { try { diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js index a7809bf1b..4205342e1 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); -importClass(org.apache.avro.Schema); -importClass(java.io.BufferedReader); -importClass(java.io.IOException); -importClass(java.nio.file.Files); -importClass(java.nio.file.Paths); executor.logger.info("Begin Execution AAIServiceCreateTask.js"); executor.logger.info(executor.subject.id); @@ -43,7 +37,7 @@ var BBS_CFS_SERVICE_TYPE = "BBS-CFS-Access_Test"; var SERVICE_INSTANCE_ID = serviceInstanceId; var AAI_VERSION = "v14"; var HTTP_PROTOCOL = "https://"; -var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var wbClient = org.onap.policy.apex.examples.bbs.WebClient; var client = new wbClient(); var AAI_USERNAME = null; var AAI_PASSWORD = null; @@ -122,7 +116,7 @@ try { aaiUpdateResult = false; } /* If Success then Fill output schema */ -if (aaiUpdateResult === true) { +if (aaiUpdateResult == true) { NomadicONTContext.put("result", "SUCCESS"); } else { NomadicONTContext.put("result", "FAILURE"); @@ -133,6 +127,8 @@ executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); -var returnValue = executor.isTrue; executor.logger.info(executor.outFields); executor.logger.info("End Execution AAIServiceCreateTask.js"); + +true; + diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js index 91316bc40..a9d7f31a4 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,5 +24,6 @@ executor.logger.info(executor.inFields); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; executor.logger.info("Begin Execution ErrorServiceUpdateOneLogTask.js"); + +true; diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js index 946d956b1..3fbb0dfbe 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,5 +22,6 @@ executor.logger.info("Begin Execution ErrorResourceUpdateLogTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; executor.logger.info("End Execution ErrorResourceUpdateLogTask.js"); + +true; diff --git a/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js b/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js index 57fe182e1..da0a955b1 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,15 +18,13 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); executor.logger.info("Begin Execution GetBBSCloseLoopEventTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; +var returnValue = true; -var clEventType = Java.type( - "org.onap.policy.controlloop.VirtualControlLoopEvent"); +var clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent; var clEvent = executor.inFields.get("VirtualControlLoopEvent"); executor.logger.info(clEvent.toString()); executor.logger.info(clEvent.getClosedLoopControlName()); @@ -107,6 +106,8 @@ if (clEvent.getAai().get("attachmentPoint") != null) { else { executor.message = "Received NULL attachment-point"; - returnValue = executor.isFalse; + returnValue = false; } +returnValue; + diff --git a/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js b/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js index 36b21b8f4..17234101e 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,8 +18,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); -importClass(org.apache.avro.Schema); executor.logger.info("Begin Execution NomadicEventSuccess.js"); executor.logger.info(executor.subject.id); @@ -32,16 +31,17 @@ executor.logger.info(executor.outFields); executor.logger.info(executor.inFields); result = NomadicONTContext.get("result"); +var returnValue = true; -if (result === "SUCCESS") { - returnValue = executor.isTrue; +if (result == "SUCCESS") { executor.outFields.put("result", "SUCCCESS"); executor.logger.info("BBS policy Execution Done"); } else { executor.logger.info("BBS policy Execution Failed"); executor.outFields.put("result", "FAILURE"); - returnValue = executor.isFalse; + returnValue = false; } -var returnValue = executor.isTrue; -executor.logger.info("End Execution NomadicEventSuccess.js"); \ No newline at end of file +executor.logger.info("End Execution NomadicEventSuccess.js"); + +returnValue; diff --git a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js index 810903a28..04a36cd28 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +22,6 @@ executor.logger.info("Begin Execution RUorInitStateSelect.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; var result = null; var attachmentPoint = executor.inFields.get("attachmentPoint"); @@ -30,7 +30,7 @@ var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( result = NomadicONTContext.get("result"); -if (result === "SUCCESS") { +if (result == "SUCCESS") { executor.subject.getTaskKey("SdncResourceUpdateTask").copyTo(executor.selectedTask); } else { executor.subject.getTaskKey("ErrorAAIServiceAssignedLogTask").copyTo( @@ -39,4 +39,6 @@ if (result === "SUCCESS") { } executor.logger.info("State Selected Task:" + executor.selectedTask); -executor.logger.info("End Execution RUorInitStateSelect.js"); \ No newline at end of file +executor.logger.info("End Execution RUorInitStateSelect.js"); + +true; diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js index 3abd75071..eafbe923c 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +22,6 @@ executor.logger.info("Begin Execution SU2orInitStateSelect.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; var result = null; var attachmentPoint = executor.inFields.get("attachmentPoint"); @@ -32,7 +32,7 @@ executor.logger.info(executor.inFields); result = NomadicONTContext.get("result"); -if (result === "SUCCESS") { +if (result == "SUCCESS") { executor.subject.getTaskKey("AAIServiceCreateTask").copyTo(executor.selectedTask); } else { executor.subject.getTaskKey("SdncResourceUpdateErrorLogOutput").copyTo( @@ -41,4 +41,6 @@ if (result === "SUCCESS") { } executor.logger.info("State Selected Task:" + executor.selectedTask); -executor.logger.info("End Execution SU2orInitStateSelect.js"); \ No newline at end of file +executor.logger.info("End Execution SU2orInitStateSelect.js"); + +true; diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js index 02fc05839..d3575a7bb 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +18,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); -importClass(org.apache.avro.Schema); -importClass(java.io.BufferedReader); -importClass(java.io.IOException); -importClass(java.nio.file.Files); -importClass(java.nio.file.Paths); - -importPackage(org.json.XML); executor.logger.info("Begin Execution SdncResourceUpdateTask.js"); executor.logger.info(executor.subject.id); @@ -33,9 +26,9 @@ executor.logger.info(executor.inFields); var attachmentPoint = executor.inFields.get("attachmentPoint"); var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); -var uuidType = Java.type("java.util.UUID"); +var uuidType = java.util.UUID; -var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var wbClient = org.onap.policy.apex.examples.bbs.WebClient; var client = new wbClient(); var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(attachmentPoint); @@ -276,7 +269,7 @@ try { /* If Success then Fill output schema */ -if (sdncUpdateResult === true) { +if (sdncUpdateResult == true) { NomadicONTContext.put("result", "SUCCESS"); executor.outFields.put("result", "SUCCESS"); } else { @@ -288,10 +281,11 @@ executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); -var returnValue = executor.isTrue; executor.logger.info(executor.outFields); executor.logger.info("End Execution SdncResourceUpdateTask.js"); +true; + function getMetaValue(metaJson, metaname) { for (var i = 0; i < metaJson.length; i++) { if (metaJson[i]['metaname'] == metaname) { diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js index 871e146a7..73e45fd7f 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,17 +18,12 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); -importClass(java.io.BufferedReader); -importClass(java.io.IOException); -importClass(java.nio.file.Files); -importClass(java.nio.file.Paths); executor.logger.info("Begin Execution ServiceUpdateStateCpeAuthTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent"); +var clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent; var clEvent = executor.inFields.get("VirtualControlLoopEvent"); var serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id"); @@ -36,7 +31,7 @@ var requestID = clEvent.getRequestId(); var jsonObj; var aaiUpdateResult = true; -var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var wbClient = org.onap.policy.apex.examples.bbs.WebClient; var client = new wbClient(); var oldState = clEvent.getAai().get("cpe.old-authentication-state"); var newState = clEvent.getAai().get("cpe.new-authentication-state"); @@ -132,5 +127,6 @@ if (aaiUpdateResult == true) { } executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js"); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-customer.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-customer.js index cefb7a97c..d62bed609 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-customer.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-customer.js @@ -1,25 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); - var logger = executor.logger; logger.trace("start: " + executor.subject.id); logger.trace("-- infields: " + executor.inFields); @@ -74,7 +73,7 @@ executor.outFields["report"] = "customer ctxt :: added customer: " + ifCustomerN logger.info("vpnsla: ctxt added customer " + ifCustomerName); -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); logger.trace("finished: " + executor.subject.id); logger.debug("."); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-edges.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-edges.js index dd667a87d..1e9d6be71 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-edges.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-edges.js @@ -1,25 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); - var logger = executor.logger; logger.trace("start: " + executor.subject.id); logger.trace("-- infields: " + executor.inFields); @@ -59,7 +58,7 @@ executor.outFields["report"] = "edge ctxt :: added edge " + ifEdgeName; logger.info("vpnsla: ctxt added edge " + ifEdgeName); -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); logger.trace("finished: " + executor.subject.id); logger.debug("."); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-nodes.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-nodes.js index 532820f15..bc360f280 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-nodes.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/ctxt-nodes.js @@ -1,25 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); - var logger = executor.logger; logger.trace("start: " + executor.subject.id); logger.trace("-- infields: " + executor.inFields); @@ -57,7 +56,7 @@ executor.outFields["report"] = "node ctxt :: added node " + ifNodeName; logger.info("vpnsla: ctxt added node " + ifNodeName); -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); logger.trace("finished: " + executor.subject.id); logger.debug("."); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-act.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-act.js index df96235d3..6ab792693 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-act.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-act.js @@ -1,25 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); - var logger = executor.logger; logger.trace("start: " + executor.subject.id); logger.trace("-- infields: " + executor.inFields); @@ -52,9 +51,6 @@ default: } -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); - if (executor.outFields["action"] != "") { logger.info("vpnsla: action is to " + executor.outFields["action"] + " " + executor.outFields["edgeName"]); } else { @@ -67,3 +63,5 @@ logger.debug(".a"); var now = new Date().getTime(); logger.info("VPN SLA finished in " + (now - ifMatchStart) + " ms"); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-none.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-none.js index ad6a51027..9471b02d0 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-none.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-none.js @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); importClass(org.slf4j.LoggerFactory); importClass(java.util.ArrayList); @@ -41,18 +41,19 @@ decision.put("description", "None, everything is ok"); decision.put("decision", "NONE"); decision.put("customers", new ArrayList()); -var returnValueType = Java.type("java.lang.Boolean"); +var returnValue = true; if (ifSituation.get("problemID") == "NONE") { logger.trace("-- no problem, everything ok"); - var returnValue = new returnValueType(true); } else { logger.trace("-- wrong problemID <" + problemID + "> for NONE task, we should not be here"); rootLogger.error(executor.subject.id + " " + "-- wrong problemID <" + problemID + "> for NONE task, we should not be here"); - var returnValue = new returnValueType(false); + returnValue = false; } executor.outFields["decision"] = decision; logger.trace("finished: " + executor.subject.id); logger.debug(".d-non"); + +returnValue; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-priority.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-priority.js index 5f2e3be92..2afedfd0c 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-priority.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-priority.js @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); importClass(org.slf4j.LoggerFactory); importClass(java.util.ArrayList); @@ -46,7 +46,7 @@ decision.put("problemID", ifSituation.get("problemID")); decision.put("customers", new ArrayList()); var problem = albumProblemMap.get(ifSituation.get("problemID")); -var returnValueType = Java.type("java.lang.Boolean"); +var returnValue = true; if (problem != null && ifSituation.get("violatedSLAs").size() > 0) { logger.trace("-- impede by priority"); for (var i = 0; i < problem.get("edgeUsedBy").size(); i++) { @@ -55,12 +55,11 @@ if (problem != null && ifSituation.get("violatedSLAs").size() > 0) { decision.get("customers").add(customerCtxt.get("customerName")); } } - var returnValue = new returnValueType(true); } else { logger.trace("-- wrong problemID <" + ifSituation.get("problemID") + "> for PRIORITY task, we should not be here"); rootLogger.error(executor.subject.id + " " + "-- wrong problemID <" + ifSituation.get("problemID") + "> for PRIORITY task, we should not be here"); - var returnValue = new returnValueType(false); + returnValue = false; } // set impededLast to decision[customers] @@ -74,3 +73,5 @@ logger.info("vpnsla: priority, impeding customers " + decision.get("customers")) logger.trace("finished: " + executor.subject.id); logger.debug(".d-pri"); + +returnValue; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-sla.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-sla.js index bd09a747b..a65814fbd 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-sla.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-sla.js @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); importClass(org.slf4j.LoggerFactory); importClass(java.util.ArrayList); @@ -46,7 +46,7 @@ decision.put("problemID", ifSituation.get("problemID")); decision.put("customers", new ArrayList()); var problem = albumProblemMap.get(ifSituation.get("problemID")); -var returnValueType = Java.type("java.lang.Boolean"); +var returnValue = true; if (problem != null && ifSituation.get("violatedSLAs").size() == 0) { logger.trace("-- impede by maximum SLA"); var customer = ""; @@ -62,12 +62,11 @@ if (problem != null && ifSituation.get("violatedSLAs").size() == 0) { } } decision.get("customers").add(customer); - var returnValue = new returnValueType(true); } else { logger.trace("-- wrong problemID <" + ifSituation.get("problemID") + "> for SLA task, we should not be here"); rootLogger.error(executor.subject.id + " " + "-- wrong problemID <" + ifSituation.get("problemID") + "> for SLA task, we should not be here"); - var returnValue = new returnValueType(false); + returnValue = false; } // set impededLast to decision[customers] @@ -81,3 +80,5 @@ logger.info("vpnsla: sla balance, impeding customers " + decision.get("customers logger.trace("finished: " + executor.subject.id); logger.debug(".d-sla"); + +returnValue; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-solved.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-solved.js index 78bc94f00..6306ee06b 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-solved.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-decide-solved.js @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); importClass(org.slf4j.LoggerFactory); importClass(java.util.ArrayList); @@ -44,15 +44,14 @@ decision.put("decision", "REBUILD"); decision.put("customers", new ArrayList()); decision.put("problemID", ifSituation.get("problemID")); -var returnValueType = Java.type("java.lang.Boolean"); +var returnValue = true; if (albumProblemMap.get(ifSituation.get("problemID")).get("status") == "SOLVED") { logger.trace("-- problem solved"); - var returnValue = new returnValueType(true); } else { logger.trace("-- wrong problemID <" + problemID + "> for SOLVED task, we should not be here"); rootLogger.error(executor.subject.id + " " + "-- wrong problemID <" + problemID + "> for SOLVED task, we should not be here"); - var returnValue = new returnValueType(false); + returnValue = false; } executor.outFields["decision"] = decision; @@ -61,3 +60,5 @@ logger.info("vpnsla: sla solved, problem solved"); logger.trace("finished: " + executor.subject.id); logger.debug(".d-non"); + +returnValue; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-establish.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-establish.js index 48d69e8eb..95a922052 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-establish.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-establish.js @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); importClass(org.slf4j.LoggerFactory); importClass(java.util.ArrayList); @@ -164,7 +164,7 @@ executor.outFields["situation"] = situation; logger.trace("-- out fields <" + executor.outFields + ">"); -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); logger.trace("finished: " + executor.subject.id); logger.debug(".e"); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-match.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-match.js index c50dd9794..87e5bc377 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-match.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/task-match.js @@ -1,25 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); - var now = new Date().getTime(); executor.outFields["matchStart"] = now; @@ -74,7 +73,7 @@ executor.outFields["status"] = ifLinkStatus; logger.info("vpnsla: detected " + ifEdgeName + " as " + ifLinkStatus); -var returnValueType = Java.type("java.lang.Boolean"); -var returnValue = new returnValueType(true); logger.trace("finished: " + executor.subject.id); logger.debug(".m"); + +true; diff --git a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/tsl-decide.js b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/tsl-decide.js index 44767467d..9d4399f27 100644 --- a/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/tsl-decide.js +++ b/examples/examples-pcvs/src/main/resources/org/onap/policy/apex/examples/pcvs/vpnsla/logic/tsl-decide.js @@ -1,24 +1,24 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -load("nashorn:mozilla_compat.js"); importClass(org.slf4j.LoggerFactory); var logger = executor.logger; @@ -30,29 +30,27 @@ var ifSituation = executor.inFields["situation"]; var albumProblemMap = executor.getContextAlbum("albumProblemMap"); -var returnValueType = Java.type("java.lang.Boolean"); +var returnValue = true; if (ifSituation.get("problemID") == "NONE") { logger.trace("-- situation has no problem, selecting "); executor.subject.getTaskKey("VpnSlaPolicyDecideNoneTask").copyTo(executor.selectedTask); - var returnValue = new returnValueType(true); } else if (albumProblemMap.get(ifSituation.get("problemID")).get("status") == "SOLVED") { logger.trace("-- situation is solved, selecting "); executor.subject.getTaskKey("VpnSlaPolicyDecideSolvedTask").copyTo(executor.selectedTask); - var returnValue = new returnValueType(true); } else if (ifSituation.get("violatedSLAs") != null && ifSituation.get("violatedSLAs").size() > 0) { logger.trace("-- situation is problem with violations, selecting "); executor.subject.getTaskKey("VpnSlaPolicyDecidePriorityTask").copyTo(executor.selectedTask); - var returnValue = new returnValueType(true); } else if (ifSituation.get("violatedSLAs") != null && ifSituation.get("violatedSLAs").size() == 0) { logger.trace("-- situation is problem without violations, selecting "); executor.subject.getTaskKey("VpnSlaPolicyDecideSlaTask").copyTo(executor.selectedTask); - var returnValue = new returnValueType(true); } else { logger.error("-- detected unknown decision for situation <" + ifSituation.get("problemID") + ">"); rootLogger.error(executor.subject.id + " " + "-- detected unknown decision for situation <" + ifSituation.get("problemID") + ">"); - var returnValue = new returnValueType(false); + returnValue = false; } logger.trace("finished: " + executor.subject.id); logger.debug(".d-tsl"); + +returnValue; diff --git a/examples/examples-periodic/src/main/resources/logic/OutputTask.js b/examples/examples-periodic/src/main/resources/logic/OutputTask.js index 5e8b5b774..b2bfc3545 100644 --- a/examples/examples-periodic/src/main/resources/logic/OutputTask.js +++ b/examples/examples-periodic/src/main/resources/logic/OutputTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,4 +24,4 @@ executor.logger.info(executor.inFields); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; \ No newline at end of file +true; \ No newline at end of file diff --git a/examples/examples-periodic/src/main/resources/logic/PeriodicTask.js b/examples/examples-periodic/src/main/resources/logic/PeriodicTask.js index bdd432086..90f1a46b4 100644 --- a/examples/examples-periodic/src/main/resources/logic/PeriodicTask.js +++ b/examples/examples-periodic/src/main/resources/logic/PeriodicTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,7 +24,7 @@ executor.logger.info(executor.inFields); var eventList = executor.subject.getOutFieldSchemaHelper("EventList").createNewInstance(); -var eventType = Java.type("org.onap.policy.apex.service.engine.event.ApexEvent"); +var eventType = org.onap.policy.apex.service.engine.event.ApexEvent; for (i = 0; i < 5; i++) { var event = new eventType("InputEvent", "0.0.1", "org.onap.policy.apex.periodic", "APEX", "APEX"); @@ -41,4 +42,4 @@ executor.outFields.put("EventList", eventList); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; \ No newline at end of file +true; \ No newline at end of file diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js index d5427582a..d428bff10 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js @@ -32,4 +32,4 @@ executor.outFields.put("intPar", intParBy2); executor.logger.info("outgoing value: " + executor.outFields.get("intPar").toString()); -executor.isTrue; \ No newline at end of file +true; \ No newline at end of file diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js index 0c15249d2..2f637338f 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js @@ -18,6 +18,5 @@ * ============LICENSE_END========================================================= */ var x = 1; -var returnValue = true; -returnValue; \ No newline at end of file +true; \ No newline at end of file diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java index 5f3e57688..606cb6874 100644 --- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java +++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java @@ -121,7 +121,7 @@ public class Model2CliTest { @Test public void testModel2CliMfp() { - testModel2CliModel("target/examples/models/MyFirstPolicy/2", "MyFirstPolicyModel"); + testModel2CliModel("target/examples/models/MyFirstPolicy/2", "MyFirstPolicyModel_0.0.1"); } @Test -- cgit 1.2.3-korg