2 * Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
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.impl;
19 import java.util.Date;
20 import java.util.List;
22 import javax.transaction.Transactional;
24 import org.hibernate.Query;
25 import org.hibernate.Session;
26 import org.hibernate.SessionFactory;
27 import org.hibernate.Transaction;
28 import org.onap.usecaseui.server.bean.AlarmsInformation;
29 import org.onap.usecaseui.server.service.AlarmsInformationService;
30 import org.onap.usecaseui.server.util.Page;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
35 import org.springframework.stereotype.Service;
38 @Service("AlarmsInformationService")
40 @org.springframework.context.annotation.Configuration
41 @EnableAspectJAutoProxy
42 public class AlarmsInformationServiceImpl implements AlarmsInformationService {
43 private static final Logger logger = LoggerFactory.getLogger(AlarmsInformationServiceImpl.class);
46 private SessionFactory sessionFactory;
49 public String saveAlarmsInformation(AlarmsInformation alarmsInformation) {
51 if (null == alarmsInformation) {
52 logger.error("alarmsInformation AlarmsInformation alarmsInformation is null!");
54 logger.info("AlarmsInformationServiceImpl saveAlarmsInformation: alarmsInformation={}", alarmsInformation);
55 Session session = sessionFactory.openSession();
56 Transaction tx = session.beginTransaction();
57 session.save(alarmsInformation);
62 } catch (Exception e) {
63 logger.error("Exception occurred while performing AlarmsInformationServiceImpl saveAlarmsInformation. Details:" + e.getMessage());
70 public String updateAlarmsInformation(AlarmsInformation alarmsInformation) {
72 if (null == alarmsInformation) {
73 logger.error("alarmsInformation AlarmsInformation alarmsInformation is null!");
75 logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}", alarmsInformation);
76 Session session = sessionFactory.openSession();
77 Transaction tx = session.beginTransaction();
78 session.update(alarmsInformation);
83 } catch (Exception e) {
84 logger.error("Exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
90 public int getAllCount() {
92 Session session = sessionFactory.openSession();
93 Transaction tx = session.beginTransaction();
94 long q=(long)session.createQuery("select count(*) from AlarmsInformation").uniqueResult();
99 } catch (Exception e) {
100 logger.error("Exception occurred while performing AlarmsInformationServiceImpl getAllCount. Details:" + e.getMessage());
105 @SuppressWarnings("unchecked")
107 public Page<AlarmsInformation> queryAlarmsInformation(AlarmsInformation alarmsInformation, int currentPage,
109 Page<AlarmsInformation> page = new Page<AlarmsInformation>();
110 int allRow =this.getAllCount();
111 int offset = page.countOffset(currentPage, pageSize);
114 StringBuffer hql =new StringBuffer("from AlarmsInformation a where 1=1");
115 if (null == alarmsInformation) {
116 logger.error("AlarmsInformationServiceImpl queryAlarmsInformation alarmsInformation is null!");
117 }else if(null!=alarmsInformation.getName()) {
118 String ver=alarmsInformation.getName();
119 hql.append(" and a.name like '%"+ver+"%'");
120 }else if(null!=alarmsInformation.getValue()) {
121 String ver=alarmsInformation.getValue();
122 hql.append(" and a.value like '%"+ver+"%'");
123 }else if(null!=alarmsInformation.getEventId()) {
124 String ver=alarmsInformation.getEventId();
125 hql.append(" and a.eventId like '%"+ver+"%'");
126 }else if(null!=alarmsInformation.getCreateTime()) {
127 Date ver =alarmsInformation.getCreateTime();
128 hql.append(" and a.createTime like '%"+ver+"%'");
129 }else if(null!=alarmsInformation.getUpdateTime()) {
130 Date ver =alarmsInformation.getUpdateTime();
131 hql.append(" and a.updateTime like '%"+ver+"%'");
133 logger.info("AlarmsInformationServiceImpl queryAlarmsInformation: alarmsInformation={}", alarmsInformation);
134 Session session = sessionFactory.openSession();
135 Transaction tx = session.beginTransaction();
136 Query query = session.createQuery(hql.toString());
137 query.setFirstResult(offset);
138 query.setMaxResults(pageSize);
139 List<AlarmsInformation> list= query.list();
140 page.setPageNo(currentPage);
141 page.setPageSize(pageSize);
142 page.setTotalRecords(allRow);
148 } catch (Exception e) {
149 logger.error("Exception occurred while performing AlarmsInformationServiceImpl queryAlarmsInformation. Details:" + e.getMessage());