fb17137767f9043717c2aa24133a2f110e49e34e
[policy/apex-pdp.git] / context / context-management / src / main / java / org / onap / policy / apex / context / parameters / SchemaParameters.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.context.parameters;
22
23 import java.util.Map;
24 import java.util.Map.Entry;
25 import java.util.TreeMap;
26
27 import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
28 import org.onap.policy.common.parameters.GroupValidationResult;
29 import org.onap.policy.common.parameters.ParameterGroup;
30
31 /**
32  * Bean class holding schema parameters for schemas and their helpers. As more than one schema can be used in Apex
33  * simultaneously, this class is used to hold the schemas that are defined in a given Apex system and to get the schema
34  * helper plugin parameters {@link SchemaHelperParameters} for each schema.
35  *
36  * <p>The default {@code Java} schema is always defined and its parameters are held in a
37  * {@link JavaSchemaHelperParameters} instance.
38  *
39  * @author Liam Fallon (liam.fallon@ericsson.com)
40  */
41 public class SchemaParameters implements ParameterGroup {
42     /** The Java schema flavour is always available for use. */
43     public static final String DEFAULT_SCHEMA_FLAVOUR = "Java";
44
45     private String name;
46
47     // A map of parameters for executors of various logic types
48     private Map<String, SchemaHelperParameters> schemaHelperParameterMap;
49
50     /**
51      * Constructor to create a distributor parameters instance and register the instance with the parameter service.
52      */
53     public SchemaParameters() {
54         super();
55
56         // Set the name for the parameters
57         this.name = ContextParameterConstants.SCHEMA_GROUP_NAME;
58
59         schemaHelperParameterMap = new TreeMap<>();
60
61         // The default schema helper
62         schemaHelperParameterMap.put(DEFAULT_SCHEMA_FLAVOUR, new JavaSchemaHelperParameters());
63     }
64
65     /**
66      * Gets a map of the schemas and schema helper parameters that are defined.
67      *
68      * @return the schema helper parameter map
69      */
70     public Map<String, SchemaHelperParameters> getSchemaHelperParameterMap() {
71         return schemaHelperParameterMap;
72     }
73
74     /**
75      * Sets the map of the schemas and schema helper parameters.
76      *
77      * @param schemaHelperParameterMap the schema helper parameter map
78      */
79     public void setSchemaHelperParameterMap(final Map<String, SchemaHelperParameters> schemaHelperParameterMap) {
80         this.schemaHelperParameterMap = schemaHelperParameterMap;
81     }
82
83     /**
84      * Gets the schema helper parameters for a given context schema flavour.
85      *
86      * @param schemaFlavour the schema flavour for which to get the schema helper parameters
87      * @return the schema helper parameters for the given schema flavour
88      */
89     public SchemaHelperParameters getSchemaHelperParameters(final String schemaFlavour) {
90         return schemaHelperParameterMap.get(schemaFlavour);
91     }
92
93     @Override
94     public String getName() {
95         return name;
96     }
97
98     @Override
99     public void setName(final String name) {
100         this.name = name;
101     }
102
103     @Override
104     public GroupValidationResult validate() {
105         final GroupValidationResult result = new GroupValidationResult(this);
106
107         for (Entry<String, SchemaHelperParameters> schemaHelperEntry : schemaHelperParameterMap.entrySet()) {
108             result.setResult("schemaHelperParameterMap", schemaHelperEntry.getKey(),
109                             schemaHelperEntry.getValue().validate());
110         }
111         return result;
112     }
113 }