[seam-commits] Seam SVN: r13445 - in modules/security/trunk: examples/idmconsole/src/main/webapp/WEB-INF and 2 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jul 20 01:47:48 EDT 2010


Author: shane.bryzak at jboss.com
Date: 2010-07-20 01:47:48 -0400 (Tue, 20 Jul 2010)
New Revision: 13445

Modified:
   modules/security/trunk/examples/idmconsole/src/main/java/org/jboss/seam/security/examples/idmconsole/action/EntityManagerProducer.java
   modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml
   modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
   modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java
Log:
implement group delete


Modified: modules/security/trunk/examples/idmconsole/src/main/java/org/jboss/seam/security/examples/idmconsole/action/EntityManagerProducer.java
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/java/org/jboss/seam/security/examples/idmconsole/action/EntityManagerProducer.java	2010-07-19 22:31:04 UTC (rev 13444)
+++ modules/security/trunk/examples/idmconsole/src/main/java/org/jboss/seam/security/examples/idmconsole/action/EntityManagerProducer.java	2010-07-20 05:47:48 UTC (rev 13445)
@@ -4,13 +4,27 @@
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.inject.Produces;
 import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
 
 import org.jboss.seam.drools.qualifiers.Stateless;
+import org.jboss.seam.persistence.SeamManaged;
 
 @Stateless
 public class EntityManagerProducer
 {
-   @Produces /*@ManagedPersistenceContext @ConversationScoped*/ @RequestScoped 
-   @PersistenceContext(unitName = "idmconsoleDatabase") EntityManager entityManager;
+   //@Produces /*@ManagedPersistenceContext @ConversationScoped*/ @RequestScoped 
+   //@PersistenceContext(unitName = "idmconsoleDatabase") EntityManager entityManager;
+   
+//   @Produces @RequestScoped
+   //public EntityManager produceEM()
+   //{
+     // return entityManager;
+   //}
+      @PersistenceUnit
+      @RequestScoped
+      @Produces
+      @SeamManaged
+      EntityManagerFactory emf;   
 }

Modified: modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml	2010-07-19 22:31:04 UTC (rev 13444)
+++ modules/security/trunk/examples/idmconsole/src/main/webapp/WEB-INF/faces-config.xml	2010-07-20 05:47:48 UTC (rev 13445)
@@ -23,9 +23,26 @@
          <to-view-id>/userdetail.xhtml</to-view-id>
          <redirect/>
       </navigation-case>
+      
+      <navigation-case>
+        <from-action>#{userAction.deleteUser(user.username)}</from-action>
+        <if>#{true}</if>
+        <to-view-id>/manageusers.xhtml</to-view-id>
+        <redirect/>
+      </navigation-case>
    </navigation-rule>
    
    <navigation-rule>
+      <from-view-id>/managegroups.xhtml</from-view-id>
+      <navigation-case>
+         <from-action>#{groupAction.deleteGroup(group.name, group.groupType)}</from-action>
+         <if>#{true}</if>
+         <to-view-id>/managegroups.xhtml</to-view-id>
+         <redirect />
+      </navigation-case>
+   </navigation-rule>
+   
+   <navigation-rule>
       <from-view-id>/userdetail.xhtml</from-view-id>
       <navigation-case>
          <from-action>#{userAction.save}</from-action>

Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java	2010-07-19 22:31:04 UTC (rev 13444)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserSearch.java	2010-07-20 05:47:48 UTC (rev 13445)
@@ -20,8 +20,11 @@
       
    @Inject IdentityManager identityManager;
    
-   @Inject public void loadUsers()
-   {       
+   private boolean loaded;
+   
+   public void loadUsers()
+   {
+      loaded = true;
       users = new ArrayList<UserDTO>();
       
       Collection<User> results = identityManager.findUsers(null);  
@@ -51,6 +54,7 @@
    
    public List<UserDTO> getUsers()
    {
+      if (!loaded) loadUsers();
       return users;
    }   
    

Modified: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java	2010-07-19 22:31:04 UTC (rev 13444)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/picketlink/JpaIdentityStore.java	2010-07-20 05:47:48 UTC (rev 13445)
@@ -1400,6 +1400,8 @@
          IdentityStoreInvocationContext ctx, IdentityObject identity)
          throws IdentityException
    {
+      removeRelationships(ctx, identity, null, false);
+      
       Property<?> nameProperty = modelProperties.get(PROPERTY_IDENTITY_NAME);
       Property<?> typeProperty = modelProperties.get(PROPERTY_IDENTITY_TYPE);
       
@@ -1484,12 +1486,65 @@
    }
 
    public void removeRelationships(
-         IdentityStoreInvocationContext invocationCtx,
+         IdentityStoreInvocationContext ctx,
          IdentityObject identity1, IdentityObject identity2, boolean named)
          throws IdentityException
    {
-      // TODO Auto-generated method stub
-      System.out.println("*** Invoked unimplemented method removeRelationships()");
+      EntityManager em = getEntityManager(ctx);
+      
+      CriteriaBuilder builder = em.getCriteriaBuilder();
+      CriteriaQuery<?> criteria = builder.createQuery(relationshipClass);
+      Root<?> root = criteria.from(relationshipClass);
+      
+      Property<?> relationshipFromProp = modelProperties.get(PROPERTY_RELATIONSHIP_FROM);
+      Property<?> relationshipToProp = modelProperties.get(PROPERTY_RELATIONSHIP_TO);
+      
+      List<Predicate> predicates = new ArrayList<Predicate>();
+      
+      if (identity1 != null)
+      {
+         predicates.add(builder.equal(root.get(relationshipFromProp.getName()),
+               lookupIdentity(identity1, em)));
+      }
+      
+      if (identity2 != null)
+      {
+         predicates.add(builder.equal(root.get(relationshipToProp.getName()),
+               lookupIdentity(identity2, em)));
+      }
+      
+      criteria.where(predicates.toArray(new Predicate[0]));
+      
+      List<?> results = em.createQuery(criteria).getResultList();
+      for (Object result : results)
+      {
+         em.remove(result);
+      }
+      
+      criteria = builder.createQuery(relationshipClass);
+      criteria.from(relationshipClass);
+      
+      predicates = new ArrayList<Predicate>();
+      
+      if (identity2 != null)
+      {
+         predicates.add(builder.equal(root.get(relationshipFromProp.getName()),
+               lookupIdentity(identity2, em)));
+      }
+      
+      if (identity1 != null)
+      {
+         predicates.add(builder.equal(root.get(relationshipToProp.getName()),
+               lookupIdentity(identity1, em)));
+      }
+      
+      criteria.where(predicates.toArray(new Predicate[0]));
+      
+      results = em.createQuery(criteria).getResultList();
+      for (Object result : results)
+      {
+         em.remove(result);
+      }
    }
 
    public Set<IdentityObjectRelationship> resolveRelationships(



More information about the seam-commits mailing list