1 package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.common.errors.ErrorCategory;
5 import org.openecomp.sdc.common.errors.ErrorCode;
6 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
7 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
8 import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil;
9 import org.openecomp.sdc.tosca.services.ToscaUtil;
10 import org.openecomp.sdc.translator.utils.ResourceWalker;
12 import java.util.HashMap;
17 * @since April 03, 2017
19 public class GlobalTypesServiceTemplates {
20 private static Map<String, ServiceTemplate> globalTypesServiceTemplates;
23 public static Map<String, ServiceTemplate> getGlobalTypesServiceTemplates() {
24 if (globalTypesServiceTemplates == null) {
25 synchronized (GlobalTypesServiceTemplates.class) {
26 if (globalTypesServiceTemplates == null) {
31 return globalTypesServiceTemplates;
34 private static void init() {
35 globalTypesServiceTemplates = new HashMap<>();
36 Map<String, String> globalTypes = null;
38 globalTypes = ResourceWalker.readResourcesFromDirectory("globalTypes");
39 } catch (CoreException coreException) {
41 } catch (Exception exception) {
42 throw new CoreException((new ErrorCode.ErrorCodeBuilder())
43 .withMessage(LoggerErrorDescription.FAILED_TO_GENERATE_GLOBAL_TYPES)
44 .withId("GlobalTypes Read Error").withCategory(ErrorCategory.APPLICATION).build(),
47 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
48 for (Map.Entry<String, String> globalTypeContent : globalTypes.entrySet()) {
49 if (globalTypeContent.getKey().contains("openecomp-inventory")) { // this global types folder
51 // processed to the CSAR
54 ToscaUtil.addServiceTemplateToMapWithKeyFileName(globalTypesServiceTemplates,
55 toscaExtensionYamlUtil.yamlToObject(globalTypeContent.getValue(), ServiceTemplate.class));
59 private GlobalTypesServiceTemplates() {