nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / service / sessionmgt / ManageService.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.service.sessionmgt;
21
22 import java.util.Calendar;
23 import java.util.Date;
24 import java.util.List;
25
26 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
27 import org.openecomp.portalapp.portal.service.EPAppService;
28 import org.openecomp.portalapp.portal.transport.OnboardingApp;
29 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
30 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
31 import org.openecomp.portalsdk.core.onboarding.crossapi.PortalTimeoutHandler;
32 import org.openecomp.portalsdk.core.util.SystemProperties;
33 import org.quartz.CronExpression;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.EnableAspectJAutoProxy;
36 import org.springframework.stereotype.Service;
37 import org.springframework.util.StringUtils;
38
39 @Service("manageService")
40 @org.springframework.context.annotation.Configuration
41 @EnableAspectJAutoProxy
42 @EPMetricsLog
43 public class ManageService implements PortalTimeoutHandler.SessionCommInf {
44         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManageService.class);
45         
46         @Autowired
47         EPAppService appService;
48         
49         @Autowired
50         SessionCommunication sessionCommunication;
51
52         public Integer fetchSessionSlotCheckInterval(String... params) throws Exception {
53
54                 String defaultCronExpressionStr = "0 0/5 * * * ? *";
55                 String cronExpressionStr = SystemProperties.getProperty(SystemProperties.SESSIONTIMEOUT_FEED_CRON);
56
57                 if (cronExpressionStr == null) {
58                         cronExpressionStr = defaultCronExpressionStr;
59                 }
60
61                 CronExpression cal = new CronExpression(cronExpressionStr);
62                 final Date nowTime = Calendar.getInstance().getTime();
63                 Date nextTime = cal.getNextValidTimeAfter(nowTime);
64                 Date nextNextTime = cal.getNextValidTimeAfter(nextTime);
65
66                 final int timeDiff = (int)(nextNextTime.getTime()-nextTime.getTime());
67                 logger.debug(EELFLoggerDelegate.debugLogger, "Time interval between subsequent session checks " + timeDiff);
68
69                 return timeDiff;
70         }
71
72         public void extendSessionTimeOuts(String... params) throws Exception {
73                 try {
74                         String sessionMap = params[3];
75         
76                         logger.debug(EELFLoggerDelegate.debugLogger, "Extending the App sessions for last minute request: " + sessionMap);
77                         
78                         if (StringUtils.isEmpty(sessionMap)) {
79                                 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts: Skipping session updates since the portal session value is empty.");
80                         } else {
81                                 List<OnboardingApp> appList = appService.getEnabledNonOpenOnboardingApps();
82                                 for (OnboardingApp onApp : appList) {
83                                         sessionCommunication.pingSession(onApp, sessionMap);
84                                 }
85                                 updateSessionExtensions(sessionMap);
86                                 sessionCommunication.clear(false);
87                         }
88                 } catch (Exception e) {
89                         logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred in extendSessionTimeOuts(). Details: " + EcompPortalUtils.getStackTrace(e)); 
90                 }
91         }
92
93         public String gatherSessionExtenstions() {
94                 return PortalTimeoutHandler.gatherSessionExtensions();
95         }
96
97         public void updateSessionExtensions(String sessionTimeoutMapStr) throws Exception {
98                 PortalTimeoutHandler.updateSessionExtensions(sessionTimeoutMapStr);
99         }
100
101 }