2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.aai.babel.xml.generator.data;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.List;
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;
33 public class WidgetConfigurationUtil {
35 private static Properties config;
36 private static List<String> instanceGroups = Collections.emptyList();
37 private static Map<String, Resource> typeToWidget = new HashMap<>();
40 * Private constructor to prevent instantiation
42 private WidgetConfigurationUtil() {
43 throw new UnsupportedOperationException("This static class should not be instantiated!");
46 public static Properties getConfig() {
50 public static void setConfig(Properties config) {
51 WidgetConfigurationUtil.config = config;
54 public static void setSupportedInstanceGroups(List<String> supportedInstanceGroups) {
55 instanceGroups = supportedInstanceGroups;
58 public static boolean isSupportedInstanceGroup(String groupType) {
59 return instanceGroups.contains(groupType);
62 public static Optional<Resource> createModelFromType(String typePrefix) {
63 return Optional.ofNullable(typeToWidget.get(typePrefix));
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);
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);