From 8f3c0bc6b0932bc8e5c829db22f9602a6bdf0b76 Mon Sep 17 00:00:00 2001 From: YuanHu Date: Tue, 25 Oct 2016 11:47:51 +0800 Subject: Parse Service Template name, vendor and version from metadata. Change-Id: I40719faec2f8bf41147664394446b33cc2d3b06d Issue-id: TOSCA-141 Signed-off-by: YuanHu --- .../catalog/model/parser/AbstractModelParser.java | 34 +++++++++++++++++ .../model/parser/yaml/aria/AriaModelParser.java | 6 +-- .../parser/yaml/zte/ToscaYamlModelParser.java | 15 ++++---- .../zte/entity/EnumYamlServiceTemplateInfo.java | 44 +++++++++++----------- 4 files changed, 66 insertions(+), 33 deletions(-) (limited to 'catalog-core/catalog-mgr') diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java index 2c40f832..5b777f9d 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/AbstractModelParser.java @@ -213,4 +213,38 @@ public abstract class AbstractModelParser { return retList.toArray(new InputParameter[0]); } + + /** + * @param metadata + * @return + */ + public String parserServiceTemplateName(Map metadata) { + if (metadata.containsKey("name")) { + return metadata.get("name"); + } + return metadata.get("template_name"); + } + + /** + * @param metadata + * @return + */ + public String parserServiceTemplateVendor(Map metadata) { + if (metadata.containsKey("vendor")) { + return metadata.get("vendor"); + } + return metadata.get("template_author"); + } + + /** + * @param metadata + * @return + */ + public String parserServiceTemplateVersion(Map metadata) { + if (metadata.containsKey("version")) { + return metadata.get("version"); + } + return metadata.get("template_version"); + } + } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java index 2501a158..d70eb932 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/aria/AriaModelParser.java @@ -243,9 +243,9 @@ public class AriaModelParser extends AbstractModelParser { ServiceTemplate st = new ServiceTemplate(); st.setServiceTemplateId(ToolUtil.generateId()); - st.setTemplateName(result.getInstance().getMetadata().get("template_name")); - st.setVendor(result.getInstance().getMetadata().get("template_author")); - st.setVersion(result.getInstance().getMetadata().get("template_version")); + st.setTemplateName(parserServiceTemplateName(result.getInstance().getMetadata())); + st.setVendor(parserServiceTemplateVendor(result.getInstance().getMetadata())); + st.setVersion(parserServiceTemplateVersion(result.getInstance().getMetadata())); st.setCsarId(packageId); st.setDownloadUri(downloadUri); st.setInputs(parseInputs(result)); diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java index f7deaa42..8ec78348 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/ToscaYamlModelParser.java @@ -15,6 +15,10 @@ */ package org.openo.commontosca.catalog.model.parser.yaml.zte; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import org.openo.commontosca.catalog.common.ToolUtil; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.resource.TemplateManager; @@ -27,7 +31,6 @@ import org.openo.commontosca.catalog.model.entity.ServiceTemplate; import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation; import org.openo.commontosca.catalog.model.entity.SubstitutionMapping; import org.openo.commontosca.catalog.model.parser.AbstractModelParser; -import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.EnumYamlServiceTemplateInfo; import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlRequestParemeter; import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult; import org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult.TopologyTemplate.Input; @@ -37,10 +40,6 @@ import org.openo.commontosca.catalog.model.parser.yaml.zte.service.YamlParseServ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.util.ArrayList; -import java.util.List; - public class ToscaYamlModelParser extends AbstractModelParser { private static final Logger logger = LoggerFactory.getLogger(ToscaYamlModelParser.class); @@ -109,9 +108,9 @@ public class ToscaYamlModelParser extends AbstractModelParser { ServiceTemplate st = new ServiceTemplate(); st.setServiceTemplateId(ToolUtil.generateId()); - st.setTemplateName(result.getMetadata().get(EnumYamlServiceTemplateInfo.ID.getName())); - st.setVendor(result.getMetadata().get(EnumYamlServiceTemplateInfo.PROVIDER.getName())); - st.setVersion(result.getMetadata().get(EnumYamlServiceTemplateInfo.VERSION.getName())); + st.setTemplateName(parserServiceTemplateName(result.getMetadata())); + st.setVendor(parserServiceTemplateVendor(result.getMetadata())); + st.setVersion(parserServiceTemplateVersion(result.getMetadata())); st.setCsarId(packageId); st.setDownloadUri(stDownloadUri); st.setInputs(parseInputs(result)); diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java index 18d457eb..a6a75ebf 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/parser/yaml/zte/entity/EnumYamlServiceTemplateInfo.java @@ -16,25 +16,25 @@ package org.openo.commontosca.catalog.model.parser.yaml.zte.entity; -public enum EnumYamlServiceTemplateInfo { - ID { - @Override - public String getName() { - return "id"; - } - }, - VERSION { - @Override - public String getName() { - return "version"; - } - }, - PROVIDER { - @Override - public String getName() { - return "vendor"; - } - }; - - public abstract String getName(); -} +//public enum EnumYamlServiceTemplateInfo { +// ID { +// @Override +// public String getName() { +// return "id"; +// } +// }, +// VERSION { +// @Override +// public String getName() { +// return "version"; +// } +// }, +// PROVIDER { +// @Override +// public String getName() { +// return "vendor"; +// } +// }; +// +// public abstract String getName(); +//} -- cgit 1.2.3-korg