Replace Resource sub-classes with configuration
[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 package org.onap.aai.babel.xml.generator.data;
22
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Optional;
28 import java.util.Properties;
29 import org.onap.aai.babel.xml.generator.model.Resource;
30 import org.onap.aai.babel.xml.generator.model.Widget;
31
32 public class WidgetConfigurationUtil {
33
34     private static Properties config;
35     private static List<String> instanceGroups = Collections.emptyList();
36     private static Map<String, Resource> typeToWidget = new HashMap<>();
37
38     /*
39      * Private constructor to prevent instantiation
40      */
41     private WidgetConfigurationUtil() {
42         throw new UnsupportedOperationException("This static class should not be instantiated!");
43     }
44
45     public static Properties getConfig() {
46         return config;
47     }
48
49     public static void setConfig(Properties config) {
50         WidgetConfigurationUtil.config = config;
51     }
52
53     public static void setSupportedInstanceGroups(List<String> supportedInstanceGroups) {
54         instanceGroups = supportedInstanceGroups;
55     }
56
57     public static boolean isSupportedInstanceGroup(String groupType) {
58         return instanceGroups.contains(groupType);
59     }
60
61     public static Optional<Resource> createModelFromType(String typePrefix) {
62         return Optional.ofNullable(typeToWidget.get(typePrefix));
63     }
64
65     public static void setWidgetMappings(List<WidgetMapping> mappings) {
66         for (WidgetMapping mapping : mappings) {
67             Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
68             resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
69             typeToWidget.put(mapping.prefix, resource);
70         }
71     }
72 }