X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fxml%2Fgenerator%2Fapi%2FAaiArtifactGenerator.java;h=11c1471a304b78cf2008b7c925250d705948a489;hb=bfde3ef00beb3c6f31cebfd12e90b9b9cdcc492e;hp=75c5073c00bca1d9f3add5cbb105f1a9c72d7870;hpb=4e828f7f2037735de2253a0dcc2b557c88c15cd3;p=aai%2Fbabel.git 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 75c5073..11c1471 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 @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2019 European Software Marketing Ltd. + * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,8 @@ 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.Widget; -import org.onap.aai.babel.xml.generator.model.Widget.Type; +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; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; @@ -68,7 +69,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { private static final String GENERATOR_AAI_INVALID_SERVICE_VERSION = "Cannot generate artifacts. Service version is incorrect"; - private AaiModelGenerator modelGenerator = new AaiModelGeneratorImpl(); + private AaiModelGenerator modelGenerator = new AaiModelGenerator(); @Override public GenerationData generateArtifact(byte[] csarArchive, List input, @@ -81,7 +82,6 @@ public class AaiArtifactGenerator implements ArtifactGenerator { } try { - ArtifactGeneratorToscaParser.initWidgetConfiguration(); ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation); } catch (IOException e) { log.error(ApplicationMsgs.LOAD_PROPERTIES, e, configLocation); @@ -123,8 +123,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator { * interface to the TOSCA parser * @return the generated Artifacts (containing XML models) * @throws XmlArtifactGenerationException + * if the configured widget mappings do not support processed widget type(s) */ - private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) + public GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) throws XmlArtifactGenerationException { List serviceNodeTemplates = csarHelper.getServiceNodeTemplates(); if (serviceNodeTemplates == null) { @@ -181,6 +182,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { * @param serviceModel * @return the generated Models * @throws XmlArtifactGenerationException + * if the configured widget mappings do not support processed widget type(s) */ private List generateResourceModels(ISdcCsarHelper csarHelper, List serviceNodeTemplates, Service serviceModel) throws XmlArtifactGenerationException { @@ -200,6 +202,16 @@ public class AaiArtifactGenerator implements ArtifactGenerator { return resources; } + /** + * @param csarHelper + * @param serviceModel + * @param resources + * @param serviceGroups + * @param parser + * @param nodeTemplate + * @throws XmlArtifactGenerationException + * if the configured widget mappings do not support processed widget type(s) + */ private void generateModelFromNodeTemplate(ISdcCsarHelper csarHelper, Service serviceModel, List resources, final List serviceGroups, ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) throws XmlArtifactGenerationException { @@ -211,7 +223,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { } parser.addRelatedModel(serviceModel, model); - if (model.isResource()) { + if (model.getModelType() == ModelType.RESOURCE) { generateResourceModel(csarHelper, resources, parser, nodeTemplate); } } else { @@ -241,14 +253,22 @@ public class AaiArtifactGenerator implements ArtifactGenerator { if (model != null) { Metadata metadata = nodeTemplate.getMetaData(); if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties()) - && model.getWidgetType() == Type.VF) { - model = new Resource(Type.ALLOTTED_RESOURCE, true); + && model.hasWidgetType("VF")) { + model = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true); } } return model; } + /** + * @param csarHelper + * @param resources + * @param parser + * @param nodeTemplate + * @throws XmlArtifactGenerationException + * if the configured widget mappings do not support processed widget type(s) + */ private void generateResourceModel(ISdcCsarHelper csarHelper, List resources, ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) throws XmlArtifactGenerationException { Resource resourceModel = getModelFor(parser, nodeTemplate); @@ -267,11 +287,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator { } if (parser.hasSubCategoryTunnelXConnect(serviceMetadata) && parser.hasAllottedResource(serviceMetadata)) { - resourceModel.addWidget(Widget.getWidget(Type.TUNNEL_XCONNECT)); + resourceModel.addWidget(Widget.createWidget("TUNNEL_XCONNECT")); } resources.addAll(parser.processInstanceGroups(resourceModel, nodeTemplate)); - resources.add((Resource) resourceModel); + resources.add(resourceModel); } /** @@ -303,7 +323,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { private String getArtifactLabel(Model model) { StringBuilder artifactName = new StringBuilder(ArtifactType.AAI.name()); artifactName.append("-"); - artifactName.append(model.getModelType().name().toLowerCase()); + artifactName.append(model.getModelTypeName()); artifactName.append("-"); artifactName.append(hashCodeUuId(model.getModelNameVersionId())); return (artifactName.toString()).replaceAll("[^a-zA-Z0-9 +]+", "-"); @@ -324,7 +344,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { artifactName.append(truncatedArtifactName); artifactName.append("-"); - artifactName.append(model.getModelType().name().toLowerCase()); + artifactName.append(model.getModelTypeName()); artifactName.append("-"); artifactName.append(model.getModelVersion()); @@ -342,7 +362,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { * AAI model as string * @return Generated {@link Artifact} model for the resource */ - private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) { + private Artifact getResourceArtifact(Resource resourceModel, String aaiResourceModel) { final String resourceArtifactLabel = getArtifactLabel(resourceModel); MDC.put(MDC_PARAM_MODEL_INFO, resourceModel.getModelName() + "," + resourceArtifactLabel); final byte[] bytes = aaiResourceModel.getBytes(); @@ -351,7 +371,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { GeneratorUtil.checkSum(bytes), GeneratorUtil.encode(bytes)); artifact.setName(getArtifactName(resourceModel)); artifact.setLabel(resourceArtifactLabel); - artifact.setDescription(ArtifactGeneratorToscaParser.getArtifactDescription(resourceModel)); + artifact.setDescription("AAI Resource Model"); return artifact; } @@ -381,8 +401,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator { String serviceArtifactLabel = getArtifactLabel(serviceModel); artifact.setName(serviceArtifactName); artifact.setLabel(serviceArtifactLabel); - String description = ArtifactGeneratorToscaParser.getArtifactDescription(serviceModel); - artifact.setDescription(description); + artifact.setDescription("AAI Service Model"); return artifact; }