Author: bdaw
Date: 2010-10-18 06:09:43 -0400 (Mon, 18 Oct 2010)
New Revision: 4706
Modified:
portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java
portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java
Log:
GTNPORTAL-1562 A MembershipType is automatically created if missing while making a
membership link
Modified:
portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java
===================================================================
---
portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java 2010-10-18
10:01:08 UTC (rev 4705)
+++
portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java 2010-10-18
10:09:43 UTC (rev 4706)
@@ -102,6 +102,11 @@
+ " because membership type is null");
}
+ if (orgService.getMembershipTypeHandler().findMembershipType(mt.getName()) ==
null)
+ {
+ throw new InvalidNameException("MembershipType doesn't exist: " +
mt.getName());
+ }
+
String plGroupName = getPLIDMGroupName(g.getGroupName());
String groupId =
Modified:
portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java
===================================================================
---
portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java 2010-10-18
10:01:08 UTC (rev 4705)
+++
portal/trunk/component/identity/src/test/java/org/exoplatform/services/organization/TestOrganizationService.java 2010-10-18
10:09:43 UTC (rev 4706)
@@ -340,6 +340,7 @@
mt = mtHandler_.createMembershipTypeInstance();
mt.setName("membershipType3");
+ mtHandler_.createMembershipType(mt, true);
membershipHandler_.linkMembership(userBenj, group2, mt, true);
/*
@@ -491,6 +492,37 @@
// userHandler_.removeUser(user.getUserName(), false);
// }
+ public void testLinkMembership() throws Exception {
+ String g1 = "grp1";
+ String usr1 = "usr1";
+ String mstype1 = "mstype1";
+
+ Group group1 = groupHandler_.createGroupInstance();
+ group1.setGroupName(g1);
+ groupHandler_.addChild(null, group1, true);
+
+ User user = createUser(usr1);
+
+ MembershipType mt = mtHandler_.createMembershipTypeInstance();
+ mt.setName(mstype1);
+
+ try {
+
+ membershipHandler_.linkMembership(user, group1, mt, true);
+ fail();
+ }
+ catch (Exception e)
+ {
+ //expected as membership type was not created first
+ }
+
+ assertNull(mtHandler_.findMembershipType(mstype1));
+
+ userHandler_.removeUser(usr1, true);
+ groupHandler_.removeGroup(group1, true);
+ }
+
+
public void testFindUsersByGroupId() throws Exception
{
PageList users = userHandler_.findUsersByGroup("/users");