diff options
author | guochuyicmri <guochuyi@chinamobile.com> | 2018-10-23 17:21:59 +0800 |
---|---|---|
committer | guochuyicmri <guochuyi@chinamobile.com> | 2018-10-23 17:22:15 +0800 |
commit | 1873741f068ceebd273177d33134876907091483 (patch) | |
tree | 486b8e2625848cecabe9228624ad431c5575db5b | |
parent | 589ae248e7b707803ee2259a45856fe72ff11f71 (diff) |
modify e2e serviceInstancelist
Change-Id: Ib3f7b509e9815aa582c1248ccbf5622854b2c9cd
Issue-ID: USECASEUI-164
Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
6 files changed, 87 insertions, 16 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java index 55c97d0a..2a0befcb 100644 --- a/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java +++ b/server/src/main/java/org/onap/usecaseui/server/controller/lcm/ServiceInstanceController.java @@ -15,7 +15,6 @@ */ package org.onap.usecaseui.server.controller.lcm; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -25,20 +24,19 @@ import javax.servlet.http.HttpServletRequest; import org.onap.usecaseui.server.bean.ServiceBean; import org.onap.usecaseui.server.service.lcm.ServiceInstanceService; import org.onap.usecaseui.server.service.lcm.ServiceLcmService; -import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstance; import org.onap.usecaseui.server.util.UuiCommonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @Controller @@ -68,7 +66,16 @@ public class ServiceInstanceController { List<String> result = new ArrayList<String>(); String customerId = request.getParameter("customerId"); String serviceType = request.getParameter("serviceType"); + String currentPage = request.getParameter("currentPage"); + String pageSize = request.getParameter("pageSize"); List<String> serviceInstances =serviceInstanceService.listServiceInstances(customerId, serviceType); + if(serviceInstances.size()>0){ + try { + result = this.parseServiceInstance(serviceInstances,currentPage,pageSize,customerId,serviceType); + } catch (JsonProcessingException e) { + logger.error("exception occurred while performing ServiceInstanceController listServiceInstances. Details:" + e.getMessage()); + } + } return result; } @ResponseBody @@ -109,15 +116,29 @@ public class ServiceInstanceController { return result.toString() ; } - private void parseServiceInstance(List<String> list){ + @SuppressWarnings("unchecked") + private List<String> parseServiceInstance(List<String> list,String currentPage,String pageSize,String customerId,String serviceType) throws JsonProcessingException{ ObjectMapper mapper = new ObjectMapper(); + List<String> result = new ArrayList<>(); for(String serviceInstance:list){ - try { - JsonNode node = mapper.readTree(serviceInstance); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + JSONObject object = JSON.parseObject(serviceInstance); + String serviceInstanceId=object.get("service-instance-id").toString(); + ServiceBean serviceBean = serviceLcmService.getServiceBeanByServiceInStanceId(serviceInstanceId); + String serviceDomain = serviceBean.getServiceDomain(); + object.put("serviceDomain",serviceDomain); + if("SOTN".equals(serviceDomain)||"CCVPN".equals(serviceDomain)||"E2E Service".equals(serviceDomain)||"Network Service".equals(serviceDomain)){ + List<String> parentIds = serviceLcmService.getServiceInstanceIdByParentId(serviceInstanceId); + List<String> parentServiceInstances = new ArrayList<>(); + if(parentIds.size()>0){ + for(String id:parentIds){ + String parentServiceInstance=serviceInstanceService.getRelationShipData(customerId, serviceType, id); + parentServiceInstances.add(parentServiceInstance); + } + } + object.put("childServiceInstances",mapper.writeValueAsString(parentServiceInstances)); + result.add(mapper.writeValueAsString(object)); + } } + return UuiCommonUtil.getPageList(result, Integer.parseInt(currentPage), Integer.parseInt(pageSize)); } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java index b99a8ed7..e9557cee 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/ServiceLcmService.java @@ -21,6 +21,8 @@ import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInf import org.onap.usecaseui.server.service.lcm.domain.so.bean.SaveOrUpdateOperationRsp; import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation; +import java.util.List; + import javax.servlet.http.HttpServletRequest; public interface ServiceLcmService { @@ -40,4 +42,6 @@ public interface ServiceLcmService { void updateServiceInstanceStatusById(String status,String serviceInstanceId); ServiceBean getServiceBeanByServiceInStanceId(String serviceInstanceId); + + List<String> getServiceInstanceIdByParentId(String serviceInstanceId); } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java index ed12b82d..477ed259 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceService.java @@ -15,9 +15,12 @@ */ package org.onap.usecaseui.server.service.lcm.impl; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import org.onap.usecaseui.server.service.lcm.ServiceInstanceService; import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService; -import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstance; import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstanceRsp; import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException; import org.onap.usecaseui.server.util.RestfulServices; @@ -29,10 +32,6 @@ import org.springframework.stereotype.Service; import okhttp3.ResponseBody; import retrofit2.Response; -import java.io.IOException; -import java.util.Collections; -import java.util.List; - @Service("ServiceInstanceService") @org.springframework.context.annotation.Configuration @EnableAspectJAutoProxy diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java index 5a2d86d0..5c7c50d3 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmService.java @@ -19,6 +19,7 @@ import static org.onap.usecaseui.server.util.RestfulServices.create; import static org.onap.usecaseui.server.util.RestfulServices.extractBody; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -209,4 +210,22 @@ public class DefaultServiceLcmService implements ServiceLcmService { return serviceBean; } + + @Override + public List<String> getServiceInstanceIdByParentId(String parentServiceInstanceId) { + List<String> list = new ArrayList<>(); + try(Session session = getSession()) { + + String string = "from ServiceBean where 1=1 and parentServiceInstanceId=:parentServiceInstanceId"; + Query q = session.createQuery(string); + q.setString("serviceInstanceId",parentServiceInstanceId); + list = q.list(); + session.flush(); + }catch (Exception e){ + list = new ArrayList<>(); + logger.error("exception occurred while performing DefaultServiceLcmService updateServiceInstanceStatusByIdDetail."+e.getMessage()); + } + return list; + + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java b/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java index ae9233be..33577e90 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/UuiCommonUtil.java @@ -18,7 +18,9 @@ package org.onap.usecaseui.server.util; import java.io.BufferedReader; import java.io.IOException; import java.lang.reflect.Array; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -123,4 +125,15 @@ public class UuiCommonUtil { } return result; } + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static List getPageList(List list,int currentPage,int pageSize){ + + List listPages = new ArrayList(); + int currIdx = (currentPage > 1 ? (currentPage -1) * pageSize : 0); + for (int i = 0; i < pageSize && i < listPages.size() - currIdx; i++) { + Object listPage= listPages.get(currIdx + i); + listPages.add(listPage); + } + return listPages; + } } diff --git a/standalone/src/main/assembly/resources/dbscripts/mysql/usecase-ui-createobj.sql b/standalone/src/main/assembly/resources/dbscripts/mysql/usecase-ui-createobj.sql index 2730887d..dfb33597 100644 --- a/standalone/src/main/assembly/resources/dbscripts/mysql/usecase-ui-createobj.sql +++ b/standalone/src/main/assembly/resources/dbscripts/mysql/usecase-ui-createobj.sql @@ -115,4 +115,19 @@ CREATE TABLE `performance_commoneventheader` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `performance_commoneventheader` ADD INDEX `performance_commoneventheader_index` (`sourceId`); +-- ---------------------------- +-- Table structure for service_instances +-- ---------------------------- +DROP TABLE IF EXISTS `service_instances`; +CREATE TABLE `service_instances` ( + `id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, + `serviceInstanceId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `customerId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `serviceType` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `serviceDomain` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `operationId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `parentServiceInstanceId` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + `status` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; |