Rename packages from openecomp to onap.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / impl / orchestration / process / OrchestrationProcessFactory.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.process;
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.datatypes.configuration.ImplementationConfiguration;
24 import org.openecomp.sdc.vendorsoftwareproduct.types.ConfigConstants;
25 import java.util.Map;
26 import java.util.Optional;
27 import java.util.concurrent.ConcurrentHashMap;
28
29 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE;
30 public class OrchestrationProcessFactory {
31
32   private static final Map<String, ImplementationConfiguration> PROCESS_IMPL_MAP;
33   private OrchestrationProcessFactory() {
34
35   }
36
37   static {
38     Configuration config = ConfigurationManager.lookup();
39     PROCESS_IMPL_MAP = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE,
40         ConfigConstants.PROCESS_IMPL_KEY, ImplementationConfiguration.class));
41
42   }
43
44   public static Optional<OrchestrationTemplateProcessHandler> getInstance(String fileSuffix) {
45
46     if (fileSuffix == null) {
47       return Optional.empty();
48     }
49     String updatedFileSuffix = fileSuffix;
50     updatedFileSuffix = updatedFileSuffix.toLowerCase().trim();
51     OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(updatedFileSuffix);
52     if (onboardingTypesEnum == null) {
53       return Optional.empty();
54     }
55
56     try {
57       return Optional.of(createInstance(PROCESS_IMPL_MAP.get(onboardingTypesEnum.toString())));
58     }catch (Exception e){
59       return Optional.empty();
60     }
61   }
62
63   private static OrchestrationTemplateProcessHandler createInstance(ImplementationConfiguration implClass)
64       throws Exception {
65     OrchestrationTemplateProcessHandler handler;
66     handler =
67         CommonMethods.newInstance(implClass.getImplementationClass(), OrchestrationTemplateProcessHandler.class);
68     return handler;
69   }
70 }