X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fxml%2Fgenerator%2Fdata%2FWidgetConfigurationUtil.java;h=7b3d4f29f4570ad4c99af443d5ed5b9daa69a1dd;hb=f5dae47e293ae63a7a2f18230b772a699a52566f;hp=5298f083a10d8366dde47793278e2eb5e2807ceb;hpb=fc779f51a624bfddc68328bf3fd3c74594ef31f6;p=aai%2Fbabel.git diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java index 5298f08..7b3d4f2 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java @@ -27,17 +27,20 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Properties; +import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; import org.onap.aai.babel.xml.generator.model.Resource; import org.onap.aai.babel.xml.generator.model.Widget; +import org.onap.aai.babel.xml.generator.model.Widget.Type; public class WidgetConfigurationUtil { private static Properties config; private static List instanceGroups = Collections.emptyList(); - private static Map typeToWidget = new HashMap<>(); + private static Map typeToResource = new HashMap<>(); + private static Map typeToWidget = new HashMap<>(); /* - * Private constructor to prevent instantiation + * Private constructor to prevent instantiation. */ private WidgetConfigurationUtil() { throw new UnsupportedOperationException("This static class should not be instantiated!"); @@ -60,7 +63,27 @@ public class WidgetConfigurationUtil { } public static Optional createModelFromType(String typePrefix) { - return Optional.ofNullable(typeToWidget.get(typePrefix)); + return Optional.ofNullable(typeToResource.get(typePrefix)); + } + + public static Widget createWidgetFromType(Type type) throws XmlArtifactGenerationException { + Optional widget = Optional.ofNullable(typeToWidget.get(type.toString())); + if (widget.isPresent()) { + // Make a copy of the Widget found in the mappings table. + return new Widget(widget.get()); + } + return null; + } + + public static void setWidgetTypes(List types) { + for (WidgetType type : types) { + if (type.type == null || type.name == null) { + throw new IllegalArgumentException("Incomplete widget type specified: " + type); + } + Type widgetType = Widget.Type.valueOf(type.type); + Widget widget = new Widget(widgetType, type.name, type.deleteFlag); + typeToWidget.put(type.type, widget); + } } public static void setWidgetMappings(List mappings) { @@ -70,7 +93,7 @@ public class WidgetConfigurationUtil { } Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag); resource.setIsResource(mapping.type.equalsIgnoreCase("resource")); - typeToWidget.put(mapping.prefix, resource); + typeToResource.put(mapping.prefix, resource); } } }