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;
26 import lombok.RequiredArgsConstructor;
28 import org.onap.policy.apex.context.SchemaHelper;
29 import org.onap.policy.common.utils.coder.CoderException;
30 import org.onap.policy.common.utils.coder.StandardCoder;
33 * Abstract class for the execution context for logic executions in logic being executed in an Apex engine. The
34 * logic must have easy access to its subject definition, the incoming and outgoing field contexts, as well as the
35 * policy, global, and external context.
38 @RequiredArgsConstructor
39 public class AbstractExecutionContext {
40 /** A constant <code>boolean true</code> value available for reuse e.g., for the return value */
41 public static final Boolean IS_TRUE = true;
44 * A constant <code>boolean false</code> value available for reuse e.g., for the return value
46 public static final Boolean IS_FALSE = false;
48 // Standard coder for JSON converts
49 private static final StandardCoder STANDARD_CODER = new StandardCoder();
51 /** the execution ID for the current APEX policy execution instance. */
52 public final Long executionId;
54 // A message specified in the logic
56 private String message;
58 // Execution properties for a policy execution
59 private final Properties executionProperties;
62 * Get a JSON representation of an object.
64 * @param theObject the object to get a JSON representation of
65 * @return the JSON version of the object
66 * @throws CoderException on JSON coding errors
68 public String stringify2Json(final Object theObject) throws CoderException {
69 return stringify2Json(theObject, null);
73 * Get a JSON representation of an object.
75 * @param theObject the object to get a JSON representation of
76 * @param schemaHelper a schema helper to use for the JSON conversion, if null, a standard conversion is done
77 * @return the JSON version of the object
78 * @throws CoderException on JSON coding errors
80 public String stringify2Json(final Object theObject, final SchemaHelper schemaHelper) throws CoderException {
81 if (schemaHelper == null) {
82 return STANDARD_CODER.encode(theObject);
84 return schemaHelper.marshal2String(theObject);