2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.core.engine.executor.context;
24 import java.util.Properties;
27 import org.onap.policy.apex.context.SchemaHelper;
28 import org.onap.policy.common.utils.coder.CoderException;
29 import org.onap.policy.common.utils.coder.StandardCoder;
32 * Abstract class for the execution context for logic executions in logic being executed in an Apex engine. The
33 * logic must have easy access to its subject definition, the incoming and outgoing field contexts, as well as the
34 * policy, global, and external context.
37 public class AbstractExecutionContext {
38 /** A constant <code>boolean true</code> value available for reuse e.g., for the return value */
39 public static final Boolean IS_TRUE = true;
42 * A constant <code>boolean false</code> value available for reuse e.g., for the return value
44 public static final Boolean IS_FALSE = false;
46 /** the execution ID for the current APEX policy execution instance. */
47 public final Long executionId;
49 // Standard coder for JSON converts
50 private static final StandardCoder STANDARD_CODER = new StandardCoder();
52 // A message specified in the logic
54 private String message;
56 // Execution properties for a policy execution
57 private final Properties executionProperties;
60 * Instantiates a new task execution context.
62 * @param executionId the execution ID for the current APEX policy execution instance
63 * @param executionProperties the execution properties for task execution
65 public AbstractExecutionContext(final long executionId, final Properties executionProperties) {
67 // Execution ID is the current policy execution instance
68 this.executionId = executionId;
69 this.executionProperties = executionProperties;
73 * Get a JSON representation of an object.
75 * @param theObject the object to get a JSON representation of
76 * @return the JSON version of the object
77 * @throws CoderException on JSON coding errors
79 public String stringify2Json(final Object theObject) throws CoderException {
80 return stringify2Json(theObject, null);
84 * Get a JSON representation of an object.
86 * @param theObject the object to get a JSON representation of
87 * @param schemaHelper a schema helper to use for the JSON conversion, if null, a standard conversion is done
88 * @return the JSON version of the object
89 * @throws CoderException on JSON coding errors
91 public String stringify2Json(final Object theObject, final SchemaHelper schemaHelper) throws CoderException {
92 if (schemaHelper == null) {
93 return STANDARD_CODER.encode(theObject);
95 return schemaHelper.marshal2String(theObject);