instantiate and terminate servce
[usecase-ui/server.git] / server / src / main / java / org / onap / usecaseui / server / controller / PerformanceController.java
1 /*
2  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.server.controller;
17
18 import com.fasterxml.jackson.core.JsonProcessingException;
19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import org.onap.usecaseui.server.bean.PerformanceHeader;
21 import org.onap.usecaseui.server.bean.PerformanceInformation;
22 import org.onap.usecaseui.server.service.PerformanceHeaderService;
23 import org.onap.usecaseui.server.service.PerformanceInformationService;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Qualifier;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.context.annotation.EnableAspectJAutoProxy;
30 import org.springframework.stereotype.Controller;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
33 import org.springframework.web.bind.annotation.ResponseBody;
34
35 import javax.annotation.Resource;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.xml.crypto.Data;
38 import java.text.ParseException;
39 import java.text.SimpleDateFormat;
40 import java.util.*;
41
42 /*
43  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
44  *
45  * Licensed under the Apache License, Version 2.0 (the "License");
46  * you may not use this file except in compliance with the License.
47  * You may obtain a copy of the License at
48  *
49  *     http://www.apache.org/licenses/LICENSE-2.0
50  *
51  * Unless required by applicable law or agreed to in writing, software
52  * distributed under the License is distributed on an "AS IS" BASIS,
53  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
54  * See the License for the specific language governing permissions and
55  * limitations under the License.
56  */
57 @Controller
58 @Configuration
59 @EnableAspectJAutoProxy
60 public class PerformanceController {
61
62     @Resource(name = "PerformanceHeaderService")
63     private PerformanceHeaderService performanceHeaderService;
64
65     @Resource(name = "PerformanceInformationService")
66     private PerformanceInformationService performanceInformationService;
67
68     private final String csvPath = "";
69
70     private Logger looger = LoggerFactory.getLogger(PerformanceController.class);
71
72     @ResponseBody
73     @RequestMapping(value = {"/pro/getData"},method = RequestMethod.GET, produces = "application/json")
74     public String getPerformanceData(HttpServletRequest request) throws JsonProcessingException {
75         String eventId = request.getParameter("PERFORMANCE_eventId");
76         String eventName = request.getParameter("PERFORMANCE_eventName");
77         String name = request.getParameter("PERFORMANCE_name");
78         String value = request.getParameter("PERFORMANCE_value");
79         int currentPage = Integer.parseInt(request.getParameter("PERFORMANCE_currentPage"));
80         int pageSize = Integer.parseInt(request.getParameter("PERFORMANCE_pageSize"));
81         PerformanceHeader performanceHeader = new PerformanceHeader();
82         PerformanceInformation performanceInformation = new PerformanceInformation();
83         if (null != eventId){
84             performanceHeader.setEventId(eventId);
85             performanceInformation.setEventId(eventId);
86         }
87         if (null != eventName)
88             performanceHeader.setEventName(eventName);
89         if (null != name)
90             performanceInformation.setName(name);
91         if (null != value)
92             performanceInformation.setValue(value);
93         List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(performanceHeader,currentPage,pageSize).getList();
94         List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(performanceInformation,currentPage,pageSize).getList();
95         Map<String,Object> maps = new HashMap<>();
96         if (null != performanceHeaders && performanceHeaders.size() > 0)
97             maps.put("performance_header",performanceHeaders);
98         if (null != performanceInformations && performanceInformations.size() > 0)
99             maps.put("performance_information",performanceInformations);
100         return new ObjectMapper().writeValueAsString(maps);
101     }
102
103     @RequestMapping(value = {"/pro/genCsv"}, method = RequestMethod.GET, produces = "application/json")
104     public String generateCsvFile(HttpServletRequest request){
105         String[] headers = new String[]{"version",
106                 "eventName","domain","eventId","eventType","nfcNamingCode",
107                 "nfNamingCode","sourceId","sourceName","reportingEntityId",
108                 "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
109                 "sequence","measurementsForVfScalingVersion","measurementInterval","value","name",
110                 "createTime","updateTime"};
111         List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(null,1,100).getList();
112         List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(null,1,100).getList();
113         List<String[]> csvData = new ArrayList<>();
114
115         return "";
116     }
117
118     @RequestMapping(value = {"/pro/genDiaCsv"}, method = RequestMethod.GET, produces = "application/json")
119     public String generateDiaCsvFile(HttpServletRequest request){
120         String[] headers = new String[]{"","","",""};
121         List<PerformanceHeader> performanceHeaders = performanceHeaderService.queryPerformanceHeader(null,1,100).getList();
122         List<PerformanceInformation> performanceInformations = performanceInformationService.queryPerformanceInformation(null,1,100).getList();
123         List<String[]> csvData = new ArrayList<>();
124
125         return "";
126     }
127
128     @ResponseBody
129     @RequestMapping(value = {"/pro/genDia"}, method = RequestMethod.GET, produces = "application/json")
130     public String generateDiagram(HttpServletRequest request) throws ParseException, JsonProcessingException {
131         String id = request.getParameter("PERFORMANCE_id");
132         String data = request.getParameter("PERFORMANCE_data");
133         SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
134         Date beginDate = new Date();
135         Calendar date = Calendar.getInstance();
136         date.setTime(beginDate);
137         PerformanceInformation p = new PerformanceInformation();
138         p.setEventId(id);
139         if ("hour".equals(data)){
140             date.set(Calendar.DATE, date.get(Calendar.HOUR) - 1);
141             Date endDate = dft.parse(dft.format(date.getTime()));
142             p.setCreateTime(endDate);
143         }
144         if ("day".equals(data)){
145             date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
146             Date endDate = dft.parse(dft.format(date.getTime()));
147             p.setCreateTime(endDate);
148         }
149         if ("month".equals(data)){
150             date.set(Calendar.DATE, date.get(Calendar.MONTH) - 1);
151             Date endDate = dft.parse(dft.format(date.getTime()));
152             p.setCreateTime(endDate);
153         }
154         if ("year".equals(data)){
155             date.set(Calendar.DATE, date.get(Calendar.YEAR) - 1);
156             Date endDate = dft.parse(dft.format(date.getTime()));
157             p.setCreateTime(endDate);
158         }
159         List<PerformanceInformation> informationList = performanceInformationService.queryPerformanceInformation(p,1,4).getList();
160         return new ObjectMapper().writeValueAsString(informationList);
161     }
162
163
164 }