Initialization of authorization service from the code is now working.
[photos] / src / main / java / org / wamblee / photos / model / plumbing / Initializer.java
index 250964148edf1b745666fbd7cf83826108f0a64e..850f6f47720b38e49adc7de50972ed5c542b2667 100644 (file)
  */
 package org.wamblee.photos.model.plumbing;
 
+import java.util.logging.Logger;
+
 import javax.annotation.PostConstruct;
 import javax.ejb.Singleton;
 import javax.ejb.Startup;
 import javax.inject.Inject;
 
+import org.wamblee.inject.InjectorBuilder;
 import org.wamblee.photos.model.Album;
 import org.wamblee.security.authentication.UserAdministration;
+import org.wamblee.security.authorization.AuthorizationService;
 
 /**
  * @author Erik Brakkee
@@ -31,18 +35,44 @@ import org.wamblee.security.authentication.UserAdministration;
 @Startup
 public class Initializer {
 
-    @Inject
-    private UserAdministration userAdmin;
+       private static final Logger LOGGER = Logger.getLogger(Initializer.class
+                       .getName());
+
+       /**
+        * We need this helper to do initialization of the beans from within the
+        * post construct method. Injecting these objects into the initializer class
+        * will lead to initialization outside of a transactional context and this
+        * is does not work because and entity manager is required.
+        * 
+        * @author Erik Brakkee
+        * 
+        */
+       public static class Helper {
+               @Inject
+               private UserAdministration userAdmin;
+
+               @Inject
+               private AuthorizationService authorizationService;
 
-    @Inject
-    @AllPhotos
-    private Album album;
+               @Inject
+               @AllPhotos
+               private Album album;
 
-    @PostConstruct
-    public void init() {
-        System.out.println("Photo application initializing");
+               public void init() {
+                       userAdmin.getUserCount();
+                       album.size();
+                       authorizationService.getRules();
+               }
+       }
 
-        userAdmin.getUserCount();
-        album.size();
-    }
+       @PostConstruct
+       public void scheduleInit() {
+               LOGGER.info("Photo application initializing");
+               // timerService.createTimer(1000, 1000, null);
+               LOGGER.info("Initializing photo application");
+               Helper helper = new Helper();
+               InjectorBuilder.getInjector().inject(helper);
+               helper.init();
+               LOGGER.info("Initialized photo application");
+       }
 }