ad0f0b4faf743c851bb1ae0969fd573497884ba2
[policy/apex-pdp.git] / model / model-api / src / main / java / org / onap / policy / apex / model / modelapi / ApexModelFactory.java
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.modelapi;
22
23 import java.util.Properties;
24
25 import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
26
27 /**
28  * A factory for creating ApexModel objects using the Apex Model implementation.
29  *
30  * @author Liam Fallon (liam.fallon@ericsson.com)
31  */
32 public class ApexModelFactory {
33
34     /**
35      * Creates a new ApexModel object from its implementation.
36      *
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
39      *        set to false
40      * @return the apex model
41      */
42     public ApexModel createApexModel(final Properties apexProperties, final boolean jsonMode) {
43         return new ApexModelImpl(setDefaultPropertyValues(apexProperties), jsonMode);
44     }
45
46     /**
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.
49      *
50      * @param apexPropertiesIn the default property values
51      * @return the properties
52      */
53     private Properties setDefaultPropertyValues(final Properties apexPropertiesIn) {
54         Properties apexProperties = apexPropertiesIn;
55
56         if (apexProperties == null) {
57             apexProperties = new Properties();
58         }
59
60         if (apexProperties.getProperty("DEFAULT_CONCEPT_VERSION") == null) {
61             apexProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
62         }
63         if (apexProperties.getProperty("DEFAULT_EVENT_NAMESPACE") == null) {
64             apexProperties.setProperty("DEFAULT_EVENT_NAMESPACE", "org.onap.policy.apex");
65         }
66         if (apexProperties.getProperty("DEFAULT_EVENT_SOURCE") == null) {
67             apexProperties.setProperty("DEFAULT_EVENT_SOURCE", "source");
68         }
69         if (apexProperties.getProperty("DEFAULT_EVENT_TARGET") == null) {
70             apexProperties.setProperty("DEFAULT_EVENT_TARGET", "target");
71         }
72         if (apexProperties.getProperty("DEFAULT_POLICY_TEMPLATE") == null) {
73             apexProperties.setProperty("DEFAULT_POLICY_TEMPLATE", "FREEFORM");
74         }
75
76         return apexProperties;
77     }
78 }