Changes for checkstyle 8.32
[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 import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
25
26 /**
27  * A factory for creating ApexModel objects using the Apex Model implementation.
28  *
29  * @author Liam Fallon (liam.fallon@ericsson.com)
30  */
31 public class ApexModelFactory {
32
33     /**
34      * Creates a new ApexModel object from its implementation.
35      *
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
38      *        set to false
39      * @return the apex model
40      */
41     public ApexModel createApexModel(final Properties apexProperties, final boolean jsonMode) {
42         return new ApexModelImpl(setDefaultPropertyValues(apexProperties), jsonMode);
43     }
44
45     /**
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.
48      *
49      * @param apexPropertiesIn the default property values
50      * @return the properties
51      */
52     private Properties setDefaultPropertyValues(final Properties apexPropertiesIn) {
53         Properties apexProperties = apexPropertiesIn;
54
55         if (apexProperties == null) {
56             apexProperties = new Properties();
57         }
58
59         if (apexProperties.getProperty("DEFAULT_CONCEPT_VERSION") == null) {
60             apexProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
61         }
62         if (apexProperties.getProperty("DEFAULT_EVENT_NAMESPACE") == null) {
63             apexProperties.setProperty("DEFAULT_EVENT_NAMESPACE", "org.onap.policy.apex");
64         }
65         if (apexProperties.getProperty("DEFAULT_EVENT_SOURCE") == null) {
66             apexProperties.setProperty("DEFAULT_EVENT_SOURCE", "source");
67         }
68         if (apexProperties.getProperty("DEFAULT_EVENT_TARGET") == null) {
69             apexProperties.setProperty("DEFAULT_EVENT_TARGET", "target");
70         }
71         if (apexProperties.getProperty("DEFAULT_POLICY_TEMPLATE") == null) {
72             apexProperties.setProperty("DEFAULT_POLICY_TEMPLATE", "FREEFORM");
73         }
74
75         return apexProperties;
76     }
77 }