Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / impl / orchestration / OrchestrationUploadFactory.java
1 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
2
3 import org.openecomp.config.api.Configuration;
4 import org.openecomp.config.api.ConfigurationManager;
5 import org.openecomp.core.utilities.CommonMethods;
6 import org.openecomp.sdc.common.errors.CoreException;
7 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.OrchestrationTemplateFileExtensionErrorBuilder;
9
10 import java.util.Map;
11 import java.util.Objects;
12 import java.util.concurrent.ConcurrentHashMap;
13
14 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE;
15 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY;
16
17 public class OrchestrationUploadFactory {
18     private static Map<String, ImplementationConfiguration> fileHanlders;
19
20     static {
21         Configuration config = ConfigurationManager.lookup();
22         fileHanlders = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE,
23                 ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class));
24
25     }
26
27     public static final OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(String fileSuffix) {
28         String fileExtension = fileSuffix.toLowerCase();
29         ImplementationConfiguration orchestrationTemplateFileHandler = fileHanlders.get(fileExtension);
30
31         if(Objects.isNull(orchestrationTemplateFileHandler)){
32             throw new CoreException(new OrchestrationTemplateFileExtensionErrorBuilder
33                 ().build());
34         }
35
36         return  CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(),
37                         OrchestrationTemplateFileHandler.class);
38     }
39 }