thematic-gateways-portlet/src/main/java/org/gcube/portlets/user/vreyard/VreYard.java

96 lines
3.8 KiB
Java

package org.gcube.portlets.user.vreyard;
import java.io.IOException;
import java.util.List;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.PrefsPropsUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.DetachedREsClient;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.DetachedREsJAXB;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.GatewayJAXB;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VOJAXB;
import org.gcube.infrastructure.detachedres.detachedreslibrary.server.is.obj.VREJAXB;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.DetachedREs;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.Gateway;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VO;
import org.gcube.infrastructure.detachedres.detachedreslibrary.shared.re.VRE;
/**
* Portlet implementation class VreYard
*/
public class VreYard extends MVCPortlet {
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(VreYard.class);
//these props are read from portal.ext.properties file
public static final String DEFAULT_USER_PROPERTY = "d4science.publicportlets.user";
public static final String DEFAULT_CONTEXT_PROPERTY = "d4science.publicportlets.context";
public static final String DEFAULT_TOKEN_PROPERTY = "d4science.publicportlets.token";
public static final String DEFAULT_SCOPE_PROPERTY = "/d4science.research-infrastructures.eu/";
public static final String DEFAULT_TOKEN = "8effc529-44ec-4895-b727-ed0dc14ad113-843339462";
public static final String DEFAULT_ROLE = "OrganizationMember";
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException {
try {
String context = PrefsPropsUtil.getString(PortalUtil.getCompanyId(renderRequest), DEFAULT_CONTEXT_PROPERTY);
String token = PrefsPropsUtil.getString(PortalUtil.getCompanyId(renderRequest), DEFAULT_TOKEN_PROPERTY);
ScopeProvider.instance.set(context);
SecurityTokenProvider.instance.set(token);
DetachedREsClient detachedREsClient = new DetachedREsClient();
DetachedREs detachedREs = detachedREsClient.getDetachedREs();
renderRequest.setAttribute("thedetachedREs", detachedREs);
int totalVREDimissed = 0;
for (Gateway gateway : detachedREs.getGateways().values()) {
_log.info("\n\n");
_log.info("Gateway: " + gateway.getName() + " \nDesc:\n" + gateway.getDescription().trim());
int vreDismissedPerGatew = 0;
for (VO vo : gateway.getVos().values()) {
_log.debug("VO: " + vo.getName());
for (VRE vre : vo.getVres().values()) {
_log.info("VRE name: " + vre.getName() + "\ndescription: " + vre.getDescription().trim()
+ "\nVRE catalogue url: " + vre.getCatalogUrl() + " VRE catalog Portlet URL: "
+ vre.getCatalogPortletURL());
vreDismissedPerGatew++;
}
}
_log.info("\n\t\t\t******** VREs dismissed per " + gateway.getName() + " are: "
+ vreDismissedPerGatew);
totalVREDimissed += vreDismissedPerGatew;
}
_log.debug("\n\nTotal VREs dismissed: " + totalVREDimissed);
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
//renderRequest.setAttribute("theGateways", theGateways);
super.render(renderRequest, renderResponse);
}
}