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