diff options
author | YuanHu <yuan.hu1@zte.com.cn> | 2016-10-25 11:47:51 +0800 |
---|---|---|
committer | YuanHu <yuan.hu1@zte.com.cn> | 2016-10-25 11:49:36 +0800 |
commit | 584fceecfb3d598113f09894431b22dcdab9b30e (patch) | |
tree | 31a17a7d4fc34119fa7815c6a85847ea982adc08 | |
parent | 8d4b7287de21461afaf6c26832346f1ef769f700 (diff) |
Parse Service Template name, vendor and version from metadata.
Change-Id: I40719faec2f8bf41147664394446b33cc2d3b06d
Issue-id: TOSCA-141
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
4 files changed, 66 insertions, 33 deletions
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<String, String> metadata) { + if (metadata.containsKey("name")) { + return metadata.get("name"); + } + return metadata.get("template_name"); + } + + /** + * @param metadata + * @return + */ + public String parserServiceTemplateVendor(Map<String, String> metadata) { + if (metadata.containsKey("vendor")) { + return metadata.get("vendor"); + } + return metadata.get("template_author"); + } + + /** + * @param metadata + * @return + */ + public String parserServiceTemplateVersion(Map<String, String> 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(); +//} |