e263d7ec1d351a4e573bf5a25fa4029a9545b875
[portal.git] / ecomp-portal-BE-os / src / main / java / org / onap / portalapp / scheduler / SessionMgtRegistry.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.scheduler;
39
40 import java.text.ParseException;
41 import java.util.HashMap;
42 import java.util.Map;
43
44 import org.onap.portalapp.portal.listener.UserSessionListener;
45 import org.onap.portalapp.service.sessionmgt.TimeoutHandler;
46 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
47 import org.onap.portalsdk.core.scheduler.CronRegistry;
48 import org.onap.portalsdk.core.util.SystemProperties;
49 import org.springframework.beans.BeansException;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.context.ApplicationContext;
52 import org.springframework.context.ApplicationContextAware;
53 import org.springframework.context.annotation.DependsOn;
54 import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
55 import org.springframework.scheduling.quartz.JobDetailFactoryBean;
56 import org.springframework.stereotype.Component;
57
58 /**
59  * Extra depends-on annotation tells Spring that the system properties object
60  * will be used in the constructor.
61  */
62 @Component
63 // @DependsOn({ "manageService", "epAppService", "systemProperties" })
64 @DependsOn({ "systemProperties" })
65 public class SessionMgtRegistry extends CronRegistry implements ApplicationContextAware {
66
67         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SessionMgtRegistry.class);
68         
69         private static final String groupName = "AppGroup";
70         private static final String jobName = "PortalSessionTimeoutFeedJob";
71         private static final String triggerName = "PortalSessionTimeoutFeedTrigger";
72
73         // Not strictly necessary, but preparing for the day
74         // when the getProperty method is not static.
75         @Autowired
76         private SystemProperties systemProperties;
77
78         private ApplicationContext applicationContext;
79
80         public JobDetailFactoryBean jobDetailFactoryBean() {
81                 Map<String, Object> map = new HashMap<String, Object>();
82                 return jobDetailFactoryBean(groupName, jobName, TimeoutHandler.class, map);
83         }
84
85         @SuppressWarnings("static-access")
86         public CronTriggerFactoryBean cronTriggerFactoryBean() throws ParseException {
87                 String property = "* * * * * ? 2099";
88                 try {
89                         property = systemProperties.getProperty(SystemProperties.SESSIONTIMEOUT_FEED_CRON);
90                 } catch (Exception e) {
91                         logger.error(EELFLoggerDelegate.errorLogger, 
92                                         "Failed to retrieve " + SystemProperties.SESSIONTIMEOUT_FEED_CRON + ", defaulting to " + property,
93                                         e);
94                 }
95                 return cronTriggerFactoryBean(groupName, triggerName, property);
96         }
97
98         @Override
99         public void setApplicationContext(ApplicationContext _applicationContext) throws BeansException {
100                 applicationContext = _applicationContext;
101                 TimeoutHandler.setApplicationContext(applicationContext);
102                 UserSessionListener.setApplicationContext(_applicationContext);
103         }
104
105 }