public link updated

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@77786 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-07-08 15:42:08 +00:00
parent 859f9b7897
commit 084947fcb9
15 changed files with 714 additions and 106 deletions

View File

@ -0,0 +1,35 @@
package org.gcube.portlets.user.workspace.client.event;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import com.google.gwt.event.shared.GwtEvent;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public class GetPublicLinkEvent extends GwtEvent<GetPublicLinkEventHandler> {
public static Type<GetPublicLinkEventHandler> TYPE = new Type<GetPublicLinkEventHandler>();
private FileModel targetFile = null;
public GetPublicLinkEvent(FileModel target) {
this.targetFile = target;
}
@Override
public Type<GetPublicLinkEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(GetPublicLinkEventHandler handler) {
handler.onGetPublicLink(this);
}
public FileModel getSourceFile() {
return targetFile;
}
}

View File

@ -0,0 +1,15 @@
package org.gcube.portlets.user.workspace.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
*/
public interface GetPublicLinkEventHandler extends EventHandler {
/**
* @param getPublicLinkEvent
*/
void onGetPublicLink(GetPublicLinkEvent getPublicLinkEvent);
}

View File

@ -160,4 +160,13 @@ public interface GWTWorkspaceService extends RemoteService{
String getShortUrl(String longUrl) throws Exception;
/**
* @param itemId
* @param shortenUrl
* @return
* @throws Exception
*/
String getPublicLinkForFolderItemId(String itemId, boolean shortenUrl)
throws Exception;
}

View File

@ -154,5 +154,8 @@ public interface GWTWorkspaceServiceAsync {
void getShortUrl(String longUrl, AsyncCallback<String> callback);
void getPublicLinkForFolderItemId(String itemId, boolean shortenUrl,
AsyncCallback<String> callback);
}

View File

@ -65,6 +65,7 @@ public class ExplorerPanel extends LayoutContainer {
this.expPanel.setTopComponent(toolBar);
// smartFolderPanel.setVisible(false);
// messagesPanel.setVisible(false);
asycTreePanel.setVisible(true);
@ -149,6 +150,7 @@ public class ExplorerPanel extends LayoutContainer {
if(isSmartFolderInstanced){
radioSmartFolder.setBoxLabel(ConstantsExplorer.SMARTFOLDER);
radioSmartFolder.setValueAttribute(ConstantsExplorer.SMARTFOLDER);
radioGroup.add(radioSmartFolder);
}

View File

@ -30,7 +30,9 @@ public class SmartFolderPanel extends LayoutContainer {
private ContentPanel cp;
private SmartButton buttDocuments = new SmartButton(GXTCategoryItemInterface.SMF_DOCUMENTS, Resources.getIconDocuments(), this);
//TODO TEMPORARY SOLUTION TO FIX SMART FOLDER
// private SmartButton buttDocuments = new SmartButton(GXTCategoryItemInterface.SMF_DOCUMENTS, Resources.getIconDocuments(), this);
private SmartButton buttImages = new SmartButton(GXTCategoryItemInterface.SMF_IMAGES, Resources.getIconImages(), this);
private SmartButton buttLinks = new SmartButton(GXTCategoryItemInterface.SMF_LINKS, Resources.getIconLinks(), this);
private SmartButton buttReports = new SmartButton(GXTCategoryItemInterface.SMF_REPORTS, Resources.getIconReport(), this);
@ -50,7 +52,9 @@ public class SmartFolderPanel extends LayoutContainer {
public void reloadPanelSmartFolder(){
cp.removeAll();
cp.add(buttDocuments);
//TODO TEMPORARY SOLUTION TO FIX SMART FOLDER
// cp.add(buttDocuments);
cp.add(buttImages);
cp.add(buttLinks);
cp.add(buttReports);
@ -100,12 +104,13 @@ public class SmartFolderPanel extends LayoutContainer {
}
});
buttDocuments.setCommand(new Command() {
@Override
public void execute() {
AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(null, GXTCategoryItemInterface.SMF_DOCUMENTS, GXTCategoryItemInterface.SMF_DOCUMENTS));
}
});
//TODO TEMPORARY SOLUTION TO FIX SMART FOLDER
// buttDocuments.setCommand(new Command() {
// @Override
// public void execute() {
// AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(null, GXTCategoryItemInterface.SMF_DOCUMENTS, GXTCategoryItemInterface.SMF_DOCUMENTS));
// }
// });
buttReports.setCommand(new Command() {
@Override

View File

@ -56,7 +56,7 @@ import com.google.gwt.user.client.ui.AbstractImagePrototype;
*/
public class AsyncTreePanel extends LayoutContainer {
private static final String TREE_MESSAGE_PANEL_ASYNC = "treeMessagePanelAsync";
private static final String TREE_MESSAGE_PANEL_ASYNC = "treeMessagePanelAsync";
// private TreeLoader<FileModel> loader;
private TreePanel<FileModel> treePanel;
private TreeStore<FileModel> store;

View File

@ -13,7 +13,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import org.gcube.common.core.utils.logging.GCUBELog;
import org.gcube.common.core.utils.logging.GCUBEClientLog;
import org.gcube.portlets.user.homelibrary.home.User;
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.portlets.user.homelibrary.home.workspace.Properties;
@ -95,23 +95,18 @@ import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
public class GWTWorkspaceBuilder {
protected static final String IMAGE_SERVICE_URL = "ImageService";
protected GCUBELog logger;
protected GCUBEClientLog logger;
protected static HashMap<String, InfoContactModel> hashTestUser = null;
// private final String UNKNOWN = "unknown";
// private final String FOLDER = "Folder";
/**
* @param logger
*/
public GWTWorkspaceBuilder(GCUBELog logger) {
this.logger = logger;
}
/**
* @param logger
*/
public GWTWorkspaceBuilder() {
logger = new GCUBEClientLog(GWTWorkspaceBuilder.class);
}
@ -809,6 +804,9 @@ public class GWTWorkspaceBuilder {
List<WorkspaceItem> listItems = (List<WorkspaceItem>) workspaceFolder.getChildren();
if(listItems!=null)
logger.trace("HL return "+listItems.size()+ "items, converting...");
//TEST TIME
// Long startTime = System.currentTimeMillis();
// Long endTime = System.currentTimeMillis() - startTime;
@ -1299,6 +1297,61 @@ public class GWTWorkspaceBuilder {
return fileModel;
}
public 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 "";
}
/**
*

View File

@ -50,6 +50,7 @@ import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil;
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
import org.gcube.portlets.user.workspace.server.util.UserUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil;
@ -67,11 +68,8 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
*/
public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWTWorkspaceService{
/**
*
*/
protected static final String RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST = " retrieving item. Either the item doesn't exist anymore or you do not have the permission to access it";
private static final long serialVersionUID = 2828885661214875589L;
public static final String LAST_OPEN_FOLDER_ATTRIBUTE = "WORKSPACE.LAST_OPEN_FOLDER";
@ -110,6 +108,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return WsUtil.getUrlShortener(this.getThreadLocalRequest().getSession());
}
protected UriResolverReaderParameter getUriResolver() {
return WsUtil.getUriResolver(this.getThreadLocalRequest().getSession());
}
@Override
public FolderModel getRootForTree() throws Exception {
@ -243,6 +245,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
WorkspaceItem wsItem = workspace.getItem(folder.getIdentifier());
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
listFileModels = builder.buildGXTListFileModelItem(wsItem, folder);
return listFileModels;
@ -250,7 +253,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) {
workspaceLogger.error("Error in server During item retrieving", e);
// workspaceLogger.trace("Error in server During item retrieving " + e);
String error = ConstantsExplorer.SERVER_ERROR + " retrieving item. Item doesn't exists or you haven't permission to access this item";
String error = ConstantsExplorer.SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST;
//GWT can't serialize all exceptions
throw new Exception(error);
}
@ -293,7 +296,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.error("Error in server During items retrieving", e);
// workspaceLogger.trace("Error in server During items retrieving " + e);
// e.printStackTrace();
String error = ConstantsExplorer.SERVER_ERROR + " retrieving item. Item doesn't exists or you haven't permission to access this item";
String error = ConstantsExplorer.SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST;
//GWT can't serialize all exceptions
throw new Exception(error);
}
@ -358,7 +361,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.error("Error in server During items retrieving", e);
// workspaceLogger.trace("Error in server During items retrieving " + e);
String error = ConstantsExplorer.SERVER_ERROR + " retrieving item. Item doesn't exists or you haven't permission to access this item";
String error = ConstantsExplorer.SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST;
// e.printStackTrace();
//GWT can't serialize all exceptions
throw new Exception(error);
@ -401,7 +404,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} catch (Exception e) {
workspaceLogger.error("Error in server during item retrieving, getItemForFileGrid", e);
String error = ConstantsExplorer.SERVER_ERROR + " retrieving item. Item doesn't exists or you haven't permission to access this item";
String error = ConstantsExplorer.SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST;
throw new Exception(error);
}
}
@ -2217,4 +2220,57 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
return longUrl;
}
}
/**
*
* @param itemId
* @param shortenUrl
* @return
*/
@Override
public String getPublicLinkForFolderItemId(String itemId, boolean shortenUrl) throws Exception{
workspaceLogger.trace("get Public Link For ItemId: "+ itemId);
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
try{
Workspace workspace = getWorkspace();
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 = getUriResolver();
String uriRequest = "";
if(uriResolver!=null && uriResolver.isAvailable()){
uriRequest = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), folderItem.getMimeType(), true);
if(shortenUrl)
return getShortUrl(uriRequest);
return uriRequest;
}
else
throw new Exception("Sorry, The Uri resolver service is temporarily unavailable. Please try again later");
}
workspaceLogger.warn("ItemId: "+ itemId +" is not a folder item, return empty public link");
return "";
}catch (Exception e) {
workspaceLogger.error("Error get short url for ", e);
return "";
}
}
}

View File

@ -6,18 +6,19 @@ package org.gcube.portlets.user.workspace.server.resolver;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.workspace.server.shortener.UrlEncoderUtil;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.impl.XQuery;
@ -29,12 +30,21 @@ import org.gcube.resources.discovery.client.queries.impl.XQuery;
public class UriResolverReaderParameter {
//Base Address
String uri = "";
//Query URL parameter
String parameter = "";
private String uriRequest = "";
// private String uri = "";
private String baseUri = "";
public static Logger log = Logger.getLogger(UriResolverReaderParameter.class);
//Query URL parameter
private String smpParameter = "";
private String fileNameParameter = "";
private String contentTypeParameter = "";
private String query = "";
private boolean isAvailable = false;
public static Logger logger = Logger.getLogger(UriResolverReaderParameter.class);
/**
@ -59,76 +69,180 @@ public class UriResolverReaderParameter {
//Base Address
// System.out.println(endpoints.get(0).address());
uri = endpoints.get(0)!=null?endpoints.get(0).address():"";
baseUri = endpoints.get(0)!=null?endpoints.get(0).address():"";
if(endpoints.get(0)!=null){
parameter = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get("parameter").value():"";
smpParameter = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get("SMP_URI_parameter").value():"";
fileNameParameter = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get("fileName_parameter").value():"";
contentTypeParameter = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get("contentType_parameter").value():"";
}
uriRequest = uri+"?"+parameter;
// uriRequest = uri+"?"+smpParameter;
isAvailable = true;
//Query URL parameter
// System.out.println(endpoints.get(0).propertyMap().get("parameter").value());
}
public InputStream resolve(String smp) throws IOException{
String query = uriRequest + "="+smp;
/**
* Resolve - open stream with http get method
* @param smp
* @return
* @throws IOException
*/
public InputStream resolveAsInputStream(String smp, String fileName, String contentType) throws Exception{
String query = resolveAsUriRequest(smp, fileName, contentType, true);
URL url = new URL(query);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.connect();
return connection.getInputStream();
}
/**
*
* @param smp
* @param fileName
* @param contentType
* @param encodeParams - if true, translates a string into <code>application/x-www-form-urlencoded</code>
* format using a specific encoding scheme
* @return the http url to get file
* @throws Exception
*/
public String resolveAsUriRequest(String smp, String fileName, String contentType, boolean encodeParams) throws Exception{
return url.openStream();
if(smp==null || smp.isEmpty())
throw new Exception("smp url is null or empty");
if(!encodeParams){ //ENCODE URI
query = smpParameter+"="+smp;
if(fileName!=null && !fileName.isEmpty())
query+="&"+fileNameParameter+"="+fileName;
if(contentType!=null && !contentType.isEmpty())
query+="&"+contentTypeParameter+"="+contentType;
}
else{
Map<String, String> hashParameters = getHashParemeters(smp, fileName, contentType);
query = UrlEncoderUtil.encodeQuery(hashParameters);
}
String uriRequest = baseUri+"?"+query;
logger.trace("resolve url request: "+uriRequest);
return uriRequest;
}
/**
*
* @return Base Address of Uri Resolver
* @param smp
* @param fileName
* @param contentType
* @return
* @throws Exception
*/
public String getUri() {
return uri;
}
public Map<String, String> getHashParemeters(String smp, String fileName, String contentType) throws Exception{
Map<String, String> hashParameters = new HashMap<String, String>();
if(smp==null || smp.isEmpty())
throw new Exception("smp url is null or empty");
hashParameters.put(smpParameter, smp);
if(fileName!=null && !fileName.isEmpty())
hashParameters.put(fileNameParameter, fileName);
if(contentType!=null && !contentType.isEmpty())
hashParameters.put(contentTypeParameter, contentType);
/**
*
* @return Query URL parameter of Uri Resolver
*/
public String getParameter() {
return parameter;
return hashParameters;
}
public boolean isAvailable() {
return isAvailable;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("UriResolverReaderParameter [uri=");
builder.append(uri);
builder.append(", parameter=");
builder.append(parameter);
builder.append("UriResolverReaderParameter [baseUri=");
builder.append(baseUri);
builder.append(", smpParameter=");
builder.append(smpParameter);
builder.append(", fileNameParameter=");
builder.append(fileNameParameter);
builder.append(", contentTypeParameter=");
builder.append(contentTypeParameter);
builder.append(", isAvailable=");
builder.append(isAvailable);
builder.append("]");
return builder.toString();
}
public static void main(String[] args) throws Exception {
log.trace(new UriResolverReaderParameter());
UriResolverReaderParameter uriResolver = new UriResolverReaderParameter();
InputStream is = uriResolver.resolve("smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV+gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
File file = new File("test.png");
FileOutputStream out = new FileOutputStream(file);
IOUtils.copy(is, out);
is.close();
out.close();
public String getBaseUri() {
return baseUri;
}
public String getSmpParameter() {
return smpParameter;
}
public String getFileNameParameter() {
return fileNameParameter;
}
public String getContentTypeParameter() {
return contentTypeParameter;
}
public static void main(String[] args) throws Exception {
logger.trace(new UriResolverReaderParameter());
UriResolverReaderParameter uriResolver = new UriResolverReaderParameter();
String fileName = "Wikipedia_logo_silver.png";
String uriRequest = uriResolver.resolveAsUriRequest("smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV+gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y", fileName, "image/png", false);
System.out.println("uriRequest "+uriRequest);
//
// InputStream is = uriResolver.resolve("smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV+gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y", fileName, "image/png");
// File file = new File(fileName);
//
// FileOutputStream out = new FileOutputStream(file);
//
//
// IOUtils.copy(is, out);
// is.close();
//
// out.close();
}
public String getQuery() {
return query;
}
}

View File

@ -66,7 +66,6 @@ public class UrlEncoderUtil {
logger.error(e);
return query;
}
}
return removeLastChar(query);

View File

@ -20,6 +20,7 @@ import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer;
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
@ -40,6 +41,7 @@ public class WsUtil {
public static final String WS_RUN_IN_TEST_MODE = "WS_RUN_IN_TEST_MODE";
public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SCOPE_UTIL";
public static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_SERVICE";
public static final String URI_RESOLVER_SERVICE = "URI_RESOLVER_SERVICE";
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //IN DEV
// public static final String TEST_SCOPE = "/gcube/devsec";
@ -147,7 +149,7 @@ public class WsUtil {
{
logger.trace("Initializing the workspace area builder");
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder(logger);
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder);
}
@ -292,4 +294,28 @@ public class WsUtil {
return shortener;
}
/**
* @param session
* @return
*/
public static UriResolverReaderParameter getUriResolver(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession);
UriResolverReaderParameter uriResolver = null;
try{
uriResolver = (UriResolverReaderParameter) session.getAttribute(WsUtil.URI_RESOLVER_SERVICE);
if(uriResolver==null){
uriResolver = new UriResolverReaderParameter();
session.setAttribute(URI_RESOLVER_SERVICE, uriResolver);
}
}catch (Exception e) {
defaultLogger.error("an error occurred in instancing uri resolver ",e);
}
return uriResolver;
}
}

View File

@ -6,11 +6,16 @@ package org.gcube.portlets.user.workspace;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItemType;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItemType;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.portlets.user.homelibrary.jcr.repository.external.GCUBEStorage;
@ -23,24 +28,55 @@ public class DonwloadServletTest {
public static void main(String[] args) {
InputStream is = null;
System.out.println("start");
is = GCUBEStorage.getRemoteFile("/Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381");
// InputStream is = null;
//
// System.out.println("start");
//
// is = GCUBEStorage.getRemoteFile("/Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381");
try {
// Workspace ws = HomeLibrary
// .getHomeManagerFactory()
// .getHomeManager()
// .getHome("francesco.mangiacrapa",
// GCUBEScope.getScope("/gcube/devsec"))
// .getWorkspace();
// //
// ExternalFile f = (ExternalFile) ws.getItem("8ad4e104-0f34-413e-a88c-e754a81104e7");
//
FileOutputStream out = new FileOutputStream(new File("/tmp/bla"));
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("francesco.mangiacrapa",
GCUBEScope.getScope("/gcube/devsec"))
.getWorkspace();
//
WorkspaceItem root = ws.getRoot();
List<? extends WorkspaceItem> children = root.getChildren();
for (WorkspaceItem workspaceItem : children) {
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
FolderItem folderItem = (FolderItem) workspaceItem;
if(folderItem.getFolderItemType().equals(FolderItemType.EXTERNAL_FILE)){
ExternalFile f = (ExternalFile) folderItem;
System.out.println("folderItem name: "+f.getName() + ", public link: "+f.getPublicLink());
}
}
}
// WorkspaceItem item = ws.getItem("8ad4e104-0f34-413e-a88c-e754a81104e7");
//
//
// ExternalFile f = (ExternalFile) item;
//
//
// System.out.println("Public link: "+f.getPublicLink());
// FileOutputStream out = new FileOutputStream(new File("/tmp/bla"));
// // byte[] buffer = new byte[1024];
// // int len;
// // while ((len = is.read(buffer)) != -1) {
@ -52,10 +88,10 @@ public class DonwloadServletTest {
// is = f.getData();
IOUtils.copy(is, out);
is.close();
out.close();
// IOUtils.copy(is, out);
// is.close();
//
// out.close();
// System.out.println("Sleeping");
// Thread.sleep(20000);

View File

@ -0,0 +1,145 @@
/**
*
*/
package org.gcube.portlets.user.workspace;
import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
import org.gcube.portlets.user.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItemType;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItemType;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalImage;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ExternalPDFFile;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.Report;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.WorkflowReport;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.gcube.Document;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.gcube.ImageDocument;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.gcube.PDFDocument;
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategoryItemInterface;
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
import org.gcube.portlets.user.workspace.client.model.FileModel;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jul 3, 2013
*
*/
public class PublicLinkTest {
protected static Logger logger = Logger.getLogger(PublicLinkTest.class);
public static void main(String[] args) {
try {
Workspace ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("francesco.mangiacrapa",
GCUBEScope.getScope("/gcube/devsec"))
.getWorkspace();
//
System.out.println("start get root");
WorkspaceItem root = ws.getRoot();
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();
}
}
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 "";
}
}

View File

@ -15,9 +15,18 @@ import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.homelibrary.home.HomeLibrary;
import org.gcube.portlets.user.homelibrary.home.workspace.Workspace;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItemType;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameter;
import org.gcube.portlets.user.workspace.server.shortener.UrlShortener;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.impl.XQuery;
@ -113,20 +122,121 @@ public class UriResolverReaderRR {
public static void main(String[] args) throws Exception {
log.trace(new UriResolverReaderRR());
UriResolverReaderRR uriResolver = new UriResolverReaderRR();
InputStream is = uriResolver.resolve("smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV+gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
File file = new File("test.png");
FileOutputStream out = new FileOutputStream(file);
IOUtils.copy(is, out);
is.close();
// log.trace(new UriResolverReaderRR());
//
// UriResolverReaderRR uriResolver = new UriResolverReaderRR();
// InputStream is = uriResolver.resolve("smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV+gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
//
// File file = new File("test.png");
//
// FileOutputStream out = new FileOutputStream(file);
//
//
// IOUtils.copy(is, out);
// is.close();
//
// out.close();
// 066086bc-5db1-48fc-b365-2ee821db2fb7
// 370dc1cc-2e5e-4321-bc6f-ad860414db97
// id: f70f01f9-5a06-4123-b6ec-bd121c1af82f, name: testResponse.html, ### Public link: smp://Home/francesco.mangiacrapa/Workspace41e79e40-ec82-416b-ba83-29b54bb43426?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/xIGDhncO9jOkV1T8u6Db7GZ/4ePgMws8Jxu8ierJajHBd20bUotElPG3BVG0ODMHf1ztm6rKJIAeb9R/0FEIDQ==
// id: 35a0298e-da69-464f-9170-3dc764da564d, name: wiki ws backup, ### Public link: smp://Home/francesco.mangiacrapa/Workspaceb7c9bf85-b0e0-47ac-87e5-eba34048f7ab?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/xIGDhncO9jOkV1T8u6Db7GZ/4ePgMws8Jxu8ierJajHBd20bUotElPG3BVG0ODMHf1ztm6rKJIAeb9R/0FEIDQ==
// id: 370dc1cc-2e5e-4321-bc6f-ad860414db97, name: testupload.txt, ### Public link: smp://Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/xIGDhncO9jOkV1T8u6Db7GZ/4ePgMws8Jxu8ierJajHBd20bUotElPG3BVG0ODMHf1ztm6rKJIAeb9R/0FEIDQ==
System.out.println("uri is: "+getPublicLinkForFolderItemId("f70f01f9-5a06-4123-b6ec-bd121c1af82f"));
//
}
public static String getPublicLinkForFolderItemId(String itemId){
try{
Workspace workspace = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome("francesco.mangiacrapa",
GCUBEScope.getScope("/gcube/devsec"))
.getWorkspace();
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
System.out.println("get item...");
WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
FolderItem folderItem = (FolderItem) wsItem;
System.out.println("get public link...");
String smpUri = builder.getPubliLinkForFolderItem(folderItem);
System.out.println("smpUri "+smpUri);
System.out.println("get uriResolver...");
UriResolverReaderParameter uriResolver = new UriResolverReaderParameter();
String url = uriResolver.resolveAsUriRequest(smpUri, "testResponse!@#$$%^^&&.html", folderItem.getMimeType(), true);
System.out.println("url econded: "+url);
//
// url = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), folderItem.getMimeType(), false);
// System.out.println("url doesn't econded: "+url);
// uriResolver.getHashParemeters(smpUri, folderItem.getName(), folderItem.getMimeType());
// HttpCallerUtil callerUtil = new HttpCallerUtil(uriResolver.getBaseUri(), "", "");
// String query = uriResolver.getQuery();
// callerUtil.callPost("", query, "application/x-www-form-urlencoded");
// String smpUri = "smp://Home/test.user/Workspace/bla8200ceb0-c525-40e6-bad1-a63f83811d3d?5ezvFfBOLqb3YESyI/kesN4T+ZD0mtmc/4sZ0vGMrl0lgx7k85j8o2Q1vF0ezJi/xIGDhncO9jOkV1T8u6Db7GZ/4ePgMws8Jxu8ierJajHBd20bUotElPG3BVG0ODMHf1ztm6rKJIAeb9R/0FEIDQ==";
UrlShortener urlShortner = new UrlShortener();
String shortUrl = urlShortner.shorten(url);
System.out.println("url shortUrl: "+shortUrl);
InputStream is = uriResolver.resolveAsInputStream(smpUri, folderItem.getName(), folderItem.getMimeType());
File file = new File(folderItem.getName());
FileOutputStream out = new FileOutputStream(file);
IOUtils.copy(is, out);
is.close();
out.close();
if(uriResolver!=null && uriResolver.isAvailable()){
return uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), folderItem.getMimeType(), true);
}
}
return "";
}catch (Exception e) {
System.out.println("Error getPublicLinkForFolderItemId url for");
e.printStackTrace();
return "";
}
out.close();
}