aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/org/onap/usecaseui/server/controller/sotn/SotnController.java
blob: af52a3fe4e61d07984999d506c0b4d54a02b82c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
 * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onap.usecaseui.server.controller.sotn;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

import org.onap.usecaseui.server.bean.sotn.NetWorkResource;
import org.onap.usecaseui.server.bean.sotn.Pinterface;
import org.onap.usecaseui.server.bean.sotn.Pnf;
import org.onap.usecaseui.server.service.sotn.SOTNService;
import org.onap.usecaseui.server.util.UuiCommonUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

@RestController
@CrossOrigin(origins="*")
@RequestMapping("/uui-sotn")
public class SotnController {
	
	@Resource(name="SOTNService")
	public SOTNService sotnService;

	public SOTNService getSotnService() {
		return sotnService;
	}

	public void setSotnService(SOTNService sotnService) {
		this.sotnService = sotnService;
	}
	
    @GetMapping(value = {"/getNetWorkResources"})
	public List<NetWorkResource> getNetWorkResources(){
    	List<NetWorkResource> result = new ArrayList<NetWorkResource>();
    	String json  = sotnService.getNetWorkResources();
    	if(json.indexOf("FAILED")!=-1){
    		return result;
    	}
    	createJson(json,result);
    	for(NetWorkResource networks:result){
    		List<Pinterface> pinterfaces = new ArrayList<Pinterface>();
    		List<Pnf> pnfs = networks.getPnfs();
    		for(Pnf pnf :pnfs){
    			List<Pinterface> tps= sotnService.getPinterfaceByPnfName(pnf.getPnfName());
    			pinterfaces.addAll(tps);
    		}
    		networks.setTps(pinterfaces);
    	}
		return result;
	}
    
    @GetMapping(value = {"/getPinterfaceByPnfName/{pnfName:.+}"})
    public List<Pinterface>  getPinterfaceByPnfName(@PathVariable(value="pnfName") String pnfName){
    	return sotnService.getPinterfaceByPnfName(pnfName);
    }
    
    @GetMapping(value = {"/getLogicalLinks"})
    public String getLogicalLinks(){
    	return sotnService.getLogicalLinks();
    }
    
    @GetMapping(value = {"/getSpecificLogicalLink/{linkName:.+}"})
    public String getSpecificLogicalLink(@PathVariable(value="linkName") String linkName){
    	return sotnService.getSpecificLogicalLink(linkName);
    }
    
    @GetMapping(value = {"/getHostUrl/{aaiId:.+}"})
    public String getHostUrl(@PathVariable(value="aaiId") String aaiId){
    	return sotnService.getHostUrl(aaiId);
    }
    
    @GetMapping(value = {"/getExtAaiId/{aaiId:.+}"})
    public String getExtAaiId(@PathVariable(value="aaiId") String aaiId){
    	return sotnService.getExtAaiId(aaiId);
    }
    
    @PutMapping(value = {"/createHostUrl/{aaiId:.+}"})
    public String createHostUrl(HttpServletRequest request,@PathVariable(value="aaiId") String aaiId){
    	return sotnService.createHostUrl(request, aaiId);
    }
    
    @PutMapping(value = {"/createTopoNetwork/{networkId:.+}"})
    public String createTopoNetwork(HttpServletRequest request,@PathVariable(value="networkId") String networkId){
    	return sotnService.createTopoNetwork(request,networkId);
    }
    
    @PutMapping(value = {"/pnf/{pnfName:.+}/p-interfaces/p-interface/{tp-id:.+}/createTerminationPoint"})
    public String createTerminationPoint(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName,@PathVariable(value="tp-id") String tpId){
    	return sotnService.createTerminationPoint(request,pnfName,tpId);
    }
    
    @PutMapping(value = {"/createLink/{linkName:.+}"})
    public String createLink(HttpServletRequest request,@PathVariable(value="linkName") String linkName){
    	return sotnService.createLink(request, linkName);
    }
    
    @PutMapping(value = {"/createPnf/{pnfName:.+}"})
    public String createPnf(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName){
    	return sotnService.createPnf(request, pnfName);
    }
    
    @DeleteMapping(value = {"/deleteLink/{linkName:.+}/{resourceVersion:.+}"})
    public String deleteLink(@PathVariable(value="linkName") String linkName,@PathVariable(value="resourceVersion") String resourceVersion){
    	return sotnService.deleteLink(linkName,resourceVersion);
    }
    
    @GetMapping(value = {"/getServiceInstanceInfo"})
    public String getServiceInstanceInfo(HttpServletRequest request){
        String customerId = request.getParameter("customerId");
        String serviceType = request.getParameter("serviceType");
        String serviceId = request.getParameter("serviceId");
    	return sotnService.serviceInstanceInfo(customerId, serviceType, serviceId);
    }
    
    @GetMapping(value = {"/getPnfInfo"})
    public String getPnfInfo(String pnfName){
    	return sotnService.getPnfInfo(pnfName);
    }
    
    @GetMapping(value = {"/getAllottedResources"})
    public String getAllottedResources(HttpServletRequest request){
        String customerId = request.getParameter("customerId");
        String serviceType = request.getParameter("serviceType");
        String serviceId = request.getParameter("serviceId");
    	return sotnService.getAllottedResources(customerId, serviceType,serviceId);
    }
    
    @GetMapping(value = {"/getConnectivityInfo"})
    public String getConnectivityInfo( String connectivityId){
    	return sotnService.getConnectivityInfo(connectivityId);
    }

	@GetMapping(value = {"/getVpnBindingInfo"})
	public String getVpnBindingInfo( String vpnId){
		return sotnService.getVpnBindingInfo(vpnId);
	}

	@GetMapping(value = {"/getNetworkRouteInfo"})
	public String getNetworkRouteInfo(String routeId){
		return sotnService.getNetworkRouteInfo(routeId);
	}

	@GetMapping(value = {"/getUniInfo"})
	public String getUniInfo(String Id){
		return sotnService.getUniInfo(Id);
	}

    @GetMapping(value = {"/getPinterfaceByVpnId/{vpnId:.+}"})
    public String getPinterfaceByVpnId(@PathVariable(value="vpnId") String vpnId){
    	return sotnService.getPinterfaceByVpnId(vpnId);
    }
    
    @GetMapping(value = {"/getServiceInstanceList"})
    public String getServiceInstanceList(HttpServletRequest request){
        String customerId = request.getParameter("customerId");
        String serviceType = request.getParameter("serviceType");
    	return sotnService.getServiceInstances(customerId, serviceType);
    }

    @DeleteMapping(value = {"/deleteExtNetWork"})
    public String deleteExtNetwork(@RequestParam String extNetworkId,@RequestParam(value="resourceVersion") String resourceVersion){
    	return sotnService.deleteExtNetwork(extNetworkId,resourceVersion);
    }
    
    private void createJson(String json,List<NetWorkResource> list){

    	ObjectMapper mapper = new ObjectMapper();
    	
    	try {
			JsonNode node = mapper.readTree(json);
			JsonNode netNode = node.get("network-resource");
			for(int i=0;i<netNode.size();i++){
				NetWorkResource netResource = new NetWorkResource();
				List<Pnf> pnfs = new ArrayList<Pnf>();
				String networkId=netNode.get(i).get("network-id").toString();
				if(networkId.indexOf("\"")!=-1){
					networkId = networkId.substring(1, networkId.length()-1);
				}
				netResource.setNetworkId(networkId);
				if(UuiCommonUtil.isNotNullOrEmpty(netNode.get(i).get("relationship-list"))){
					String relationJson = netNode.get(i).get("relationship-list").toString();
					JsonNode relationNode = mapper.readTree(relationJson);
					
					JsonNode shipNode = relationNode.get("relationship");
					for(int j=0;j<shipNode.size();j++){
						Pnf pnf = new Pnf();
						JsonNode shipDataNode = shipNode.get(j).get("relationship-data");
						String shipDataValue = shipDataNode.get(0).get("relationship-value").toString();
						String shipDataKey = shipDataNode.get(0).get("relationship-key").toString();
						if(shipDataKey.indexOf("\"")!=-1){
							shipDataKey = shipDataKey.substring(1, shipDataKey.length()-1);
						}
						if("ext-aai-network.aai-id".equals(shipDataKey)){
							netResource.setAaiId(shipDataKey);
							continue;
						}
						if(shipDataValue.indexOf("\"")!=-1){
							shipDataValue = shipDataValue.substring(1, shipDataValue.length()-1);
						}
						pnf.setPnfName(shipDataValue);
						pnfs.add(pnf);
					}
					netResource.setPnfs(pnfs);
					list.add(netResource);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
}