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