Package org.exoplatform.services.organization

Examples of org.exoplatform.services.organization.Membership


    */
   public void testFindMembership() throws Exception
   {
      createMembership(userName, groupName1, membershipType);

      Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
      assertNotNull(mHandler.findMembership(m.getId()));

      // try to find not existed membership. We are supposed to get Exception
      try
      {
         assertNull(mHandler.findMembership("not-existed-id"));
View Full Code Here


   /**
    * Find membership by user and group.
    */
   public void testFindMembershipByUserGroupAndType() throws Exception
   {
      Membership m = mHandler.findMembershipByUserGroupAndType("marry", "/platform/users", "member");

      assertNotNull(m);
      assertEquals(m.getGroupId(), "/platform/users");
      assertEquals(m.getMembershipType(), "member");
      assertEquals(m.getUserName(), "marry");

      // try to find not existed membership. We are supposed to get null instead of Exception
      try
      {
         assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/platform/users", "member"));
View Full Code Here

      // link membership
      mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1), mtHandler
               .findMembershipType(membershipType), true);

      Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
      assertNotNull(m);

      // try to create already existed membership. Exception should not be thrown
      try
      {
         mHandler.linkMembership(uHandler.findUserByName(userName), gHandler.findGroupById("/" + groupName1),
            mtHandler.findMembershipType(membershipType), true);
      }
      catch (Exception e)
      {
         fail("Exception should not be thrown");
      }

      // we expect only 1 membership record
      assertEquals(1, mHandler.findMembershipsByUser(userName).size());

      // test deprecated memthod create membership
      mHandler.removeMembership(m.getId(), true);
      mHandler.createMembership(m, true);
      m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);
      assertNotNull(m);

      // try to link membership with not existed entries. We are supposed to get Exception
View Full Code Here

    */
   public void testRemoveMembership() throws Exception
   {

      createMembership(userName, groupName1, membershipType);
      Membership m = mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType);

      assertNotNull(m);

      m = mHandler.removeMembership(m.getId(), true);
      assertEquals(m.getGroupId(), "/" + groupName1);
      assertEquals(m.getMembershipType(), membershipType);
      assertEquals(m.getUserName(), userName);

      assertNull(mHandler.findMembershipByUserGroupAndType(userName, "/" + groupName1, membershipType));

     
      // try to remove not existed membership. We are supposed to get "null" instead of Exception
View Full Code Here

            Tools.logMethodIn(log, LogLevel.TRACE, "removeMembership", new Object[] { "id", id, "broadcast", broadcast });
        }

        orgService.flush();

        Membership m = new MembershipImpl(id);

        String plGroupName = getPLIDMGroupName(getGroupNameFromId(m.getGroupId()));

        String groupId = getIdentitySession().getPersistenceManager().createGroupKey(plGroupName,
                getGroupTypeFromId(m.getGroupId()));

        boolean hasRole = false;

        try {
            hasRole = getIdentitySession().getRoleManager().hasRole(m.getUserName(), groupId, m.getMembershipType());
        } catch (Exception e) {
            // TODO:
            handleException("Identity operation error: ", e);

        }

        boolean associated = false;

        try {
            associated = getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId, m.getUserName());
        } catch (Exception e) {
            // TODO:
            handleException("Identity operation error: ", e);
        }

        if (!hasRole && !(isAssociationMapped() && getAssociationMapping().equals(m.getMembershipType()) && associated)) {
            return m;
        }

        if (broadcast) {
            preDelete(m);
        }

        if (isCreateMembership(m.getMembershipType(), m.getGroupId())) {

            try {
                getIdentitySession().getRoleManager().removeRole(m.getMembershipType(), m.getUserName(), groupId);
            } catch (Exception e) {
                // TODO:
                handleException("Identity operation error: ", e);

            }
        }

        if (isAssociationMapped() && getAssociationMapping().equals(m.getMembershipType()) && associated) {
            Set<String> keys = new HashSet<String>();
            keys.add(m.getUserName());
            try {
                getIdentitySession().getRelationshipManager().disassociateUsersByKeys(groupId, keys);
            } catch (Exception e) {
                // TODO:
                handleException("Identity operation error: ", e);
View Full Code Here

        if (role != null
                && (!isAssociationMapped() || !getAssociationMapping().equals(role.getRoleType()) || !ignoreMappedMembershipType(groupId))) {
            hasMembership = true;
        }

        Membership result = null;

        if (hasMembership) {

            MembershipImpl m = new MembershipImpl();
            m.setGroupId(groupId);
View Full Code Here

            Tools.logMethodIn(log, LogLevel.TRACE, "findMembership", new Object[] { "id", id });
        }

        orgService.flush();

        Membership m = new MembershipImpl(id);

        String plGroupName = getPLIDMGroupName(getGroupNameFromId(m.getGroupId()));

        String groupId = getIdentitySession().getPersistenceManager().createGroupKey(plGroupName,
                getGroupTypeFromId(m.getGroupId()));

        try {
            if (isCreateMembership(m.getMembershipType(), m.getGroupId())
                    && getIdentitySession().getRoleManager().hasRole(m.getUserName(), groupId, m.getMembershipType())) {
                if (log.isTraceEnabled()) {
                    Tools.logMethodOut(log, LogLevel.TRACE, "findMembership", m);
                }
                return m;
            }
        } catch (Exception e) {
            // TODO:
            handleException("Identity operation error: ", e);

        }

        try {
            if (isAssociationMapped() && getAssociationMapping().equals(m.getMembershipType())
                    && getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId, m.getUserName())) {
                if (log.isTraceEnabled()) {
                    Tools.logMethodOut(log, LogLevel.TRACE, "findMembership", m);
                }

                return m;
View Full Code Here

                     }
                     else
                     {
                        userName = dao.findUserByDN(ctx, userDN).getUserName();
                     }
                     Membership membership = dao.createMembershipObject(userName, groupId, membershipType);

                     memberships[counter++] = membership;

                     if (counter == length)
                     {
View Full Code Here

               Attributes attrs = sr.getAttributes();

               String membershipDN = sr.getNameInNamespace();
               Group group = getGroupFromMembershipDN(ctx, membershipDN);
               String type = explodeDN(membershipDN, true)[0];
               Membership membership = createMembershipObject(username, group.getId(), type);
               memberships.add(membership);
               if (broadcast)
                  preDelete(membership);

               if (attrs.get(ldapAttrMapping.membershipTypeMemberValue).size() > 1)
View Full Code Here

    * {@inheritDoc}
    */
   public Membership findMembership(String id) throws Exception
   {
      String[] membershipParts = id.split(",");
      Membership membership =
         findMembershipByUserGroupAndType(membershipParts[0], membershipParts[2], membershipParts[1]);
      return membership;
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.organization.Membership

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.