4b2decd4127984215d2b8a1b846b9be608425fd1
[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.onap.config.api.Configuration;
20 import org.onap.config.api.ConfigurationManager;
21 import org.openecomp.core.utilities.CommonMethods;
22 import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
23 import org.openecomp.sdc.common.errors.CoreException;
24 import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.OrchestrationTemplateFileExtensionErrorBuilder;
26
27 import java.util.Map;
28 import java.util.Objects;
29 import java.util.concurrent.ConcurrentHashMap;
30
31 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE;
32 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY;
33
34 public class OrchestrationUploadFactory {
35     private static final Map<String, ImplementationConfiguration> FILE_HANLDERS;
36     private OrchestrationUploadFactory() {
37
38     }
39     static {
40         Configuration config = ConfigurationManager.lookup();
41         FILE_HANLDERS = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE,
42                 ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class));
43
44     }
45
46     public static OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(
47             final OnboardingTypesEnum onboardingType) {
48         final ImplementationConfiguration orchestrationTemplateFileHandler = FILE_HANLDERS.get(onboardingType.toString());
49
50         if(Objects.isNull(orchestrationTemplateFileHandler)){
51             throw new CoreException(new OrchestrationTemplateFileExtensionErrorBuilder
52                 ().build());
53         }
54
55         return  CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(),
56                         OrchestrationTemplateFileHandler.class);
57     }
58 }