Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
KualiHttpSessionListener |
|
| 3.0;3 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php | |
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.kuali.rice.krad.web.listener; | |
17 | ||
18 | import javax.servlet.http.HttpSessionEvent; | |
19 | import javax.servlet.http.HttpSessionListener; | |
20 | ||
21 | import org.apache.commons.lang.StringUtils; | |
22 | import org.kuali.rice.kew.api.exception.WorkflowException; | |
23 | import org.kuali.rice.krad.UserSession; | |
24 | import org.kuali.rice.krad.document.Document; | |
25 | import org.kuali.rice.krad.document.authorization.PessimisticLock; | |
26 | import org.kuali.rice.krad.service.KRADServiceLocatorWeb; | |
27 | import org.kuali.rice.krad.util.GlobalVariables; | |
28 | import org.kuali.rice.krad.util.KRADConstants; | |
29 | import org.kuali.rice.krad.util.ObjectUtils; | |
30 | ||
31 | ||
32 | /** | |
33 | * This class is used to handle session timeouts where {@link PessimisticLock} objects should | |
34 | * be removed from a document | |
35 | * | |
36 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
37 | * | |
38 | */ | |
39 | 0 | public class KualiHttpSessionListener implements HttpSessionListener { |
40 | ||
41 | /** | |
42 | * EMPTY METHOD IMPLEMENTATION | |
43 | */ | |
44 | public void sessionCreated(HttpSessionEvent se) { | |
45 | // no operation required at this time | |
46 | 0 | } |
47 | ||
48 | /** | |
49 | * This method checks for the existence of a document based on session variables and deletes any locks | |
50 | * associated with the document that belong to the current user | |
51 | * | |
52 | * @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent) | |
53 | */ | |
54 | public void sessionDestroyed(HttpSessionEvent se) { | |
55 | 0 | String documentNumber = (String) se.getSession().getAttribute(KRADConstants.DOCUMENT_HTTP_SESSION_KEY); |
56 | 0 | if (StringUtils.isNotBlank(documentNumber)) { |
57 | try { | |
58 | // document service needs the usersession to operate but we need the document from document service to verify it exists | |
59 | 0 | GlobalVariables.setUserSession((UserSession)se.getSession().getAttribute(KRADConstants.USER_SESSION_KEY)); |
60 | 0 | Document document = KRADServiceLocatorWeb.getDocumentService().getByDocumentHeaderId(documentNumber); |
61 | 0 | if (ObjectUtils.isNotNull(document)) { |
62 | 0 | KRADServiceLocatorWeb.getPessimisticLockService().releaseAllLocksForUser(document.getPessimisticLocks(), GlobalVariables.getUserSession().getPerson()); |
63 | } | |
64 | 0 | } catch (WorkflowException e) { |
65 | 0 | throw new RuntimeException(e); |
66 | } finally { | |
67 | 0 | GlobalVariables.setUserSession(null); |
68 | 0 | } |
69 | ||
70 | } | |
71 | 0 | } |
72 | ||
73 | } | |
74 |