refactored to use shared library

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/join-vre@119980 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2015-10-22 16:37:01 +00:00
parent c0cceaa9a6
commit 8f8568dffc
1 changed files with 3 additions and 41 deletions

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.user.joinvre.server;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@ -12,6 +11,7 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.common.portal.PortalContext;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portal.custom.communitymanager.impl.OrganizationManagerImpl;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.user.joinvre.client.JoinService;
import org.gcube.portlets.user.joinvre.shared.UserBelonging;
@ -35,8 +35,6 @@ import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;
/**
* @author Massimiliano Assante, ISTI-CNR - massimiliano.assante@isti.cnr.it
@ -47,7 +45,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
private static Log _log = LogFactoryUtil.getLog(JoinServiceImpl.class);
private static final String REQUEST_BASED_GROUP = "Requestbasedgroup";
private static final String CATEGORY = "Virtualgroup";
private static final String IS_EXTERNAL = "Isexternal";
private static final String URL_IF_EXTERNAL = "Url";
@ -171,20 +168,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
return portalBasicUrl;
}
public List<String> getVirtualGroups() throws PortalException, SystemException {
try {
ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(OrganizationsUtil.getCompany().getCompanyId(), Organization.class.getName());
String[] groups = (String[]) expandoBridge.getAttributeDefault("Virtualgroup");
return Arrays.asList(groups);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public VRECustomAttributes getVRECustomAttr(Organization organization) throws PortalException, SystemException {
VRECustomAttributes toReturn = new VRECustomAttributes();
@ -226,27 +209,6 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
public String getCategory(Organization organization){
try {
long companyId = OrganizationsUtil.getCompany().getCompanyId();
_log.debug("Setting Thread Permission");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, false);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
_log.debug("Setting Permission ok!");
if (organization.getExpandoBridge().getAttribute(CATEGORY) == null || organization.getExpandoBridge().getAttribute(CATEGORY).equals("")) {
_log.warn(String.format("Attribute %s not initialized.", CATEGORY));
return null;
} else {
String[] values = (String[]) organization.getExpandoBridge().getAttribute(CATEGORY);
return values[0];
}
} catch (Exception e) {
e.printStackTrace();
return "Exception ";
}
}
/**
*
* @return the Virtual groups with their VREs in the order estabilished in the LR Control Panel
@ -257,7 +219,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
LinkedHashMap<VRECategory, ArrayList<VRE>> toReturn = new LinkedHashMap<VRECategory, ArrayList<VRE>>();
//before iterating the actual groups create the virtualGroups in the correct order
List<String> virtualGroups = getVirtualGroups();
List<String> virtualGroups = OrganizationManagerImpl.getVirtualGroups();
for (String vg : virtualGroups) {
String[] splits = vg.split("\\|");
String gName = splits[0];
@ -310,7 +272,7 @@ public class JoinServiceImpl extends RemoteServiceServlet implements JoinService
boolean isExternal = attrs.isExternal();
String urlIfAny = attrs.getUrlIfAny();
String catName = getCategory(vreOrganization);
String catName = OrganizationManagerImpl.getVirtualGroupName(vreOrganization);
String[] splits = catName.split("\\|");
catName = splits[0];