1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
|
/*
* Copyright (C) 2017 CMCC, Inc. and others. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onap.usecaseui.server.service.impl;
import java.util.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.transaction.Transactional;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.service.AlarmsHeaderService;
import org.onap.usecaseui.server.util.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
@Service("AlarmsHeaderService")
@Transactional
@org.springframework.context.annotation.Configuration
@EnableAspectJAutoProxy
public class AlarmsHeaderServiceImpl implements AlarmsHeaderService {
private static final Logger logger = LoggerFactory.getLogger(AlarmsHeaderServiceImpl.class);
@Autowired
private SessionFactory sessionFactory;
private Session getSession() {
return sessionFactory.openSession();
}
public String saveAlarmsHeader(AlarmsHeader alarmsHeader) {
try(Session session = getSession()){
if (null == alarmsHeader) {
logger.error("AlarmsHeaderServiceImpl saveAlarmsHeader alarmsHeader is null!");
}
logger.info("AlarmsHeaderServiceImpl saveAlarmsHeader: alarmsHeader={}", alarmsHeader);
Transaction tx = session.beginTransaction();
session.save(alarmsHeader);
tx.commit();
session.flush();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl saveAlarmsHeader. Details:" + e.getMessage());
return "0";
}
}
@Override
public String updateAlarmsHeader2018(String status, Timestamp date, String startEpochMicrosecCleared, String lastEpochMicroSecCleared, String eventName, String reportingEntityName, String specificProblem) {
try(Session session = getSession()){
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
Transaction tx = session.beginTransaction();
Query q=session.createQuery("update AlarmsHeader set status=:status, updateTime=:date, startEpochMicrosecCleared=:startEpochMicrosecCleared ,lastEpochMicroSecCleared=:lastEpochMicroSecCleared where eventName=:eventName and reportingEntityName=:reportingEntityName and specificProblem =:specificProblem");
q.setString("status",status);
q.setDate("date",date);
q.setString("startEpochMicrosecCleared",startEpochMicrosecCleared);
q.setString("lastEpochMicroSecCleared",lastEpochMicroSecCleared);
q.setString("eventName",eventName);
q.setString("reportingEntityName",reportingEntityName);
q.setString("specificProblem",specificProblem);
q.executeUpdate();
tx = session.getTransaction();
tx.commit();
session.flush();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
return "0";
}
}
@Override
public Boolean getStatusBySourceName(String sourceName) {
try(Session session = getSession()){
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
Query q=session.createQuery("select status from AlarmsHeader where sourceName='"+sourceName+"' and status='active'");
q.setMaxResults(1);
String s=(String)q.uniqueResult();
Boolean status=false;
if(s!=null && "active".equals(s)){
status = true;
}else{
status = false;
}
session.flush();
return status;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
return false;
}
}
@Override
public AlarmsHeader getIdByStatusSourceName(String sourceName) {
AlarmsHeader s = new AlarmsHeader();
try(Session session = getSession()){
logger.info("AlarmsInformationServiceImpl updateAlarmsInformation: alarmsInformation={}");
Query q=session.createQuery("from AlarmsHeader where sourceName='"+sourceName+"' and status='active' order by createTime desc");
q.setMaxResults(1);
s = (AlarmsHeader)q.uniqueResult();
session.flush();
return s;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsInformationServiceImpl updateAlarmsInformation. Details:" + e.getMessage());
return s;
}
}
@Override
public String updateAlarmsHeader(AlarmsHeader alarmsHeader) {
try(Session session = getSession()){
if (null == alarmsHeader){
logger.error("AlarmsHeaderServiceImpl updateAlarmsHeader alarmsHeader is null!");
}
logger.info("AlarmsHeaderServiceImpl updateAlarmsHeader: alarmsHeader={}", alarmsHeader);
Transaction tx = session.beginTransaction();
session.update(alarmsHeader);
tx.commit();
session.flush();
return "1";
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl updateAlarmsHeader. Details:" + e.getMessage());
return "0";
}
}
@Override
public int getAllCountByStatus(String status){
try (Session session = getSession()){
StringBuffer count = new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
if(!"0".equals(status)){
count.append(" and a.status=:status");
}
Query query = session.createQuery(count.toString());
query.setString("status",status);
String num = query.uniqueResult().toString();
session.flush();
return Integer.parseInt(num);
}catch (Exception e){
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
return 0;
}
}
@Override
public List<AlarmsHeader> getAllByStatus(String status,String eventName,String sourceName,String eventServrity,String reportingEntityName, Date createTime, Date endTime){
try (Session session = getSession()){
StringBuffer string = new StringBuffer("from AlarmsHeader a where 1=1");
if(!"0".equals(status)){
string.append(" and a.status=:status");
}
if(!"0".equals(eventName) && eventName!=null){
string.append(" and a.eventName=:eventName");
}
if(!"0".equals(sourceName) && sourceName!=null){
string.append(" and a.sourceName=:sourceName");
}
if(!"0".equals(eventServrity) && eventServrity!=null){
string.append(" and a.eventServrity=:eventServrity");
}
if(!"0".equals(reportingEntityName) && reportingEntityName!=null){
string.append(" and a.reportingEntityName=:reportingEntityName");
}
if( null!=createTime && endTime!= null) {
string.append(" and a.createTime between :startTime and :endTime");
}
Query query = session.createQuery(string.toString());
if(!"0".equals(status)) {
query.setString("status", status);
}
if(!"0".equals(eventName) && eventName!=null) {
query.setString("eventName", eventName);
}
if(!"0".equals(sourceName) && sourceName!=null) {
query.setString("sourceName", sourceName);
}
if(!"0".equals(eventServrity) && eventServrity!=null) {
query.setString("eventServrity", eventServrity);
}
if(!"0".equals(reportingEntityName) && reportingEntityName!=null) {
query.setString("reportingEntityName", reportingEntityName);
}
if( null!=createTime && endTime!= null) {
query.setDate("startTime",createTime);
query.setDate("endTime",endTime);
}
List<AlarmsHeader> list =query.list();
return list;
}catch (Exception e){
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
return null;
}
}
@Override
public AlarmsHeader getAlarmsHeaderDetail(Integer id) {
try(Session session = getSession()) {
String string = "from AlarmsHeader a where 1=1 and a.id=:id";
Query q = session.createQuery(string);
q.setInteger("id",id);
AlarmsHeader alarmsHeader =(AlarmsHeader)q.uniqueResult();
session.flush();
return alarmsHeader;
}catch (Exception e){
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAlarmsHeaderDetail."+e.getMessage());
return null;
}
}
@Override
public int getAllByDatetime(String status,String eventId, String eventServrity, String createTime) {
try (Session session = getSession()){
StringBuffer string = new StringBuffer("select count(*) as count from AlarmsHeader a where 1=1");
if(!"0".equals(status) && status!=null){
string.append(" and a.status=:status");
}
if(!"0".equals(eventId) && eventId!=null){
string.append(" and a.eventId=:eventId");
}
if(!"0".equals(eventServrity) && eventServrity!=null){
string.append(" and a.eventServrity=:eventServrity");
}
if( null!=createTime) {
string.append(" and to_days(a.createTime) = to_days('"+createTime+"')");
}
Query query = session.createQuery(string.toString());
if(!"0".equals(status) && status!=null) {
query.setString("status", status);
}
if(!"0".equals(eventId) && eventId!=null) {
query.setString("eventId", eventId);
}
if(!"0".equals(eventServrity) && eventServrity!=null) {
query.setString("eventServrity", eventServrity);
}
String num = query.uniqueResult().toString();
session.flush();
return Integer.parseInt(num);
}catch (Exception e){
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount."+e.getMessage());
return 0;
}
}
public int getAllCount(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
try(Session session = getSession()){
StringBuffer count=new StringBuffer("select count(*) from AlarmsHeader a where 1=1");
if (null == alarmsHeader) {
//logger.error("AlarmsHeaderServiceImpl getAllCount alarmsHeader is null!");
}else {
if(null!=alarmsHeader.getVersion()) {
String ver=alarmsHeader.getVersion();
count.append(" and a.version like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventName()) {
String ver=alarmsHeader.getEventName();
count.append(" and a.eventName like '%"+ver+"%'");
}
if(null!=alarmsHeader.getAlarmCondition()) {
String ver=alarmsHeader.getAlarmCondition();
count.append(" and a.alarmCondition like '%"+ver+"%'");
}
if(null!=alarmsHeader.getDomain()) {
String ver=alarmsHeader.getDomain();
count.append(" and a.domain like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventId()) {
String ver=alarmsHeader.getEventId();
count.append(" and a.eventId = '"+ver+"'");
}
if(null!=alarmsHeader.getNfcNamingCode()) {
String ver=alarmsHeader.getNfcNamingCode();
count.append(" and a.nfcNamingCode like '%"+ver+"%'");
}
if(null!=alarmsHeader.getNfNamingCode()) {
String ver=alarmsHeader.getNfNamingCode();
count.append(" and a.nfNamingCode like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSourceId()) {
String ver =alarmsHeader.getSourceId();
count.append(" and a.sourceId like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSourceName()) {
String ver =alarmsHeader.getSourceName();
count.append(" and a.sourceName like '%"+ver+"%'");
}
if(null!=alarmsHeader.getReportingEntityId()) {
String ver =alarmsHeader.getReportingEntityId();
count.append(" and a.reportingEntityId like '%"+ver+"%'");
}
if(null!=alarmsHeader.getReportingEntityName()) {
String ver =alarmsHeader.getReportingEntityName();
count.append(" and a.reportingEntityName like '%"+ver+"%'");
}
if(null!=alarmsHeader.getPriority()) {
String ver =alarmsHeader.getPriority();
count.append(" and a.priority like '%"+ver+"%'");
}
if(null!=alarmsHeader.getStartEpochMicrosec()) {
String ver =alarmsHeader.getStartEpochMicrosec();
count.append(" and a.startEpochMicrosec like '%"+ver+"%'");
}
if(null!=alarmsHeader.getLastEpochMicroSec()) {
String ver =alarmsHeader.getLastEpochMicroSec();
count.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSequence()) {
String ver =alarmsHeader.getSequence();
count.append(" and a.sequence like '%"+ver+"%'");
}
if(null!=alarmsHeader.getFaultFieldsVersion()) {
String ver =alarmsHeader.getFaultFieldsVersion();
count.append(" and a.faultFieldsVersion like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventServrity()) {
String ver =alarmsHeader.getEventServrity();
count.append(" and a.eventServrity like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventType()) {
String ver =alarmsHeader.getEventType();
count.append(" and a.eventSourceType like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventCategory()) {
String ver =alarmsHeader.getEventCategory();
count.append(" and a.eventCategory like '%"+ver+"%'");
}
if(null!=alarmsHeader.getAlarmCondition()) {
String ver =alarmsHeader.getAlarmCondition();
count.append(" and a.alarmCondition like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSpecificProblem()) {
String ver =alarmsHeader.getSpecificProblem();
count.append(" and a.specificProblem like '%"+ver+"%'");
}
if(null!=alarmsHeader.getAlarmInterfaceA()) {
String ver =alarmsHeader.getAlarmInterfaceA();
count.append(" and a.alarmInterfaceA like '%"+ver+"%'");
}
if(null!=alarmsHeader.getStatus()) {
String ver =alarmsHeader.getStatus();
count.append(" and a.status = '"+ver+"'");
}
if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
count.append(" and a.createTime between :startTime and :endTime");
}
}
Query query = session.createQuery(count.toString());
if (null != alarmsHeader)
if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
query.setDate("startTime",alarmsHeader.getCreateTime());
query.setDate("endTime",alarmsHeader.getUpdateTime());
}
String num = query.uniqueResult().toString();
session.flush();
return Integer.parseInt(num);
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl getAllCount. Details:" + e.getMessage());
return -1;
}
}
@SuppressWarnings("unchecked")
@Override
public Page<AlarmsHeader> queryAlarmsHeader(AlarmsHeader alarmsHeader,int currentPage,int pageSize) {
Page<AlarmsHeader> page = new Page<AlarmsHeader>();
int allRow =this.getAllCount(alarmsHeader,currentPage,pageSize);
int offset = page.countOffset(currentPage, pageSize);
try(Session session = getSession()){
StringBuffer hql =new StringBuffer("from AlarmsHeader a where 1=1");
if (null != alarmsHeader) {
if(null!=alarmsHeader.getVersion()) {
String ver=alarmsHeader.getVersion();
hql.append(" and a.version like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventName()) {
String ver=alarmsHeader.getEventName();
hql.append(" and a.eventName = '"+ver+"'");
}
if(null!=alarmsHeader.getAlarmCondition()) {
String ver=alarmsHeader.getAlarmCondition();
hql.append(" and a.alarmCondition like '%"+ver+"%'");
}
if(null!=alarmsHeader.getDomain()) {
String ver=alarmsHeader.getDomain();
hql.append(" and a.domain like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventId()) {
String ver=alarmsHeader.getEventId();
hql.append(" and a.eventId = '"+ver+"'");
}
if(null!=alarmsHeader.getNfcNamingCode()) {
String ver=alarmsHeader.getNfcNamingCode();
hql.append(" and a.nfcNamingCode like '%"+ver+"%'");
}
if(null!=alarmsHeader.getNfNamingCode()) {
String ver=alarmsHeader.getNfNamingCode();
hql.append(" and a.nfNamingCode like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSourceId()) {
String ver =alarmsHeader.getSourceId();
hql.append(" and a.sourceId like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSourceName()) {
String ver =alarmsHeader.getSourceName();
hql.append(" and a.sourceName like '%"+ver+"%'");
}
if(null!=alarmsHeader.getReportingEntityId()) {
String ver =alarmsHeader.getReportingEntityId();
hql.append(" and a.reportingEntityId like '%"+ver+"%'");
}
if(null!=alarmsHeader.getReportingEntityName()) {
String ver =alarmsHeader.getReportingEntityName();
hql.append(" and a.reportingEntityName like '%"+ver+"%'");
}
if(null!=alarmsHeader.getPriority()) {
String ver =alarmsHeader.getPriority();
hql.append(" and a.priority like '%"+ver+"%'");
}
if(null!=alarmsHeader.getStartEpochMicrosec()) {
String ver =alarmsHeader.getStartEpochMicrosec();
hql.append(" and a.startEpochMicrosec like '%"+ver+"%'");
}
if(null!=alarmsHeader.getLastEpochMicroSec()) {
String ver =alarmsHeader.getLastEpochMicroSec();
hql.append(" and a.lastEpochMicroSec like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSequence()) {
String ver =alarmsHeader.getSequence();
hql.append(" and a.sequence like '%"+ver+"%'");
}
if(null!=alarmsHeader.getFaultFieldsVersion()) {
String ver =alarmsHeader.getFaultFieldsVersion();
hql.append(" and a.faultFieldsVersion like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventServrity()) {
String ver =alarmsHeader.getEventServrity();
hql.append(" and a.eventServrity like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventType()) {
String ver =alarmsHeader.getEventType();
hql.append(" and a.eventSourceType like '%"+ver+"%'");
}
if(null!=alarmsHeader.getEventCategory()) {
String ver =alarmsHeader.getEventCategory();
hql.append(" and a.eventCategory like '%"+ver+"%'");
}
if(null!=alarmsHeader.getAlarmCondition()) {
String ver =alarmsHeader.getAlarmCondition();
hql.append(" and a.alarmCondition like '%"+ver+"%'");
}
if(null!=alarmsHeader.getSpecificProblem()) {
String ver =alarmsHeader.getSpecificProblem();
hql.append(" and a.specificProblem like '%"+ver+"%'");
}
/*if(null!=alarmsHeader.getVfStatus()) {
String ver =alarmsHeader.getVfStatus();
hql.append(" and a.vfStatus = '"+ver+"'");
}*/
if(null!=alarmsHeader.getAlarmInterfaceA()) {
String ver =alarmsHeader.getAlarmInterfaceA();
hql.append(" and a.alarmInterfaceA like '%"+ver+"%'");
}
if(null!=alarmsHeader.getStatus()) {
String ver =alarmsHeader.getStatus();
hql.append(" and a.status = '"+ver+"'");
}
if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
hql.append(" and a.createTime between :startTime and :endTime");
}
}
logger.info("AlarmsHeaderServiceImpl queryAlarmsHeader: alarmsHeader={}", alarmsHeader);
Query query = session.createQuery(hql.toString());
if (null != alarmsHeader)
if(null!=alarmsHeader.getCreateTime() || alarmsHeader.getUpdateTime()!= null) {
query.setDate("startTime",alarmsHeader.getCreateTime());
query.setDate("endTime",alarmsHeader.getUpdateTime());
}
query.setFirstResult(offset);
query.setMaxResults(pageSize);
List<AlarmsHeader> list= query.list();
page.setPageNo(currentPage);
page.setPageSize(pageSize);
page.setTotalRecords(allRow);
page.setList(list);
session.flush();
return page;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryAlarmsHeader. Details:" + e.getMessage());
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public List<AlarmsHeader> queryId(String[] id) {
try(Session session = getSession()){
if(id.length==0) {
logger.error("AlarmsHeaderServiceImpl queryId is null!");
}
List<AlarmsHeader> list = new ArrayList<AlarmsHeader>();
Query query = session.createQuery("from AlarmsHeader a where a.eventName IN (:alist)");
list = query.setParameterList("alist", id).list();
return list;
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryId. Details:" + e.getMessage());
return null;
}
}
@Override
public String queryStatusCount(String status) {
try(Session session = getSession()){
String hql = "select count(status) from AlarmsHeader a";
if (!status.equals("0"))
hql+=" where a.status = :status";
Query query = session.createQuery(hql);
if (!status.equals("0"))
query.setString("status",status);
return query.uniqueResult().toString();
} catch (Exception e) {
logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryStatusCount. Details:" + e.getMessage());
return null;
}
}
}
|