diff options
author | Jian Huang <huang.jian12@zte.com.cn> | 2016-10-25 06:09:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@open-o.org> | 2016-10-25 06:09:01 +0000 |
commit | c148cab3258dbc26498f4a78aa0c1f8484285d1b (patch) | |
tree | 823514938f7e61d12f4e9f4cd4f63213e2394622 | |
parent | a9f5cfa9a20ac29fe07f21691927add142cc6c90 (diff) | |
parent | 584fceecfb3d598113f09894431b22dcdab9b30e (diff) |
Merge "Parse Service Template name, vendor and version from metadata." into sun
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(); +//} |