4e0f8f9cd7eac64a13d51d3b70cbe79ceaf336a8
[usecase-ui/server.git] / src / main / java / org / onap / usecaseui / server / service / impl / AlarmServiceImpl.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.service.impl;
17
18 import java.util.UUID;
19
20 import javax.transaction.Transactional;
21
22 import org.hibernate.Session;
23 import org.hibernate.SessionFactory;
24 import org.hibernate.Transaction;
25 import org.onap.usecaseui.server.bean.ActiveAlarmInfo;
26 import org.onap.usecaseui.server.service.AlarmService;
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.Service;
32
33
34 @Service("AlarmService")
35 @Transactional
36 @org.springframework.context.annotation.Configuration
37 @EnableAspectJAutoProxy
38 public class AlarmServiceImpl implements AlarmService
39 {
40     private static final Logger logger = LoggerFactory.getLogger(AlarmServiceImpl.class);
41
42     @Autowired
43     private SessionFactory sessionFactory;
44     
45     public String hello()
46     {
47         return "Hello";
48     }
49
50
51     @Transactional
52     public String saveActiveAlarmInfo(ActiveAlarmInfo acAlarmInfo)
53     {
54         try
55         {
56             if (null == acAlarmInfo)
57             {
58                 logger.error("AlarmServiceImpl saveActiveAlarmInfo acAlarmInfo is null!");
59             }
60             logger.info("AlarmServiceImpl saveActiveAlarmInfo: acAlarmInfo={}", acAlarmInfo);
61             Session session = sessionFactory.openSession();
62             Transaction tx = session.beginTransaction();     
63             acAlarmInfo.setId(UUID.randomUUID().toString());
64             session.save(acAlarmInfo);
65             tx.commit();
66             session.flush();
67             session.close();
68         }
69         catch (Exception e)
70         {
71             logger.error("Exception occurred while performing AlarmServiceImpl saveActiveAlarmInfo. Details:" + e.getMessage());
72         }
73         
74         return acAlarmInfo.getId();
75     }
76     
77 }