2 * Copyright 2016-2017 ZTE Corporation.
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.service.lcm.impl;
18 import com.alibaba.fastjson.JSONObject;
19 import com.fasterxml.jackson.core.type.TypeReference;
20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import okhttp3.ResponseBody;
22 import org.json.simple.parser.JSONParser;
23 import org.json.simple.parser.ParseException;
24 import org.onap.usecaseui.server.bean.activateEdge.ServiceInstance;
25 import org.onap.usecaseui.server.bean.lcm.sotne2eservice.ModelConfig;
26 import org.onap.usecaseui.server.bean.lcm.sotne2eservicemonitor.ResponseServiceInstanceWrapper;
27 import org.onap.usecaseui.server.bean.lcm.sotne2eservicemonitor.ServiceInstanceList;
28 import org.onap.usecaseui.server.bean.lcm.sotne2eservicemonitor.ServiceInstanceListWrapper;
29 //import org.onap.usecaseui.server.bean.lcm.sotne2eservicemonitor.ServiceSubscriptionWrapper;
30 import org.onap.usecaseui.server.service.lcm.SotnServiceQryService;
31 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
32 import org.onap.usecaseui.server.util.RestfulServices;
33 import org.onap.usecaseui.server.util.UuiCommonUtil;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.context.annotation.EnableAspectJAutoProxy;
37 import org.springframework.stereotype.Service;
38 import retrofit2.Response;
40 import java.io.FileReader;
41 import java.io.IOException;
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.List;
46 @Service("SotnServiceQry")
47 @org.springframework.context.annotation.Configuration
48 @EnableAspectJAutoProxy
49 public class SotnServiceQryServiceImpl implements SotnServiceQryService {
51 private static final Logger logger = LoggerFactory.getLogger(SotnServiceQryServiceImpl.class);
53 private AAIService aaiService;
55 public SotnServiceQryServiceImpl() {
56 this(RestfulServices.create(AAIService.class));
59 public SotnServiceQryServiceImpl(AAIService aaiService) {
60 this.aaiService = aaiService;
64 public String getServiceInstances(String serviceType) {
65 ModelConfig modelConfig = readFile();
66 String customerid = modelConfig.getSubscriberId();
67 List<String> result = new ArrayList<>();
69 //serviceType = "generic";
70 ObjectMapper mapper = new ObjectMapper();
71 JSONParser parser = new JSONParser();
74 Response<ResponseBody> response = aaiService.listServiceInstances(customerid, serviceType).execute();
75 if (response.isSuccessful()) {
76 String resultStr=new String(response.body().bytes());
77 ServiceInstanceListWrapper serviceInstances = mapper.readValue(resultStr, new TypeReference<ServiceInstanceListWrapper>() {
79 List<ServiceInstanceList> serviceIntances = new ArrayList<>();
80 for(ServiceInstance ServiceInstance : serviceInstances.getServiceIntances()) {
81 if(!ServiceInstance.getServiceInstanceName().contains("Site_Service_")){
82 ServiceInstanceList serviceInstanceList = new ServiceInstanceList();
83 serviceInstanceList.setServiceInstance(ServiceInstance.getServiceInstanceId());
84 serviceInstanceList.setServiceInstancename(ServiceInstance.getServiceInstanceName());
85 serviceIntances.add(serviceInstanceList);
88 ResponseServiceInstanceWrapper responseServiceInstanceWrapper= new ResponseServiceInstanceWrapper();
89 responseServiceInstanceWrapper.setServiceInstanceListList(serviceIntances);
90 return responseServiceInstanceWrapper.toString();
94 logger.info(String.format("Can not get service instances[code=%s, message=%s]", response.code(), response.message()));
97 } catch (IOException e) {
98 logger.error("list services instances occur exception"+e.getMessage());
103 public ModelConfig readFile() {
104 JSONParser parser = new JSONParser();
105 //String jsonPath = "/home/root1/Desktop/modelconfig.json";
106 //String absolutepath = "/home/root1/Desktop/Subhosree/gerrit clone for ui backend";//configure absolute path as per systempath
107 String jsonPath = "/home/modelconfig.json";
108 String jsonString = null;
109 ObjectMapper mapper = new ObjectMapper();
113 Object object = parser.parse(new FileReader(jsonPath));
114 //System.out.println(object.toString());
115 ModelConfig modelInformation = mapper.readValue(object.toString(), new TypeReference<ModelConfig>() {
118 return modelInformation;
119 } catch (ParseException | IOException ex) {
120 logger.error("Exception occured while reading configuration file:" + ex);