aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-03-25 15:41:12 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-03-25 15:41:12 +0000
commit6c585913c11b2e1973bfcd0d7671d4114e1c3e66 (patch)
tree37b1cef3205428fc2b4b8b5d3878799e28d7be2d /src/main/java/org/onap
parent8c6980a4b3bf7ddcff8cc5757c29961385222606 (diff)
Add hasWidgetType() helper method
Replace getWidgetType() == WidgetType.valueOf("type") with hasWidgetType("type") for improved readability. Change-Id: Id51bed7c4cb9ce38799bf3ff34301c8feb664922 Issue-ID: AAI-2281 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java20
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java6
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java1
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java17
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java8
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Service.java1
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java6
7 files changed, 41 insertions, 18 deletions
diff --git a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
index 3f2e670..684324a 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -95,7 +95,7 @@ public class ArtifactGeneratorToscaParser {
/**
* Initializes the Widget to UUID mapping configuration.
- *
+ *
* @throws IOException
* if an error occurs reading the configuration properties
*/
@@ -119,7 +119,7 @@ public class ArtifactGeneratorToscaParser {
/**
* Initializes the group filtering and TOSCA to Widget mapping configuration.
- *
+ *
* @param configLocation
* the pathname to the JSON mappings file
* @throws IOException
@@ -198,7 +198,7 @@ public class ArtifactGeneratorToscaParser {
/**
* Add the resource/widget to the specified model.
- *
+ *
* @param model
* @param relation
* resource or widget model to add
@@ -238,7 +238,7 @@ public class ArtifactGeneratorToscaParser {
// Process each VF Group
for (Group serviceGroup : serviceGroups) {
Model groupModel = Model.getModelFor(serviceGroup.getType());
- if (groupModel.getWidgetType() == WidgetType.valueOf("VFMODULE")) {
+ if (groupModel.hasWidgetType("VFMODULE")) {
processVfModule(resources, resourceModel, serviceGroup, serviceNode, (Resource) groupModel);
}
}
@@ -258,7 +258,7 @@ public class ArtifactGeneratorToscaParser {
Resource model = Model.getModelFor(nodeTypeName, metaDataType);
if (metadata != null && hasAllottedResource(metadata.getAllProperties())
- && model.getWidgetType() == WidgetType.valueOf("VSERVER")) {
+ && model.hasWidgetType("VSERVER")) {
model = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), false);
Map<String, Object> props = new HashMap<>();
props.put("providingService", true);
@@ -268,7 +268,7 @@ public class ArtifactGeneratorToscaParser {
foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties());
}
- if (resourceModel.getWidgetType() == WidgetType.valueOf("ALLOTTED_RESOURCE") && !foundProvidingService) {
+ if (resourceModel.hasWidgetType("ALLOTTED_RESOURCE") && !foundProvidingService) {
final String modelInvariantId = resourceModel.getModelId();
throw new IllegalArgumentException(String.format(GENERATOR_AAI_PROVIDING_SERVICE_MISSING,
modelInvariantId == null ? "<null ID>" : modelInvariantId));
@@ -369,7 +369,7 @@ public class ArtifactGeneratorToscaParser {
/**
* Process the Widget members of a VF Module Group
- *
+ *
* @param group
* @param member
* @throws XmlArtifactGenerationException
@@ -379,7 +379,7 @@ public class ArtifactGeneratorToscaParser {
log.debug(member.getType() + " mapped to " + resource);
- if (resource.getWidgetType() == WidgetType.valueOf("L3_NET")) {
+ if (resource.hasWidgetType("L3_NET")) {
// An l3-network inside a vf-module is treated as a Widget
resource.setModelType(ModelType.WIDGET);
}
@@ -426,11 +426,11 @@ public class ArtifactGeneratorToscaParser {
if (foundProvidingService) {
processProvidingService(resourceModel, resourceNode, nodeProperties);
} else if (resourceNode != null && resourceNode.getModelType() == ModelType.RESOURCE
- && resourceNode.getWidgetType() != WidgetType.valueOf("L3_NET")) {
+ && !resourceNode.hasWidgetType("L3_NET")) {
if (metaData != null) {
resourceNode.populateModelIdentificationInformation(metaData.getAllProperties());
}
- resourceModel.addResource((Resource) resourceNode);
+ resourceModel.addResource(resourceNode);
}
return foundProvidingService;
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
index 741c194..d35814a 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
@@ -44,8 +44,8 @@ import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.model.Model;
import org.onap.aai.babel.xml.generator.model.Resource;
import org.onap.aai.babel.xml.generator.model.Service;
-import org.onap.aai.babel.xml.generator.model.WidgetType;
import org.onap.aai.babel.xml.generator.model.Widget;
+import org.onap.aai.babel.xml.generator.model.WidgetType;
import org.onap.aai.babel.xml.generator.types.ModelType;
import org.onap.aai.cl.api.Logger;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
@@ -242,7 +242,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
if (model != null) {
Metadata metadata = nodeTemplate.getMetaData();
if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())
- && model.getWidgetType() == WidgetType.valueOf("VF")) {
+ && model.hasWidgetType("VF")) {
model = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true);
}
}
@@ -272,7 +272,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
}
resources.addAll(parser.processInstanceGroups(resourceModel, nodeTemplate));
- resources.add((Resource) resourceModel);
+ resources.add(resourceModel);
}
/**
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 df5224c..1e41f60 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
@@ -84,6 +84,7 @@ public class WidgetConfigurationUtil {
}
public static void setWidgetTypes(List<WidgetTypeConfig> types) {
+ WidgetType.clearElements();
for (WidgetTypeConfig type : types) {
if (type.type == null || type.name == null) {
throw new IllegalArgumentException("Incomplete widget type specified: " + type);
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
index ea1d478..b2020cd 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
@@ -157,10 +157,24 @@ public abstract class Model {
public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
+ /**
+ * @return the Widget Type of this model.
+ */
public abstract WidgetType getWidgetType();
public abstract String getModelTypeName();
+ /**
+ * Check whether the model's Widget Type matches the supplied type.
+ *
+ * @param type
+ * the Widget Type to compare
+ * @return true if the Widget Type of this model matches the supplied type
+ */
+ public boolean hasWidgetType(String type) {
+ return getWidgetType() == WidgetType.valueOf(type);
+ }
+
public boolean addResource(Resource resource) {
return resources.add(resource);
}
@@ -221,6 +235,9 @@ public abstract class Model {
* the model ident info
*/
public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
+ if (modelIdentInfo == null) {
+ return;
+ }
Iterator<String> iter = modelIdentInfo.keySet().iterator();
String property;
while (iter.hasNext()) {
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
index 89d02bb..77679ac 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
@@ -105,15 +105,15 @@ public class Resource extends Model {
public boolean addWidget(Widget widget) throws XmlArtifactGenerationException {
if (type == WidgetType.valueOf("VFMODULE")) {
if (widget.memberOf(members)) {
- if (vserver == null && widget.getWidgetType() == WidgetType.valueOf("VSERVER")) {
+ if (vserver == null && widget.hasWidgetType("VSERVER")) {
addVserverWidget(widget);
- } else if (widget.getWidgetType() == WidgetType.valueOf("LINT")) {
+ } else if (widget.hasWidgetType("LINT")) {
return addLIntfWidget(widget);
- } else if (widget.getWidgetType() == WidgetType.valueOf("VOLUME")) {
+ } else if (widget.hasWidgetType("VOLUME")) {
addVolumeWidget(widget);
return true;
}
- if (widget.getWidgetType() != WidgetType.valueOf("OAM_NETWORK")) {
+ if (!widget.hasWidgetType("OAM_NETWORK")) {
return widgets.add(widget);
}
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
index 0d20c2d..894fe44 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java
@@ -33,6 +33,7 @@ public class Service extends Model {
return WidgetType.valueOf("SERVICE");
}
+ @Override
public String getModelTypeName() {
return "service";
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java b/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java
index 2cab6ae..b6f995f 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/WidgetType.java
@@ -52,6 +52,10 @@ public class WidgetType {
elements.put(name, this);
}
+ public static void clearElements() {
+ elements.clear();
+ }
+
public static void validateElements() {
mandatoryElements.forEach(WidgetType::valueOf);
}
@@ -59,7 +63,7 @@ public class WidgetType {
public static WidgetType valueOf(String typeName) {
WidgetType type = elements.get(typeName);
if (type == null) {
- throw new IllegalArgumentException("Unknown type " + typeName);
+ throw new IllegalArgumentException("Unknown WidgetType " + typeName);
}
return type;
}