dbd8ee1bca88745708397783b636d85fe8adb227
[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.Dictionary;
36 import org.onap.clamp.tosca.DictionaryElement;
37 import org.onap.clamp.tosca.DictionaryService;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
40
41 /**
42  * This class is used to execute a code based on a key found in the metadata section.
43  */
44 @Component
45 public class ToscaMetadataExecutor {
46
47     private static final EELFLogger logger =
48             EELFManager.getInstance().getLogger(ToscaMetadataExecutor.class);
49
50     @Autowired
51     private DictionaryService dictionaryService;
52
53     private Map<String, ToscaMetadataProcess> mapOfProcesses = new HashMap<>();
54
55     /**
56      * This method executes the required process specified in processInfo
57      *
58      * @param processInfo  A String containing the process to execute, like "cds/param1:value1/param2:value2"
59      * @param childObject  The jsonObject
60      * @param serviceModel The service model associated to do clamp enrichment
61      */
62     public void executeTheProcess(String processInfo, JsonObject childObject, Service serviceModel) {
63         String[] processParameters = (processInfo + "/ ").split("/");
64         logger.info("Executing the Tosca clamp process " + processParameters[0] + " with parameters "
65                 + processParameters[1].trim());
66         mapOfProcesses.get(processParameters[0]).executeProcess(processParameters[1].trim(), childObject, serviceModel);
67     }
68
69     /**
70      * Init method.
71      */
72     @PostConstruct
73     public void init() {
74         mapOfProcesses.put("CDS", new ToscaMetadataCdsProcess());
75         mapOfProcesses.put("CSAR_RESOURCES", new ToscaMetadataTargetProcess());
76
77         preProvisionDictionaryTable();
78     }
79
80     private void preProvisionDictionaryTable() {
81         // Set up dictionary elements
82         Dictionary actorDictionary = new Dictionary();
83         actorDictionary.setName("DefaultActor");
84         actorDictionary.setSecondLevelDictionary(0);
85         actorDictionary.setSubDictionaryType("");
86
87         DictionaryElement elementSo = new DictionaryElement();
88         elementSo.setName("SO");
89         elementSo.setShortName("SO");
90         elementSo.setType("string");
91         elementSo.setDescription("SO component");
92         actorDictionary.addDictionaryElements(elementSo);
93
94         DictionaryElement elementSdnc = new DictionaryElement();
95         elementSdnc.setName("SDNC");
96         elementSdnc.setShortName("SDNC");
97         elementSdnc.setType("string");
98         elementSdnc.setDescription("SDNC component");
99         actorDictionary.addDictionaryElements(elementSdnc);
100
101         DictionaryElement elementCds = new DictionaryElement();
102         elementCds.setName("CDS");
103         elementCds.setShortName("CDS");
104         elementCds.setType("string");
105         elementCds.setDescription("CDS component");
106         actorDictionary.addDictionaryElements(elementCds);
107
108         dictionaryService.saveOrUpdateDictionary(actorDictionary);
109    }
110 }