summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Gaffa <avi.gaffa@amdocs.com>2017-11-16 07:02:02 +0000
committerGerrit Code Review <gerrit@onap.org>2017-11-16 07:02:02 +0000
commit5d0f52a1833aa44bb740f6ca6152cdb3846691a7 (patch)
treef6557be41a4b29a096d2dba12a2ff10f3701250d
parentd83844341d03178eab318404fe46661837e5a69e (diff)
parent0872b963f2b2c0db594cea153efd09ad43c48888 (diff)
Merge "import tosca"
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java20
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java49
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java4
3 files changed, 63 insertions, 10 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java
new file mode 100644
index 0000000000..9ae66dd91c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/errors/SubstitutionMappingsConverterErrorBuilder.java
@@ -0,0 +1,20 @@
+package org.openecomp.core.converter.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+public class SubstitutionMappingsConverterErrorBuilder extends BaseErrorBuilder {
+ private static final String SUB_MAPPINGS_CAPABILITY_REQUIREMENT_ENTRY_VALUE_ILLEGAL = "%s value" +
+ " in substitution mappings is invalid, expected it to be %s";
+ private static final String IMPORT_TOSCA = "IMPORT_TOSCA";
+
+
+ public SubstitutionMappingsConverterErrorBuilder(String section,
+ String expectedType) {
+ getErrorCodeBuilder()
+ .withId(IMPORT_TOSCA)
+ .withCategory(ErrorCategory.APPLICATION)
+ .withMessage(String.format(SUB_MAPPINGS_CAPABILITY_REQUIREMENT_ENTRY_VALUE_ILLEGAL, section, expectedType));
+
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
index 9b694c5207..685f39c3cb 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
@@ -1,10 +1,12 @@
package org.openecomp.core.impl;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.core.converter.ServiceTemplateReaderService;
import org.openecomp.core.converter.ToscaConverter;
import org.openecomp.core.converter.datatypes.Constants;
import org.openecomp.core.converter.datatypes.CsarFileTypes;
+import org.openecomp.core.converter.errors.SubstitutionMappingsConverterErrorBuilder;
import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.json.JsonUtil;
@@ -326,16 +328,51 @@ public class ToscaConverterImpl implements ToscaConverter {
SubstitutionMapping substitutionMapping = new SubstitutionMapping();
substitutionMapping.setNode_type((String) substitutionMappings.get(nodeType));
- substitutionMapping.setCapabilities(
- convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(capabilities)));
- substitutionMapping.setRequirements(
- convertSubstitutionMappingsSections((Map<String, Object>) substitutionMappings.get(requirements)));
+ setSubstitutionMappingsSection(
+ capabilities, substitutionMapping,
+ convertSubstitutionMappingsSections(capabilities, substitutionMappings.get(capabilities)));
+ setSubstitutionMappingsSection(
+ requirements, substitutionMapping,
+ convertSubstitutionMappingsSections(requirements, substitutionMappings.get(requirements)));
return substitutionMapping;
}
- private Map<String, List<String>> convertSubstitutionMappingsSections(
- Map<String, Object> sectionToConvert) {
+ private void setSubstitutionMappingsSection(String sectionName,
+ SubstitutionMapping substitutionMapping,
+ Map<String, List<String>> convertedSection) {
+ if(MapUtils.isEmpty(convertedSection)
+ || StringUtils.isEmpty(sectionName)
+ || Objects.isNull(substitutionMapping)){
+ return;
+ }
+
+ switch (sectionName){
+ case requirements:
+ substitutionMapping.setRequirements(convertedSection);
+ break;
+ case capabilities:
+ substitutionMapping.setCapabilities(convertedSection);
+ break;
+ }
+ }
+
+ private Map<String, List<String>> convertSubstitutionMappingsSections(String sectionName,
+ Object sectionToConvert) {
+ if(Objects.isNull(sectionToConvert)){
+ return null;
+ }
+
+ if(!(sectionToConvert instanceof Map)){
+ throw new CoreException(
+ new SubstitutionMappingsConverterErrorBuilder(
+ sectionName, "Map").build());
+ }
+
+ return convertSubstitutionMappongsSection((Map<String, Object>) sectionToConvert);
+ }
+
+ private Map<String, List<String>> convertSubstitutionMappongsSection(Map<String, Object> sectionToConvert) {
Map<String, List<String>> convertedSection = new HashMap<>();
if (MapUtils.isEmpty(sectionToConvert)) {
return null;
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
index fa8532546c..8155fcc7f6 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java
@@ -1,11 +1,7 @@
package org.openecomp.core.impl.services;
import org.openecomp.core.converter.ServiceTemplateReaderService;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.tosca.services.YamlUtil;
-import org.yaml.snakeyaml.error.YAMLException;
import java.util.HashMap;
import java.util.Map;
id='n433' href='#n433'>433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568