Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / so-bpmn-moi / src / main / java / org / onap / so / bpmn / moi / tasks / DeleteRANNssiBBTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (c) 2022 Deutsche telekom
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21
22 package org.onap.so.bpmn.moi.tasks;
23
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import org.onap.aaiclient.client.aai.AAIRestClientImpl;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.common.InjectionHelper;
29 import org.onap.so.bpmn.moi.util.AAISliceProfileUtil;
30 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Map;
38
39
40 @Component
41 public class DeleteRANNssiBBTask {
42     private static final Logger LOGGER = LoggerFactory.getLogger(DeleteRANNssiBBTask.class);
43
44     @Autowired
45     private InjectionHelper injectionHelper;
46
47     @Autowired
48     AAISliceProfileUtil aaiSliceProfileUtil;
49
50     private AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
51
52     private static final ObjectMapper mapper = new ObjectMapper();
53
54
55     public void deleteNssi(BuildingBlockExecution execution) throws JsonProcessingException {
56         GeneralBuildingBlock gBB = execution.getGeneralBuildingBlock();
57         List<Map<String, Object>> sliceProfilesData = gBB.getRequestContext().getRequestParameters().getUserParams();
58         String sliceProfileIdFromRequest = mapUserParamsToSliceProfile(sliceProfilesData);
59         aaiSliceProfileUtil.deleteSliceProfile(execution, sliceProfileIdFromRequest);
60     }
61
62
63
64     private String mapUserParamsToSliceProfile(List<Map<String, Object>> sliceProfilesData)
65             throws JsonProcessingException {
66         Map<String, Object> mapParam = (Map<String, Object>) sliceProfilesData.get(0).get("nssi");
67         List<Object> list = (ArrayList<Object>) mapParam.get("sliceProfileList");
68         Map<String, Object> idMap = (Map<String, Object>) list.get(0);
69         String sliceProfileId = (String) idMap.get("sliceProfileId");
70         return sliceProfileId;
71     }
72
73 }