Rename the groupfilter.config System Property
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / data / WidgetConfigurationUtil.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2019 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.aai.babel.xml.generator.data;
23
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Optional;
29 import java.util.Properties;
30 import org.onap.aai.babel.xml.generator.model.Resource;
31 import org.onap.aai.babel.xml.generator.model.Widget;
32
33 public class WidgetConfigurationUtil {
34
35     private static Properties config;
36     private static List<String> instanceGroups = Collections.emptyList();
37     private static Map<String, Resource> typeToWidget = new HashMap<>();
38
39     /*
40      * Private constructor to prevent instantiation
41      */
42     private WidgetConfigurationUtil() {
43         throw new UnsupportedOperationException("This static class should not be instantiated!");
44     }
45
46     public static Properties getConfig() {
47         return config;
48     }
49
50     public static void setConfig(Properties config) {
51         WidgetConfigurationUtil.config = config;
52     }
53
54     public static void setSupportedInstanceGroups(List<String> supportedInstanceGroups) {
55         instanceGroups = supportedInstanceGroups;
56     }
57
58     public static boolean isSupportedInstanceGroup(String groupType) {
59         return instanceGroups.contains(groupType);
60     }
61
62     public static Optional<Resource> createModelFromType(String typePrefix) {
63         return Optional.ofNullable(typeToWidget.get(typePrefix));
64     }
65
66     public static void setWidgetMappings(List<WidgetMapping> mappings) {
67         for (WidgetMapping mapping : mappings) {
68             if (mapping.prefix == null || mapping.widget == null) {
69                 throw new IllegalArgumentException("Incomplete widget mapping specified: " + mapping);
70             }
71             Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
72             resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
73             typeToWidget.put(mapping.prefix, resource);
74         }
75     }
76 }