instantiate and terminate servce
[usecase-ui/server.git] / src / main / java / org / onap / usecaseui / server / controller / AlarmController.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 javax.annotation.Resource;
19 import javax.servlet.http.HttpServletRequest;
20
21 import com.fasterxml.jackson.core.JsonProcessingException;
22 import com.fasterxml.jackson.databind.ObjectMapper;
23 import org.onap.usecaseui.server.bean.AlarmsHeader;
24 import org.onap.usecaseui.server.bean.AlarmsInformation;
25 import org.onap.usecaseui.server.service.AlarmsHeaderService;
26 import org.onap.usecaseui.server.service.AlarmsInformationService;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.EnableAspectJAutoProxy;
31 import org.springframework.stereotype.Controller;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.RequestMethod;
34 import org.springframework.web.bind.annotation.ResponseBody;
35
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39
40 /*
41  * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
42  *
43  * Licensed under the Apache License, Version 2.0 (the "License");
44  * you may not use this file except in compliance with the License.
45  * You may obtain a copy of the License at
46  *
47  *     http://www.apache.org/licenses/LICENSE-2.0
48  *
49  * Unless required by applicable law or agreed to in writing, software
50  * distributed under the License is distributed on an "AS IS" BASIS,
51  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
52  * See the License for the specific language governing permissions and
53  * limitations under the License.
54  */
55 @Controller
56 @org.springframework.context.annotation.Configuration
57 @EnableAspectJAutoProxy
58 public class AlarmController
59 {
60
61
62     private static final Logger logger = LoggerFactory.getLogger(AlarmController.class);
63
64     @Resource(name = "AlarmsHeaderService")
65     private AlarmsHeaderService alarmsHeaderService;
66
67     @Resource(name = "AlarmsInformationService")
68     private AlarmsInformationService alarmsInformationService;
69
70
71     @ResponseBody
72     @RequestMapping(value = {"/alarm/getData"}, method = RequestMethod.GET , produces = "application/json")
73     public String getAlarmData(HttpServletRequest request) throws JsonProcessingException {
74         String eventId = request.getParameter("ALARM_eventId");
75         String vfStatus = request.getParameter("ALARM_vfStatus");
76         String status = request.getParameter("ALARM_status");
77         String eventName = request.getParameter("ALARM_eventName");
78         String name = request.getParameter("ALARM_name");
79         String value = request.getParameter("ALARM_value");
80         int currentPage = Integer.parseInt(request.getParameter("ALARM_currentPage"));
81         int pageSize = Integer.parseInt(request.getParameter("ALARM_pageSize"));
82         AlarmsHeader alarmsHeader = new AlarmsHeader();
83         AlarmsInformation alarmsInformation = new AlarmsInformation();
84         if (null != eventId){
85             alarmsHeader.setEventId(eventId);
86             alarmsInformation.setEventId(eventId);
87         }
88         if (null != vfStatus)
89             alarmsHeader.setVfStatus(vfStatus);
90         if (null != status)
91             alarmsHeader.setStatus(status);
92         if (null != eventName)
93             alarmsHeader.setEventName(eventName);
94         if (null != name)
95             alarmsInformation.setName(name);
96         if (null != value)
97             alarmsInformation.setValue(value);
98         List<AlarmsHeader> alarmsHeaders = alarmsHeaderService.queryAlarmsHeader(alarmsHeader,currentPage,pageSize).getList();
99         List<AlarmsInformation> alarmsInformations = alarmsInformationService.queryAlarmsInformation(alarmsInformation,currentPage,pageSize).getList();
100         Map<String,Object> maps = new HashMap<>();
101         if (null != alarmsHeaders && alarmsHeaders.size() > 0)
102             maps.put("alarms_header",alarmsHeaders);
103         if (null != alarmsInformations && alarmsInformations.size() > 0)
104             maps.put("alarms_information",alarmsInformations);
105         return new ObjectMapper().writeValueAsString(maps);
106     }
107
108     @RequestMapping(value = { "/alarm/genCsv" } , method = RequestMethod.GET , produces = "application/json")
109     public String generateCsvFile(HttpServletRequest request){
110         String[] headers = new String[]{"version",
111                 "eventName","domain","eventId","eventType","nfcNamingCode",
112                 "nfNamingCode","sourceId","sourceName","reportingEntityId",
113                 "reportingEntityName","priority","startEpochMicrosec","lastEpochMicroSec",
114                 "sequence","measurementsForVfScalingVersion","measurementInterval","value","name",
115                 "createTime","updateTime"};
116         String event_ids = request.getParameter("ids");
117         String[] eventId = event_ids.split(",");
118
119         return "";
120     }
121
122
123     @RequestMapping(value = { "/alarm/updateStatus" } , method = RequestMethod.GET , produces = "application/json")
124     public String updateStatus(HttpServletRequest request){
125         String id = request.getParameter("ALARM_eventId");
126         String vfStatus = request.getParameter("ALARM_vfstatus");
127         String status = request.getParameter("ALARM_status");
128         AlarmsHeader alarmsHeader = new AlarmsHeader();
129         if (null != id)
130             alarmsHeader.setEventId(id);
131         if (null != vfStatus)
132             alarmsHeader.setVfStatus(vfStatus);
133         if (null != status)
134             alarmsHeader.setStatus(status);
135         String result = alarmsHeaderService.updateAlarmsHeader(alarmsHeader);
136         return result;
137     }
138
139
140
141
142 }