diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-21 12:25:13 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-03-21 12:25:13 +0000 |
commit | b3c57a21bca3898e6a2497e58bb665a90318435a (patch) | |
tree | 0593ebdf8bff21316f137717b6589270f1cfb3d7 /src/main/java | |
parent | 6f265707c398404924c277bc17762fe73970b983 (diff) |
Create new Resource objects for each new model
When creating multiple Resources of the same type, ensure that each
Resource has a new Java Object: follow the same pattern as used for
Widget types.
Change-Id: I1e41d3258a3ccdad91448234ae3cf40235d7b210
Issue-ID: AAI-2267
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java | 9 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java | 12 |
2 files changed, 19 insertions, 2 deletions
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 7683f7c..df5224c 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 @@ -31,8 +31,8 @@ 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.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; public class WidgetConfigurationUtil { @@ -66,7 +66,12 @@ public class WidgetConfigurationUtil { } public static Optional<Resource> createModelFromType(String typePrefix) { - return Optional.ofNullable(typeToResource.get(typePrefix)); + Optional<Resource> resource = Optional.ofNullable(typeToResource.get(typePrefix)); + if (resource.isPresent()) { + // Make a copy of the Resource found in the mappings table. + return Optional.of(new Resource(resource.get())); + } + return resource; } public static Widget createWidgetFromType(String widgetType) throws XmlArtifactGenerationException { 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 f5f7c50..89d02bb 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 @@ -44,6 +44,16 @@ public class Resource extends Model { this.deleteFlag = deleteFlag; } + /** + * Copy Constructor. + * + * @param baseResource + */ + public Resource(Resource baseResource) { + this(baseResource.getWidgetType(), baseResource.getDeleteFlag()); + setModelType(baseResource.getModelType()); + } + @Override public int hashCode() { final String uuid = getModelNameVersionId(); @@ -113,10 +123,12 @@ public class Resource extends Model { } } + @Override public WidgetType getWidgetType() { return type; } + @Override public String getModelTypeName() { return "resource"; } |