2 * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.usecaseui.server.controller.sotn;
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.List;
22 import javax.annotation.Resource;
23 import javax.servlet.http.HttpServletRequest;
25 import org.onap.usecaseui.server.bean.sotn.NetWorkResource;
26 import org.onap.usecaseui.server.bean.sotn.Pinterface;
27 import org.onap.usecaseui.server.bean.sotn.Pnf;
28 import org.onap.usecaseui.server.service.sotn.SOTNService;
29 import org.onap.usecaseui.server.util.UuiCommonUtil;
30 import org.springframework.web.bind.annotation.CrossOrigin;
31 import org.springframework.web.bind.annotation.PathVariable;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.GetMapping;
34 import org.springframework.web.bind.annotation.PutMapping;
35 import org.springframework.web.bind.annotation.DeleteMapping;
36 import org.springframework.web.bind.annotation.RequestParam;
37 import org.springframework.web.bind.annotation.RestController;
39 import com.fasterxml.jackson.databind.JsonNode;
40 import com.fasterxml.jackson.databind.ObjectMapper;
43 @CrossOrigin(origins="*")
44 @RequestMapping("/uui-sotn")
45 public class SotnController {
47 @Resource(name="SOTNService")
48 public SOTNService sotnService;
50 public SOTNService getSotnService() {
54 public void setSotnService(SOTNService sotnService) {
55 this.sotnService = sotnService;
58 @GetMapping(value = {"/getNetWorkResources"})
59 public List<NetWorkResource> getNetWorkResources(){
60 List<NetWorkResource> result = new ArrayList<NetWorkResource>();
61 String json = sotnService.getNetWorkResources();
62 if(json.indexOf("FAILED")!=-1){
65 createJson(json,result);
66 for(NetWorkResource networks:result){
67 List<Pinterface> pinterfaces = new ArrayList<Pinterface>();
68 List<Pnf> pnfs = networks.getPnfs();
70 List<Pinterface> tps= sotnService.getPinterfaceByPnfName(pnf.getPnfName());
71 pinterfaces.addAll(tps);
73 networks.setTps(pinterfaces);
78 @GetMapping(value = {"/getPinterfaceByPnfName/{pnfName:.+}"})
79 public List<Pinterface> getPinterfaceByPnfName(@PathVariable(value="pnfName") String pnfName){
80 return sotnService.getPinterfaceByPnfName(pnfName);
83 @GetMapping(value = {"/getLogicalLinks"})
84 public String getLogicalLinks(){
85 return sotnService.getLogicalLinks();
88 @GetMapping(value = {"/getSpecificLogicalLink/{linkName:.+}"})
89 public String getSpecificLogicalLink(@PathVariable(value="linkName") String linkName){
90 return sotnService.getSpecificLogicalLink(linkName);
93 @GetMapping(value = {"/getHostUrl/{aaiId:.+}"})
94 public String getHostUrl(@PathVariable(value="aaiId") String aaiId){
95 return sotnService.getHostUrl(aaiId);
98 @GetMapping(value = {"/getExtAaiId/{aaiId:.+}"})
99 public String getExtAaiId(@PathVariable(value="aaiId") String aaiId){
100 return sotnService.getExtAaiId(aaiId);
103 @PutMapping(value = {"/createHostUrl/{aaiId:.+}"})
104 public String createHostUrl(HttpServletRequest request,@PathVariable(value="aaiId") String aaiId){
105 return sotnService.createHostUrl(request, aaiId);
108 @PutMapping(value = {"/createTopoNetwork/{networkId:.+}"})
109 public String createTopoNetwork(HttpServletRequest request,@PathVariable(value="networkId") String networkId){
110 return sotnService.createTopoNetwork(request,networkId);
113 @PutMapping(value = {"/pnf/{pnfName:.+}/p-interfaces/p-interface/{tp-id:.+}/createTerminationPoint"})
114 public String createTerminationPoint(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName,@PathVariable(value="tp-id") String tpId){
115 return sotnService.createTerminationPoint(request,pnfName,tpId);
118 @PutMapping(value = {"/createLink/{linkName:.+}"})
119 public String createLink(HttpServletRequest request,@PathVariable(value="linkName") String linkName){
120 return sotnService.createLink(request, linkName);
123 @PutMapping(value = {"/createPnf/{pnfName:.+}"})
124 public String createPnf(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName){
125 return sotnService.createPnf(request, pnfName);
128 @DeleteMapping(value = {"/deleteLink/{linkName:.+}/{resourceVersion:.+}"})
129 public String deleteLink(@PathVariable(value="linkName") String linkName,@PathVariable(value="resourceVersion") String resourceVersion){
130 return sotnService.deleteLink(linkName,resourceVersion);
133 @GetMapping(value = {"/getServiceInstanceInfo"})
134 public String getServiceInstanceInfo(HttpServletRequest request){
135 String customerId = request.getParameter("customerId");
136 String serviceType = request.getParameter("serviceType");
137 String serviceId = request.getParameter("serviceId");
138 return sotnService.serviceInstanceInfo(customerId, serviceType, serviceId);
141 @GetMapping(value = {"/getPnfInfo", "/getPnfInfo/{pnfName}"})
142 public String getPnfInfo(@PathVariable(required = false) String pnfName){
143 return sotnService.getPnfInfo(pnfName);
146 @GetMapping(value = {"/getAllottedResources"})
147 public String getAllottedResources(HttpServletRequest request){
148 String customerId = request.getParameter("customerId");
149 String serviceType = request.getParameter("serviceType");
150 String serviceId = request.getParameter("serviceId");
151 return sotnService.getAllottedResources(customerId, serviceType,serviceId);
154 @GetMapping(value = {"/getConnectivityInfo", "/getConnectivityInfo/{connectivityId}"})
155 public String getConnectivityInfo(@PathVariable(required = false) String connectivityId){
156 return sotnService.getConnectivityInfo(connectivityId);
159 @GetMapping(value = {"/getVpnBindingInfo", "/getVpnBindingInfo/{vpnId}"})
160 public String getVpnBindingInfo(@PathVariable(required = false) String vpnId){
161 return sotnService.getVpnBindingInfo(vpnId);
164 @GetMapping(value = {"/getNetworkRouteInfo", "/getNetworkRouteInfo/{routeId}"})
165 public String getNetworkRouteInfo(@PathVariable(required = false) String routeId){
166 return sotnService.getNetworkRouteInfo(routeId);
169 @GetMapping(value = {"/getPinterfaceByVpnId/{vpnId:.+}"})
170 public String getPinterfaceByVpnId(@PathVariable(value="vpnId") String vpnId){
171 return sotnService.getPinterfaceByVpnId(vpnId);
174 @GetMapping(value = {"/getServiceInstanceList"})
175 public String getServiceInstanceList(HttpServletRequest request){
176 String customerId = request.getParameter("customerId");
177 String serviceType = request.getParameter("serviceType");
178 return sotnService.getServiceInstances(customerId, serviceType);
181 @DeleteMapping(value = {"/deleteExtNetWork"})
182 public String deleteExtNetwork(@RequestParam String extNetworkId,@RequestParam(value="resourceVersion") String resourceVersion){
183 return sotnService.deleteExtNetwork(extNetworkId,resourceVersion);
186 private void createJson(String json,List<NetWorkResource> list){
188 ObjectMapper mapper = new ObjectMapper();
191 JsonNode node = mapper.readTree(json);
192 JsonNode netNode = node.get("network-resource");
193 for(int i=0;i<netNode.size();i++){
194 NetWorkResource netResource = new NetWorkResource();
195 List<Pnf> pnfs = new ArrayList<Pnf>();
196 String networkId=netNode.get(i).get("network-id").toString();
197 if(networkId.indexOf("\"")!=-1){
198 networkId = networkId.substring(1, networkId.length()-1);
200 netResource.setNetworkId(networkId);
201 if(UuiCommonUtil.isNotNullOrEmpty(netNode.get(i).get("relationship-list"))){
202 String relationJson = netNode.get(i).get("relationship-list").toString();
203 JsonNode relationNode = mapper.readTree(relationJson);
205 JsonNode shipNode = relationNode.get("relationship");
206 for(int j=0;j<shipNode.size();j++){
208 JsonNode shipDataNode = shipNode.get(j).get("relationship-data");
209 String shipDataValue = shipDataNode.get(0).get("relationship-value").toString();
210 String shipDataKey = shipDataNode.get(0).get("relationship-key").toString();
211 if(shipDataKey.indexOf("\"")!=-1){
212 shipDataKey = shipDataKey.substring(1, shipDataKey.length()-1);
214 if("ext-aai-network.aai-id".equals(shipDataKey)){
215 netResource.setAaiId(shipDataKey);
218 if(shipDataValue.indexOf("\"")!=-1){
219 shipDataValue = shipDataValue.substring(1, shipDataValue.length()-1);
221 pnf.setPnfName(shipDataValue);
224 netResource.setPnfs(pnfs);
225 list.add(netResource);
228 } catch (IOException e) {