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;
24 import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
27 * A factory for creating ApexModel objects using the Apex Model implementation.
29 * @author Liam Fallon (liam.fallon@ericsson.com)
31 public class ApexModelFactory {
34 * Creates a new ApexModel object from its implementation.
36 * @param apexProperties default values and other configuration information for the apex model
37 * @param jsonMode set to true to return JSON strings in list and delete operations, otherwise
39 * @return the apex model
41 public ApexModel createApexModel(final Properties apexProperties, final boolean jsonMode) {
42 return new ApexModelImpl(setDefaultPropertyValues(apexProperties), jsonMode);
46 * Sets default property values for Apex properties that must be set for the Apex model
47 * implementation if those properties are not already set.
49 * @param apexPropertiesIn the default property values
50 * @return the properties
52 private Properties setDefaultPropertyValues(final Properties apexPropertiesIn) {
53 Properties apexProperties = apexPropertiesIn;
55 if (apexProperties == null) {
56 apexProperties = new Properties();
59 if (apexProperties.getProperty("DEFAULT_CONCEPT_VERSION") == null) {
60 apexProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
62 if (apexProperties.getProperty("DEFAULT_EVENT_NAMESPACE") == null) {
63 apexProperties.setProperty("DEFAULT_EVENT_NAMESPACE", "org.onap.policy.apex");
65 if (apexProperties.getProperty("DEFAULT_EVENT_SOURCE") == null) {
66 apexProperties.setProperty("DEFAULT_EVENT_SOURCE", "source");
68 if (apexProperties.getProperty("DEFAULT_EVENT_TARGET") == null) {
69 apexProperties.setProperty("DEFAULT_EVENT_TARGET", "target");
71 if (apexProperties.getProperty("DEFAULT_POLICY_TEMPLATE") == null) {
72 apexProperties.setProperty("DEFAULT_POLICY_TEMPLATE", "FREEFORM");
75 return apexProperties;