2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.model.modelapi;
23 import java.util.Properties;
25 import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
28 * A factory for creating ApexModel objects using the Apex Model implementation.
30 * @author Liam Fallon (liam.fallon@ericsson.com)
32 public class ApexModelFactory {
35 * Creates a new ApexModel object from its implementation.
37 * @param apexProperties default values and other configuration information for the apex model
38 * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
40 * @return the apex model
42 public ApexModel createApexModel(final Properties apexProperties, final boolean jsonMode) {
43 return new ApexModelImpl(setDefaultPropertyValues(apexProperties), jsonMode);
47 * Sets default property values for Apex properties that must be set for the Apex model
48 * implementation if those properties are not already set.
50 * @param apexPropertiesIn the default property values
51 * @return the properties
53 private Properties setDefaultPropertyValues(final Properties apexPropertiesIn) {
54 Properties apexProperties = apexPropertiesIn;
56 if (apexProperties == null) {
57 apexProperties = new Properties();
60 if (apexProperties.getProperty("DEFAULT_CONCEPT_VERSION") == null) {
61 apexProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
63 if (apexProperties.getProperty("DEFAULT_EVENT_NAMESPACE") == null) {
64 apexProperties.setProperty("DEFAULT_EVENT_NAMESPACE", "org.onap.policy.apex");
66 if (apexProperties.getProperty("DEFAULT_EVENT_SOURCE") == null) {
67 apexProperties.setProperty("DEFAULT_EVENT_SOURCE", "source");
69 if (apexProperties.getProperty("DEFAULT_EVENT_TARGET") == null) {
70 apexProperties.setProperty("DEFAULT_EVENT_TARGET", "target");
72 if (apexProperties.getProperty("DEFAULT_POLICY_TEMPLATE") == null) {
73 apexProperties.setProperty("DEFAULT_POLICY_TEMPLATE", "FREEFORM");
76 return apexProperties;