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