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/{pnfName:.+}"})
142 public String getPnfInfo(@PathVariable(value="pnfName") 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 = {"/getPinterfaceByVpnId/{vpnId:.+}"})
160 public String getPinterfaceByVpnId(@PathVariable(value="vpnId") String vpnId){
161 return sotnService.getPinterfaceByVpnId(vpnId);
164 @GetMapping(value = {"/getServiceInstanceList"})
165 public String getServiceInstanceList(HttpServletRequest request){
166 String customerId = request.getParameter("customerId");
167 String serviceType = request.getParameter("serviceType");
168 return sotnService.getServiceInstances(customerId, serviceType);
171 @DeleteMapping(value = {"/deleteExtNetWork"})
172 public String deleteExtNetwork(@RequestParam String extNetworkId,@RequestParam(value="resourceVersion") String resourceVersion){
173 return sotnService.deleteExtNetwork(extNetworkId,resourceVersion);
176 private void createJson(String json,List<NetWorkResource> list){
178 ObjectMapper mapper = new ObjectMapper();
181 JsonNode node = mapper.readTree(json);
182 JsonNode netNode = node.get("network-resource");
183 for(int i=0;i<netNode.size();i++){
184 NetWorkResource netResource = new NetWorkResource();
185 List<Pnf> pnfs = new ArrayList<Pnf>();
186 String networkId=netNode.get(i).get("network-id").toString();
187 if(networkId.indexOf("\"")!=-1){
188 networkId = networkId.substring(1, networkId.length()-1);
190 netResource.setNetworkId(networkId);
191 if(UuiCommonUtil.isNotNullOrEmpty(netNode.get(i).get("relationship-list"))){
192 String relationJson = netNode.get(i).get("relationship-list").toString();
193 JsonNode relationNode = mapper.readTree(relationJson);
195 JsonNode shipNode = relationNode.get("relationship");
196 for(int j=0;j<shipNode.size();j++){
198 JsonNode shipDataNode = shipNode.get(j).get("relationship-data");
199 String shipDataValue = shipDataNode.get(0).get("relationship-value").toString();
200 String shipDataKey = shipDataNode.get(0).get("relationship-key").toString();
201 if(shipDataKey.indexOf("\"")!=-1){
202 shipDataKey = shipDataKey.substring(1, shipDataKey.length()-1);
204 if("ext-aai-network.aai-id".equals(shipDataKey)){
205 netResource.setAaiId(shipDataKey);
208 if(shipDataValue.indexOf("\"")!=-1){
209 shipDataValue = shipDataValue.substring(1, shipDataValue.length()-1);
211 pnf.setPnfName(shipDataValue);
214 netResource.setPnfs(pnfs);
215 list.add(netResource);
218 } catch (IOException e) {