added a new class to test public link

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@90346 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-01-21 17:11:36 +00:00
parent a6690e4f5c
commit 798322bd36
4 changed files with 217 additions and 6 deletions

View File

@ -2254,7 +2254,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
}
}catch (Exception e) {
workspaceLogger.error("Error getPublicLinkForFolderItemId for item: "+itemId);
workspaceLogger.error("Error getPublicLinkForFolderItemId for item: "+itemId, e);
throw new Exception(e.getMessage());
}

View File

@ -74,10 +74,10 @@ public class WsUtil {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
// user=TEST_USER;
user=TEST_USER;
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
user = "francesco.mangiacrapa";
// user = "francesco.mangiacrapa";
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);

View File

@ -19,6 +19,7 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalPDFFile;
import org.gcube.common.homelibrary.home.workspace.folder.items.gcube.ImageDocument;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
@ -30,23 +31,26 @@ public class PublicLinkTest {
protected static Logger logger = Logger.getLogger(PublicLinkTest.class);
public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
public static void main(String[] args) {
try {
ScopeBean scope = new ScopeBean("/gcube/devsec");
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("francesco.mangiacrapa")
.getHome("leonardo.candela")
.getWorkspace();
//
System.out.println("start get root");
WorkspaceItem root = ws.getRoot();
System.out.println("start get children");
List<? extends WorkspaceItem> children = root.getChildren();

View File

@ -0,0 +1,207 @@
/**
*
*/
package org.gcube.portlets.user.workspace;
import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItemType;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalImage;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalPDFFile;
import org.gcube.common.homelibrary.home.workspace.folder.items.gcube.ImageDocument;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl;
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
import org.gcube.portlets.user.workspace.server.util.HttpRequestUtil;
import org.gcube.portlets.user.workspace.server.util.StringUtil;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jul 3, 2013
*
*/
public class SinglePublicLinkTest {
protected static Logger logger = Logger.getLogger(SinglePublicLinkTest.class);
public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
public static void main(String[] args) {
try {
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("leonardo.candela")
.getWorkspace();
//
System.out.println("start get root");
// WorkspaceItem root = ws.getRoot();
getPublicLinkForFolderItemId("0e875263-f6bc-4945-9435-bfb8774027ca", true, ws);
// System.out.println("start get children");
// List<? extends WorkspaceItem> children = root.getChildren();
//
//
// System.out.println("children size: "+children.size());
//
// int i=0;
// for (WorkspaceItem workspaceItem : children) {
//
//
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER) || workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
//
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
//
// System.out.println(++i+") folder name: "+folder.getName() + " is shared: "+folder.isShared());
// }else{
//
//
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
//
// FolderItem folderItem = (FolderItem) workspaceItem;
//
// String publicLink = getPubliLinkForFolderItem(folderItem);
//
// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", ### Public link: "+publicLink);
// }
//
// }
// }
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getPublicLinkForFolderItemId(String itemId, boolean shortenUrl, Workspace workspace) throws Exception{
logger.trace("get Public Link For ItemId: "+ itemId);
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
try{
WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
FolderItem folderItem = (FolderItem) wsItem;
String smpUri = builder.getPubliLinkForFolderItem(folderItem);
if(smpUri==null || smpUri.isEmpty())
throw new Exception("Sorry, public link on "+wsItem.getName() +" is not available");
UriResolverReaderParameter uriResolver = new UriResolverReaderParameter(DEFAULT_SCOPE);
String uriRequest = "";
if(uriResolver!=null && uriResolver.isAvailable()){
String itemName = StringUtil.removeSpecialCharacters(folderItem.getName());
itemName = StringUtil.replaceAllWhiteSpace(itemName, "_");
uriRequest = uriResolver.resolveAsUriRequest(smpUri, itemName, folderItem.getMimeType(), true);
//VALIDATE CONNECTION
if(!HttpRequestUtil.urlExists(uriRequest))
throw new Exception("Sorry, The Public Link for selected file is unavailable");
// if(shortenUrl)
// uriRequest = getShortUrl(uriRequest);
return uriRequest;
}
else
throw new Exception("Sorry, The Uri resolver service is temporarily unavailable. Please try again later");
}else{
logger.warn("ItemId: "+ itemId +" is not a folder item, sent exception Public Link unavailable");
throw new Exception("Sorry, The Public Link for selected file is unavailable");
}
}catch (Exception e) {
logger.error("Error getPublicLinkForFolderItemId for item: "+itemId, e);
throw new Exception(e.getMessage());
}
}
protected static String getPubliLinkForFolderItem(FolderItem worspaceFolderItem) throws InternalErrorException{
if(worspaceFolderItem==null)
return "";
try{
switch(worspaceFolderItem.getFolderItemType())
{
case EXTERNAL_IMAGE:
return ((ExternalImage) worspaceFolderItem).getPublicLink();
case EXTERNAL_FILE:
return ((ExternalFile) worspaceFolderItem).getPublicLink();
case EXTERNAL_PDF_FILE:
return ((ExternalPDFFile) worspaceFolderItem).getPublicLink();
case EXTERNAL_URL:
break;
case REPORT_TEMPLATE:
break;
case REPORT:
break;
case QUERY:
break;
case TIME_SERIES:
break;
// case AQUAMAPS_ITEM:
// break;
case PDF_DOCUMENT:
break;
case IMAGE_DOCUMENT:
return ((ImageDocument) worspaceFolderItem).getPublicLink();
case DOCUMENT:
break;
case URL_DOCUMENT:
break;
case METADATA:
break;
case WORKFLOW_REPORT:
break;
case WORKFLOW_TEMPLATE:
break;
case EXTERNAL_RESOURCE_LINK:
break;
default:
return "";
}
}catch (Exception e) {
logger.error("an error occurred when get public link for item: "+worspaceFolderItem.getName());
return "";
}
return "";
}
}