Commits

gfouquet  committed 29ba659

[Issue 1762] Execution "opening" was not registered because application state
was not properly initialized.

Renamed HttpSessionListenerImpl into OpenedEntitiesLifecycleListener

  • Participants
  • Parent commits 940e21e

Comments (0)

Files changed (6)

File core/core.web/src/main/webapp/WEB-INF/web.xml

 		<param-value>${project.stage}</param-value><!--  ensure that the values are DEV or RELEASE -->
 	</context-param>	
 	 <!-- ================ Listner ====================== -->
-	 <listener><listener-class>org.squashtest.csp.tm.web.internal.listner.HttpSessionListnerImpl</listener-class></listener>
+  <listener>
+    <listener-class>org.squashtest.csp.tm.web.internal.listner.OpenedEntitiesLifecycleListener</listener-class>
+  </listener>
 </web-app>

File tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/interceptor/OpenedEntities.java

 import org.squashtest.csp.tm.domain.campaign.Campaign;
 import org.squashtest.csp.tm.domain.campaign.Iteration;
 import org.squashtest.csp.tm.domain.campaign.TestSuite;
+import org.squashtest.csp.tm.domain.execution.Execution;
 import org.squashtest.csp.tm.domain.requirement.Requirement;
 import org.squashtest.csp.tm.domain.testcase.TestCase;
 /**
  * 	handle the opening of a new view and add the boolean "otherViewers" to the mav. </li>
  * <li>add the <span style="color:darkgreen">component "opened-object"</span> in the view to notify the user if he is not alone viewing this object and to send a quit request if the user leaves the view</li>
  * <li>add the leaveObject method in the <span style="color:darkgreen">ObjectAccessController</span> </li>
- * <li>add the object class.simpleName to the <span style="color:darkgreen">MANAGED_ENTITIES_LIST</span> below</li>. This will allow the HttpSessionListnerImpl to create the needed OpenedEntities at the start of squash and to close the view of a user the end of his session</ol>
+ * <li>add the object class.simpleName to the <span style="color:darkgreen">MANAGED_ENTITIES_LIST</span> below</li>. This will allow the OpenedEntitiesLifecycleListener to create the needed OpenedEntities at the start of squash and to close the view of a user the end of his session</ol>
  * <br>
  * <b>How to add a view to a managed entity</b>
  * <ol><li>add the view's access url to the rightful interceptor in the <span style="color:darkgreen">serlvet.xml</span></li>
 	private Map<Long, OpenedEntity> entitiesViewers;
 	
 	public static final List<String> MANAGED_ENTITIES_LIST = Arrays.asList(TestCase.class.getSimpleName(),
-			Requirement.class.getSimpleName(), Campaign.class.getSimpleName(), Iteration.class.getSimpleName(), TestSuite.class.getSimpleName());
+			Requirement.class.getSimpleName(), Campaign.class.getSimpleName(), Iteration.class.getSimpleName(), TestSuite.class.getSimpleName(), Execution.class.getSimpleName());
 
 	public OpenedEntities(){
 		entitiesViewers = new HashMap<Long, OpenedEntity>();

File tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/listner/HttpSessionListnerImpl.java

-/**
- *     This file is part of the Squashtest platform.
- *     Copyright (C) 2010 - 2012 Henix, henix.fr
- *
- *     See the NOTICE file distributed with this work for additional
- *     information regarding copyright ownership.
- *
- *     This is free software: you can redistribute it and/or modify
- *     it under the terms of the GNU Lesser General Public License as published by
- *     the Free Software Foundation, either version 3 of the License, or
- *     (at your option) any later version.
- *
- *     this software is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU Lesser General Public License for more details.
- *
- *     You should have received a copy of the GNU Lesser General Public License
- *     along with this software.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.squashtest.csp.tm.web.internal.listner;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-import javax.servlet.http.HttpSessionListener;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContext;
-import org.squashtest.csp.tm.web.internal.interceptor.OpenedEntities;
-/**
- * This lisner acts when the ServletContext is created or when a user's session is ending.
- * <ul><li>When the servletContext is created : a OpenedEntities instance is created and stored in the servletContext for each entry in the {@linkplain OpenedEntities#MANAGED_ENTITIES_LIST}.</li>
- * <li>When a user's session is ending, all his stored views on the existing OpenedEntities are removed</li></ul>
- * The aim of all this is to notify a user when someone else is viewing the same object than him. See {@linkplain OpenedEntities}'s java doc for more details.
- * 
- * @author mpagnon
- *
- */
-public class HttpSessionListnerImpl implements HttpSessionListener, ServletContextListener{
-	private static final Logger LOGGER = LoggerFactory.getLogger(HttpSessionListnerImpl.class);
-
-	@Override
-	public void sessionCreated(HttpSessionEvent arg0) {
-		// TODO Auto-generated method stub
-
-	}
-	
-	@Override
-	public void sessionDestroyed(HttpSessionEvent arg0) {
-		ServletContext context = arg0.getSession().getServletContext();
-		HttpSession session = arg0.getSession();
-		SecurityContext securityContext = (SecurityContext) session.getAttribute("SPRING_SECURITY_CONTEXT");
-		String login = null ;
-		if(securityContext != null){
-			Authentication authentication = securityContext.getAuthentication();
-			if(authentication != null ){
-				login = authentication.getName();
-			}
-		}
-		if (login != null) {
-			LOGGER.debug("Session Closed for user "+login);
-			for (String managedEntityKey : OpenedEntities.MANAGED_ENTITIES_LIST) {
-				removeUserFromViewers(managedEntityKey, login, context);
-			}
-		}
-	}
-
-	private void removeUserFromViewers(String managedEntityKey, String login, ServletContext context) {
-		OpenedEntities openedEntities = (OpenedEntities) context.getAttribute(managedEntityKey);
-		if(openedEntities != null){openedEntities.removeViewer(login);}
-	}
-
-
-
-	@Override
-	public void contextDestroyed(ServletContextEvent arg0) {
-		
-		
-	}
-
-
-
-	@Override
-	public void contextInitialized(ServletContextEvent arg0) {
-		ServletContext context = arg0.getServletContext();
-		LOGGER.debug("ServletContext attribute is null");
-		for (String contextAttributeName : OpenedEntities.MANAGED_ENTITIES_LIST) {
-			OpenedEntities entities = new OpenedEntities();
-			context.setAttribute(contextAttributeName, entities);
-		}
-		
-	}
-
-}

File tm/tm.web/src/main/java/org/squashtest/csp/tm/web/internal/listner/OpenedEntitiesLifecycleListener.java

+/**
+ *     This file is part of the Squashtest platform.
+ *     Copyright (C) 2010 - 2012 Henix, henix.fr
+ *
+ *     See the NOTICE file distributed with this work for additional
+ *     information regarding copyright ownership.
+ *
+ *     This is free software: you can redistribute it and/or modify
+ *     it under the terms of the GNU Lesser General Public License as published by
+ *     the Free Software Foundation, either version 3 of the License, or
+ *     (at your option) any later version.
+ *
+ *     this software is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU Lesser General Public License for more details.
+ *
+ *     You should have received a copy of the GNU Lesser General Public License
+ *     along with this software.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.squashtest.csp.tm.web.internal.listner;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContext;
+import org.squashtest.csp.tm.web.internal.interceptor.OpenedEntities;
+
+/**
+ * This lisner acts when the ServletContext is created or when a user's session is ending.
+ * <ul>
+ * <li>When the servletContext is created : a OpenedEntities instance is created and stored in the servletContext for
+ * each entry in the {@linkplain OpenedEntities#MANAGED_ENTITIES_LIST}.</li>
+ * <li>When a user's session is ending, all his stored views on the existing OpenedEntities are removed</li>
+ * </ul>
+ * The aim of all this is to notify a user when someone else is viewing the same object than him. See
+ * {@linkplain OpenedEntities}'s java doc for more details.
+ * 
+ * @author mpagnon
+ * 
+ */
+public class OpenedEntitiesLifecycleListener implements HttpSessionListener, ServletContextListener {
+	private static final Logger LOGGER = LoggerFactory.getLogger(OpenedEntitiesLifecycleListener.class);
+
+	@Override
+	public void sessionCreated(HttpSessionEvent event) {
+		// NOOP
+
+	}
+
+	@Override
+	public void sessionDestroyed(HttpSessionEvent event) {
+		ServletContext context = event.getSession().getServletContext();
+		HttpSession session = event.getSession();
+		SecurityContext securityContext = (SecurityContext) session.getAttribute("SPRING_SECURITY_CONTEXT");
+
+		String login = retrieveLogin(securityContext);
+		
+		unregisterLogin(context, login);
+	}
+
+	private void unregisterLogin(ServletContext context, String login) {
+		if (login != null) {
+			LOGGER.debug("Session Closed for user {}", login);
+			
+			for (String managedEntityKey : OpenedEntities.MANAGED_ENTITIES_LIST) {
+				removeUserFromViewers(managedEntityKey, login, context);
+			}
+		}
+	}
+
+	private String retrieveLogin(SecurityContext securityContext) {
+		String login = null;
+		
+		if (securityContext != null) {
+			Authentication authentication = securityContext.getAuthentication();
+			if (authentication != null) {
+				login = authentication.getName();
+			}
+		}
+		return login;
+	}
+
+	private void removeUserFromViewers(String managedEntityKey, String login, ServletContext context) {
+		OpenedEntities openedEntities = (OpenedEntities) context.getAttribute(managedEntityKey);
+		if (openedEntities != null) {
+			openedEntities.removeViewer(login);
+		}
+	}
+
+	@Override
+	public void contextDestroyed(ServletContextEvent event) {
+		// NOOP
+
+	}
+
+	@Override
+	public void contextInitialized(ServletContextEvent event) {
+		ServletContext context = event.getServletContext();
+
+		for (String contextAttributeName : OpenedEntities.MANAGED_ENTITIES_LIST) {
+			OpenedEntities entities = new OpenedEntities();
+			context.setAttribute(contextAttributeName, entities);
+		}
+
+	}
+
+}

File tm/tm.web/src/main/webapp/WEB-INF/jsp/fragment/executions/edit-execution.jsp

 <comp:rich-jeditable-header />
 <%-- ----------------------------------- Authorization ----------------------------------------------%>
 <c:set var="editable" value="${ false }" />
-<authz:authorized hasRole="ROLE_ADMIN" hasPermission="EXECUTE"
-	domainObject="${ execution }">
+<authz:authorized hasRole="ROLE_ADMIN" hasPermission="EXECUTE" domainObject="${ execution }">
 	<c:set var="editable" value="${ true }" />
 </authz:authorized>
 <c:set var="automated"
 
 </script>
 
-
 <div
 	class="ui-widget-header ui-state-default ui-corner-all fragment-header">
 
 
 
 	<div style="clear: both;"></div>
-	<c:if test="${ editable }">
-		<comp:opened-object otherViewers="${ otherViewers }"
-			objectUrl="${ executionUrl }" isContextual="false" />
-	</c:if>
 </div>
 
 <div class="fragment-body">
 			</c:if>
 		</div>
 		<div style="clear: both;"></div>
+    <c:if test="${ editable }">
+      <comp:opened-object otherViewers="${ otherViewers }" objectUrl="${ executionUrl }" isContextual="false" />
+    </c:if>
 	</div>
 
 	<%----------------------------------- Information -----------------------------------------------%>

File tm/tm.web/src/main/webapp/WEB-INF/jsp/fragment/iterations/edit-iteration.jsp

 	</div>
 	<div style="clear: both;"></div>
 	<c:if test="${ moreThanReadOnly }">
-		<comp:opened-object otherViewers="${ otherViewers }"
-			objectUrl="${ iterationUrl }" isContextual="${ ! param.isInfoPage }" />
+		<comp:opened-object otherViewers="${ otherViewers }" objectUrl="${ iterationUrl }" isContextual="${ ! param.isInfoPage }" />
 	</c:if>
 </div>
 
+<comp:fragment-tabs />
 
-<comp:fragment-tabs />
 <div class="fragment-tabs fragment-body">
 	<ul>
 		<li><a href="#tabs-1"><f:message key="tabs.label.information" />