2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.engine.executor.context;
23 import java.util.Properties;
26 import org.onap.policy.apex.context.SchemaHelper;
27 import org.onap.policy.common.utils.coder.CoderException;
28 import org.onap.policy.common.utils.coder.StandardCoder;
31 * Abstract class for the execution context for logic executions in logic being executed in an Apex engine. The
32 * logic must have easy access to its subject definition, the incoming and outgoing field contexts, as well as the
33 * policy, global, and external context.
36 public class AbstractExecutionContext {
37 /** A constant <code>boolean true</code> value available for reuse e.g., for the return value */
38 public final Boolean isTrue = true;
41 * A constant <code>boolean false</code> value available for reuse e.g., for the return value
43 public final Boolean isFalse = false;
45 /** the execution ID for the current APEX policy execution instance. */
46 public final Long executionId;
48 // Standard coder for JSON converts
49 private static final StandardCoder STANDARD_CODER = new StandardCoder();
51 // A message specified in the logic
53 private String message;
55 // Execution properties for a policy execution
56 private final Properties executionProperties;
59 * Instantiates a new task execution context.
61 * @param executionId the execution ID for the current APEX policy execution instance
62 * @param executionProperties the execution properties for task execution
64 public AbstractExecutionContext(final long executionId, final Properties executionProperties) {
66 // Execution ID is the current policy execution instance
67 this.executionId = executionId;
68 this.executionProperties = executionProperties;
72 * Get a JSON representation of an object.
74 * @param theObject the object to get a JSON representation of
75 * @return the JSON version of the object
76 * @throws CoderException on JSON coding errors
78 public String stringify2Json(final Object theObject) throws CoderException {
79 return stringify2Json(theObject, null);
83 * Get a JSON representation of an object.
85 * @param theObject the object to get a JSON representation of
86 * @param schemaHelper a schema helper to use for the JSON conversion, if null, a standard conversion is done
87 * @return the JSON version of the object
88 * @throws CoderException on JSON coding errors
90 public String stringify2Json(final Object theObject, final SchemaHelper schemaHelper) throws CoderException {
91 if (schemaHelper == null) {
92 return STANDARD_CODER.encode(theObject);
94 return schemaHelper.marshal2String(theObject);