fixed possibility to add double join request

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@130581 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-07-20 12:13:41 +00:00
parent c048f3276c
commit 70c456ab50
1 changed files with 25 additions and 10 deletions

View File

@ -168,13 +168,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
ASLSession session = getASLSession();
GroupManager gm = new LiferayGroupManager();
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
//before iterating the actual groups create the virtualGroups in the correct order
// List<VirtualGroup> virtualGroups = gm.getVirtualGroups();
// for (VirtualGroup vg : virtualGroups) {
// ArrayList<VRE> toCreate = new ArrayList<VRE>();
// VRECategory cat = new VRECategory(1L, vg.getName(), vg.getDescription());
// toReturn.put(cat, toCreate);
// }
long currentSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId();
List<VirtualGroup> currentSiteVGroups = getVirtualGroups(currentSiteGroupId);
@ -192,6 +185,13 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
_log.error("Cannot find root organziation, please check gcube-data.properties file in $CATALINA_HOME/conf folder, unless your installing the Bundle");
return toReturn;
}
CacheRegistryUtil.clear();
List<GCubeGroup> currUserGroups = new ArrayList<GCubeGroup>();
if (session.getUsername().compareTo(TEST_USER) != 0) {
GCubeUser currUser = new LiferayUserManager().getUserByUsername(session.getUsername());
currUserGroups = gm.listGroupsByUser(currUser.getUserId());
}
//for each root sub organizations (VO)
for (GCubeGroup vOrg : rootGroupVO.getChildren()) {
@ -226,8 +226,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
if (session.getUsername().compareTo(TEST_USER) != 0) {
GCubeUser currUser = new LiferayUserManager().getUserByUsername(session.getUsername());
//check if the user belongs to it
CacheRegistryUtil.clear();
if (gm.listGroupsByUser(currUser.getUserId()).contains(vreOrganization)) {
if (currUserGroups.contains(vreOrganization)) {
toAdd.setUserBelonging(UserBelonging.BELONGING);
}
else if (checkPending(currUser.getUsername(), vreOrganization.getGroupId()))
@ -353,7 +352,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
* @throws UserManagementSystemException
*/
private static boolean checkPending(String screenName, long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault {
CacheRegistryUtil.clear();
UserManager um = new LiferayUserManager();
List<GCubeMembershipRequest> requests = um.listMembershipRequestsByGroup(groupId);
for (GCubeMembershipRequest r : requests) {
@ -369,6 +367,23 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
if (optionalMessage == null || optionalMessage.compareTo("") == 0)
optionalMessage = "none";
try {
CacheRegistryUtil.clear();
GroupManager gm = new LiferayGroupManager();
long groupId = gm.getGroupIdFromInfrastructureScope(scope);
_log.debug("Look if a request exists already");
List<GCubeGroup> userGroups = gm.listGroupsByUser(new LiferayUserManager().getUserId(username));
for (GCubeGroup g : userGroups) {
if (g.getGroupId() == groupId) {
_log.warn("User already belongs to " + scope + " SKIP addMembershipRequest");
return;
}
}
CacheRegistryUtil.clear();
if (checkPending(username, groupId)) {
_log.warn("User already asked for " + scope + " REQUEST IS IN PENDING - SKIP addMembershipRequest");
return;
}
_log.debug("Request does not exist, addMembershipRequest for user " + username);
LoginServiceUtil.addMembershipRequest(username, scope, optionalMessage, getThreadLocalRequest());
} catch (Exception e) {
e.printStackTrace();