3d32ff66133bfdb9637d8a1c73c8c2aa5ad47947
[clamp.git] / src / main / java / org / onap / clamp / clds / tosca / update / execution / ToscaMetadataExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.tosca.update.execution;
25
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.google.gson.JsonObject;
29 import java.util.HashMap;
30 import java.util.Map;
31 import javax.annotation.PostConstruct;
32 import org.onap.clamp.clds.tosca.update.execution.cds.ToscaMetadataCdsProcess;
33 import org.onap.clamp.clds.tosca.update.execution.target.ToscaMetadataTargetProcess;
34 import org.onap.clamp.loop.service.Service;
35 import org.onap.clamp.tosca.DictionaryService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38
39 /**
40  * This class is used to execute a code based on a key found in the metadata section.
41  */
42 @Component
43 public class ToscaMetadataExecutor {
44
45     private static final EELFLogger logger =
46             EELFManager.getInstance().getLogger(ToscaMetadataExecutor.class);
47
48     @Autowired
49     private DictionaryService dictionaryService;
50
51     private Map<String, ToscaMetadataProcess> mapOfProcesses = new HashMap<>();
52
53     /**
54      * This method executes the required process specified in processInfo
55      *
56      * @param processInfo  A String containing the process to execute, like "cds/param1:value1/param2:value2"
57      * @param childObject  The jsonObject
58      * @param serviceModel The service model associated to do clamp enrichment
59      */
60     public void executeTheProcess(String processInfo, JsonObject childObject, Service serviceModel) {
61         String[] processParameters = (processInfo + "/ ").split("/");
62         logger.info("Executing the Tosca clamp process " + processParameters[0] + " with parameters "
63                 + processParameters[1].trim());
64         mapOfProcesses.get(processParameters[0].trim()).executeProcess(processParameters[1].trim(), childObject, serviceModel);
65     }
66
67     /**
68      * Init method.
69      */
70     @PostConstruct
71     public void init() {
72         mapOfProcesses.put("CDS", new ToscaMetadataCdsProcess());
73         mapOfProcesses.put("CSAR_RESOURCES", new ToscaMetadataTargetProcess());
74     }
75 }