52913c9f8276bd4191b88fb886287227652ca09b
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / impl / orchestration / OrchestrationUploadFactory.java
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
18
19 import org.openecomp.config.api.Configuration;
20 import org.openecomp.config.api.ConfigurationManager;
21 import org.openecomp.core.utilities.CommonMethods;
22 import org.openecomp.sdc.common.errors.CoreException;
23 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
24 import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.OrchestrationTemplateFileExtensionErrorBuilder;
25
26 import java.util.Map;
27 import java.util.Objects;
28 import java.util.concurrent.ConcurrentHashMap;
29
30 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE;
31 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY;
32
33 public class OrchestrationUploadFactory {
34     private static final Map<String, ImplementationConfiguration> FILE_HANLDERS;
35     private OrchestrationUploadFactory() {
36
37     }
38     static {
39         Configuration config = ConfigurationManager.lookup();
40         FILE_HANLDERS = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE,
41                 ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class));
42
43     }
44
45     public static OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(String fileSuffix) {
46         String fileExtension = fileSuffix.toLowerCase();
47         ImplementationConfiguration orchestrationTemplateFileHandler = FILE_HANLDERS.get(fileExtension);
48
49         if(Objects.isNull(orchestrationTemplateFileHandler)){
50             throw new CoreException(new OrchestrationTemplateFileExtensionErrorBuilder
51                 ().build());
52         }
53
54         return  CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(),
55                         OrchestrationTemplateFileHandler.class);
56     }
57 }