diff options
8 files changed, 123 insertions, 50 deletions
diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java index 6c591f1c..a26a32bc 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/common/TemplateDataHelper.java @@ -21,6 +21,7 @@ import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; import org.openo.commontosca.catalog.db.entity.TemplateData; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; +import org.openo.commontosca.catalog.db.resource.TemplateManager; import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; import org.openo.commontosca.catalog.model.entity.NodeTemplate; import org.openo.commontosca.catalog.model.entity.Parameters; @@ -68,6 +69,7 @@ public class TemplateDataHelper { String rawData) { ServiceTemplateData std = new ServiceTemplateData(); std.setServiceTemplateId(st.getServiceTemplateId()); + std.setServiceTemplateOriginalId(st.getId()); std.setTemplateName(st.getTemplateName()); std.setVendor(st.getVendor()); std.setVersion(st.getVersion()); @@ -146,9 +148,22 @@ public class TemplateDataHelper { ToolUtil.fromJson(std.getOperations(), ServiceTemplateOperation[].class); String downloadUri = buildSTDownloadUri(std.getCsarId(), std.getDownloadUri()); - return new ServiceTemplate(std.getServiceTemplateId(), std.getTemplateName(), std.getTemplateName(), std.getVendor(), + return new ServiceTemplate(std.getServiceTemplateId(), std.getServiceTemplateOriginalId(), + std.getTemplateName(), std.getVendor(), std.getVersion(), std.getCsarId(), std.getType(), downloadUri, - parameters.getInputs(), parameters.getOutputs(), operations); + parameters.getInputs(), parameters.getOutputs(), operations, + getSubstitutionMappingsByServiceTemplateId(std.getServiceTemplateId())); + } + + private static SubstitutionMapping getSubstitutionMappingsByServiceTemplateId(String serviceTemplateId) + throws CatalogResourceException { + List<ServiceTemplateMappingData> stmDataList = + TemplateManager.getInstance().queryServiceTemplateMapping(null, serviceTemplateId); + if (stmDataList == null || stmDataList.isEmpty()) { + return null; + } + + return convert2SubstitutionMapping(stmDataList.get(0)); } private static String buildSTDownloadUri(String packageId, String stFileName) diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java new file mode 100644 index 00000000..6afbd492 --- /dev/null +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/CapReqMapping.java @@ -0,0 +1,33 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.commontosca.catalog.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author 10090474 + * + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CapReqMapping { + private String mapped_name; + private String node_id; + private String name; +} diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java index cbc75667..6f5dfb3a 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/ServiceTemplate.java @@ -46,4 +46,6 @@ public class ServiceTemplate { private ServiceTemplateOperation[] operations; + private SubstitutionMapping substitution; + } diff --git a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java index cadbb34a..2f34a4a9 100644 --- a/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java +++ b/catalog-core/catalog-mgr/src/main/java/org/openo/commontosca/catalog/model/entity/SubstitutionMapping.java @@ -15,9 +15,6 @@ */ package org.openo.commontosca.catalog.model.entity; -import java.util.HashMap; -import java.util.Map; - import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -32,28 +29,8 @@ public class SubstitutionMapping { @JsonIgnore private String serviceTemplateId; private String nodeType; - private Map<String, String[]> requirements = new HashMap<String, String[]>(); - private Map<String, String[]> capabilities = new HashMap<String, String[]>(); - - /** - * put requirement. - * @param key key - * @param value value - * @return string list - */ - public String[] putRequirement(String key, String[] value) { - return this.requirements.put(key, value); - } - - /** - * put capability. - * @param key key - * @param value value - * @return string list - */ - public String[] putCapability(String key, String[] value) { - return this.capabilities.put(key, value); - } + private CapReqMapping[] requirements; + private CapReqMapping[] capabilities; /** * substitution mapping. 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 fb556543..76cc97a0 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,17 +213,27 @@ public abstract class AbstractModelParser { return retList.toArray(new InputParameter[0]); } - /** * @param metadata * @return */ - public String parserServiceTemplateName(Map<String, String> metadata) { + public String parserId(Map<String, String> metadata) { if (metadata.containsKey("id")) { return metadata.get("id"); } return metadata.get("template_name"); } + + /** + * @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 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 fd2b3507..5145d647 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 @@ -16,7 +16,6 @@ package org.openo.commontosca.catalog.model.parser.yaml.aria; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -26,6 +25,7 @@ import org.openo.commontosca.catalog.db.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.resource.TemplateManager; import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse; import org.openo.commontosca.catalog.model.common.TemplateDataHelper; +import org.openo.commontosca.catalog.model.entity.CapReqMapping; import org.openo.commontosca.catalog.model.entity.InputParameter; import org.openo.commontosca.catalog.model.entity.NodeTemplate; import org.openo.commontosca.catalog.model.entity.OutputParameter; @@ -111,30 +111,30 @@ public class AriaModelParser extends AbstractModelParser { * @param capabilities * @return */ - private Map<String, String[]> parseSubstitutionCapabilities(Mapping[] capabilities) { + private CapReqMapping[] parseSubstitutionCapabilities(Mapping[] capabilities) { return parseMappings(capabilities); } - - - private Map<String, String[]> parseMappings(Mapping[] mappings) { - Map<String, String[]> ret = new HashMap<>(); - if (mappings != null) { - for (Mapping mapping : mappings) { - ret.put(mapping.getMapped_name(), new String[]{mapping.getNode_id(), mapping.getName()}); - } - } - - return ret; - } - + /** * @param requirement * @return */ - private Map<String, String[]> parseSubstitutionRequirements(Mapping[] requirement) { + private CapReqMapping[] parseSubstitutionRequirements(Mapping[] requirement) { return parseMappings(requirement); } + private CapReqMapping[] parseMappings(Mapping[] mappings) { + List<CapReqMapping> ret = new ArrayList<>(); + if (mappings != null) { + for (Mapping mapping : mappings) { + ret.add(new CapReqMapping( + mapping.getMapped_name(), mapping.getNode_id(), mapping.getName())); + } + } + + return ret.toArray(new CapReqMapping[0]); + } + /** * @param result * @return @@ -243,7 +243,7 @@ public class AriaModelParser extends AbstractModelParser { ServiceTemplate st = new ServiceTemplate(); st.setServiceTemplateId(ToolUtil.generateId()); - st.setId(parserServiceTemplateName(result.getInstance().getMetadata())); // TODO + st.setId(parserId(result.getInstance().getMetadata())); st.setTemplateName(parserServiceTemplateName(result.getInstance().getMetadata())); st.setVendor(parserServiceTemplateVendor(result.getInstance().getMetadata())); st.setVersion(parserServiceTemplateVersion(result.getInstance().getMetadata())); 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 4a50b02d..b02a6b23 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 @@ -18,11 +18,14 @@ package org.openo.commontosca.catalog.model.parser.yaml.zte; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import org.openo.commontosca.catalog.common.ToolUtil; import org.openo.commontosca.catalog.db.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.resource.TemplateManager; import org.openo.commontosca.catalog.model.common.TemplateDataHelper; +import org.openo.commontosca.catalog.model.entity.CapReqMapping; import org.openo.commontosca.catalog.model.entity.InputParameter; import org.openo.commontosca.catalog.model.entity.NodeTemplate; import org.openo.commontosca.catalog.model.entity.OutputParameter; @@ -99,8 +102,39 @@ public class ToscaYamlModelParser extends AbstractModelParser { org.openo.commontosca.catalog.model.parser.yaml.zte.entity.ParseYamlResult .TopologyTemplate.SubstitutionMapping stm = result.getTopologyTemplate().getSubstitutionMappings(); - return new SubstitutionMapping(serviceTemplateId, type, stm.getRequirementList(), - stm.getCapabilityList()); + return new SubstitutionMapping( + serviceTemplateId, type, + parseSubstitutionRequirements(stm.getRequirementList()), + parseSubstitutionCapabilities(stm.getCapabilityList())); + } + + /** + * @param requirementList + * @return + */ + private CapReqMapping[] parseSubstitutionRequirements(Map<String, String[]> requirementList) { + return parseMappings(requirementList); + } + + /** + * @param capabilityList + * @return + */ + private CapReqMapping[] parseSubstitutionCapabilities(Map<String, String[]> capabilityList) { + return parseMappings(capabilityList); + } + + private CapReqMapping[] parseMappings(Map<String, String[]> mappings) { + List<CapReqMapping> ret = new ArrayList<>(); + if (mappings != null) { + for (Entry<String, String[]> mapping : mappings.entrySet()) { + if (mapping.getValue().length >= 2) { + ret.add(new CapReqMapping( + mapping.getKey(), mapping.getValue()[0], mapping.getValue()[1])); + } + } + } + return ret.toArray(new CapReqMapping[0]); } private ServiceTemplate parseServiceTemplate(ParseYamlResult result, String packageId, @@ -108,7 +142,7 @@ public class ToscaYamlModelParser extends AbstractModelParser { ServiceTemplate st = new ServiceTemplate(); st.setServiceTemplateId(ToolUtil.generateId()); - st.setId(parserServiceTemplateName(result.getMetadata())); // TODO + st.setId(parserId(result.getMetadata())); st.setTemplateName(parserServiceTemplateName(result.getMetadata())); st.setVendor(parserServiceTemplateVendor(result.getMetadata())); st.setVersion(parserServiceTemplateVersion(result.getMetadata())); diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java index 8a9bf745..76af3744 100644 --- a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/ServiceTemplateWrapperTest.java @@ -55,6 +55,7 @@ import org.openo.commontosca.catalog.model.entity.RelationShip; import org.openo.commontosca.catalog.model.entity.ServiceTemplate; import org.openo.commontosca.catalog.model.entity.ServiceTemplateOperation; import org.openo.commontosca.catalog.model.entity.ServiceTemplateRawData; +import org.openo.commontosca.catalog.model.entity.SubstitutionMapping; import org.openo.commontosca.catalog.model.wrapper.ServiceTemplateWrapper; import java.util.ArrayList; @@ -370,11 +371,12 @@ public class ServiceTemplateWrapperTest { OutputParameter[] outputs = getOutputs(); serviceTemplate.setOutputs(outputs); serviceTemplate.setServiceTemplateId("serviceTemplateId"); - serviceTemplate.setId("templateName"); serviceTemplate.setTemplateName("templateName"); serviceTemplate.setType("NS"); serviceTemplate.setVendor("ZTE"); serviceTemplate.setVersion("0.0.1"); + serviceTemplate.setSubstitution( + new SubstitutionMapping("serviceTemplateId", "tosca.nodes.nfv.VL")); return serviceTemplate; } |