Simplified the return condition 07/26207/6
authorojasdubey <ojas.dubey@amdocs.com>
Wed, 13 Dec 2017 10:53:43 +0000 (16:23 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Wed, 27 Dec 2017 09:37:31 +0000 (09:37 +0000)
Note: Sonar violations will be handled as a separate
task

Change-Id: I862247f5c693f4d64dff4ce18f2f71e42c85355a
Issue-ID: SDC-749
Signed-off-by: ojasdubey <ojas.dubey@amdocs.com>
17 files changed:
openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/ForwarderCapabilityHealer.java
openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/tosca/PortMirroringEnricher.java
openecomp-be/lib/openecomp-sdc-tosca-generator-lib/openecomp-sdc-tosca-generator-core/src/main/java/org/openecomp/sdc/generator/core/services/ManualVspToscaGenerationService.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesGenerator.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplates.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplatesTest.java [new file with mode: 0644]
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/datatypes/Constants.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/GlobalSubstitutionServiceTemplate.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/ToscaConverterImpl.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/conversionWithInt/out/MainServiceTemplate.yaml
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertCsar/out/MainServiceTemplate.yaml
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertMainSt/out/MainServiceTemplate.yaml
openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/mock/toscaConverter/convertParameters/out/MainServiceTemplate.yaml

index 85fe305..91cbc2c 100644 (file)
@@ -1,10 +1,26 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.core.utilities.orchestration;
 
 import java.util.Optional;
 
 import static java.util.Arrays.asList;
 public enum OnboardingTypesEnum {
-    CSAR("csar"), ZIP("zip"), NONE("none");
+    CSAR("csar"), ZIP("zip"), MANUAL("manual"), NONE("none");
     private String type;
 
     OnboardingTypesEnum(String type) {
index 7991c59..f3e5f4d 100644 (file)
@@ -1,9 +1,26 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.sdc.healing.healers;
 
 import org.apache.commons.collections.MapUtils;
 import org.openecomp.core.model.dao.ServiceModelDao;
 import org.openecomp.core.model.dao.ServiceModelDaoFactory;
 import org.openecomp.core.model.types.ServiceElement;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.common.togglz.ToggleableFeature;
 import org.openecomp.sdc.healing.interfaces.Healer;
 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
@@ -76,7 +93,7 @@ public class ForwarderCapabilityHealer implements Healer {
 
   private void handleGlobalTypes(ToscaServiceModel serviceModel) {
     Map<String, ServiceTemplate> globalTypesServiceTemplates =
-        GlobalTypesServiceTemplates.getGlobalTypesServiceTemplates();
+        GlobalTypesServiceTemplates.getGlobalTypesServiceTemplates(OnboardingTypesEnum.ZIP);
 
     if (MapUtils.isEmpty(globalTypesServiceTemplates)) {
       return;
index a855a74..f731e37 100644 (file)
@@ -1,7 +1,24 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.sdc.enrichment.impl.tosca;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.datatypes.error.ErrorMessage;
 import org.openecomp.sdc.enrichment.impl.tosca.model.PortMirroringConnectionPointDescription;
 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
@@ -49,7 +66,7 @@ public class PortMirroringEnricher {
   private Map<String, List<String>> portNodeTemplateIdsFromAbstract = new HashMap<>();
   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
   private Map<String, ServiceTemplate> globalTypesServiceTemplate =
-      GlobalTypesGenerator.getGlobalTypesServiceTemplate();
+      GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
 
   /**
    * Enrich tosca for port mirroring.
index 8234179..ab57506 100644 (file)
@@ -1,7 +1,24 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.sdc.generator.core.services;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.generator.core.utils.GeneratorUtils;
 import org.openecomp.sdc.generator.datatypes.tosca.MultiFlavorVfcImage;
 import org.openecomp.sdc.generator.datatypes.tosca.VspModelInfo;
@@ -69,7 +86,7 @@ public class ManualVspToscaGenerationService {
     ToscaServiceModel toscaServiceModel = new ToscaServiceModel();
     ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
     Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(GlobalTypesGenerator
-        .getGlobalTypesServiceTemplate());
+        .getGlobalTypesServiceTemplate(OnboardingTypesEnum.MANUAL));
     toscaServiceModel.setServiceTemplates(serviceTemplates);
     toscaServiceModel.setEntryDefinitionServiceTemplate(Constants.MAIN_TEMPLATE_NAME
         + TOSCA_SERVICE_TEMPLATE_FILE_NAME_SUFFIX);
index 675a2c5..d2ad6da 100644 (file)
@@ -1,21 +1,17 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
  * 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.
- * ============LICENSE_END=========================================================
  */
 
 package org.openecomp.sdc.translator.datatypes.heattotosca;
@@ -25,6 +21,7 @@ import org.openecomp.config.api.Configuration;
 import org.openecomp.config.api.ConfigurationManager;
 import org.openecomp.core.utilities.CommonMethods;
 import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.utils.SdcCommon;
 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
@@ -70,7 +67,8 @@ public class TranslationContext {
     translationMapping =
         config.generateMap(ConfigConstants.MAPPING_NAMESPACE, ConfigConstants.RESOURCE_MAPPING_KEY);
     try {
-      globalServiceTemplates = GlobalTypesGenerator.getGlobalTypesServiceTemplate();
+      globalServiceTemplates =
+          GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
     } catch (Exception exc) {
       throw new RuntimeException("Failed to load GlobalTypes", exc);
     }
index 9d875d2..a0a7a51 100644 (file)
@@ -1,21 +1,17 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
  * 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.
- * ============LICENSE_END=========================================================
  */
 
 package org.openecomp.sdc.translator.services.heattotosca;
@@ -27,6 +23,7 @@ import org.openecomp.core.translator.datatypes.TranslatorOutput;
 import org.openecomp.core.translator.factory.HeatToToscaTranslatorFactory;
 import org.openecomp.core.utilities.file.FileContentHandler;
 import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.core.validation.util.MessageContainerUtil;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.togglz.ToggleableFeature;
@@ -1457,7 +1454,8 @@ public class HeatToToscaUtil {
     mdcDataDebugMessage.debugEntryMessage(null, null);
 
     List<ServiceTemplate> serviceTemplates = new ArrayList<>();
-    serviceTemplates.addAll(GlobalTypesGenerator.getGlobalTypesServiceTemplate().values());
+    serviceTemplates.addAll(GlobalTypesGenerator
+        .getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP).values());
     serviceTemplates.addAll(translationContext.getTranslatedServiceTemplates().values());
     Map<String, ServiceTemplate> serviceTemplatesMap = new HashMap<>();
 
index 9eadfc2..ecc0a5f 100644 (file)
@@ -1,25 +1,22 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
  * 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.
- * ============LICENSE_END=========================================================
  */
 
 package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
 
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.tosca.datatypes.model.Import;
 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
 import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
@@ -40,8 +37,9 @@ public class GlobalTypesGenerator {
    *
    * @return the global types service template
    */
-  public static Map<String, ServiceTemplate> getGlobalTypesServiceTemplate() {
-    return GlobalTypesServiceTemplates.getGlobalTypesServiceTemplates();
+  public static Map<String, ServiceTemplate> getGlobalTypesServiceTemplate(OnboardingTypesEnum
+                                                                               onboardingType) {
+    return GlobalTypesServiceTemplates.getGlobalTypesServiceTemplates(onboardingType);
   }
 
   /**
@@ -53,7 +51,7 @@ public class GlobalTypesGenerator {
     List<Map<String, Import>> globalImports = new ArrayList<>();
     Map<String, Import> globalImportMap = new HashMap<>();
     Map<String, ServiceTemplate> globalTypesServiceTemplate =
-        GlobalTypesGenerator.getGlobalTypesServiceTemplate();
+        GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.ZIP);
     globalImportMap.put("openecomp_heat_index",
         HeatToToscaUtil.createServiceTemplateImport(globalTypesServiceTemplate.get
             ("openecomp-heat/_index.yml")));
@@ -70,7 +68,7 @@ public class GlobalTypesGenerator {
     List<Map<String, Import>> globalImports = new ArrayList<>();
     Map<String, Import> globalImportMap = new HashMap<>();
     Map<String, ServiceTemplate> globalTypesServiceTemplate =
-        GlobalTypesGenerator.getGlobalTypesServiceTemplate();
+        GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.MANUAL);
     globalImportMap.put("openecomp_index",
         HeatToToscaUtil.createServiceTemplateImport(globalTypesServiceTemplate.get
             ("openecomp/_index.yml")));
index dff208f..5490452 100644 (file)
@@ -1,5 +1,22 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.sdc.translator.services.heattotosca.globaltypes;
 
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.ErrorCategory;
 import org.openecomp.sdc.common.errors.ErrorCode;
@@ -9,31 +26,20 @@ import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil;
 import org.openecomp.sdc.tosca.services.ToscaUtil;
 import org.openecomp.sdc.translator.utils.ResourceWalker;
 
+import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.Map;
 
-/**
- * @author Avrahamg
- * @since April 03, 2017
- */
 public class GlobalTypesServiceTemplates {
-  private static Map<String, ServiceTemplate> globalTypesServiceTemplates;
 
+  private static final Map<OnboardingTypesEnum, Map<String, ServiceTemplate>>
+      onboardingGlobalTypesServiceTemplates;
 
-  public static Map<String, ServiceTemplate> getGlobalTypesServiceTemplates() {
-    if (globalTypesServiceTemplates == null) {
-      synchronized (GlobalTypesServiceTemplates.class) {
-        if (globalTypesServiceTemplates == null) {
-          init();
-        }
-      }
-    }
-    return globalTypesServiceTemplates;
+  private GlobalTypesServiceTemplates() {
   }
 
-  private static void init() {
-    globalTypesServiceTemplates = new HashMap<>();
-    Map<String, String> globalTypes = null;
+  static {
+    Map<String, String> globalTypes;
     try {
       globalTypes = ResourceWalker.readResourcesFromDirectory("globalTypes");
     } catch (CoreException coreException) {
@@ -44,18 +50,66 @@ public class GlobalTypesServiceTemplates {
           .withId("GlobalTypes Read Error").withCategory(ErrorCategory.APPLICATION).build(),
           exception);
     }
+    onboardingGlobalTypesServiceTemplates = init(globalTypes);
+  }
+
+  public static Map<String, ServiceTemplate> getGlobalTypesServiceTemplates(OnboardingTypesEnum
+                                                                                onboardingType) {
+    if (onboardingType == null) {
+      throw new CoreException((new ErrorCode.ErrorCodeBuilder())
+          .withMessage(LoggerErrorDescription.FAILED_TO_GENERATE_GLOBAL_TYPES)
+          .withId("Invalid Onboarding Type").withCategory(ErrorCategory.APPLICATION).build());
+    }
+    return onboardingGlobalTypesServiceTemplates.get(onboardingType);
+  }
+
+  private static Map<OnboardingTypesEnum, Map<String, ServiceTemplate>>
+                                      init(Map<String, String> globalTypes) {
+    Map<OnboardingTypesEnum, Map<String, ServiceTemplate>>
+        onboardingGlobalTypesServiceTemplates = new EnumMap<>(OnboardingTypesEnum.class);
+    Map<String, ServiceTemplate> zipOnboardingGlobalTypes =
+        getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.ZIP);
+    Map<String, ServiceTemplate> csarOnboardingGlobalTypes =
+        getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.CSAR);
+    Map<String, ServiceTemplate> manualOnboardingGlobalTypes =
+        getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.MANUAL);
+    Map<String, ServiceTemplate> defaultOnboardingGlobalTypes =
+        getOnboardingGlobalTypes(globalTypes, OnboardingTypesEnum.NONE);
+    onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.ZIP, zipOnboardingGlobalTypes);
+    onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.CSAR, csarOnboardingGlobalTypes);
+    onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.MANUAL,
+        manualOnboardingGlobalTypes);
+    onboardingGlobalTypesServiceTemplates.put(OnboardingTypesEnum.NONE,
+        defaultOnboardingGlobalTypes);
+    return onboardingGlobalTypesServiceTemplates;
+  }
+
+  private static Map<String, ServiceTemplate> getOnboardingGlobalTypes(Map<String, String>
+                                                                         globalTypes,
+                                                                       OnboardingTypesEnum
+                                                                           onboardingType) {
+    Map<String, ServiceTemplate> globalTypesServiceTemplates = new HashMap<>();
     ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
     for (Map.Entry<String, String> globalTypeContent : globalTypes.entrySet()) {
-      if (globalTypeContent.getKey().contains("openecomp-inventory")) { // this global types folder
-        // should not be
-        // processed to the CSAR
+      if (!isTypeValidCandidateForCsarPacking(globalTypeContent.getKey(), onboardingType)) {
+        // this global types folders should not be processed to the CSAR
         continue;
       }
       ToscaUtil.addServiceTemplateToMapWithKeyFileName(globalTypesServiceTemplates,
           toscaExtensionYamlUtil.yamlToObject(globalTypeContent.getValue(), ServiceTemplate.class));
     }
+    return globalTypesServiceTemplates;
   }
 
-  private GlobalTypesServiceTemplates() {
+  private static boolean isTypeValidCandidateForCsarPacking(String globalTypeResourceKey,
+                                                            OnboardingTypesEnum
+                                                                onboardingType) {
+    if (globalTypeResourceKey.contains("openecomp-inventory")) {
+      // this global types folders should not be processed to the CSAR
+      return false;
+    }
+    //Global types specific to csar onboarding should not be packed for other onboarding types
+    return !globalTypeResourceKey.contains("onap") || onboardingType == OnboardingTypesEnum.CSAR;
   }
+
 }
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplatesTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/globaltypes/GlobalTypesServiceTemplatesTest.java
new file mode 100644 (file)
index 0000000..d97128e
--- /dev/null
@@ -0,0 +1,93 @@
+/*\r
+ * Copyright © 2016-2017 European Support Limited\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.openecomp.sdc.translator.services.heattotosca.globaltypes;\r
+\r
+import static org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesServiceTemplates.getGlobalTypesServiceTemplates;\r
+\r
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;\r
+import org.openecomp.sdc.common.errors.CoreException;\r
+import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;\r
+import org.testng.Assert;\r
+import org.testng.annotations.Test;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.stream.Collectors;\r
+\r
+public class GlobalTypesServiceTemplatesTest {\r
+\r
+  @Test(expectedExceptions = CoreException.class,\r
+      expectedExceptionsMessageRegExp = "Failed to generate globalTypes")\r
+  public void testGetGlobalTypesServiceTemplatesOnboardingMethodNull() {\r
+    Map<String, ServiceTemplate> globalTypesServiceTemplates = getGlobalTypesServiceTemplates(null);\r
+  }\r
+\r
+  @Test\r
+  public void testGetGlobalTypesServiceTemplatesOnboardingMethodToscaCsar() {\r
+    Map<String, ServiceTemplate> globalTypesServiceTemplates =\r
+        getGlobalTypesServiceTemplates(OnboardingTypesEnum.CSAR);\r
+    Assert.assertNotNull(globalTypesServiceTemplates);\r
+    Assert.assertEquals(globalTypesServiceTemplates.size(), 24);\r
+    Set<String> globalTypeFolders = globalTypesServiceTemplates.keySet();\r
+    List<String> onapGlobalTypes = globalTypeFolders.stream()\r
+        .filter(resourceKey -> resourceKey.contains("onap"))\r
+        .collect(Collectors.toList());\r
+    Assert.assertNotNull(onapGlobalTypes);\r
+    Assert.assertEquals(onapGlobalTypes.size(), 5);\r
+  }\r
+\r
+  @Test\r
+  public void testGetGlobalTypesServiceTemplatesOnboardingMethodHeat() {\r
+    Map<String, ServiceTemplate> globalTypesServiceTemplates =\r
+        getGlobalTypesServiceTemplates(OnboardingTypesEnum.ZIP);\r
+    Assert.assertNotNull(globalTypesServiceTemplates);\r
+    Assert.assertEquals(globalTypesServiceTemplates.size(), 19);\r
+    Set<String> globalTypeFolders = globalTypesServiceTemplates.keySet();\r
+    List<String> onapGlobalTypes = globalTypeFolders.stream()\r
+        .filter(resourceKey -> resourceKey.contains("onap"))\r
+        .collect(Collectors.toList());\r
+    Assert.assertEquals(onapGlobalTypes.size(), 0);\r
+  }\r
+\r
+  @Test\r
+  public void testGetGlobalTypesServiceTemplatesOnboardingMethodManual() {\r
+    Map<String, ServiceTemplate> globalTypesServiceTemplates =\r
+        getGlobalTypesServiceTemplates(OnboardingTypesEnum.MANUAL);\r
+    Assert.assertNotNull(globalTypesServiceTemplates);\r
+    Assert.assertEquals(globalTypesServiceTemplates.size(), 19);\r
+    Set<String> globalTypeFolders = globalTypesServiceTemplates.keySet();\r
+    List<String> onapGlobalTypes = globalTypeFolders.stream()\r
+        .filter(resourceKey -> resourceKey.contains("onap"))\r
+        .collect(Collectors.toList());\r
+    Assert.assertEquals(onapGlobalTypes.size(), 0);\r
+  }\r
+\r
+  @Test\r
+  public void testGetGlobalTypesServiceTemplatesOnboardingMethodNone() {\r
+    Map<String, ServiceTemplate> globalTypesServiceTemplates =\r
+        getGlobalTypesServiceTemplates(OnboardingTypesEnum.NONE);\r
+    Assert.assertNotNull(globalTypesServiceTemplates);\r
+    Assert.assertEquals(globalTypesServiceTemplates.size(), 19);\r
+    Set<String> globalTypeFolders = globalTypesServiceTemplates.keySet();\r
+    List<String> onapGlobalTypes = globalTypeFolders.stream()\r
+        .filter(resourceKey -> resourceKey.contains("onap"))\r
+        .collect(Collectors.toList());\r
+    Assert.assertEquals(onapGlobalTypes.size(), 0);\r
+  }\r
+\r
+}\r
\ No newline at end of file
index 6f7e6be..90ce3f6 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.core.converter.datatypes;
 
 import java.io.File;
@@ -39,6 +55,7 @@ public class Constants {
   public static final String requirements = "requirements";
 
   public static final String openecompHeatIndex = "openecomp_heat_index";
+  public static final String ONAP_INDEX = "onap_index";
   public static final String globalSubstitution = "GlobalSubstitutionTypes";
 
   public static final String externalFilesFolder = "External" + File.separator;
index 4ff8af4..4a1f7c5 100644 (file)
@@ -1,6 +1,25 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.core.impl;
 
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
+
 import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.logging.api.Logger;
 import org.openecomp.sdc.logging.api.LoggerFactory;
 import org.openecomp.sdc.tosca.datatypes.model.Import;
@@ -23,8 +42,10 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
     public static final String TEMPLATE_NAME_PROPERTY = "template_name";
     public static final String DEFININTION_VERSION = "tosca_simple_yaml_1_0_0";
     public static final String HEAT_INDEX = "openecomp_heat_index";
+    public static final String HEAT_INDEX_IMPORT_FILE = "openecomp-heat/_index.yml";
+    public static final String ONAP_INDEX_IMPORT_FILE = "onap/_index.yml";
     private static final Map<String, ServiceTemplate> globalServiceTemplates =
-        GlobalTypesGenerator.getGlobalTypesServiceTemplate();
+        GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR);
 
     public GlobalSubstitutionServiceTemplate() {
         super();
@@ -52,8 +73,11 @@ public class GlobalSubstitutionServiceTemplate extends ServiceTemplate {
         imports.add(stringImportMap);
         setImports(imports);
         Import imprtObj = new Import();
-        imprtObj.setFile("openecomp-heat/_index.yml");
-        stringImportMap.put("openecomp_heat_index", imprtObj);
+        imprtObj.setFile(HEAT_INDEX_IMPORT_FILE);
+        stringImportMap.put(HEAT_INDEX, imprtObj);
+        Import onapDefinitionsImport = new Import();
+        onapDefinitionsImport.setFile(ONAP_INDEX_IMPORT_FILE);
+        stringImportMap.put(ONAP_INDEX, onapDefinitionsImport);
     }
 
 
index 39a53b4..283f7fc 100644 (file)
@@ -1,5 +1,38 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * 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.openecomp.core.impl;
 
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
+import static org.openecomp.core.converter.datatypes.Constants.capabilities;
+import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
+import static org.openecomp.core.converter.datatypes.Constants.globalStName;
+import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
+import static org.openecomp.core.converter.datatypes.Constants.inputs;
+import static org.openecomp.core.converter.datatypes.Constants.mainStName;
+import static org.openecomp.core.converter.datatypes.Constants.manifestFileName;
+import static org.openecomp.core.converter.datatypes.Constants.metadataFile;
+import static org.openecomp.core.converter.datatypes.Constants.nodeType;
+import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
+import static org.openecomp.core.converter.datatypes.Constants.outputs;
+import static org.openecomp.core.converter.datatypes.Constants.requirements;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
+
 import org.apache.commons.collections.MapUtils;
 import org.openecomp.core.converter.ServiceTemplateReaderService;
 import org.openecomp.core.converter.ToscaConverter;
@@ -8,6 +41,7 @@ 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.orchestration.OnboardingTypesEnum;
 import org.openecomp.sdc.common.errors.CoreException;
 import org.openecomp.sdc.common.errors.ErrorCategory;
 import org.openecomp.sdc.common.errors.ErrorCode;
@@ -41,20 +75,6 @@ import java.util.Optional;
 import java.util.jar.Manifest;
 import java.util.regex.Pattern;
 
-import static org.openecomp.core.converter.datatypes.Constants.capabilities;
-import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
-import static org.openecomp.core.converter.datatypes.Constants.globalStName;
-import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
-import static org.openecomp.core.converter.datatypes.Constants.inputs;
-import static org.openecomp.core.converter.datatypes.Constants.mainStName;
-import static org.openecomp.core.converter.datatypes.Constants.manifestFileName;
-import static org.openecomp.core.converter.datatypes.Constants.metadataFile;
-import static org.openecomp.core.converter.datatypes.Constants.nodeType;
-import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
-import static org.openecomp.core.converter.datatypes.Constants.outputs;
-import static org.openecomp.core.converter.datatypes.Constants.requirements;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
-
 public class ToscaConverterImpl implements ToscaConverter {
 
     public ToscaConverterImpl() {
@@ -138,7 +158,7 @@ public class ToscaConverterImpl implements ToscaConverter {
                                          GlobalSubstitutionServiceTemplate globalSubstitutionServiceTemplate,
                                          Map<String, byte[]> csarFiles) {
         Collection<ServiceTemplate> globalServiceTemplates =
-            GlobalTypesGenerator.getGlobalTypesServiceTemplate().values();
+            GlobalTypesGenerator.getGlobalTypesServiceTemplate(OnboardingTypesEnum.CSAR).values();
         addGlobalServiceTemplates(globalServiceTemplates, serviceTemplates);
         toscaServiceModel.setEntryDefinitionServiceTemplate(mainStName);
         toscaServiceModel.setServiceTemplates(serviceTemplates);
@@ -224,7 +244,8 @@ public class ToscaConverterImpl implements ToscaConverter {
     private void convertImports(ServiceTemplate serviceTemplate) {
         serviceTemplate.setImports(new ArrayList<>());
         serviceTemplate.getImports()
-            .add(createImportMap(openecompHeatIndex, "openecomp-heat/_index.yml"));
+            .add(createImportMap(openecompHeatIndex, HEAT_INDEX_IMPORT_FILE));
+        serviceTemplate.getImports().add(createImportMap(ONAP_INDEX, ONAP_INDEX_IMPORT_FILE));
         serviceTemplate.getImports().add(createImportMap(globalSubstitution, globalStName));
 
     }
index 82a3695..0fec361 100644 (file)
@@ -1,5 +1,16 @@
 package org.openecomp.core.converter.impl;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.DEFININTION_VERSION;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.TEMPLATE_NAME_PROPERTY;
+import static org.openecomp.sdc.common.utils.CommonUtil.validateAndUploadFileContent;
+
 import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 import org.openecomp.core.impl.GlobalSubstitutionServiceTemplate;
@@ -12,16 +23,6 @@ import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
 import java.net.URL;
 import java.util.Map;
 import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.DEFININTION_VERSION;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.TEMPLATE_NAME_PROPERTY;
-import static org.openecomp.sdc.common.utils.CommonUtil.validateAndUploadFileContent;
 public class ToscaConvertorDefinitionsTest {
 
 
@@ -48,6 +49,7 @@ public class ToscaConvertorDefinitionsTest {
         assertFalse(serviceTemplate.getImports().isEmpty());
         assertEquals(1 ,serviceTemplate.getImports().size());
         assertTrue(serviceTemplate.getImports().get(0).containsKey(HEAT_INDEX));
+        assertTrue(serviceTemplate.getImports().get(0).containsKey(ONAP_INDEX));
 
         assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());