2 * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onap.usecaseui.server.service.impl;
\r
19 import java.util.ArrayList;
\r
20 import java.util.List;
\r
21 import javax.persistence.EntityManagerFactory;
\r
22 import javax.transaction.Transactional;
\r
23 import org.hibernate.Query;
\r
24 import org.hibernate.Session;
\r
25 import org.hibernate.SessionFactory;
\r
26 import org.hibernate.Transaction;
\r
27 import org.onap.usecaseui.server.bean.AlarmsInformation;
\r
28 import org.onap.usecaseui.server.bean.maxAndMinTimeBean;
\r
29 import org.onap.usecaseui.server.service.AlarmsInformationService;
\r
30 import org.onap.usecaseui.server.util.UuiCommonUtil;
\r
31 import org.slf4j.Logger;
\r
32 import org.slf4j.LoggerFactory;
\r
33 import org.springframework.beans.factory.annotation.Autowired;
\r
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
\r
35 import org.springframework.stereotype.Service;
\r
38 @Service("AlarmsInformationService")
\r
40 @org.springframework.context.annotation.Configuration
\r
41 @EnableAspectJAutoProxy
\r
42 public class AlarmsInformationServiceImpl implements AlarmsInformationService {
\r
43 private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);
\r
46 private EntityManagerFactory entityManagerFactory;
\r
48 public Session getSession() {
\r
49 return entityManagerFactory.unwrap(SessionFactory.class).getCurrentSession();}
\r
52 public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {
\r
53 Session session = getSession();
\r
55 if (null == alarmsInformation) {
\r
56 logger.error("alarmsInformation saveAlarmsInformation alarmsInformation is null!");
\r
58 Transaction tx = session.beginTransaction();
\r
59 session.save(alarmsInformation);
\r
63 } catch (Exception e) {
\r
64 logger.error("exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());
\r
71 public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {
\r
72 Session session = getSession();
\r
74 if (null == alarmsInformation) {
\r
75 logger.error("alarmsInformation updateAlarmsInformation alarmsInformation is null!");
\r
77 Transaction tx = session.beginTransaction();
\r
78 session.update(alarmsInformation);
\r
82 } catch (Exception e) {
\r
83 logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
\r
89 public int getAllCount(AlarmsInformation alarmsInformation, int currentPage, int pageSize) {
\r
90 Session session = getSession();
\r
92 StringBuilder hql = new StringBuilder("select count(*) from AlarmsInformation a where 1=1");
\r
93 if (null == alarmsInformation) {
\r
95 if(null!=alarmsInformation.getName()) {
\r
96 String ver=alarmsInformation.getName();
\r
97 hql.append(" and a.name like '%"+ver+"%'");
\r
99 if(null!=alarmsInformation.getValue()) {
\r
100 String ver=alarmsInformation.getValue();
\r
101 hql.append(" and a.value like '%"+ver+"%'");
\r
103 if(null!=alarmsInformation.getSourceId()) {
\r
104 String ver=alarmsInformation.getSourceId();
\r
105 hql.append(" and a.sourceId = '"+ver+"'");
\r
107 if(null!=alarmsInformation.getStartEpochMicroSec()) {
\r
108 String ver =alarmsInformation.getStartEpochMicroSec();
\r
109 hql.append(" and a.createTime > '%"+ver+"%'");
\r
111 if(null!=alarmsInformation.getLastEpochMicroSec()) {
\r
112 String ver =alarmsInformation.getLastEpochMicroSec();
\r
113 hql.append(" and a.updateTime like '%"+ver+"%'");
\r
116 long q=(long)session.createQuery(hql.toString()).uniqueResult();
\r
119 } catch (Exception e) {
\r
120 logger.error("exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
\r
125 @SuppressWarnings("unchecked")
\r
127 public List<AlarmsInformation> queryId(String[] id) {
\r
128 Session session = getSession();
\r
132 List<AlarmsInformation> list = new ArrayList<AlarmsInformation>();
\r
134 Query query = session.createQuery("from AlarmsInformation a where a.sourceId IN (:alist)");
\r
135 list = query.setParameterList("alist", id).list();
\r
137 } catch (Exception e) {
\r
138 logger.error("exception occurred while performing AlarmsInformationServiceImpl queryId. Details:" + e.getMessage());
\r
145 public int queryDateBetween(String sourceName, String startTime, String endTime,String status) {
\r
146 if("1526554800000".equals(startTime)){
\r
147 System.out.print(startTime);
\r
149 Session session = getSession();
\r
151 String hql = "select count(*) from AlarmsHeader a where 1=1 ";
\r
152 if (sourceName != null && !"".equals(sourceName)){
\r
153 hql += " and a.sourceName = :sourceName";
\r
155 if (UuiCommonUtil.isNotNullOrEmpty(status)){
\r
156 hql += " and a.status = :status";
\r
159 if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
\r
160 hql += " and (CASE WHEN a.startEpochMicrosec=:zero THEN a.lastEpochMicroSec ELSE a.startEpochMicrosec END) between :startTime and :endTime ";
\r
162 Query query = session.createQuery(hql);
\r
163 query.setString("zero",zero);
\r
164 if (sourceName != null && !"".equals(sourceName)){
\r
165 query.setString("sourceName",sourceName);
\r
167 if (UuiCommonUtil.isNotNullOrEmpty(status)){
\r
168 query.setString("status",status);
\r
170 if (startTime != null && !"".equals(startTime) && endTime != null && !"".equals(endTime)){
\r
171 query.setString("startTime", startTime).setString("endTime", endTime);
\r
173 long num=(long) query.uniqueResult();
\r
175 } catch (Exception e) {
\r
176 logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. Details:" + e.getMessage());
\r
182 public List<maxAndMinTimeBean> queryMaxAndMinTime(){
\r
183 List<maxAndMinTimeBean> list = new ArrayList<>();
\r
184 Session session = getSession();
\r
186 String sql = "select MAX(startEpochMicrosec),MIN(startEpochMicrosec) FROM alarms_commoneventheader";
\r
187 Query query = session.createSQLQuery(sql);
\r
188 list = query.list();
\r
190 }catch (Exception e){
\r
191 logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. LIST:" + e.getMessage());
\r
193 list = new ArrayList<>();
\r
200 public List<AlarmsInformation> getAllAlarmsInformationByHeaderId(String headerId) {
\r
201 Session session = getSession();
\r
203 String string = "from AlarmsInformation a where 1=1 and a.headerId=:headerId";
\r
204 Query query = session.createQuery(string);
\r
205 query.setString("headerId",headerId);
\r
206 List<AlarmsInformation> list = query.list();
\r
209 }catch (Exception e){
\r
210 logger.error("exception occurred while performing PerformanceInformationServiceImpl queryDateBetween. LIST:" + e.getMessage());
\r