2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.scheduler;
22 import java.text.ParseException;
23 import java.util.HashMap;
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;
41 * Extra depends-on annotation tells Spring that the system properties object
42 * will be used in the constructor.
45 // @DependsOn({ "manageService", "epAppService", "systemProperties" })
46 @DependsOn({ "systemProperties" })
47 public class SessionMgtRegistry extends CronRegistry implements ApplicationContextAware {
49 EELFLoggerDelegate logger = null;
51 private static final String groupName = "AppGroup";
52 private static final String jobName = "PortalSessionTimeoutFeedJob";
53 private static final String triggerName = "PortalSessionTimeoutFeedTrigger";
55 // Not strictly necessary, but preparing for the day
56 // when the getProperty method is not static.
58 private SystemProperties systemProperties;
60 private ApplicationContext applicationContext;
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);
68 @SuppressWarnings("static-access")
69 public CronTriggerFactoryBean cronTriggerFactoryBean() throws ParseException {
70 logger = EELFLoggerDelegate.getLogger(SessionMgtRegistry.class);
71 String property = "* * * * * ? 2099";
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,
79 return cronTriggerFactoryBean(groupName, triggerName, property);
83 public void setApplicationContext(ApplicationContext _applicationContext) throws BeansException {
84 applicationContext = _applicationContext;
85 TimeoutHandler.setApplicationContext(applicationContext);
86 UserSessionListener.setApplicationContext(_applicationContext);