Author: Alex.Kolonitsky
Date: 2009-05-07 10:28:03 -0400 (Thu, 07 May 2009)
New Revision: 14065
Added:
trunk/examples/photoalbum/source/web/src/main/resources/environment.properties
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java
Log:
add environment.properties
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java 2009-05-07
14:27:57 UTC (rev 14064)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/SessionListener.java 2009-05-07
14:28:03 UTC (rev 14065)
@@ -1,10 +1,16 @@
package org.richfaces.photoalbum.util;
import java.util.List;
+import java.util.Properties;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
import javax.persistence.EntityManager;
+import javax.servlet.ServletContext;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.contexts.ServletLifecycle;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
@@ -22,24 +28,55 @@
@Name("sessionListener")
@Startup
public class SessionListener {
+ public static final String ENVIRONMENT_PROPERTIES = "environment.properties";
- @In(required=false) User user;
-
- @In IImageAction imageAction;
-
- @In(value="entityManager") EntityManager em;
-
- @Destroy @Transactional @Observer("org.jboss.seam.sessionExpired")
+ public static final String ENVIRONMENT = "environment";
+ public static final String DEVELOPMENT = "development";
+ public static final String PRODUCTION = "production";
+
+
+ @In(required=false)
+ private User user;
+
+ @In
+ private IImageAction imageAction;
+ @In(value="entityManager")
+ private EntityManager em;
+
+ @Destroy
+ @Transactional
+ @Observer("org.jboss.seam.sessionExpired")
public void onDestroy(){
+ final String environment = getEnviroment();
+ if (DEVELOPMENT.equals(environment)) {
+ return;
+ }
+
if(user.getId() != null && !user.isPreDefined()){
user = em.merge(user);
- List<Comment> userComments = imageAction.findAllUserComments(user);
- for(Comment c : userComments){
+ final List<Comment> userComments = imageAction.findAllUserComments(user);
+ for (Comment c : userComments) {
em.remove(c);
}
em.remove(user);
em.flush();
+
Events.instance().raiseEvent(Constants.USER_DELETED_EVENT, user);
}
}
+
+ private String getEnviroment() {
+ try {
+ final Properties props = new Properties();
+ props.load(new FileInputStream(ServletLifecycle.getServletContext()
+ .getRealPath("WEB-INF/classes/" + ENVIRONMENT_PROPERTIES)));
+ return props.getProperty(ENVIRONMENT);
+ } catch (FileNotFoundException e) {
+ // Do nothing.
+ } catch (IOException e) {
+ // Do nothing.
+ }
+
+ return null;
+ }
}
Added: trunk/examples/photoalbum/source/web/src/main/resources/environment.properties
===================================================================
--- trunk/examples/photoalbum/source/web/src/main/resources/environment.properties
(rev 0)
+++
trunk/examples/photoalbum/source/web/src/main/resources/environment.properties 2009-05-07
14:28:03 UTC (rev 14065)
@@ -0,0 +1 @@
+environment=development
\ No newline at end of file
Show replies by date