|
|
|
@ -17,33 +17,17 @@ import org.gcube.portlet.user.my_vres.client.MyVREsService;
|
|
|
|
|
import org.gcube.portlet.user.my_vres.shared.UserBelonging;
|
|
|
|
|
import org.gcube.portlet.user.my_vres.shared.VRE;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.VirtualGroup;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.liferay.portal.kernel.exception.PortalException;
|
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException;
|
|
|
|
|
import com.liferay.portal.kernel.util.StringBundler;
|
|
|
|
|
import com.liferay.portal.model.Group;
|
|
|
|
|
import com.liferay.portal.model.VirtualHost;
|
|
|
|
|
import com.liferay.portal.security.auth.PrincipalThreadLocal;
|
|
|
|
|
import com.liferay.portal.security.permission.PermissionChecker;
|
|
|
|
|
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
|
|
|
|
|
import com.liferay.portal.security.permission.PermissionThreadLocal;
|
|
|
|
|
import com.liferay.portal.service.GroupLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.LayoutSetLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.VirtualHostLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.util.PortalUtil;
|
|
|
|
|
import com.liferay.portal.webserver.WebServerServletTokenUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
@ -57,6 +41,9 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public static final String CACHED_VOS = "CACHED_VRES";
|
|
|
|
|
|
|
|
|
|
public static final String ADD_MORE_CATEGORY = "Add More";
|
|
|
|
|
public static final String ADD_MORE_IMAGE_PATH= "images/More.png";
|
|
|
|
|
|
|
|
|
|
private ASLSession getASLSession() {
|
|
|
|
|
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
|
|
|
@ -70,10 +57,7 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
|
|
|
|
|
}
|
|
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String showMoreVREs() {
|
|
|
|
|
return PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getSiteLandingPagePath() {
|
|
|
|
|
String user = getASLSession().getUsername();
|
|
|
|
@ -111,8 +95,8 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
|
|
|
|
|
|
|
|
|
|
LinkedHashMap<String, ArrayList<VRE>> toReturn = new LinkedHashMap<String, ArrayList<VRE>>();
|
|
|
|
|
|
|
|
|
|
long currentSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId();
|
|
|
|
|
List<VirtualGroup> currentSiteVGroups = getVirtualGroups(currentSiteGroupId);
|
|
|
|
|
|
|
|
|
|
List<VirtualGroup> currentSiteVGroups = ManagementUtils.getVirtualGroupsBySiteGroupId(ManagementUtils.getSiteGroupIdFromServletRequest(getThreadLocalRequest().getServerName()));
|
|
|
|
|
for (VirtualGroup vg : currentSiteVGroups) {
|
|
|
|
|
String gName = vg.getName();
|
|
|
|
|
ArrayList<VRE> toCreate = new ArrayList<VRE>();
|
|
|
|
@ -162,6 +146,17 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
|
|
|
|
|
ArrayList<VRE> toSort = toReturn.get(cat);
|
|
|
|
|
Collections.sort(toSort);
|
|
|
|
|
}
|
|
|
|
|
HttpServletRequest request = getThreadLocalRequest();
|
|
|
|
|
PortalContext context = PortalContext.getConfiguration();
|
|
|
|
|
String gatewayURL = context.getGatewayURL(request);
|
|
|
|
|
String exploreURL = gatewayURL+context.getSiteLandingPagePath(request)+GCubePortalConstants.VRES_EXPLORE_FRIENDLY_URL;
|
|
|
|
|
VRE addMore = new VRE("", "", "", "", exploreURL, UserBelonging.BELONGING);
|
|
|
|
|
//add a fake category and addMoreVRE
|
|
|
|
|
ArrayList<VRE> addMoreVREs = new ArrayList<VRE>();
|
|
|
|
|
addMoreVREs.add(addMore);
|
|
|
|
|
toReturn.put(ADD_MORE_CATEGORY, addMoreVREs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -170,25 +165,6 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param scope
|
|
|
|
|
*/
|
|
|
|
|
public void loadLayout(String scope, String URL) {
|
|
|
|
|
_log.trace("Calling Load Layout...");
|
|
|
|
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
|
|
|
|
ASLSession mysession = getASLSession();
|
|
|
|
|
mysession.setAttribute("loadlayout", "true");
|
|
|
|
|
session.setAttribute("loadLayout", "true");
|
|
|
|
|
session.setAttribute("selectedVRE", scope);
|
|
|
|
|
mysession.logUserLogin(scope);
|
|
|
|
|
mysession.setScope(scope);
|
|
|
|
|
|
|
|
|
|
_log.trace("User login logged to: " + scope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* simply returns fake VREs for development purpose
|
|
|
|
|
* @return
|
|
|
|
@ -261,72 +237,6 @@ public class MyVREsServiceImpl extends RemoteServiceServlet implements MyVREsSer
|
|
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* read the list of virtual groups the current site (i-marine, services etc. ) should show up
|
|
|
|
|
* @param actualGroupId
|
|
|
|
|
* @return he list of virtual groups the current site (i-marine, services etc. ) should show up
|
|
|
|
|
* @throws GroupRetrievalFault
|
|
|
|
|
* @throws VirtualGroupNotExistingException
|
|
|
|
|
*/
|
|
|
|
|
private List<VirtualGroup> getVirtualGroups(long actualGroupId) throws GroupRetrievalFault, VirtualGroupNotExistingException {
|
|
|
|
|
List<VirtualGroup> toReturn = new ArrayList<VirtualGroup>();
|
|
|
|
|
try {
|
|
|
|
|
long userId = LiferayUserManager.getAdmin().getUserId();
|
|
|
|
|
PrincipalThreadLocal.setName(userId);
|
|
|
|
|
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(UserLocalServiceUtil.getUser(userId));
|
|
|
|
|
PermissionThreadLocal.setPermissionChecker(permissionChecker);
|
|
|
|
|
Group site = GroupLocalServiceUtil.getGroup(actualGroupId);
|
|
|
|
|
_log.debug("Set Thread Permission done, getVirtual Group of " + site.getName());
|
|
|
|
|
if (site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()) == null || site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName()).equals("")) {
|
|
|
|
|
String warningMessage = String.format("Attribute %s not initialized.", CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
|
|
|
|
|
_log.warn(warningMessage);
|
|
|
|
|
throw new VirtualGroupNotExistingException(warningMessage);
|
|
|
|
|
} else {
|
|
|
|
|
String[] values = (String[]) site.getExpandoBridge().getAttribute(CustomAttributeKeys.VIRTUAL_GROUP.getKeyName());
|
|
|
|
|
VirtualGroup toAdd = new VirtualGroup();
|
|
|
|
|
if (values != null && values.length > 0) {
|
|
|
|
|
for (int i = 0; i < values.length; i++) {
|
|
|
|
|
toAdd = new VirtualGroup();
|
|
|
|
|
String[] splits = values[i].split("\\|");
|
|
|
|
|
toAdd.setName(splits[0]);
|
|
|
|
|
toAdd.setDescription(splits[1]);
|
|
|
|
|
toReturn.add(toAdd);
|
|
|
|
|
_log.debug("VirtualGroup selected found for " + site.getName() + " -> " + toAdd.getName());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toAdd.setName("NoVirtualGroupAssigned");
|
|
|
|
|
toAdd.setDescription("NoVirtualGroupDescription");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param request
|
|
|
|
|
* @return the current Group instance based on the request
|
|
|
|
|
* @throws PortalException
|
|
|
|
|
* @throws SystemException
|
|
|
|
|
*/
|
|
|
|
|
private Group getSiteFromServletRequest(final HttpServletRequest request) throws PortalException, SystemException {
|
|
|
|
|
String serverName = request.getServerName();
|
|
|
|
|
_log.trace("currentHost is " + serverName);
|
|
|
|
|
Group site = null;
|
|
|
|
|
List<VirtualHost> vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount());
|
|
|
|
|
for (VirtualHost virtualHost : vHosts) {
|
|
|
|
|
_log.trace("Found " + virtualHost.getHostname());
|
|
|
|
|
if (virtualHost.getHostname().compareTo("localhost") != 0 &&
|
|
|
|
|
virtualHost.getLayoutSetId() != 0 &&
|
|
|
|
|
virtualHost.getHostname().compareTo(serverName) == 0) {
|
|
|
|
|
long layoutSetId = virtualHost.getLayoutSetId();
|
|
|
|
|
site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup();
|
|
|
|
|
_log.trace("Found match! Your site is " + site.getName());
|
|
|
|
|
return site;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|