merged with private version at 181504
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@181670 82a268e6-3cf1-43bd-a215-b396298e98cftask/19600
parent
2b54518c31
commit
40f4088413
@ -1,29 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
public class FilterScopeEvent extends GwtEvent<FilterScopeEventHandler> {
|
||||
public static Type<FilterScopeEventHandler> TYPE = new Type<FilterScopeEventHandler>();
|
||||
private String scopeId;
|
||||
|
||||
|
||||
public FilterScopeEvent(String scopeId) {
|
||||
this.scopeId = scopeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<FilterScopeEventHandler> getAssociatedType() {
|
||||
// TODO Auto-generated method stub
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(FilterScopeEventHandler handler) {
|
||||
handler.onClickScopeFilter(this);
|
||||
|
||||
}
|
||||
|
||||
public String getScopeId() {
|
||||
return scopeId;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface FilterScopeEventHandler extends EventHandler {
|
||||
void onClickScopeFilter(FilterScopeEvent filterScopeEvent);
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
* The Class LoadTreeEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jul 31, 2019
|
||||
*/
|
||||
public class LoadTreeEvent extends GwtEvent<LoadTreeEventHandler> {
|
||||
public static Type<LoadTreeEventHandler> TYPE = new Type<LoadTreeEventHandler>();
|
||||
private boolean selectRoot;
|
||||
|
||||
/**
|
||||
* Instantiates a new load tree event.
|
||||
*
|
||||
* @param selectRoot the select root
|
||||
*/
|
||||
public LoadTreeEvent(boolean selectRoot) {
|
||||
this.selectRoot = selectRoot;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<LoadTreeEventHandler> getAssociatedType() {
|
||||
// TODO Auto-generated method stub
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(LoadTreeEventHandler handler) {
|
||||
handler.doLoadTree(this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is select root.
|
||||
*
|
||||
* @return true, if is select root
|
||||
*/
|
||||
public boolean isSelectRoot() {
|
||||
return selectRoot;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface LoadTreeEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jul 31, 2019
|
||||
*/
|
||||
public interface LoadTreeEventHandler extends EventHandler {
|
||||
|
||||
/**
|
||||
* Do load tree.
|
||||
*
|
||||
* @param loadTreeEvent the load tree event
|
||||
*/
|
||||
void doLoadTree(LoadTreeEvent loadTreeEvent);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
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{@literal @}isti.cnr.it
|
||||
*
|
||||
*/
|
||||
public class OpenReportsEvent extends GwtEvent<OpenReportsEventHandler> {
|
||||
public static Type<OpenReportsEventHandler> TYPE = new Type<OpenReportsEventHandler>();
|
||||
|
||||
private FileModel sourceFileModel = null; //Report template
|
||||
|
||||
public OpenReportsEvent(FileModel fileSourceModel) {
|
||||
this.sourceFileModel = fileSourceModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<OpenReportsEventHandler> getAssociatedType() {
|
||||
// TODO Auto-generated method stub
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(OpenReportsEventHandler handler) {
|
||||
handler.onClickOpenReports(this);
|
||||
|
||||
}
|
||||
|
||||
public FileModel getSourceFileModel() {
|
||||
return sourceFileModel;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface OpenReportsEventHandler extends EventHandler {
|
||||
void onClickOpenReports(OpenReportsEvent openReportTemplateEvent);
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.view.smartfolder;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
||||
import org.gcube.portlets.user.workspace.client.event.DeleteSmartFolderEvent;
|
||||
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
||||
|
||||
import com.extjs.gxt.ui.client.widget.Composite;
|
||||
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.MouseOutEvent;
|
||||
import com.google.gwt.event.dom.client.MouseOutHandler;
|
||||
import com.google.gwt.event.dom.client.MouseOverEvent;
|
||||
import com.google.gwt.event.dom.client.MouseOverHandler;
|
||||
import com.google.gwt.user.client.Command;
|
||||
import com.google.gwt.user.client.ui.AbstractImagePrototype;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
/**
|
||||
*
|
||||
* @author Massimiliano Assante ISTI-CNR
|
||||
*
|
||||
* @version 1.0 May 14th 2012
|
||||
*/
|
||||
public class SmartButton extends Composite {
|
||||
|
||||
private final static String BASE_STYLE = "smartButton";
|
||||
|
||||
private boolean selected;
|
||||
|
||||
private String caption;
|
||||
|
||||
private HorizontalPanel myPanel = new HorizontalPanel();
|
||||
|
||||
private HTML text = new HTML();
|
||||
|
||||
private Command myCommand = null;
|
||||
|
||||
private SmartFolderPanel caller;
|
||||
|
||||
private Image delete = new Image(Resources.ICONS.close());
|
||||
|
||||
public SmartButton(String caption, AbstractImagePrototype img, SmartFolderPanel caller) {
|
||||
super();
|
||||
selected = false;
|
||||
this.caption = caption;
|
||||
this.caller = caller;
|
||||
super.setWidth(300);
|
||||
text.setPixelSize(300, 30);
|
||||
myPanel.setWidth("100%");
|
||||
|
||||
text.setHTML("<div style=\"width: 100%; height: 30px; line-height: 32px; text-align:left; padding-left: 20px;\">" +
|
||||
"<span style=\"display:inline-block; vertical-align:middle;\" >" + img.getHTML() + "</span>" +
|
||||
"<span style=\"padding-left: 20px;\">"+ caption+"</span></div>");
|
||||
|
||||
myPanel.add(text);
|
||||
|
||||
myPanel.setStyleName(BASE_STYLE);
|
||||
initComponent(myPanel);
|
||||
|
||||
text.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
selected = selected? false : true;
|
||||
if (selected) {
|
||||
myPanel.addStyleName(BASE_STYLE + "-selected");
|
||||
} else {
|
||||
myPanel.removeStyleName(BASE_STYLE + "-selected");
|
||||
}
|
||||
deselectOthers();
|
||||
if (myCommand != null)
|
||||
myCommand.execute();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public SmartButton(String caption, AbstractImagePrototype img, SmartFolderPanel caller, boolean isDeletable) {
|
||||
this(caption, img, caller);
|
||||
|
||||
delete.getElement().getStyle().setOpacity(0.6);
|
||||
delete.getElement().getStyle().setMarginTop(3, com.google.gwt.dom.client.Style.Unit.PX);
|
||||
myPanel.add(delete);
|
||||
delete.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
deleteFolder();
|
||||
}
|
||||
});
|
||||
|
||||
delete.addMouseOutHandler(new MouseOutHandler() {
|
||||
@Override
|
||||
public void onMouseOut(MouseOutEvent event) {
|
||||
delete.getElement().getStyle().setOpacity(0.6);
|
||||
}
|
||||
});
|
||||
|
||||
delete.addMouseOverHandler(new MouseOverHandler() {
|
||||
@Override
|
||||
public void onMouseOver(MouseOverEvent event) {
|
||||
delete.getElement().getStyle().setOpacity(0.9);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteFolder() {
|
||||
AppControllerExplorer.getEventBus().fireEvent(new DeleteSmartFolderEvent(this.getId(), caption));
|
||||
}
|
||||
|
||||
private void deselectOthers() {
|
||||
caller.toggleOthers(this);
|
||||
}
|
||||
|
||||
public void setCommand(Command cmd) {
|
||||
myCommand = cmd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the button is pressed.
|
||||
*
|
||||
* @return the pressed state
|
||||
*/
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current selected state.
|
||||
*
|
||||
* @param state true to set selected state
|
||||
*/
|
||||
protected void toggle(boolean state) {
|
||||
this.selected = state;
|
||||
if (selected) {
|
||||
myPanel.addStyleName(BASE_STYLE + "-selected");
|
||||
} else {
|
||||
myPanel.removeStyleName(BASE_STYLE + "-selected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,203 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.view.smartfolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
import org.gcube.portlets.user.workspace.client.event.SmartFolderSelectedEvent;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder;
|
||||
import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
|
||||
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
||||
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
|
||||
|
||||
import com.extjs.gxt.ui.client.Style.Scroll;
|
||||
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
||||
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.Command;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
/**
|
||||
* The Class SmartFolderPanel.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* @author Massimiliano Assante ISTI-CNR
|
||||
* @version 1.0 May 14th 2012
|
||||
*/
|
||||
|
||||
public class SmartFolderPanel extends LayoutContainer {
|
||||
|
||||
private ContentPanel cp;
|
||||
private SmartButton buttDocuments = new SmartButton(GXTCategorySmartFolder.SMF_DOCUMENTS.getValue(), Resources.getIconDocuments(), this);
|
||||
private SmartButton buttImages = new SmartButton(GXTCategorySmartFolder.SMF_IMAGES.getValue(), Resources.getIconImages(), this);
|
||||
private SmartButton buttLinks = new SmartButton(GXTCategorySmartFolder.SMF_LINKS.getValue(), Resources.getIconLinks(), this);
|
||||
private SmartButton buttPublicFolder = new SmartButton(GXTCategorySmartFolder.SMF_PUBLIC_FOLDERS.getValue(), Resources.getIconFolderPublic(), this);
|
||||
|
||||
/**
|
||||
* Instantiates a new smart folder panel.
|
||||
*/
|
||||
public SmartFolderPanel() {
|
||||
this.cp = new ContentPanel();
|
||||
cp.setBodyBorder(false);
|
||||
cp.setHeaderVisible(false);
|
||||
cp.setScrollMode(Scroll.AUTO);
|
||||
addListeners();
|
||||
add(cp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload panel smart folder.
|
||||
*/
|
||||
public void reloadPanelSmartFolder(){
|
||||
cp.removeAll();
|
||||
cp.add(buttDocuments);
|
||||
cp.add(buttImages);
|
||||
cp.add(buttLinks);
|
||||
cp.add(buttPublicFolder);
|
||||
cp.layout();
|
||||
addUserSmartFolder();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deselect all.
|
||||
*/
|
||||
public void deselectAll(){
|
||||
for (int i = 0; i < cp.getItemCount(); i++ )
|
||||
if (cp.getItem(i) instanceof SmartButton) {
|
||||
SmartButton b = (SmartButton) cp.getItem(i);
|
||||
b.toggle(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the user smart folder.
|
||||
*/
|
||||
private void addUserSmartFolder() {
|
||||
AppControllerExplorer.rpcWorkspaceService.getAllSmartFolders(new AsyncCallback<List<SmartFolderModel>>() {
|
||||
@Override
|
||||
public void onSuccess(List<SmartFolderModel> result) {
|
||||
loadSmartFolders(result);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
new MessageBoxAlert("Error", ConstantsExplorer.SERVER_ERROR + " getting User's Smart Folders. " +ConstantsExplorer.TRY_AGAIN, null);
|
||||
GWT.log("Error in load smart folder " + caught.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the listeners.
|
||||
*/
|
||||
private void addListeners() {
|
||||
|
||||
buttImages.setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(GXTCategorySmartFolder.SMF_IMAGES));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
buttLinks.setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(GXTCategorySmartFolder.SMF_LINKS));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
buttDocuments.setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(GXTCategorySmartFolder.SMF_DOCUMENTS));
|
||||
}
|
||||
});
|
||||
|
||||
buttPublicFolder.setCommand(new Command() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(GXTCategorySmartFolder.SMF_PUBLIC_FOLDERS));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load smart folders.
|
||||
*
|
||||
* @param result the result
|
||||
*/
|
||||
public void loadSmartFolders(List<SmartFolderModel> result) {
|
||||
if (result != null && result.size() > 0) {
|
||||
for (SmartFolderModel smart : result) {
|
||||
loadSmartFolder(smart);
|
||||
}
|
||||
cp.layout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load smart folder.
|
||||
*
|
||||
* @param smart the smart
|
||||
*/
|
||||
public void loadSmartFolder(final SmartFolderModel smart) {
|
||||
|
||||
SmartButton userSmartFolder = new SmartButton(smart.getName(), Resources.getIconStar(), this, true);
|
||||
userSmartFolder.setId(smart.getIdentifier());
|
||||
userSmartFolder.setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
AppControllerExplorer.getEventBus().fireEvent(new SmartFolderSelectedEvent(smart.getIdentifier(), smart.getName(), null));
|
||||
}
|
||||
});
|
||||
cp.add(userSmartFolder);
|
||||
cp.layout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size smart panel.
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
*/
|
||||
public void setSizeSmartPanel(int width, int height) {
|
||||
cp.setSize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the smart folder.
|
||||
*
|
||||
* @param smartIdentifier the smart identifier
|
||||
*/
|
||||
public void removeSmartFolder(String smartIdentifier) {
|
||||
cp.remove(cp.getItemByItemId(smartIdentifier));
|
||||
cp.layout(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Un pressed all toogle.
|
||||
*/
|
||||
public void unPressedAllToogle(){
|
||||
deselectAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle others.
|
||||
*
|
||||
* @param button the button
|
||||
*/
|
||||
public void toggleOthers(SmartButton button){
|
||||
for (int i = 0; i < cp.getItemCount(); i++ )
|
||||
if (cp.getItem(i) instanceof SmartButton) {
|
||||
SmartButton b = (SmartButton) cp.getItem(i);
|
||||
if (! b.equals(button))
|
||||
b.toggle(false);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,94 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
package org.gcube.portlets.user.workspace.server;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* The Class ReusableInputStream.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jul 30, 2019
|
||||
*/
|
||||
public class ReusableInputStream extends InputStream {
|
||||
|
||||
private InputStream input;
|
||||
private ByteArrayOutputStream output;
|
||||
private ByteBuffer buffer;
|
||||
|
||||
/**
|
||||
* Instantiates a new reusable input stream.
|
||||
*
|
||||
* @param input the input
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public ReusableInputStream(InputStream input) throws IOException {
|
||||
|
||||
this.input = input;
|
||||
// Note: it's resizable anyway.
|
||||
this.output = new ByteArrayOutputStream(input.available());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#read()
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
|
||||
byte[] b = new byte[1];
|
||||
read(b, 0, 1);
|
||||
return b[0];
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#read(byte[])
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] bytes) throws IOException {
|
||||
|
||||
return read(bytes, 0, bytes.length);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.io.InputStream#read(byte[], int, int)
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] bytes, int offset, int length) throws IOException {
|
||||
|
||||
if (buffer == null) {
|
||||
int read = input.read(bytes, offset, length);
|
||||
if (read <= 0) {
|
||||
input.close();
|
||||
input = null;
|
||||
buffer = ByteBuffer.wrap(output.toByteArray());
|
||||
output = null;
|
||||
return -1;
|
||||
} else {
|
||||
output.write(bytes, offset, read);
|
||||
return read;
|
||||
}
|
||||
} else {
|
||||
int read = Math.min(length, buffer.remaining());
|
||||
if (read <= 0) {
|
||||
buffer.flip();
|
||||
return -1;
|
||||
} else {
|
||||
buffer.get(bytes, offset, read);
|
||||
return read;
|
||||
}
|
||||
}
|
||||
}
|
||||
// You might want to @Override flush(), close(), etc to delegate to input.
|
||||
}
|
@ -1,695 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.portlets.user.workspace.server.util.DifferenceBetweenInfoContactModel;
|
||||
import org.gcube.portlets.user.workspace.server.util.PortalContextInfo;
|
||||
import org.gcube.portlets.user.workspace.server.util.UserUtil;
|
||||
import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
||||
|
||||
/**
|
||||
* The Class NotificationsProducer.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
*/
|
||||
public class NotificationsProducer {
|
||||
|
||||
protected ScopeBean scope;
|
||||
|
||||
protected static Logger logger = Logger.getLogger(NotificationsProducer.class);
|
||||
|
||||
protected NotificationsManager notificationsMng;
|
||||
protected HttpSession httpSession;
|
||||
protected String userId;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new notifications producer.
|
||||
*
|
||||
* @param httpServletRequest the http servlet request
|
||||
*/
|
||||
public NotificationsProducer(HttpServletRequest httpServletRequest) {
|
||||
PortalContextInfo info = WsUtil.getPortalContext(httpServletRequest);
|
||||
this.notificationsMng = WsUtil.getNotificationManager(httpServletRequest);
|
||||
this.userId = info.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the notifications mng.
|
||||
*
|
||||
* @return the notifications mng
|
||||
*/
|
||||
public NotificationsManager getNotificationsMng() {
|
||||
return notificationsMng;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the notification mng.
|
||||
*
|
||||
* @param notificationMng the new notification mng
|
||||
*/
|
||||
public void setNotificationMng(NotificationsManager notificationMng) {
|
||||
this.notificationsMng = notificationMng;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyFolderSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.trace("Send notifies folder sharing is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.debug("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification new share folder "+sharedFolder.getName()+" for user "+infoContactModel.getLogin());
|
||||
|
||||
boolean notify = notificationsMng.notifyFolderSharing(infoContactModel.getLogin(), sharedFolder);
|
||||
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderSharing ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies share folder is completed");
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the updated (add/remove) contacts to sharing.
|
||||
*
|
||||
* @param listSharedContact - list of contacts already shared
|
||||
* @param listSharingContact - list of "new" contacts to share
|
||||
* @param sharedFolder - the shared folder
|
||||
*/
|
||||
public void notifyUpdatedUsersToSharing(final List<InfoContactModel> listSharedContact, final List<InfoContactModel> listSharingContact, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try{
|
||||
|
||||
//NEW USER SHARED
|
||||
DifferenceBetweenInfoContactModel diff = new DifferenceBetweenInfoContactModel(listSharingContact, listSharedContact);
|
||||
|
||||
List<InfoContactModel> listNewContactsShared = diff.getDifferentsContacts();
|
||||
|
||||
logger.info("list new contacts shared: "+listNewContactsShared.size());
|
||||
|
||||
if(listNewContactsShared.size()>0){
|
||||
|
||||
if(listNewContactsShared.size()==1){ //CASE ONLY ONE CONTACS WAS ADDED
|
||||
|
||||
InfoContactModel infoContactModel = listNewContactsShared.get(0);
|
||||
|
||||
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THAT A NEW USER WAS ADDED
|
||||
|
||||
try{
|
||||
|
||||
logger.trace("Sending notification to user "+contact.getLogin()+", added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
|
||||
|
||||
boolean notify = notificationsMng.notifyFolderAddedUser(contact.getLogin(), sharedFolder, infoContactModel.getLogin());
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notifies user: "+contact.getLogin());
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderAddedUser ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
List<InfoContactModel> listCts = new ArrayList<InfoContactModel>();
|
||||
listCts.add(infoContactModel);
|
||||
notifyFolderSharing(listCts, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
|
||||
|
||||
}else{ //CASE MORE THEN ONE CONTACT WAS ADDED
|
||||
|
||||
List<String> listLogins = UserUtil.getListLoginByInfoContactModel(listNewContactsShared);
|
||||
|
||||
for (InfoContactModel contact : listSharedContact) { //NOTIFIES ALREADY SHARED CONTACTS THATH A NEW USER WAS ADDED
|
||||
|
||||
try{
|
||||
|
||||
logger.trace("Sending notification to user "+contact.getLogin()+", added "+listLogins.size()+" users to share folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification added user "+ infoContactModel.getLogin() +" to share folder "+sharedFolder.getName() + " for user "+contact.getLogin());
|
||||
|
||||
boolean notify = notificationsMng.notifyFolderAddedUsers(contact.getLogin(), sharedFolder, listLogins);
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notifies user: "+contact.getLogin());
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderAddedUser ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
notifyFolderSharing(listNewContactsShared, sharedFolder); //NOTIFIER NEW USER OF SHARING FOLDER
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//USER REMOVED FROM SHARE
|
||||
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel(listSharedContact, listSharingContact);
|
||||
|
||||
List<InfoContactModel> listRemovedUsersFromShare = diff2.getDifferentsContacts();
|
||||
|
||||
logger.info("list removed contacts from share: "+listRemovedUsersFromShare.size());
|
||||
|
||||
if(listRemovedUsersFromShare.size()>0){
|
||||
|
||||
for (InfoContactModel contact : listRemovedUsersFromShare)
|
||||
notifyFolderRemovedUser(contact, sharedFolder);
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyAddedUserToSharing ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param unShareFolderId the un share folder id
|
||||
* @param unSharedFolderName the un shared folder name
|
||||
*/
|
||||
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final String unShareFolderId, final String unSharedFolderName) {
|
||||
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.trace("Send notifies folder un share is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" unshare folder "+unSharedFolderName);
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" un shared folder "+unSharedFolder.getName());
|
||||
// boolean notify = notificationsMng.notifyFolderRemovedUser(infoContactModel.getLogin(), (WorkspaceSharedFolder) unSharedFolder);
|
||||
|
||||
boolean notify = notificationsMng.notifyFolderUnsharing(infoContactModel.getLogin(), unShareFolderId, unSharedFolderName);
|
||||
if(!notify)
|
||||
logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderUnSharing ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies of un share notifications is completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify folder removed user.
|
||||
*
|
||||
* @param userUnShared the user un shared
|
||||
* @param shareFolder the share folder
|
||||
*/
|
||||
public void notifyFolderRemovedUser(final InfoContactModel userUnShared, final WorkspaceSharedFolder shareFolder) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.trace("Send notifies removed user from shared folder is running...");
|
||||
try{
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(userUnShared.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.debug("Sending notification to user "+userUnShared.getLogin() +" unshared from folder "+shareFolder.getName());
|
||||
boolean notify = notificationsMng.notifyFolderRemovedUser(userUnShared.getLogin(), shareFolder);
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notifies user: "+userUnShared.getLogin());
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderRemovedUser ", e);
|
||||
}
|
||||
|
||||
logger.trace("notifies of un unshare user is completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param workspaceItem the workspace item
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyAddedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.trace("Send notifies added item in sharedfolder is running...");
|
||||
|
||||
//DEBUG
|
||||
System.out.println("Send notifies added item in sharedfolder is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item [id: "+workspaceItem.getId() +"] name: "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
|
||||
|
||||
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
//DEBUG
|
||||
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyAddedItemToSharing ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies of added item in shared folder is completed");
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("notifies of added item in shared folder is completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param workspaceItem the workspace item
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyUpdatedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.trace("Send notifies updated item in shared folder is running...");
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Send notifies updated item in shared folder is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
|
||||
|
||||
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error updated when notify user: "+infoContactModel.getLogin());
|
||||
//DEBUG
|
||||
// System.out.println("An error updated when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error updated in notifyAddedItemToSharing ", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies of updated item in shared folder is completed");
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("notifies of updated item in shared folder is completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param workspaceItem the workspace item
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyMovedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.trace("Sending notification remove item in shared folder is running...");
|
||||
// printContacts(listContacts);
|
||||
|
||||
try {
|
||||
|
||||
if(NotificationsUtil.checkIsRootFolderShared(workspaceItem.getId(), sharedFolder.getId())){
|
||||
logger.trace("Notification isn't sent because the event is on root shared folder");
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (InternalErrorException e1) {
|
||||
logger.error("An error occurred in checkIsRootFolderShared ", e1);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.trace("Sending notification moved item in shared folder is running...");
|
||||
|
||||
// System.out.println("Sending notification moved item in shared folder is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
boolean notify = notificationsMng.notifyMovedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in notifyMovedItemToSharing ", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies of moved item in shared folder is completed");
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("notifies of moved item in shared folder is completed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param itemName the item name
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.trace("Sending notification remove item in shared folder is running...");
|
||||
// printContacts(listContacts);
|
||||
|
||||
if(itemName==null || itemName.isEmpty()){
|
||||
logger.trace("Notification isn't sent - itemName is null or empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if(sharedFolder==null){
|
||||
logger.trace("Notification isn't sent - sharedFolder is null");
|
||||
}
|
||||
|
||||
logger.trace("Sending notification removed item in shared folder is running...");
|
||||
|
||||
// System.out.println("Sending notification removed item in shared folder is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("Sending notification to user "+infoContactModel.getLogin() +" removed item "+itemName+" in shared folder "+sharedFolder.getName());
|
||||
|
||||
boolean notify = notificationsMng.notifyRemovedItem(infoContactModel.getLogin(), itemName, sharedFolder);
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in notifyRemovedItemToSharing ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies of moved item in shared folder is completed");
|
||||
|
||||
//DEBUG
|
||||
// System.out.println("notifies of moved item in shared folder is completed");
|
||||
}
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
* @param folderNameDeleted the folder name deleted
|
||||
*/
|
||||
public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) {
|
||||
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.trace("Send notifies shared folder deleted is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
try{
|
||||
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.trace("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted);
|
||||
|
||||
//DEBUG
|
||||
System.out.println("Sending notification to user "+infoContactModel.getLogin() +" deleted shared folder "+folderNameDeleted);
|
||||
|
||||
//TODO
|
||||
// boolean notify = notificationsMng.
|
||||
|
||||
// if(!notify)
|
||||
// logger.error("An error occured when notifies user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifySharedFolderDeleted ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies of deleted shared foder is completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param userToNotify the user to notify
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyAdministratorUpgrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.trace("Send notifies administrator upgrade is running...");
|
||||
if(userToNotify==null || userToNotify.getLogin()==null){
|
||||
logger.warn("Notification abort user to notify is null...");
|
||||
return;
|
||||
}
|
||||
|
||||
if(sharedFolder==null){
|
||||
logger.warn("Notification abort sharedFolder to notify is null...");
|
||||
return;
|
||||
}
|
||||
try{
|
||||
String login = userToNotify.getLogin();
|
||||
logger.trace("Send notifies administrator upgrade for login: "+login);
|
||||
|
||||
boolean notify = notificationsMng.notifyAdministratorUpgrade(login, sharedFolder);
|
||||
logger.trace("Notification sent correctly? "+notify);
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyAdministratorUpgrade ", e);
|
||||
}
|
||||
|
||||
|
||||
logger.trace("notifies of administrator upgrade completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param userToNotify the user to notify
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyAdministratorDowngrade(final InfoContactModel userToNotify, final WorkspaceSharedFolder sharedFolder){
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.trace("Send notifies administrator Downgrade is running...");
|
||||
if(userToNotify==null || userToNotify.getLogin()==null){
|
||||
logger.warn("Notification abort user to notify is null...");
|
||||
return;
|
||||
}
|
||||
|
||||
if(sharedFolder==null){
|
||||
logger.warn("Notification abort sharedFolder to notify is null...");
|
||||
return;
|
||||
}
|
||||
try{
|
||||
String login = userToNotify.getLogin();
|
||||
logger.trace("Send notifies administrator Downgrade for login: "+login);
|
||||
|
||||
boolean notify = notificationsMng.notifyAdministratorDowngrade(login, sharedFolder);
|
||||
logger.trace("Notification sent correctly? "+notify);
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyAdministratorDowngrade ", e);
|
||||
}
|
||||
|
||||
|
||||
logger.trace("notifies of administrator Downgrade completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
//DEBUG
|
||||
/**
|
||||
* Prints the contacts.
|
||||
*
|
||||
* @param listContacts the list contacts
|
||||
*/
|
||||
private void printContacts(List<InfoContactModel> listContacts){
|
||||
|
||||
System.out.println("Print contacts");
|
||||
for (InfoContactModel infoContactModel : listContacts) {
|
||||
System.out.println(infoContactModel);
|
||||
}
|
||||
System.out.println("End print contacts");
|
||||
}
|
||||
}
|
@ -1,252 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
||||
|
||||
/**
|
||||
* The Class NotificationsUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* May 27, 2013
|
||||
*/
|
||||
public class NotificationsUtil {
|
||||
|
||||
|
||||
protected static Logger logger = Logger.getLogger(NotificationsUtil.class);
|
||||
|
||||
/**
|
||||
* Send a notification if an item is added or updated to sharing folder.
|
||||
*
|
||||
* @param request the request
|
||||
* @param httpSession the http session
|
||||
* @param sourceItem the source item
|
||||
* @param sourceSharedId the source shared id
|
||||
* @param folderDestinationItem the folder destination item
|
||||
* @param isOverwrite the is overwrite
|
||||
*/
|
||||
public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
|
||||
|
||||
logger.trace("checkSendNotifyAddItemToShare");
|
||||
|
||||
if(folderDestinationItem!=null){
|
||||
|
||||
try{
|
||||
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
|
||||
|
||||
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
|
||||
//share condition is true if source shared folder is not null
|
||||
boolean shareChangeCondition = sourceSharedId==null?false:true;
|
||||
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
|
||||
logger.trace("shareChangeCondition add item: "+shareChangeCondition);
|
||||
|
||||
//if shareChangeCondition is true.. notifies added item to sharing
|
||||
if(shareChangeCondition){
|
||||
|
||||
Workspace workspace = WsUtil.getWorkspace(request);
|
||||
List<InfoContactModel> listContacts = getListUsersSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
|
||||
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
|
||||
NotificationsProducer np = new NotificationsProducer(request);
|
||||
|
||||
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
||||
|
||||
//SWITCH BEETWEEN ADDED OR UPDATED
|
||||
if(!isOverwrite)
|
||||
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
||||
else
|
||||
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
||||
|
||||
logger.trace("The notifies was sent correctly");
|
||||
}else
|
||||
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
|
||||
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
logger.trace("folder destination is not shared");
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in checkSendNotifyAddItemToShare ",e);
|
||||
}
|
||||
}else
|
||||
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list users shared by folder shared id.
|
||||
*
|
||||
* @param workspace the workspace
|
||||
* @param idSharedFolder the id shared folder
|
||||
* @return the list users shared by folder shared id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static List<InfoContactModel> getListUsersSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
|
||||
|
||||
logger.trace("getListUsersSharedByFolderSharedId "+ idSharedFolder);
|
||||
|
||||
try {
|
||||
|
||||
WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
|
||||
|
||||
if(isASharedFolder(wsItem)){
|
||||
|
||||
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
|
||||
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
List<String> listPortalLogin = wsFolder.getUsers();
|
||||
logger.trace("getListUserSharedByFolderSharedId return "+ listPortalLogin.size() + " user");
|
||||
return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
|
||||
}
|
||||
else{
|
||||
logger.trace("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
|
||||
|
||||
//DEBUG
|
||||
//System.out.println("the item with id: "+folderSharedId+ " is not "+WorkspaceItemType.SHARED_FOLDER);
|
||||
}
|
||||
return new ArrayList<InfoContactModel>();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in getListUserSharedByItemId ", e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check send notify remove item to share.
|
||||
*
|
||||
* @param request the request
|
||||
* @param sourceItemIsShared the source item is shared
|
||||
* @param oldItemName the old item name
|
||||
* @param oldItemId the old item id
|
||||
* @param sourceFolderSharedId the source folder shared id
|
||||
*/
|
||||
public static void checkSendNotifyRemoveItemToShare(HttpServletRequest request, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
|
||||
|
||||
logger.trace("checkNotifyRemoveItemToShare:");
|
||||
|
||||
try{
|
||||
|
||||
if(!sourceItemIsShared){
|
||||
logger.trace("checkSendNotifyRemoveItemToShare returned, source item is not shared");
|
||||
return;
|
||||
}
|
||||
|
||||
String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:"";
|
||||
boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder);
|
||||
logger.trace("isRootFolderShared is: "+ isRootFolderShared);
|
||||
/*
|
||||
if(isRootFolderShared){
|
||||
logger.trace("Notification doesn't sent because the event is on root shared folder");
|
||||
return;
|
||||
}*/
|
||||
boolean isSharedFolder = isASharedFolderForId(request,idSharedFolder);
|
||||
if(isSharedFolder){
|
||||
|
||||
logger.trace("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder);
|
||||
Workspace workspace = WsUtil.getWorkspace(request);
|
||||
//get contacts
|
||||
List<InfoContactModel> listContacts = getListUsersSharedByFolderSharedId(workspace, idSharedFolder);
|
||||
WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder);
|
||||
//System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName());
|
||||
NotificationsProducer np = new NotificationsProducer(request);
|
||||
|
||||
//Notify Removed Item To Sharing?
|
||||
if(!isRootFolderShared){
|
||||
if(sourceSharedFolder instanceof WorkspaceSharedFolder){
|
||||
np.notifyRemovedItemToSharing(listContacts, oldItemName, (WorkspaceSharedFolder) sourceSharedFolder);
|
||||
logger.trace("The notifies was sent correctly");
|
||||
}
|
||||
else
|
||||
logger.trace("The notifies doesn't sent because "+sourceSharedFolder+ " is not instance of WorkspaceSharedFolder");
|
||||
|
||||
}else{
|
||||
//Case removed shared folder
|
||||
np.notifySharedFolderDeleted(listContacts, oldItemName);
|
||||
}
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in checkSendNotifyRemoveItemToShare ",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is a shared folder.
|
||||
*
|
||||
* @param wsItem the ws item
|
||||
* @return true, if is a shared folder
|
||||
*/
|
||||
public static boolean isASharedFolder(WorkspaceItem wsItem){
|
||||
if(wsItem!=null)
|
||||
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is a shared folder for id.
|
||||
*
|
||||
* @param request the request
|
||||
* @param itemId the item id
|
||||
* @return true, if is a shared folder for id
|
||||
*/
|
||||
public static boolean isASharedFolderForId(HttpServletRequest request, String itemId){
|
||||
|
||||
if(itemId==null || itemId.isEmpty())
|
||||
return false;
|
||||
|
||||
try {
|
||||
|
||||
Workspace workspace = WsUtil.getWorkspace(request);
|
||||
|
||||
WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||
|
||||
if(wsItem!=null)
|
||||
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
|
||||
return false;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("An errror occurred in isASharedFolderForId", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check is root folder shared.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @param rootFolderSharedId the root folder shared id
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {
|
||||
|
||||
logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
|
||||
if(itemId==null)
|
||||
return false;
|
||||
|
||||
if(rootFolderSharedId==null)
|
||||
return false;
|
||||
|
||||
if(itemId.compareTo(rootFolderSharedId)==0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package org.gcube.portlets.user.workspace.server.tostoragehub;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
import org.gcube.portlets.user.workspace.client.util.ImageRequestType;
|
||||
|
||||
/**
|
||||
* The Class BuildServiceURLUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jul 17, 2019
|
||||
*/
|
||||
public class BuildServiceURLUtil {
|
||||
|
||||
|
||||
protected static final String IMAGE_SERVICE_URL = "ImageService";
|
||||
|
||||
/**
|
||||
* Builds the image url.
|
||||
*
|
||||
* @param id the id
|
||||
* @param currentGroupId the current group id
|
||||
* @param currUserId the curr user id
|
||||
* @return the string
|
||||
*/
|
||||
protected static String buildImageUrl(String id, String currentGroupId, String currUserId)
|
||||
{
|
||||
return buildImageServiceUrl(id, ImageRequestType.IMAGE, currentGroupId, currUserId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Builds the thumbnail url.
|
||||
*
|
||||
* @param id the id
|
||||
* @param currentGroupId the current group id
|
||||
* @param currUserId the curr user id
|
||||
* @return the string
|
||||
*/
|
||||
protected static String buildThumbnailUrl(String id, String currentGroupId, String currUserId)
|
||||
{
|
||||
return buildImageServiceUrl(id, ImageRequestType.THUMBNAIL, currentGroupId, currUserId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the image service url.
|
||||
*
|
||||
* @param id the id
|
||||
* @param requestType the request type
|
||||
* @param currentGroupId the current group id read from PortalContext
|
||||
* @param currUserId the curr user id
|
||||
* @return the string
|
||||
*/
|
||||
protected static String buildImageServiceUrl(String id, ImageRequestType requestType, String currentGroupId, String currUserId){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(IMAGE_SERVICE_URL);
|
||||
sb.append("?id=");
|
||||
sb.append(id);
|
||||
sb.append("&type=");
|
||||
sb.append(requestType.toString());
|
||||
sb.append("&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"=");
|
||||
sb.append(currentGroupId);
|
||||
// sb.append("&"+ConstantsExplorer.CURRENT_USER_ID+"=");
|
||||
// sb.append(currUserId);
|
||||
sb.append("&random=");
|
||||
sb.append(UUID.randomUUID().toString());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package org.gcube.portlets.user.workspace.server.tostoragehub;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* The Class FormatterUtil.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Jul 17, 2019
|
||||
*/
|
||||
public class FormatterUtil {
|
||||
|
||||
/**
|
||||
* To date.
|
||||
*
|
||||
* @param calendar the calendar
|
||||
* @return the date
|
||||
*/
|
||||
public static Date toDate(Calendar calendar){
|
||||
if (calendar == null) return new Date(0);
|
||||
return calendar.getTime();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To date format to string.
|
||||
*
|
||||
* @param calendar the calendar
|
||||
* @return the string
|
||||
*/
|
||||
protected String toDateFormatToString(Calendar calendar){
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z");
|
||||
Date resultdate = getDate(calendar);
|
||||
return dateFormat.format(resultdate);
|
||||
}
|
||||
|
||||
/**
|
||||
* To date format.
|
||||
*
|
||||
* @param calendar
|
||||
* the calendar
|
||||
* @return the date
|
||||
*/
|
||||
protected Date toDateFormat(Calendar calendar) {
|
||||
|
||||
SimpleDateFormat dateFormat =
|
||||
new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z");
|
||||
Date resultdate = getDate(calendar);
|
||||
try {
|
||||
resultdate = dateFormat.parse(dateFormat.format(resultdate));
|
||||
}
|
||||
catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
resultdate = new Date(0);
|
||||
}
|
||||
return resultdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date.
|
||||
*
|
||||
* @param calendar the calendar
|
||||
* @return the date
|
||||
*/
|
||||
private Date getDate(Calendar calendar) {
|
||||
|
||||
Date resultdate = null;
|
||||
|
||||
if (calendar == null)
|
||||
resultdate = new Date(0);
|
||||
else
|
||||
resultdate = new Date(calendar.getTimeInMillis());
|
||||
|
||||
return resultdate;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format file size.
|
||||
*
|
||||
* @param size the size
|
||||
* @return the string
|
||||
*/
|
||||
public static String formatFileSize(long size) {
|
||||
String formattedSize = null;
|
||||
|
||||
double b = size;
|
||||
double k = size/1024.0;
|
||||
double m = size/1024.0/1024.0;
|
||||
double g = size/1024.0/1024.0/1024.0;
|
||||
double t = size/1024.0/1024.0/1024.0/1024.0;
|
||||
|
||||
DecimalFormat dec = new DecimalFormat("0.00");
|
||||
|
||||
if ( t>1 ) {
|
||||
formattedSize = dec.format(t).concat(" TB");
|
||||
} else if ( g>1 ) {
|
||||
formattedSize = dec.format(g).concat(" GB");
|
||||
} else if ( m>1 ) {
|
||||
formattedSize = dec.format(m).concat(" MB");
|
||||
} else if ( k>1 ) {
|
||||
formattedSize = dec.format(k).concat(" KB");
|
||||
} else {
|
||||
formattedSize = dec.format(b).concat(" Bytes");
|
||||
}
|
||||
|
||||
return formattedSize;
|
||||
}
|
||||
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
||||
|
||||
/**
|
||||
* The Class AclTypeComparator.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Mar 5, 2015
|
||||
*/
|
||||
public class AclTypeComparator implements Comparator<ACLType>{
|
||||
|
||||
|
||||
public static final Map<ACLType, Integer> aclTypeOrder;
|
||||
static
|
||||
{
|
||||
aclTypeOrder = new LinkedHashMap<ACLType, Integer>();
|
||||
aclTypeOrder.put(ACLType.READ_ONLY, 0);
|
||||
aclTypeOrder.put(ACLType.WRITE_OWNER, 1);
|
||||
aclTypeOrder.put(ACLType.WRITE_ALL, 2);
|
||||
// aclTypeOrder.put(ACLType.ADMINISTRATOR, 3);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compare(ACLType o1, ACLType o2) {
|
||||
if(o1==null)
|
||||
return -1;
|
||||
if(o2==null)
|
||||
return 1;
|
||||
|
||||
Integer order1 = aclTypeOrder.get(o1);
|
||||
Integer order2 = aclTypeOrder.get(o2);
|
||||
|
||||
if(order1==null)
|
||||
return -1;
|
||||
|
||||
if(order2==null)
|
||||
return 1;
|
||||
|
||||
if(order1==order2)
|
||||
return 0;
|
||||
|
||||
return order1<order2?-1:1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the allowed.
|
||||
*
|
||||
* @param aclType the acl type to compare
|
||||
* @param includeEqual if true include equal ACLType, no otherwise
|
||||
* @return the allowed
|
||||
*/
|
||||
public List<ACLType> getAllowed(ACLType aclType, boolean includeEqual) {
|
||||
|
||||
List<ACLType> allowed = new ArrayList<ACLType>();
|
||||
|
||||
if(aclType==null)
|
||||
return allowed;
|
||||
|
||||
//IF MAP DOES NOT CONTAINS ACT TYPE IT IS NOT COMPARABLE
|
||||
if(aclTypeOrder.get(aclType)==null)
|
||||
return allowed;
|
||||
|
||||
for (ACLType aMap : aclTypeOrder.keySet()) {
|
||||
int comparator = compare(aMap, aclType);
|
||||
if(comparator==1)
|
||||
allowed.add(aMap);
|
||||
else if(includeEqual && comparator==0)
|
||||
allowed.add(aMap);
|
||||
}
|
||||
|
||||
return allowed;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
AclTypeComparator comparator = new AclTypeComparator();
|
||||
|
||||
List<ACLType> allowed = comparator.getAllowed(ACLType.WRITE_ALL, false);
|
||||
|
||||
System.out.println(allowed);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace.server.util;
|
||||
//
|
||||
//import java.util.concurrent.BlockingQueue;
|
||||
//import java.util.concurrent.LinkedBlockingQueue;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibrary.home.workspace.events.WorkspaceEvent;
|
||||
//import org.gcube.common.homelibrary.home.workspace.events.WorkspaceListener;
|
||||
//
|
||||
///**
|
||||
// * @author Federico De Faveri defaveriAtisti.cnr.it
|
||||
// *
|
||||
// */
|
||||
//public class WorkspaceEventCollector implements WorkspaceListener {
|
||||
//
|
||||
// protected static Logger logger = Logger.getLogger(WorkspaceEventCollector.class);
|
||||
//
|
||||
// protected BlockingQueue<WorkspaceEvent> eventsQueue = new LinkedBlockingQueue<WorkspaceEvent>();
|
||||
//
|
||||
// /**
|
||||
// * @param logger
|
||||
// */
|
||||
// public WorkspaceEventCollector() {
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * {@inheritDoc}
|
||||
// */
|
||||
// public void workspaceEvent(WorkspaceEvent event) {
|
||||
// try {
|
||||
// logger.trace("EventCollector workspaceEvent"+event);
|
||||
// eventsQueue.put(event);
|
||||
// } catch (InterruptedException e) {
|
||||
// logger.warn("Error adding a new event", e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public WorkspaceEvent getEvent() throws InterruptedException
|
||||
// {
|
||||
// logger.trace("getEvent");
|
||||
// return eventsQueue.take();
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,43 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Nov 4, 2015
|
||||
*/
|
||||
public class ListContact<T extends InfoContactModel> extends ArrayList<T> implements Serializable{
|
||||
|
||||
|
||||
private static final long serialVersionUID = 544202687567940083L;
|
||||
|
||||
public ListContact() {
|
||||
}
|
||||
|
||||
public boolean contains(InfoContactModel infoContactModel) {
|
||||
|
||||
if(infoContactModel==null)
|
||||
return false;
|
||||
|
||||
|
||||
if(infoContactModel.getLogin()==null)
|
||||
return false;
|
||||
|
||||
|
||||
for (int i = 0; i < this.size(); i++){
|
||||
|
||||
InfoContactModel log = get(i);
|
||||
if (log.getLogin()!=null && log.getLogin().compareTo(infoContactModel.getLogin())==0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,86 +1,88 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it Jul 14, 2015
|
||||
*/
|
||||
public class CreateSharedFolder {
|
||||
|
||||
protected static Logger logger = Logger.getLogger(CreateSharedFolder.class);
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
|
||||
public static String USER = "francesco.mangiacrapa"; //PRODUCTION
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||
.getHomeManager().getHome(USER)
|
||||
.getWorkspace();
|
||||
|
||||
String folderName = "Test Folder";
|
||||
String desc = "descr";
|
||||
List<String> listLogin = new ArrayList<String>();
|
||||
|
||||
listLogin.add("valentina.marioli");
|
||||
listLogin.add("massimiliano.assante");
|
||||
|
||||
WorkspaceSharedFolder sharedFolder = workspace.createSharedFolder(
|
||||
folderName, desc, listLogin, workspace.getRoot().getId());
|
||||
|
||||
if (sharedFolder == null)
|
||||
System.out.println("shared folder is null");
|
||||
|
||||
System.out
|
||||
.println("Shared folder created: " + sharedFolder.getId());
|
||||
} catch (InsufficientPrivilegesException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ItemAlreadyExistException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (WrongDestinationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ItemNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (WorkspaceFolderNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (HomeNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it Jul 14, 2015
|
||||
// */
|
||||
//public class CreateSharedFolder {
|
||||
//
|
||||
// protected static Logger logger = Logger.getLogger(CreateSharedFolder.class);
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
//
|
||||
// public static String USER = "francesco.mangiacrapa"; //PRODUCTION
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
// Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||
// .getHomeManager().getHome(USER)
|
||||
// .getWorkspace();
|
||||
//
|
||||
// String folderName = "Test Folder";
|
||||
// String desc = "descr";
|
||||
// List<String> listLogin = new ArrayList<String>();
|
||||
//
|
||||
// listLogin.add("valentina.marioli");
|
||||
// listLogin.add("massimiliano.assante");
|
||||
//
|
||||
// WorkspaceSharedFolder sharedFolder = workspace.createSharedFolder(
|
||||
// folderName, desc, listLogin, workspace.getRoot().getId());
|
||||
//
|
||||
// if (sharedFolder == null)
|
||||
// System.out.println("shared folder is null");
|
||||
//
|
||||
// System.out
|
||||
// .println("Shared folder created: " + sharedFolder.getId());
|
||||
// } catch (InsufficientPrivilegesException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (ItemAlreadyExistException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (WrongDestinationException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (ItemNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (WorkspaceFolderNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (HomeNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (UserNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,229 +1,238 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
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.exceptions.InsufficientPrivilegesException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Oct 28, 2015
|
||||
*/
|
||||
public class DeleteTest {
|
||||
|
||||
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/DESCRAMBLE";
|
||||
public static String TEST_USER = "francesco.mangiacrapa";
|
||||
|
||||
public static String PARENT_ID = "a9ead58c-d645-4699-addd-5c6e5f1aff06";
|
||||
private static Workspace ws;
|
||||
|
||||
private static GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome(TEST_USER)
|
||||
.getWorkspace();
|
||||
//
|
||||
|
||||
final List<String> children = getIdsOnlyFolderForID(PARENT_ID);
|
||||
|
||||
|
||||
if(children.size()<2){
|
||||
System.err.println("children size < 2, add others children");
|
||||
return;
|
||||
}
|
||||
|
||||
final int medium = children.size()/2;
|
||||
|
||||
Thread t1 = new Thread("T1"){
|
||||
public void run() {
|
||||
System.out.println("T1 start...");
|
||||
removeRange(children, 0, medium);
|
||||
System.out.println("T1 end");
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
t1.start();
|
||||
t1.join();
|
||||
|
||||
List<? extends WorkspaceItem> childrenNEW = getChildrenForID(PARENT_ID);
|
||||
|
||||
print(childrenNEW);
|
||||
|
||||
|
||||
Thread t2 = new Thread("T2"){
|
||||
public void run() {
|
||||
System.out.println("T2 start...");
|
||||
removeRange(children, medium, children.size());
|
||||
System.out.println("T2 end");
|
||||
};
|
||||
};
|
||||
|
||||
t2.start();
|
||||
t2.join();
|
||||
|
||||
childrenNEW = getChildrenForID(PARENT_ID);
|
||||
print(childrenNEW);
|
||||
|
||||
|
||||
System.out.println("\n\nDONE!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void print(final List<? extends WorkspaceItem> children){
|
||||
int i=0;
|
||||
System.out.println("\n\n");
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
|
||||
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER) || workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
||||
|
||||
WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
||||
|
||||
try {
|
||||
System.err.println(++i+") folder id: "+folder.getId() +", folder name: "+folder.getName());
|
||||
} catch (InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
|
||||
|
||||
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
|
||||
FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
|
||||
try {
|
||||
System.err.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", size: "+folderItem.getLength());
|
||||
} catch (InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\n\n");
|
||||
}
|
||||
|
||||
private static List<? extends WorkspaceItem> getChildrenForID(String id){
|
||||
|
||||
WorkspaceFolder folder;
|
||||
try {
|
||||
System.out.println("start getItem on id "+id);
|
||||
folder = (WorkspaceFolder) ws.getItem(id);
|
||||
System.out.println("start get children on folder "+folder.getName());
|
||||
final List<? extends WorkspaceItem> children = folder.getChildren();
|
||||
|
||||
builder.buildGXTListFileGridModelItem(folder.getChildren(), null);
|
||||
|
||||
// builder.buildGXTFileGridModelItem(folder, null);
|
||||
|
||||
System.out.println("children size: "+children.size());
|
||||
return children;
|
||||
} catch (ItemNotFoundException | InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getIdsForID(String id){
|
||||
|
||||
|
||||
try {
|
||||
List<? extends WorkspaceItem> children = getChildrenForID(id);
|
||||
List<String> ids = new ArrayList<String>(children.size());
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
ids.add(workspaceItem.getId());
|
||||
}
|
||||
return ids;
|
||||
} catch (InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> getIdsOnlyFolderForID(String id){
|
||||
|
||||
|
||||
try {
|
||||
List<? extends WorkspaceItem> children = getChildrenForID(id);
|
||||
List<String> ids = new ArrayList<String>(children.size());
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
if(workspaceItem.isFolder())
|
||||
ids.add(workspaceItem.getId());
|
||||
}
|
||||
return ids;
|
||||
} catch (InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void removeRange(List<String> children, int start, int end) {
|
||||
|
||||
System.out.println("start "+start);
|
||||
System.out.println("end "+end);
|
||||
// System.out.println("(end - start)"+(end - start));
|
||||
|
||||
List<String> sub = children.subList(start, end);
|
||||
String[] array = new String[sub.size()];
|
||||
array = sub.toArray(array);
|
||||
|
||||
System.out.println("array lenght: "+array.length);
|
||||
|
||||
for (String id : array)
|
||||
System.out.println("Removing "+id);
|
||||
|
||||
try {
|
||||
ws.removeItems(array);
|
||||
|
||||
System.out.println("Remove OK ");
|
||||
} catch (ItemNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InsufficientPrivilegesException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InternalErrorException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//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.exceptions.InsufficientPrivilegesException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Oct 28, 2015
|
||||
// */
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//public class DeleteTest {
|
||||
//
|
||||
//
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/DESCRAMBLE";
|
||||
// public static String TEST_USER = "francesco.mangiacrapa";
|
||||
//
|
||||
// public static String PARENT_ID = "a9ead58c-d645-4699-addd-5c6e5f1aff06";
|
||||
// private static Workspace ws;
|
||||
//
|
||||
// private static GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// ws = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome(TEST_USER)
|
||||
// .getWorkspace();
|
||||
// //
|
||||
//
|
||||
// final List<String> children = getIdsOnlyFolderForID(PARENT_ID);
|
||||
//
|
||||
//
|
||||
// if(children.size()<2){
|
||||
// System.err.println("children size < 2, add others children");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final int medium = children.size()/2;
|
||||
//
|
||||
// Thread t1 = new Thread("T1"){
|
||||
// public void run() {
|
||||
// System.out.println("T1 start...");
|
||||
// removeRange(children, 0, medium);
|
||||
// System.out.println("T1 end");
|
||||
//
|
||||
// };
|
||||
// };
|
||||
//
|
||||
// t1.start();
|
||||
// t1.join();
|
||||
//
|
||||
// List<? extends WorkspaceItem> childrenNEW = getChildrenForID(PARENT_ID);
|
||||
//
|
||||
// print(childrenNEW);
|
||||
//
|
||||
//
|
||||
// Thread t2 = new Thread("T2"){
|
||||
// public void run() {
|
||||
// System.out.println("T2 start...");
|
||||
// removeRange(children, medium, children.size());
|
||||
// System.out.println("T2 end");
|
||||
// };
|
||||
// };
|
||||
//
|
||||
// t2.start();
|
||||
// t2.join();
|
||||
//
|
||||
// childrenNEW = getChildrenForID(PARENT_ID);
|
||||
// print(childrenNEW);
|
||||
//
|
||||
//
|
||||
// System.out.println("\n\nDONE!");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static void print(final List<? extends WorkspaceItem> children){
|
||||
// int i=0;
|
||||
// System.out.println("\n\n");
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
//
|
||||
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER) || workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
||||
//
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
||||
//
|
||||
// try {
|
||||
// System.err.println(++i+") folder id: "+folder.getId() +", folder name: "+folder.getName());
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }else{
|
||||
//
|
||||
//
|
||||
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
//
|
||||
// FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
//
|
||||
// try {
|
||||
// System.err.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", size: "+folderItem.getLength());
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// System.out.println("\n\n");
|
||||
// }
|
||||
//
|
||||
// private static List<? extends WorkspaceItem> getChildrenForID(String id){
|
||||
//
|
||||
// WorkspaceFolder folder;
|
||||
// try {
|
||||
// System.out.println("start getItem on id "+id);
|
||||
// folder = (WorkspaceFolder) ws.getItem(id);
|
||||
// System.out.println("start get children on folder "+folder.getName());
|
||||
// final List<? extends WorkspaceItem> children = folder.getChildren();
|
||||
//
|
||||
// builder.buildGXTListFileGridModelItem(folder.getChildren(), null);
|
||||
//
|
||||
//// builder.buildGXTFileGridModelItem(folder, null);
|
||||
//
|
||||
// System.out.println("children size: "+children.size());
|
||||
// return children;
|
||||
// } catch (ItemNotFoundException | InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static List<String> getIdsForID(String id){
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// List<? extends WorkspaceItem> children = getChildrenForID(id);
|
||||
// List<String> ids = new ArrayList<String>(children.size());
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// ids.add(workspaceItem.getId());
|
||||
// }
|
||||
// return ids;
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static List<String> getIdsOnlyFolderForID(String id){
|
||||
//
|
||||
//
|
||||
// try {
|
||||
// List<? extends WorkspaceItem> children = getChildrenForID(id);
|
||||
// List<String> ids = new ArrayList<String>(children.size());
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// if(workspaceItem.isFolder())
|
||||
// ids.add(workspaceItem.getId());
|
||||
// }
|
||||
// return ids;
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// private static void removeRange(List<String> children, int start, int end) {
|
||||
//
|
||||
// System.out.println("start "+start);
|
||||
// System.out.println("end "+end);
|
||||
//// System.out.println("(end - start)"+(end - start));
|
||||
//
|
||||
// List<String> sub = children.subList(start, end);
|
||||
// String[] array = new String[sub.size()];
|
||||
// array = sub.toArray(array);
|
||||
//
|
||||
// System.out.println("array lenght: "+array.length);
|
||||
//
|
||||
// for (String id : array)
|
||||
// System.out.println("Removing "+id);
|
||||
//
|
||||
// try {
|
||||
// ws.removeItems(array);
|
||||
//
|
||||
// System.out.println("Remove OK ");
|
||||
// } catch (ItemNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (InsufficientPrivilegesException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//*/
|
||||
|
@ -1,199 +1,209 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.items.type.FolderItemType;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
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.folder.FolderItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* @Dec 17, 2013
|
||||
*
|
||||
*/
|
||||
public class DephtVisitDonwloadFilesTester {
|
||||
|
||||
|
||||
protected static Logger logger = Logger.getLogger(SearchTextTest.class);
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
|
||||
public static String USER = "francesco.mangiacrapa"; //PRODUCTION
|
||||
|
||||
private static BufferedWriter writer;
|
||||
private static OutputStreamWriter out;
|
||||
|
||||
static final String itemID = "165ba18a-a08a-42c6-ade5-9b93d1f844ac";
|
||||
static WorkspaceItem root;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome(USER).getWorkspace();
|
||||
out = new OutputStreamWriter(new FileOutputStream("Csv-error-file.csv"), "UTF-8");
|
||||
writer = new BufferedWriter(out);
|
||||
|
||||
writer.write("Id;Name;Path;Parent");
|
||||
|
||||
|
||||
System.out.println("Start");
|
||||
// WorkspaceItem root = ws.getRoot();
|
||||
|
||||
root = ws.getItem(itemID);
|
||||
|
||||
depthVisit(root);
|
||||
|
||||
// new Thread(){
|
||||
// public void run() {
|
||||
// try {
|
||||
//
|
||||
// depthVisit(root);
|
||||
//
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.io.BufferedWriter;
|
||||
//import java.io.FileOutputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.OutputStreamWriter;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibary.model.items.type.FolderItemType;
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//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.folder.FolderItem;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * @Dec 17, 2013
|
||||
// *
|
||||
// */
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//public class DephtVisitDonwloadFilesTester {
|
||||
//
|
||||
//
|
||||
// protected static Logger logger = Logger.getLogger(SearchTextTest.class);
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
//
|
||||
// public static String USER = "francesco.mangiacrapa"; //PRODUCTION
|
||||
//
|
||||
// private static BufferedWriter writer;
|
||||
// private static OutputStreamWriter out;
|
||||
//
|
||||
// static final String itemID = "165ba18a-a08a-42c6-ade5-9b93d1f844ac";
|
||||
// static WorkspaceItem root;
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getHome(USER).getWorkspace();
|
||||
// out = new OutputStreamWriter(new FileOutputStream("Csv-error-file.csv"), "UTF-8");
|
||||
// writer = new BufferedWriter(out);
|
||||
//
|
||||
// writer.write("Id;Name;Path;Parent");
|
||||
//
|
||||
//
|
||||
// System.out.println("Start");
|
||||
//// WorkspaceItem root = ws.getRoot();
|
||||
//
|
||||
// root = ws.getItem(itemID);
|
||||
//
|
||||
// depthVisit(root);
|
||||
//
|
||||
//// new Thread(){
|
||||
//// public void run() {
|
||||
//// try {
|
||||
////
|
||||
//// depthVisit(root);
|
||||
////
|
||||
//// } catch (InternalErrorException e) {
|
||||
//// // TODO Auto-generated catch block
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
//// };
|
||||
////
|
||||
//// }.start();
|
||||
//
|
||||
// System.out.println("waiting 10 sec..");
|
||||
// Thread.sleep(10000);
|
||||
//
|
||||
//
|
||||
// System.out.println("End");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }finally{
|
||||
// System.out.println("writer close");
|
||||
// try {writer.close();} catch (Exception ex) {}
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void depthVisit(WorkspaceItem item) throws InternalErrorException {
|
||||
//
|
||||
// if (item.getType().equals(WorkspaceItemType.FOLDER) || item.getType().equals(WorkspaceItemType.SHARED_FOLDER)) {
|
||||
//
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) item;
|
||||
// System.out.println("\nVisit Folder: " + folder.getName() +"; Folder is shared: "+folder.isShared());
|
||||
// List<? extends WorkspaceItem> children = folder.getChildren();
|
||||
//
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// depthVisit(workspaceItem);
|
||||
// }
|
||||
// } else {
|
||||
//
|
||||
// System.out.println("Item name: " + item.getName() +"; Parent Folder: "+item.getParent().getName());
|
||||
//
|
||||
// if(item.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
//
|
||||
// FolderItem folderItem = (FolderItem) item;
|
||||
//
|
||||
// if(folderItem.getFolderItemType().equals(FolderItemType.EXTERNAL_FILE)){
|
||||
//
|
||||
// System.out.println("Item is external file: " + item.getName());
|
||||
//
|
||||
// final ExternalFile f = (ExternalFile) folderItem;
|
||||
//
|
||||
// try{
|
||||
//
|
||||
// Thread t = new Thread(){
|
||||
//
|
||||
// public void run() {
|
||||
//
|
||||
// try {
|
||||
// tryGetPayload(f);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// try {
|
||||
// System.out.println("Item name: "+f.getName() + "not exists into storage");
|
||||
// erroFile(f);
|
||||
// } catch (InternalErrorException e1) {
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// t.start();
|
||||
//
|
||||
//// System.out.println("join 3 sec");
|
||||
//// t.join(1000);
|
||||
////
|
||||
//// System.out.println("join 1 sec terminated");
|
||||
//// if(is==null)
|
||||
//// throw new Exception("is is null");
|
||||
//
|
||||
// }catch (Exception e) {
|
||||
// System.out.println("Item name: "+f.getName() + "not exists into storage");
|
||||
// erroFile(f);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// }.start();
|
||||
|
||||
System.out.println("waiting 10 sec..");
|
||||
Thread.sleep(10000);
|
||||
|
||||
|
||||
System.out.println("End");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
System.out.println("writer close");
|
||||
try {writer.close();} catch (Exception ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
public static void depthVisit(WorkspaceItem item) throws InternalErrorException {
|
||||
|
||||
if (item.getType().equals(WorkspaceItemType.FOLDER) || item.getType().equals(WorkspaceItemType.SHARED_FOLDER)) {
|
||||
|
||||
WorkspaceFolder folder = (WorkspaceFolder) item;
|
||||
System.out.println("\nVisit Folder: " + folder.getName() +"; Folder is shared: "+folder.isShared());
|
||||
List<? extends WorkspaceItem> children = folder.getChildren();
|
||||
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
depthVisit(workspaceItem);
|
||||
}
|
||||
} else {
|
||||
|
||||
System.out.println("Item name: " + item.getName() +"; Parent Folder: "+item.getParent().getName());
|
||||
|
||||
if(item.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
|
||||
FolderItem folderItem = (FolderItem) item;
|
||||
|
||||
if(folderItem.getFolderItemType().equals(FolderItemType.EXTERNAL_FILE)){
|
||||
|
||||
System.out.println("Item is external file: " + item.getName());
|
||||
|
||||
final ExternalFile f = (ExternalFile) folderItem;
|
||||
|
||||
try{
|
||||
|
||||
Thread t = new Thread(){
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
tryGetPayload(f);
|
||||
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
System.out.println("Item name: "+f.getName() + "not exists into storage");
|
||||
erroFile(f);
|
||||
} catch (InternalErrorException e1) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
t.start();
|
||||
|
||||
// System.out.println("join 3 sec");
|
||||
// t.join(1000);
|
||||
//
|
||||
// System.out.println("join 1 sec terminated");
|
||||
// if(is==null)
|
||||
// throw new Exception("is is null");
|
||||
|
||||
}catch (Exception e) {
|
||||
System.out.println("Item name: "+f.getName() + "not exists into storage");
|
||||
erroFile(f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void tryGetPayload(ExternalFile f) throws Exception{
|
||||
|
||||
try {
|
||||
|
||||
InputStream is = f.getData();
|
||||
System.out.println("Get payload for file : "+f.getName() +" terminated");
|
||||
|
||||
if(is==null)
|
||||
throw new Exception("is is null");
|
||||
|
||||
} catch (InternalErrorException e1) {
|
||||
System.out.println("Error on :"+f.getName());
|
||||
throw new Exception("is is null");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized static void erroFile(WorkspaceItem item) throws InternalErrorException{
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
|
||||
String parentName="";
|
||||
|
||||
if(item.getParent()!=null)
|
||||
parentName = item.getParent().getName();
|
||||
|
||||
writer.write("\n "+item.getId()+";"+item.getName()+";"+item.getPath()+";"+parentName);
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void tryGetPayload(ExternalFile f) throws Exception{
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// InputStream is = f.getData();
|
||||
// System.out.println("Get payload for file : "+f.getName() +" terminated");
|
||||
//
|
||||
// if(is==null)
|
||||
// throw new Exception("is is null");
|
||||
//
|
||||
// } catch (InternalErrorException e1) {
|
||||
// System.out.println("Error on :"+f.getName());
|
||||
// throw new Exception("is is null");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public synchronized static void erroFile(WorkspaceItem item) throws InternalErrorException{
|
||||
//
|
||||
// try{
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// String parentName="";
|
||||
//
|
||||
// if(item.getParent()!=null)
|
||||
// parentName = item.getParent().getName();
|
||||
//
|
||||
// writer.write("\n "+item.getId()+";"+item.getName()+";"+item.getPath()+";"+parentName);
|
||||
//
|
||||
// } catch (IOException ex) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//*/
|
||||
|
@ -1,119 +1,121 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibary.model.items.type.FolderItemType;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
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.folder.FolderItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jun 18, 2013
|
||||
*
|
||||
*/
|
||||
public class DonwloadServletTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// InputStream is = null;
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
// System.out.println("start");
|
||||
//import java.util.List;
|
||||
//
|
||||
// is = GCUBEStorage.getRemoteFile("/Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381");
|
||||
|
||||
try {
|
||||
|
||||
Workspace ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("francesco.mangiacrapa")
|
||||
.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");
|
||||
//import org.gcube.common.homelibary.model.items.type.FolderItemType;
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//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.folder.FolderItem;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jun 18, 2013
|
||||
// *
|
||||
// */
|
||||
//public class DonwloadServletTest {
|
||||
//
|
||||
// ExternalFile f = (ExternalFile) item;
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
//// InputStream is = null;
|
||||
////
|
||||
//// System.out.println("start");
|
||||
////
|
||||
//// is = GCUBEStorage.getRemoteFile("/Home/francesco.mangiacrapa/Workspace284ee688-e6fb-4080-bbcb-cc7c8cc5c381");
|
||||
//
|
||||
// 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) {
|
||||
// // out.write(buffer, 0, len);
|
||||
// // }
|
||||
// try {
|
||||
//
|
||||
|
||||
|
||||
// is = f.getData();
|
||||
|
||||
|
||||
// IOUtils.copy(is, out);
|
||||
// is.close();
|
||||
// Workspace ws = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome("francesco.mangiacrapa")
|
||||
// .getWorkspace();
|
||||
// //
|
||||
//
|
||||
// out.close();
|
||||
|
||||
// System.out.println("Sleeping");
|
||||
// Thread.sleep(20000);
|
||||
// System.out.println("Alive");
|
||||
|
||||
System.out.println("end");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void depthVisit(WorkspaceItem item) throws InternalErrorException{
|
||||
|
||||
|
||||
if(item.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
|
||||
WorkspaceFolder folder = (WorkspaceFolder) item;
|
||||
System.out.println("Visit Folder: "+folder.getName());
|
||||
List<? extends WorkspaceItem> children = folder.getChildren();
|
||||
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
depthVisit(workspaceItem);
|
||||
}
|
||||
}else{
|
||||
|
||||
System.out.println("Item name: "+item.getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 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) {
|
||||
//// // out.write(buffer, 0, len);
|
||||
//// // }
|
||||
////
|
||||
//
|
||||
//
|
||||
//// is = f.getData();
|
||||
//
|
||||
//
|
||||
//// IOUtils.copy(is, out);
|
||||
//// is.close();
|
||||
////
|
||||
//// out.close();
|
||||
//
|
||||
// // System.out.println("Sleeping");
|
||||
// // Thread.sleep(20000);
|
||||
// // System.out.println("Alive");
|
||||
//
|
||||
// System.out.println("end");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void depthVisit(WorkspaceItem item) throws InternalErrorException{
|
||||
//
|
||||
//
|
||||
// if(item.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
//
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) item;
|
||||
// System.out.println("Visit Folder: "+folder.getName());
|
||||
// List<? extends WorkspaceItem> children = folder.getChildren();
|
||||
//
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// depthVisit(workspaceItem);
|
||||
// }
|
||||
// }else{
|
||||
//
|
||||
// System.out.println("Item name: "+item.getName());
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,53 +1,54 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jun 12, 2015
|
||||
*/
|
||||
public class GcubeProperties {
|
||||
public static Logger logger = Logger.getLogger(GcubeProperties.class);
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
public static String TEST_USER = "francesco.mangiacrapa";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try{
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
Workspace ws = getWorkspace();
|
||||
GCubeItem item = (GCubeItem) ws.getItem("7d5fd78a-6543-4d20-b6e7-9ae490fa1ad8");
|
||||
// Properties props = item.getProperties();
|
||||
// item.getProperties().addProperty("key06", "value0006");
|
||||
// item.getProperties().addProperty("key05", "value0005");
|
||||
// item.getProperties().update();
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jun 12, 2015
|
||||
// */
|
||||
//public class GcubeProperties {
|
||||
// public static Logger logger = Logger.getLogger(GcubeProperties.class);
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String TEST_USER = "francesco.mangiacrapa";
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try{
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
// Workspace ws = getWorkspace();
|
||||
// GCubeItem item = (GCubeItem) ws.getItem("7d5fd78a-6543-4d20-b6e7-9ae490fa1ad8");
|
||||
// // Properties props = item.getProperties();
|
||||
//// item.getProperties().addProperty("key06", "value0006");
|
||||
//// item.getProperties().addProperty("key05", "value0005");
|
||||
//// item.getProperties().update();
|
||||
////
|
||||
//
|
||||
// System.out.println(item.getProperties().getProperties());
|
||||
//
|
||||
|
||||
System.out.println(item.getProperties().getProperties());
|
||||
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
|
||||
logger.trace("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER);
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
logger.trace("Scope provider instancied");
|
||||
Workspace workspace = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
return workspace;
|
||||
}
|
||||
}
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
|
||||
// logger.trace("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER);
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
// logger.trace("Scope provider instancied");
|
||||
// Workspace workspace = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
// return workspace;
|
||||
// }
|
||||
//}
|
||||
|
@ -1,188 +1,189 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
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.WorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jan 29, 2014
|
||||
*
|
||||
*/
|
||||
public class ItemRetrieve {
|
||||
|
||||
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
public static String TEST_USER = "francesco.mangiacrapa";
|
||||
// public static String ITEMID = "63832213-098d-42d1-8774-89b6349764c0"; //Activity T3.4 working drafts/T2-EC-IMAR-HO-14-015 iMarine Sustainability WP - Business Model tools.pdf
|
||||
public static String ITEMID = "ce4866ee-8079-4acf-bcd6-1c9dd786eb73";
|
||||
// d81d3a64-603f-4907-ae74-be8353211807
|
||||
protected static Logger logger = Logger.getLogger(ItemRetrieve.class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
System.out.println("init HL");
|
||||
try {
|
||||
Workspace ws = getWorkspace();
|
||||
|
||||
System.out.println(ws.getRoot().getId());
|
||||
retrieveFirstLevel(ws, null);
|
||||
//
|
||||
// retrieveFirstLevel(ws, ITEMID);
|
||||
//
|
||||
// System.out.println("get workspace -> OK");
|
||||
WorkspaceItem item = ws.getItem(ITEMID);
|
||||
System.out.println("get item id: "+item.getId()+", name: "+item.getName() +", parent: "+item.getParent().getId() +", parent name: "+item.getParent().getName()+", path :"+item.getPath());
|
||||
System.out.println(item);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// } catch (WorkspaceFolderNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (InternalErrorException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (HomeNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// } catch (UserNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
//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.WorkspaceSharedFolder;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jan 29, 2014
|
||||
// *
|
||||
// */
|
||||
//public class ItemRetrieve {
|
||||
//
|
||||
//
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String TEST_USER = "francesco.mangiacrapa";
|
||||
//// public static String ITEMID = "63832213-098d-42d1-8774-89b6349764c0"; //Activity T3.4 working drafts/T2-EC-IMAR-HO-14-015 iMarine Sustainability WP - Business Model tools.pdf
|
||||
// public static String ITEMID = "ce4866ee-8079-4acf-bcd6-1c9dd786eb73";
|
||||
//// d81d3a64-603f-4907-ae74-be8353211807
|
||||
// protected static Logger logger = Logger.getLogger(ItemRetrieve.class);
|
||||
//
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// System.out.println("init HL");
|
||||
// try {
|
||||
// Workspace ws = getWorkspace();
|
||||
//
|
||||
// System.out.println(ws.getRoot().getId());
|
||||
// retrieveFirstLevel(ws, null);
|
||||
////
|
||||
//// retrieveFirstLevel(ws, ITEMID);
|
||||
////
|
||||
//// System.out.println("get workspace -> OK");
|
||||
// WorkspaceItem item = ws.getItem(ITEMID);
|
||||
// System.out.println("get item id: "+item.getId()+", name: "+item.getName() +", parent: "+item.getParent().getId() +", parent name: "+item.getParent().getName()+", path :"+item.getPath());
|
||||
// System.out.println(item);
|
||||
// }catch(Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, UserNotFoundException
|
||||
{
|
||||
|
||||
logger.trace("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER);
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
logger.trace("Scope provider instancied");
|
||||
|
||||
// return HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
return HomeLibrary.getHomeManagerFactory().getHomeManager().getHome(TEST_USER).getWorkspace();
|
||||
}
|
||||
|
||||
|
||||
private static void retrieveFirstLevel(Workspace ws, String foundFolder){
|
||||
|
||||
try {
|
||||
|
||||
//TEST TIME
|
||||
Long startTime = System.currentTimeMillis();
|
||||
Long endTime = System.currentTimeMillis() - startTime;
|
||||
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
System.out.println("Start foundFolder at time: "+startTime);
|
||||
// WorkspaceItem root = ws.getItem(ITEMID);
|
||||
WorkspaceItem fd;
|
||||
if(foundFolder!=null){
|
||||
fd = ws.getItem(foundFolder);
|
||||
System.out.println("foundFolder id: "+foundFolder);
|
||||
System.out.println("start get children");
|
||||
}else
|
||||
fd = ws.getRoot();
|
||||
|
||||
List<? extends WorkspaceItem> children = fd.getChildren();
|
||||
System.out.println("tree getChildren() returning "+children.size()+" elements in " + time);
|
||||
|
||||
System.out.println("children size: "+children.size());
|
||||
|
||||
int i=0;
|
||||
int foldersCounter = 0;
|
||||
int sharedFoldersCounter = 0;
|
||||
int folderItemCounter = 0;
|
||||
int othersCounter = 0;
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
try{
|
||||
|
||||
/*if(foundFolder!=null && !foundFolder.isEmpty()){
|
||||
if(workspaceItem.getId().compareTo(foundFolder)==0){
|
||||
System.out.println("ITEM FOUND id: "+workspaceItem.getId()+", name: "+workspaceItem.getName());
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
switch (workspaceItem.getType()) {
|
||||
|
||||
case FOLDER:
|
||||
|
||||
WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
||||
|
||||
// System.out.println(++i+") "+folder.getId() +" folder name: "+folder.getName() + " owner "+folder.getOwner() +" path: "+folder.getPath());
|
||||
System.out.println(++i+") "+folder.getId() +" folder name: "+folder.getName() + " owner "+folder.getOwner());
|
||||
foldersCounter++;
|
||||
|
||||
break;
|
||||
|
||||
case SHARED_FOLDER:
|
||||
|
||||
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
|
||||
|
||||
// System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName() + " owner "+shared.getOwner()+" isVRE "+shared.isVreFolder() +" ACLOwner: "+shared.getACLOwner()+" AclUser: "+shared.getACLUser() +" path: "+shared.getPath());
|
||||
System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName());
|
||||
|
||||
// System.out.println(++i+") shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin());
|
||||
sharedFoldersCounter++;
|
||||
|
||||
break;
|
||||
|
||||
case FOLDER_ITEM:
|
||||
|
||||
FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
|
||||
// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", own: "+folderItem.getOwner() +" path: "+folderItem.getPath());
|
||||
System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", own: "+folderItem.getOwner());
|
||||
folderItemCounter++;
|
||||
|
||||
break;
|
||||
default:
|
||||
// System.out.println(++i+") DEFAULT - item id: "+workspaceItem.getId() +", name: "+workspaceItem.getName() + ", own: "+workspaceItem.getOwner());
|
||||
// othersCounter++;
|
||||
break;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TEST TIME
|
||||
endTime = System.currentTimeMillis();
|
||||
long difference = endTime - startTime;
|
||||
time = String.format("%d msc %d sec", difference, TimeUnit.MILLISECONDS.toSeconds(difference));
|
||||
System.out.println("End time is "+endTime+ " difference is "+time);
|
||||
System.out.println("Folders are: "+foldersCounter);
|
||||
System.out.println("Shared Folders are: "+sharedFoldersCounter);
|
||||
System.out.println("Folder Item are: "+folderItemCounter);
|
||||
System.out.println("Others are: "+othersCounter);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
//// } catch (WorkspaceFolderNotFoundException e) {
|
||||
//// // TODO Auto-generated catch block
|
||||
//// e.printStackTrace();
|
||||
//// } catch (InternalErrorException e) {
|
||||
//// // TODO Auto-generated catch block
|
||||
//// e.printStackTrace();
|
||||
//// } catch (HomeNotFoundException e) {
|
||||
//// // TODO Auto-generated catch block
|
||||
//// e.printStackTrace();
|
||||
//// } catch (UserNotFoundException e) {
|
||||
//// // TODO Auto-generated catch block
|
||||
//// e.printStackTrace();
|
||||
//// }
|
||||
////
|
||||
// }
|
||||
//
|
||||
// public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, UserNotFoundException
|
||||
// {
|
||||
//
|
||||
// logger.trace("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER);
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
// logger.trace("Scope provider instancied");
|
||||
//
|
||||
//// return HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
// return HomeLibrary.getHomeManagerFactory().getHomeManager().getHome(TEST_USER).getWorkspace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static void retrieveFirstLevel(Workspace ws, String foundFolder){
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// //TEST TIME
|
||||
// Long startTime = System.currentTimeMillis();
|
||||
// Long endTime = System.currentTimeMillis() - startTime;
|
||||
// String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
|
||||
//
|
||||
// startTime = System.currentTimeMillis();
|
||||
// System.out.println("Start foundFolder at time: "+startTime);
|
||||
//// WorkspaceItem root = ws.getItem(ITEMID);
|
||||
// WorkspaceItem fd;
|
||||
// if(foundFolder!=null){
|
||||
// fd = ws.getItem(foundFolder);
|
||||
// System.out.println("foundFolder id: "+foundFolder);
|
||||
// System.out.println("start get children");
|
||||
// }else
|
||||
// fd = ws.getRoot();
|
||||
//
|
||||
// List<? extends WorkspaceItem> children = fd.getChildren();
|
||||
// System.out.println("tree getChildren() returning "+children.size()+" elements in " + time);
|
||||
//
|
||||
// System.out.println("children size: "+children.size());
|
||||
//
|
||||
// int i=0;
|
||||
// int foldersCounter = 0;
|
||||
// int sharedFoldersCounter = 0;
|
||||
// int folderItemCounter = 0;
|
||||
// int othersCounter = 0;
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// try{
|
||||
//
|
||||
// /*if(foundFolder!=null && !foundFolder.isEmpty()){
|
||||
// if(workspaceItem.getId().compareTo(foundFolder)==0){
|
||||
// System.out.println("ITEM FOUND id: "+workspaceItem.getId()+", name: "+workspaceItem.getName());
|
||||
// return;
|
||||
// }
|
||||
// }*/
|
||||
//
|
||||
// switch (workspaceItem.getType()) {
|
||||
//
|
||||
// case FOLDER:
|
||||
//
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
||||
//
|
||||
//// System.out.println(++i+") "+folder.getId() +" folder name: "+folder.getName() + " owner "+folder.getOwner() +" path: "+folder.getPath());
|
||||
// System.out.println(++i+") "+folder.getId() +" folder name: "+folder.getName() + " owner "+folder.getOwner());
|
||||
// foldersCounter++;
|
||||
//
|
||||
// break;
|
||||
//
|
||||
// case SHARED_FOLDER:
|
||||
//
|
||||
// WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
|
||||
//
|
||||
//// System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName() + " owner "+shared.getOwner()+" isVRE "+shared.isVreFolder() +" ACLOwner: "+shared.getACLOwner()+" AclUser: "+shared.getACLUser() +" path: "+shared.getPath());
|
||||
// System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName());
|
||||
//
|
||||
// // System.out.println(++i+") shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin());
|
||||
// sharedFoldersCounter++;
|
||||
//
|
||||
// break;
|
||||
//
|
||||
// case FOLDER_ITEM:
|
||||
//
|
||||
// FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
//
|
||||
//// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", own: "+folderItem.getOwner() +" path: "+folderItem.getPath());
|
||||
// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", own: "+folderItem.getOwner());
|
||||
// folderItemCounter++;
|
||||
//
|
||||
// break;
|
||||
// default:
|
||||
// // System.out.println(++i+") DEFAULT - item id: "+workspaceItem.getId() +", name: "+workspaceItem.getName() + ", own: "+workspaceItem.getOwner());
|
||||
// // othersCounter++;
|
||||
// break;
|
||||
// }
|
||||
// }catch (Exception e) {
|
||||
// // TODO: handle exception
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// //TEST TIME
|
||||
// endTime = System.currentTimeMillis();
|
||||
// long difference = endTime - startTime;
|
||||
// time = String.format("%d msc %d sec", difference, TimeUnit.MILLISECONDS.toSeconds(difference));
|
||||
// System.out.println("End time is "+endTime+ " difference is "+time);
|
||||
// System.out.println("Folders are: "+foldersCounter);
|
||||
// System.out.println("Shared Folders are: "+sharedFoldersCounter);
|
||||
// System.out.println("Folder Item are: "+folderItemCounter);
|
||||
// System.out.println("Others are: "+othersCounter);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,138 +1,139 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
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.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.GCubeItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jul 3, 2013
|
||||
*
|
||||
*/
|
||||
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(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();
|
||||
|
||||
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:
|
||||
GCubeItem imgDoc = (GCubeItem) worspaceFolderItem; //Cast GCubeItem
|
||||
return imgDoc.getPublicLink(false);
|
||||
case DOCUMENT:
|
||||
break;
|
||||
case URL_DOCUMENT:
|
||||
break;
|
||||
case METADATA:
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("an error occurred when get public link for item: "+worspaceFolderItem.getName());
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//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.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.GCubeItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jul 3, 2013
|
||||
// *
|
||||
// */
|
||||
//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(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();
|
||||
//
|
||||
// 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:
|
||||
// GCubeItem imgDoc = (GCubeItem) worspaceFolderItem; //Cast GCubeItem
|
||||
// return imgDoc.getPublicLink(false);
|
||||
// case DOCUMENT:
|
||||
// break;
|
||||
// case URL_DOCUMENT:
|
||||
// break;
|
||||
// case METADATA:
|
||||
// break;
|
||||
// default:
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// }catch (Exception e) {
|
||||
// logger.error("an error occurred when get public link for item: "+worspaceFolderItem.getName());
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,72 +1,83 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jul 3, 2013
|
||||
*
|
||||
*/
|
||||
public class SearchTextTest {
|
||||
|
||||
|
||||
protected static Logger logger = Logger.getLogger(SearchTextTest.class);
|
||||
private static String text = "1_Networking Activities";
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec/devVRE"; //PRODUCTION
|
||||
|
||||
public static String USER = "francesco.mangiacrapa"; //PRODUCTION
|
||||
|
||||
static GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
static Workspace workspace;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
// DEFAULT_SCOPE = "/gcube/devsec";
|
||||
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
System.out.println("start get workspace\n");
|
||||
|
||||
workspace = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome(USER)
|
||||
.getWorkspace();
|
||||
//
|
||||
|
||||
// List<SearchItem> listSearchItems = ws.searchByName(text);
|
||||
|
||||
logger.info("Calling search HL..");
|
||||
List<SearchItem> listSearchItems = workspace.searchByName(text, workspace.getRoot().getId());
|
||||
logger.info("HL search returning "+listSearchItems.size()+" items");
|
||||
|
||||
logger.info("Converting "+listSearchItems.size()+" items");
|
||||
|
||||
List<FileGridModel> listFileGridModels = builder.buildGXTListFileGridModelItemForSearch(listSearchItems);
|
||||
logger.info("Search objects converted, returning");
|
||||
|
||||
for (FileGridModel fileGridModel : listFileGridModels) {
|
||||
logger.info(fileGridModel);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//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.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jul 3, 2013
|
||||
// *
|
||||
// */
|
||||
//
|
||||
//
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//public class SearchTextTest {
|
||||
//
|
||||
//
|
||||
// protected static Logger logger = Logger.getLogger(SearchTextTest.class);
|
||||
// private static String text = "1_Networking Activities";
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec/devVRE"; //PRODUCTION
|
||||
//
|
||||
// public static String USER = "francesco.mangiacrapa"; //PRODUCTION
|
||||
//
|
||||
// static GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
// static Workspace workspace;
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
//// DEFAULT_SCOPE = "/gcube/devsec";
|
||||
//
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// System.out.println("start get workspace\n");
|
||||
//
|
||||
// workspace = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome(USER)
|
||||
// .getWorkspace();
|
||||
// //
|
||||
//
|
||||
//// List<SearchItem> listSearchItems = ws.searchByName(text);
|
||||
//
|
||||
// logger.info("Calling search HL..");
|
||||
// List<SearchItem> listSearchItems = workspace.searchByName(text, workspace.getRoot().getId());
|
||||
// logger.info("HL search returning "+listSearchItems.size()+" items");
|
||||
//
|
||||
// logger.info("Converting "+listSearchItems.size()+" items");
|
||||
//
|
||||
// List<FileGridModel> listFileGridModels = builder.buildGXTListFileGridModelItemForSearch(listSearchItems);
|
||||
// logger.info("Search objects converted, returning");
|
||||
//
|
||||
// for (FileGridModel fileGridModel : listFileGridModels) {
|
||||
// logger.info(fileGridModel);
|
||||
// }
|
||||
//
|
||||
// }catch(Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//*/
|
||||
|
@ -1,78 +1,79 @@
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
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.WorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
public class ShareFolder {
|
||||
|
||||
private static final String SUB_FOLDER_NAME = "subfoldermycourse";
|
||||
private static final String FOLDER_NAME = "_mycourse";
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
|
||||
public static String TEST_USER = "francesco.mangiacrapa";
|
||||
// public static String FOLDER_ID = "4f0ff79d-3c1e-4d2a-bc74-6f731edcac98";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
// System.out.println("start");
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
|
||||
Workspace workspace = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome(TEST_USER)
|
||||
.getWorkspace();
|
||||
//
|
||||
|
||||
System.out.println("start get root");
|
||||
WorkspaceItem theRoot = workspace.getRoot();
|
||||
|
||||
System.out.println("\n\n CREATING folder: "+FOLDER_NAME + "\n\n");
|
||||
|
||||
WorkspaceFolder myCourseFolder = workspace.createFolder(FOLDER_NAME, "", theRoot.getId());
|
||||
|
||||
System.out.println("\n\n FOLDER id: "+myCourseFolder.getId() +"\n\n");
|
||||
|
||||
System.out.println("\n\n CREATING sub folder: "+SUB_FOLDER_NAME+"\n\n");
|
||||
|
||||
WorkspaceFolder subFolderMyCourse = workspace.createFolder(SUB_FOLDER_NAME, "", myCourseFolder.getId());
|
||||
|
||||
System.out.println("\n\n SUB_FOLDER id: "+subFolderMyCourse.getId() +"\n\n");
|
||||
|
||||
List<String> users = new ArrayList<String>();
|
||||
users.add("costantino.perciante");
|
||||
WorkspaceSharedFolder subShareFolder = workspace.shareFolder(users, subFolderMyCourse.getId());
|
||||
subShareFolder.setACL(users, ACLType.READ_ONLY);
|
||||
System.out.println("\n\n SHARED SUB_FOLDER id: "+subShareFolder.getId() +"\n\n");
|
||||
|
||||
// WorkspaceSharedFolder sharedFolder = subFolderMyCourse.share(users);
|
||||
|
||||
|
||||
// System.out.println("\n\n SHARED subFolderMyCourse id: "+sharedFolder.getId());
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//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.WorkspaceSharedFolder;
|
||||
//import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
//public class ShareFolder {
|
||||
//
|
||||
// private static final String SUB_FOLDER_NAME = "subfoldermycourse";
|
||||
// private static final String FOLDER_NAME = "_mycourse";
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
|
||||
// public static String TEST_USER = "francesco.mangiacrapa";
|
||||
//// public static String FOLDER_ID = "4f0ff79d-3c1e-4d2a-bc74-6f731edcac98";
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
//// System.out.println("start");
|
||||
//// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
//
|
||||
// Workspace workspace = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome(TEST_USER)
|
||||
// .getWorkspace();
|
||||
// //
|
||||
//
|
||||
// System.out.println("start get root");
|
||||
// WorkspaceItem theRoot = workspace.getRoot();
|
||||
//
|
||||
// System.out.println("\n\n CREATING folder: "+FOLDER_NAME + "\n\n");
|
||||
//
|
||||
// WorkspaceFolder myCourseFolder = workspace.createFolder(FOLDER_NAME, "", theRoot.getId());
|
||||
//
|
||||
// System.out.println("\n\n FOLDER id: "+myCourseFolder.getId() +"\n\n");
|
||||
//
|
||||
// System.out.println("\n\n CREATING sub folder: "+SUB_FOLDER_NAME+"\n\n");
|
||||
//
|
||||
// WorkspaceFolder subFolderMyCourse = workspace.createFolder(SUB_FOLDER_NAME, "", myCourseFolder.getId());
|
||||
//
|
||||
// System.out.println("\n\n SUB_FOLDER id: "+subFolderMyCourse.getId() +"\n\n");
|
||||
//
|
||||
// List<String> users = new ArrayList<String>();
|
||||
// users.add("costantino.perciante");
|
||||
// WorkspaceSharedFolder subShareFolder = workspace.shareFolder(users, subFolderMyCourse.getId());
|
||||
// subShareFolder.setACL(users, ACLType.READ_ONLY);
|
||||
// System.out.println("\n\n SHARED SUB_FOLDER id: "+subShareFolder.getId() +"\n\n");
|
||||
//
|
||||
//// WorkspaceSharedFolder sharedFolder = subFolderMyCourse.share(users);
|
||||
//
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(sharedFolder.getId());
|
||||
//
|
||||
// System.out.println("\n\n FINAL id: "+folder.getId());
|
||||
|
||||
System.out.println("end");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//// System.out.println("\n\n SHARED subFolderMyCourse id: "+sharedFolder.getId());
|
||||
////
|
||||
////
|
||||
//// WorkspaceFolder folder = (WorkspaceFolder) workspace.getItem(sharedFolder.getId());
|
||||
////
|
||||
//// System.out.println("\n\n FINAL id: "+folder.getId());
|
||||
//
|
||||
// System.out.println("end");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,208 +1,217 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
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.WorkspaceItem;
|
||||
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.GCubeItem;
|
||||
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.resolver.UriResolverReaderParameterForResolverIndex;
|
||||
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE;
|
||||
import org.gcube.portlets.user.workspace.server.util.HttpRequestUtil;
|
||||
import org.gcube.portlets.user.workspace.server.util.StringUtil;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}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("francesco.mangiacrapa")
|
||||
.getWorkspace();
|
||||
//
|
||||
|
||||
System.out.println("start get root");
|
||||
WorkspaceItem root = ws.getRoot();
|
||||
|
||||
|
||||
for (WorkspaceItem wsi : root.getChildren()) {
|
||||
if(wsi.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
try{
|
||||
String publicLink = getPublicLinkForFolderItemId(wsi.getId(), true, ws);
|
||||
System.out.println("\nITEM: "+wsi.getName());
|
||||
System.out.println(publicLink);
|
||||
// break;
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// System.out.println("start get children");
|
||||
// List<? extends WorkspaceItem> children = root.getChildren();
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//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.WorkspaceItem;
|
||||
//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.GCubeItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex;
|
||||
//import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE;
|
||||
//import org.gcube.portlets.user.workspace.server.util.HttpRequestUtil;
|
||||
//import org.gcube.portlets.user.workspace.server.util.StringUtil;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jul 3, 2013
|
||||
// *
|
||||
// */
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//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("francesco.mangiacrapa")
|
||||
// .getWorkspace();
|
||||
// //
|
||||
//
|
||||
// System.out.println("children size: "+children.size());
|
||||
// System.out.println("start get root");
|
||||
// WorkspaceItem root = ws.getRoot();
|
||||
//
|
||||
// int i=0;
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
//
|
||||
// for (WorkspaceItem wsi : root.getChildren()) {
|
||||
// if(wsi.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
// try{
|
||||
// String publicLink = getPublicLinkForFolderItemId(wsi.getId(), true, ws);
|
||||
// System.out.println("\nITEM: "+wsi.getName());
|
||||
// System.out.println(publicLink);
|
||||
//// break;
|
||||
// }catch(Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//// 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 storageID = builder.getStorageIDForFolderItem(folderItem);
|
||||
//
|
||||
// if(storageID==null || storageID.isEmpty())
|
||||
// throw new Exception("Sorry, public link on "+wsItem.getName() +" is not available");
|
||||
//
|
||||
// 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{
|
||||
//
|
||||
// UriResolverReaderParameterForResolverIndex uriResolver = new UriResolverReaderParameterForResolverIndex(DEFAULT_SCOPE, RESOLVER_TYPE.SMP_ID);
|
||||
//
|
||||
// String uriRequest = "";
|
||||
//
|
||||
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
// if(uriResolver!=null && uriResolver.isAvailable()){
|
||||
//
|
||||
// FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
//
|
||||
// String publicLink = getPubliLinkForFolderItem(folderItem);
|
||||
// String itemName = StringUtil.removeSpecialCharacters(folderItem.getName());
|
||||
// itemName = StringUtil.replaceAllWhiteSpace(itemName, "_");
|
||||
// uriRequest = uriResolver.resolveAsUriRequest(storageID, itemName, folderItem.getMimeType(), true);
|
||||
//
|
||||
// //VALIDATE CONNECTION
|
||||
// if(!HttpRequestUtil.urlExists(uriRequest+"&validation=true"))
|
||||
// throw new Exception("Sorry, The Public Link for selected file is unavailable");
|
||||
//
|
||||
// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", ### Public link: "+publicLink);
|
||||
// }
|
||||
//// 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);
|
||||
// e.printStackTrace();
|
||||
// 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:
|
||||
// GCubeItem imgDoc = (GCubeItem) worspaceFolderItem; //Cast GCubeItem
|
||||
// return imgDoc.getPublicLink(false);
|
||||
// case DOCUMENT:
|
||||
// break;
|
||||
// case URL_DOCUMENT:
|
||||
// break;
|
||||
// case METADATA:
|
||||
// break;
|
||||
// default:
|
||||
// return "";
|
||||
// }
|
||||
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 storageID = builder.getStorageIDForFolderItem(folderItem);
|
||||
|
||||
if(storageID==null || storageID.isEmpty())
|
||||
throw new Exception("Sorry, public link on "+wsItem.getName() +" is not available");
|
||||
|
||||
UriResolverReaderParameterForResolverIndex uriResolver = new UriResolverReaderParameterForResolverIndex(DEFAULT_SCOPE, RESOLVER_TYPE.SMP_ID);
|
||||
|
||||
String uriRequest = "";
|
||||
|
||||
if(uriResolver!=null && uriResolver.isAvailable()){
|
||||
|
||||
String itemName = StringUtil.removeSpecialCharacters(folderItem.getName());
|
||||
itemName = StringUtil.replaceAllWhiteSpace(itemName, "_");
|
||||
uriRequest = uriResolver.resolveAsUriRequest(storageID, itemName, folderItem.getMimeType(), true);
|
||||
|
||||
//VALIDATE CONNECTION
|
||||
if(!HttpRequestUtil.urlExists(uriRequest+"&validation=true"))
|
||||
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);
|
||||
e.printStackTrace();
|
||||
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:
|
||||
GCubeItem imgDoc = (GCubeItem) worspaceFolderItem; //Cast GCubeItem
|
||||
return imgDoc.getPublicLink(false);
|
||||
case DOCUMENT:
|
||||
break;
|
||||
case URL_DOCUMENT:
|
||||
break;
|
||||
case METADATA:
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("an error occurred when get public link for item: "+worspaceFolderItem.getName());
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
//
|
||||
// }catch (Exception e) {
|
||||
// logger.error("an error occurred when get public link for item: "+worspaceFolderItem.getName());
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//*/
|
@ -1,92 +1,101 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
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.folder.FolderItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jan 29, 2014
|
||||
*
|
||||
*/
|
||||
public class SizeRetrieving {
|
||||
|
||||
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
|
||||
public static String TEST_USER = "francesco.mangiacrapa";
|
||||
// public static String FOLDER_ID = "4f0ff79d-3c1e-4d2a-bc74-6f731edcac98";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
Workspace ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome(TEST_USER)
|
||||
.getWorkspace();
|
||||
//
|
||||
|
||||
// System.out.println("start get root");
|
||||
WorkspaceItem folder = ws.getRoot();
|
||||
// List<WorkspaceItem> children = (List<WorkspaceItem>) root.getChildren();
|
||||
|
||||
System.out.println("start get children");
|
||||
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(FOLDER_ID);
|
||||
List<WorkspaceItem> children = (List<WorkspaceItem>) folder.getChildren();
|
||||
// List<? extends WorkspaceItem> children = root.getChildren();
|
||||
|
||||
System.out.println("children size: "+children.size());
|
||||
|
||||
// GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//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.folder.FolderItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jan 29, 2014
|
||||
// *
|
||||
// */
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//public class SizeRetrieving {
|
||||
//
|
||||
//
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps";
|
||||
// public static String TEST_USER = "francesco.mangiacrapa";
|
||||
//// public static String FOLDER_ID = "4f0ff79d-3c1e-4d2a-bc74-6f731edcac98";
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// builder.buildGXTListFileGridModelItem(children, null);
|
||||
|
||||
|
||||
|
||||
int i=0;
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
|
||||
|
||||
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER) || workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
||||
|
||||
folder = (WorkspaceFolder) workspaceItem;
|
||||
|
||||
|
||||
System.out.println(++i+") folder name: "+folder.getName() +", id: "+folder.getId());
|
||||
}else{
|
||||
|
||||
|
||||
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
|
||||
FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
|
||||
System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", size: "+folderItem.getLength());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
System.out.println("end");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Workspace ws = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome(TEST_USER)
|
||||
// .getWorkspace();
|
||||
// //
|
||||
//
|
||||
//// System.out.println("start get root");
|
||||
// WorkspaceItem folder = ws.getRoot();
|
||||
//// List<WorkspaceItem> children = (List<WorkspaceItem>) root.getChildren();
|
||||
//
|
||||
// System.out.println("start get children");
|
||||
//
|
||||
//// WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(FOLDER_ID);
|
||||
// List<WorkspaceItem> children = (List<WorkspaceItem>) folder.getChildren();
|
||||
//// List<? extends WorkspaceItem> children = root.getChildren();
|
||||
//
|
||||
// System.out.println("children size: "+children.size());
|
||||
//
|
||||
//// GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
////
|
||||
//// builder.buildGXTListFileGridModelItem(children, null);
|
||||
//
|
||||
//
|
||||
//
|
||||
// int i=0;
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
//
|
||||
//
|
||||
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER) || workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
||||
//
|
||||
// folder = (WorkspaceFolder) workspaceItem;
|
||||
//
|
||||
//
|
||||
// System.out.println(++i+") folder name: "+folder.getName() +", id: "+folder.getId());
|
||||
// }else{
|
||||
//
|
||||
//
|
||||
// if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||
//
|
||||
// FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
//
|
||||
// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", size: "+folderItem.getLength());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// System.out.println("end");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//*/
|
@ -1,138 +1,137 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.items.type.FolderItemType;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
|
||||
/**
|
||||
* The Class SmartFolderTest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Sep 29, 2016
|
||||
*/
|
||||
public class SmartFolderTest {
|
||||
|
||||
|
||||
protected static Logger logger = Logger.getLogger(SmartFolderTest.class);
|
||||
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
|
||||
private static Workspace workspace;
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
System.out.println("instancing workspace");
|
||||
workspace = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("francesco.mangiacrapa")
|
||||
.getWorkspace();
|
||||
//
|
||||
System.out.println("start");
|
||||
List<FileGridModel> smarts = getSmartFolderResultsByCategory(GXTCategorySmartFolder.SMF_IMAGES);
|
||||
|
||||
for (FileGridModel fileGridModel : smarts) {
|
||||
System.out.println(fileGridModel.toString());
|
||||
}
|
||||
System.out.println("end");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the smart folder results by category.
|
||||
*
|
||||
* @param category the category
|
||||
* @return the smart folder results by category
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static List<FileGridModel> getSmartFolderResultsByCategory(GXTCategorySmartFolder category) throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
|
||||
List<SearchItem> listWorkspaceItems = new ArrayList<SearchItem>();
|
||||
|
||||
//Category IMAGES
|
||||
if(category.equals(GXTCategorySmartFolder.SMF_IMAGES.toString())){
|
||||
|
||||
listWorkspaceItems = workspace.getFolderItems(FolderItemType.IMAGE_DOCUMENT, FolderItemType.EXTERNAL_IMAGE);
|
||||
|
||||
//Category BIODIVERSITY
|
||||
}else if(category.equals(GXTCategorySmartFolder.SMF_BIODIVERSITY.toString())){
|
||||
|
||||
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
|
||||
|
||||
//Category DOCUMENTS
|
||||
}else if(category.equals(GXTCategorySmartFolder.SMF_DOCUMENTS.toString())){
|
||||
|
||||
listWorkspaceItems = workspace.getFolderItems(
|
||||
FolderItemType.EXTERNAL_FILE,
|
||||
FolderItemType.EXTERNAL_PDF_FILE,
|
||||
FolderItemType.QUERY,
|
||||
FolderItemType.PDF_DOCUMENT,
|
||||
FolderItemType.METADATA,
|
||||
// FolderItemType.WORKFLOW_REPORT,
|
||||
// FolderItemType.WORKFLOW_TEMPLATE,
|
||||
// FolderItemType.URL_DOCUMENT,
|
||||
FolderItemType.DOCUMENT
|
||||
);
|
||||
|
||||
//Category LINKS
|
||||
}else if(category.equals(GXTCategorySmartFolder.SMF_LINKS.toString())){
|
||||
|
||||
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK);
|
||||
|
||||
//Category REPORTS
|
||||
}else if(category.equals(GXTCategorySmartFolder.SMF_REPORTS.toString())){
|
||||
|
||||
listWorkspaceItems = workspace.getFolderItems(FolderItemType.REPORT_TEMPLATE, FolderItemType.REPORT);
|
||||
|
||||
//Category TIME SERIES
|
||||
}else if(category.equals(GXTCategorySmartFolder.SMF_TIMESERIES.toString())){
|
||||
|
||||
listWorkspaceItems = workspace.getFolderItems(FolderItemType.TIME_SERIES);
|
||||
}
|
||||
else
|
||||
new Exception("Smart folder category unknown");
|
||||
|
||||
|
||||
return builder.filterListFileGridModelItemByCategory(listWorkspaceItems, category);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error in server get smart folder by category");
|
||||
e.printStackTrace();
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibary.model.items.type.FolderItemType;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder;
|
||||
//import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * The Class SmartFolderTest.
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Sep 29, 2016
|
||||
// */
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//public class SmartFolderTest {
|
||||
//
|
||||
//
|
||||
// protected static Logger logger = Logger.getLogger(SmartFolderTest.class);
|
||||
//
|
||||
//// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling"; //PRODUCTION
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
//
|
||||
// private static Workspace workspace;
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// System.out.println("instancing workspace");
|
||||
// workspace = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome("francesco.mangiacrapa")
|
||||
// .getWorkspace();
|
||||
// //
|
||||
// System.out.println("start");
|
||||
// List<FileGridModel> smarts = getSmartFolderResultsByCategory(GXTCategorySmartFolder.SMF_IMAGES);
|
||||
//
|
||||
// for (FileGridModel fileGridModel : smarts) {
|
||||
// System.out.println(fileGridModel.toString());
|
||||
// }
|
||||
// System.out.println("end");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static List<FileGridModel> getSmartFolderResultsByCategory(GXTCategorySmartFolder category) throws Exception {
|
||||
//
|
||||
// try {
|
||||
//
|
||||
//
|
||||
// GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
|
||||
//
|
||||
// List<SearchItem> listWorkspaceItems = new ArrayList<SearchItem>();
|
||||
//
|
||||
// //Category IMAGES
|
||||
// if(category.equals(GXTCategorySmartFolder.SMF_IMAGES.toString())){
|
||||
//
|
||||
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.IMAGE_DOCUMENT, FolderItemType.EXTERNAL_IMAGE);
|
||||
//
|
||||
// //Category BIODIVERSITY
|
||||
// }else if(category.equals(GXTCategorySmartFolder.SMF_BIODIVERSITY.toString())){
|
||||
//
|
||||
//// listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
|
||||
//
|
||||
// //Category DOCUMENTS
|
||||
// }else if(category.equals(GXTCategorySmartFolder.SMF_DOCUMENTS.toString())){
|
||||
//
|
||||
// listWorkspaceItems = workspace.getFolderItems(
|
||||
// FolderItemType.EXTERNAL_FILE,
|
||||
// FolderItemType.EXTERNAL_PDF_FILE,
|
||||
// FolderItemType.QUERY,
|
||||
// FolderItemType.PDF_DOCUMENT,
|
||||
// FolderItemType.METADATA,
|
||||
//// FolderItemType.WORKFLOW_REPORT,
|
||||
//// FolderItemType.WORKFLOW_TEMPLATE,
|
||||
//// FolderItemType.URL_DOCUMENT,
|
||||
// FolderItemType.DOCUMENT
|
||||
// );
|
||||
//
|
||||
// //Category LINKS
|
||||
// }else if(category.equals(GXTCategorySmartFolder.SMF_LINKS.toString())){
|
||||
//
|
||||
//// listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK);
|
||||
//
|
||||
// //Category REPORTS
|
||||
// }else if(category.equals(GXTCategorySmartFolder.SMF_REPORTS.toString())){
|
||||
//
|
||||
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.REPORT_TEMPLATE, FolderItemType.REPORT);
|
||||
//
|
||||
// //Category TIME SERIES
|
||||
// }else if(category.equals(GXTCategorySmartFolder.SMF_TIMESERIES.toString())){
|
||||
//
|
||||
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.TIME_SERIES);
|
||||
// }
|
||||
// else
|
||||
// new Exception("Smart folder category unknown");
|
||||
//
|
||||
//
|
||||
// return builder.filterListFileGridModelItemByCategory(listWorkspaceItems, category);
|
||||
//
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Error in server get smart folder by category");
|
||||
// e.printStackTrace();
|
||||
// throw new Exception(e.getMessage());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//*/
|
||||
|
@ -1,207 +1,208 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
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.WorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jan 29, 2014
|
||||
*
|
||||
*/
|
||||
public class TestSync {
|
||||
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
public static String TEST_USER = "francesco.mangiacrapa";
|
||||
public static String FOLDER_SYNC = "d6dae663-91d1-4da7-b13d-959de6fb2f86"; //TestSync is root Folder
|
||||
|
||||
public static String FOLDER_A = "983d4ab9-e8fd-4c6d-869e-734a730e3e50";
|
||||
public static String FOLDER_B = "94995b10-6fcb-4ed8-a3ea-4a6dd7d33a7a";
|
||||
public static String FOLDER_C = "e945fcfd-9da9-45a0-98a9-d1940d1720bb";
|
||||
|
||||
protected static int i=0;
|
||||
protected static int foldersCounter = 0;
|
||||
protected static int sharedFoldersCounter = 0;
|
||||
protected static int folderItemCounter = 0;
|
||||
protected static int othersCounter = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
System.out.println("init HL");
|
||||
try {
|
||||
|
||||
Workspace ws = getWorkspace();
|
||||
// List<? extends WorkspaceItem> children = ws.getItem(FOLDER_A).getChildren();
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
//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.WorkspaceSharedFolder;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jan 29, 2014
|
||||
// *
|
||||
// */
|
||||
//public class TestSync {
|
||||
//
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String TEST_USER = "francesco.mangiacrapa";
|
||||
// public static String FOLDER_SYNC = "d6dae663-91d1-4da7-b13d-959de6fb2f86"; //TestSync is root Folder
|
||||
//
|
||||
// public static String FOLDER_A = "983d4ab9-e8fd-4c6d-869e-734a730e3e50";
|
||||
// public static String FOLDER_B = "94995b10-6fcb-4ed8-a3ea-4a6dd7d33a7a";
|
||||
// public static String FOLDER_C = "e945fcfd-9da9-45a0-98a9-d1940d1720bb";
|
||||
//
|
||||
// protected static int i=0;
|
||||
// protected static int foldersCounter = 0;
|
||||
// protected static int sharedFoldersCounter = 0;
|
||||
// protected static int folderItemCounter = 0;
|
||||
// protected static int othersCounter = 0;
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// System.out.println("init HL");
|
||||
// try {
|
||||
//
|
||||
// Workspace ws = getWorkspace();
|
||||
//// List<? extends WorkspaceItem> children = ws.getItem(FOLDER_A).getChildren();
|
||||
//// for (WorkspaceItem workspaceItem : children) {
|
||||
//// printItem(workspaceItem);
|
||||
//// }
|
||||
// WorkspaceItem item_40MB = ws.getItem(FOLDER_A).getChildren().get(0);
|
||||
// threadCopy(ws, item_40MB, FOLDER_B);
|
||||
//
|
||||
// System.out.println("THREAD MAIN SLEEPING 10 sec.");
|
||||
// Thread.sleep(10000);
|
||||
// System.out.println("THREAD MAIN ACTIVE..");
|
||||
//// WorkspaceItem cp_item_260MB = ws.getItem(FOLDER_B).getChildren().get(0);
|
||||
//
|
||||
// List<? extends WorkspaceItem> children = ws.getItem(FOLDER_B).getChildren();
|
||||
// System.out.println("FOLDER_B children..");
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// printItem(workspaceItem);
|
||||
// }
|
||||
WorkspaceItem item_40MB = ws.getItem(FOLDER_A).getChildren().get(0);
|
||||
threadCopy(ws, item_40MB, FOLDER_B);
|
||||
|
||||
System.out.println("THREAD MAIN SLEEPING 10 sec.");
|
||||
Thread.sleep(10000);
|
||||
System.out.println("THREAD MAIN ACTIVE..");
|
||||
// WorkspaceItem cp_item_260MB = ws.getItem(FOLDER_B).getChildren().get(0);
|
||||
|
||||
List<? extends WorkspaceItem> children = ws.getItem(FOLDER_B).getChildren();
|
||||
System.out.println("FOLDER_B children..");
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
printItem(workspaceItem);
|
||||
}
|
||||
|
||||
threadMove(ws, children.get(0), FOLDER_C);
|
||||
|
||||
Thread.sleep(60000);
|
||||
System.out.println("THREAD MAIN TERMINATED");
|
||||
// retrieveFirstLevel(ws);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void threadCopy(final Workspace ws, final WorkspaceItem item, final String destinationFolderId){
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long time = System.currentTimeMillis();
|
||||
long diff;
|
||||
System.out.println("Starting copy "+item.getName()+", time: "+time);
|
||||
ws.copy(item.getId(), destinationFolderId);
|
||||
diff = (System.currentTimeMillis()-time)/1000;
|
||||
System.out.println("End copy! [time diff: "+diff+" sec.]");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Copy Exception: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
public static void threadMove(final Workspace ws, final WorkspaceItem item, final String destinationFolderId){
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
long time = System.currentTimeMillis();
|
||||
long diff;
|
||||
System.out.println("Starting move "+item.getName()+", time: "+time);
|
||||
ws.moveItem(item.getId(), destinationFolderId);
|
||||
diff = (System.currentTimeMillis()-time)/1000;
|
||||
System.out.println("End move! [time diff: "+diff+" sec.]");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Move Exception: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
|
||||
{
|
||||
|
||||
System.out.println("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER);
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
Workspace workspace = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
return workspace;
|
||||
}
|
||||
|
||||
|
||||
private static void retrieveFirstLevel(Workspace ws){
|
||||
|
||||
try {
|
||||
|
||||
//TEST TIME
|
||||
Long startTime = System.currentTimeMillis();
|
||||
Long endTime = System.currentTimeMillis() - startTime;
|
||||
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
System.out.println("Start get root at time: "+startTime);
|
||||
// WorkspaceItem root = ws.getItem(ITEMID);
|
||||
WorkspaceItem root = ws.getRoot();
|
||||
|
||||
System.out.println("start get children");
|
||||
List<? extends WorkspaceItem> children = root.getChildren();
|
||||
System.out.println("tree getChildren() returning "+children.size()+" elements in " + time);
|
||||
|
||||
System.out.println("children size: "+children.size());
|
||||
|
||||
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
printItem(workspaceItem);
|
||||
}
|
||||
|
||||
//TEST TIME
|
||||
endTime = System.currentTimeMillis();
|
||||
long difference = endTime - startTime;
|
||||
time = String.format("%d msc %d sec", difference, TimeUnit.MILLISECONDS.toSeconds(difference));
|
||||
System.out.println("End time is "+endTime+ " difference is "+time);
|
||||
System.out.println("Folders are: "+foldersCounter);
|
||||
System.out.println("Shared Folders are: "+sharedFoldersCounter);
|
||||
System.out.println("Folder Item are: "+folderItemCounter);
|
||||
System.out.println("Others are: "+othersCounter);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void printItem(WorkspaceItem workspaceItem) throws InternalErrorException{
|
||||
|
||||
switch (workspaceItem.getType()) {
|
||||
|
||||
case FOLDER:
|
||||
|
||||
WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
||||
|
||||
System.out.println(++i+") "+folder.getId() +" folder name: "+folder.getName() + " owner "+folder.getOwner());
|
||||
foldersCounter++;
|
||||
|
||||
break;
|
||||
|
||||
case SHARED_FOLDER:
|
||||
|
||||
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
|
||||
|
||||
System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName() + " owner "+shared.getOwner()+" isVRE "+shared.isVreFolder() +" ACLOwner: "+shared.getACLOwner()+" AclUser: "+shared.getACLUser());
|
||||
|
||||
// System.out.println(++i+") shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin());
|
||||
sharedFoldersCounter++;
|
||||
|
||||
break;
|
||||
|
||||
case FOLDER_ITEM:
|
||||
|
||||
FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
|
||||
System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", own: "+folderItem.getOwner());
|
||||
folderItemCounter++;
|
||||
|
||||
break;
|
||||
default:
|
||||
System.out.println(++i+") DEFAULT - item id: "+workspaceItem.getId() +", name: "+workspaceItem.getName() + ", own: "+workspaceItem.getOwner());
|
||||
othersCounter++;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//
|
||||
// threadMove(ws, children.get(0), FOLDER_C);
|
||||
//
|
||||
// Thread.sleep(60000);
|
||||
// System.out.println("THREAD MAIN TERMINATED");
|
||||
//// retrieveFirstLevel(ws);
|
||||
// }catch(Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void threadCopy(final Workspace ws, final WorkspaceItem item, final String destinationFolderId){
|
||||
//
|
||||
// new Thread(){
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// long time = System.currentTimeMillis();
|
||||
// long diff;
|
||||
// System.out.println("Starting copy "+item.getName()+", time: "+time);
|
||||
// ws.copy(item.getId(), destinationFolderId);
|
||||
// diff = (System.currentTimeMillis()-time)/1000;
|
||||
// System.out.println("End copy! [time diff: "+diff+" sec.]");
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Copy Exception: "+e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }.start();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static void threadMove(final Workspace ws, final WorkspaceItem item, final String destinationFolderId){
|
||||
//
|
||||
// new Thread(){
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// long time = System.currentTimeMillis();
|
||||
// long diff;
|
||||
// System.out.println("Starting move "+item.getName()+", time: "+time);
|
||||
// ws.moveItem(item.getId(), destinationFolderId);
|
||||
// diff = (System.currentTimeMillis()-time)/1000;
|
||||
// System.out.println("End move! [time diff: "+diff+" sec.]");
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Move Exception: "+e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// }.start();
|
||||
// }
|
||||
//
|
||||
// public static Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
|
||||
// {
|
||||
//
|
||||
// System.out.println("Get Workspace scope: "+DEFAULT_SCOPE + " username: "+TEST_USER);
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
// Workspace workspace = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
// return workspace;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private static void retrieveFirstLevel(Workspace ws){
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// //TEST TIME
|
||||
// Long startTime = System.currentTimeMillis();
|
||||
// Long endTime = System.currentTimeMillis() - startTime;
|
||||
// String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
|
||||
//
|
||||
// startTime = System.currentTimeMillis();
|
||||
// System.out.println("Start get root at time: "+startTime);
|
||||
//// WorkspaceItem root = ws.getItem(ITEMID);
|
||||
// WorkspaceItem root = ws.getRoot();
|
||||
//
|
||||
// System.out.println("start get children");
|
||||
// List<? extends WorkspaceItem> children = root.getChildren();
|
||||
// System.out.println("tree getChildren() returning "+children.size()+" elements in " + time);
|
||||
//
|
||||
// System.out.println("children size: "+children.size());
|
||||
//
|
||||
//
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// printItem(workspaceItem);
|
||||
// }
|
||||
//
|
||||
// //TEST TIME
|
||||
// endTime = System.currentTimeMillis();
|
||||
// long difference = endTime - startTime;
|
||||
// time = String.format("%d msc %d sec", difference, TimeUnit.MILLISECONDS.toSeconds(difference));
|
||||
// System.out.println("End time is "+endTime+ " difference is "+time);
|
||||
// System.out.println("Folders are: "+foldersCounter);
|
||||
// System.out.println("Shared Folders are: "+sharedFoldersCounter);
|
||||
// System.out.println("Folder Item are: "+folderItemCounter);
|
||||
// System.out.println("Others are: "+othersCounter);
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void printItem(WorkspaceItem workspaceItem) throws InternalErrorException{
|
||||
//
|
||||
// switch (workspaceItem.getType()) {
|
||||
//
|
||||
// case FOLDER:
|
||||
//
|
||||
// WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
|
||||
//
|
||||
// System.out.println(++i+") "+folder.getId() +" folder name: "+folder.getName() + " owner "+folder.getOwner());
|
||||
// foldersCounter++;
|
||||
//
|
||||
// break;
|
||||
//
|
||||
// case SHARED_FOLDER:
|
||||
//
|
||||
// WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
|
||||
//
|
||||
// System.out.println(++i+") "+shared.getId() +" shared folder name: "+shared.getName() + " owner "+shared.getOwner()+" isVRE "+shared.isVreFolder() +" ACLOwner: "+shared.getACLOwner()+" AclUser: "+shared.getACLUser());
|
||||
//
|
||||
//// System.out.println(++i+") shared folder name: "+shared.getName() + " owner "+shared.getOwner().getPortalLogin());
|
||||
// sharedFoldersCounter++;
|
||||
//
|
||||
// break;
|
||||
//
|
||||
// case FOLDER_ITEM:
|
||||
//
|
||||
// FolderItem folderItem = (FolderItem) workspaceItem;
|
||||
//
|
||||
// System.out.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", own: "+folderItem.getOwner());
|
||||
// folderItemCounter++;
|
||||
//
|
||||
// break;
|
||||
// default:
|
||||
// System.out.println(++i+") DEFAULT - item id: "+workspaceItem.getId() +", name: "+workspaceItem.getName() + ", own: "+workspaceItem.getOwner());
|
||||
// othersCounter++;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
@ -1,76 +1,77 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
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.scope.api.ScopeProvider;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* May 15, 2014
|
||||
*
|
||||
*/
|
||||
public class TestWithTime {
|
||||
|
||||
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
public static String TEST_USER = "fabio.simeoni";
|
||||
|
||||
@Test
|
||||
public void accessTest() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
System.out.println("Start Test Simeoni");
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
Workspace ws = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
|
||||
for (WorkspaceItem item : ws.getRoot().getChildren())
|
||||
item.getProperties().getProperties().keySet();
|
||||
|
||||
long diff = System.currentTimeMillis()-time;
|
||||
System.out.println("End Test Simeoni: "+diff);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void accessTest1() throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
|
||||
System.out.println("Start Test");
|
||||
long time = System.currentTimeMillis();
|
||||
long diff;
|
||||
|
||||
System.out.println("Get worskpace");
|
||||
Workspace ws = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
diff = System.currentTimeMillis()-time;
|
||||
System.out.println("Worskapce returned in: "+diff);
|
||||
|
||||
System.out.println("Get Root");
|
||||
WorkspaceFolder root = ws.getRoot();
|
||||
diff = System.currentTimeMillis()-time;
|
||||
System.out.println("Root returned in: "+diff);
|
||||
|
||||
System.out.println("Get Children");
|
||||
List<WorkspaceItem> children = root.getChildren();
|
||||
diff = System.currentTimeMillis()-time;
|
||||
System.out.println("Get Children returned in: "+diff);
|
||||
|
||||
System.out.println("Children size is: "+children.size());
|
||||
for (WorkspaceItem item : children){
|
||||
diff = System.currentTimeMillis()-time;
|
||||
System.out.println("Item: +"+item.getId()+", keyset: "+item.getProperties().getProperties().keySet() + ", Diff is: "+diff);
|
||||
}
|
||||
diff = System.currentTimeMillis()-time;
|
||||
System.out.println("Children properties returned in: "+diff);
|
||||
|
||||
diff = System.currentTimeMillis()-time;
|
||||
System.out.println("End test: "+diff);
|
||||
}
|
||||
}
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//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.scope.api.ScopeProvider;
|
||||
//import org.junit.Test;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * May 15, 2014
|
||||
// *
|
||||
// */
|
||||
//public class TestWithTime {
|
||||
//
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
|
||||
// public static String TEST_USER = "fabio.simeoni";
|
||||
//
|
||||
// @Test
|
||||
// public void accessTest() throws Exception {
|
||||
//
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
// System.out.println("Start Test Simeoni");
|
||||
// long time = System.currentTimeMillis();
|
||||
//
|
||||
// Workspace ws = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
//
|
||||
// for (WorkspaceItem item : ws.getRoot().getChildren())
|
||||
// item.getProperties().getProperties().keySet();
|
||||
//
|
||||
// long diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("End Test Simeoni: "+diff);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void accessTest1() throws Exception {
|
||||
//
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
//
|
||||
// System.out.println("Start Test");
|
||||
// long time = System.currentTimeMillis();
|
||||
// long diff;
|
||||
//
|
||||
// System.out.println("Get worskpace");
|
||||
// Workspace ws = HomeLibrary.getUserWorkspace(TEST_USER);
|
||||
// diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("Worskapce returned in: "+diff);
|
||||
//
|
||||
// System.out.println("Get Root");
|
||||
// WorkspaceFolder root = ws.getRoot();
|
||||
// diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("Root returned in: "+diff);
|
||||
//
|
||||
// System.out.println("Get Children");
|
||||
// List<WorkspaceItem> children = root.getChildren();
|
||||
// diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("Get Children returned in: "+diff);
|
||||
//
|
||||
// System.out.println("Children size is: "+children.size());
|
||||
// for (WorkspaceItem item : children){
|
||||
// diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("Item: +"+item.getId()+", keyset: "+item.getProperties().getProperties().keySet() + ", Diff is: "+diff);
|
||||
// }
|
||||
// diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("Children properties returned in: "+diff);
|
||||
//
|
||||
// diff = System.currentTimeMillis()-time;
|
||||
// System.out.println("End test: "+diff);
|
||||
// }
|
||||
//}
|
||||
|
@ -1,137 +1,138 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
|
||||
/**
|
||||
* The Class UploadServletTest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jul 23, 2018
|
||||
*/
|
||||
public class UploadServletTest {
|
||||
|
||||
|
||||
public static String YOUR_TOKEN = "YOUR TOKEN";
|
||||
public static String YOUR_USERNAME = "name.surname";
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||
* @throws HomeNotFoundException the home not found exception
|
||||
* @throws UserNotFoundException the user not found exception
|
||||
* @throws InsufficientPrivilegesException the insufficient privileges exception
|
||||
* @throws ItemAlreadyExistException the item already exist exception
|
||||
* @throws WrongDestinationException the wrong destination exception
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void main(String[] args) throws InternalErrorException,
|
||||
WorkspaceFolderNotFoundException, HomeNotFoundException,
|
||||
UserNotFoundException, InsufficientPrivilegesException,
|
||||
ItemAlreadyExistException, WrongDestinationException, IOException {
|
||||
|
||||
ScopeBean scope = new ScopeBean("/gcube/devsec");
|
||||
|
||||
|
||||
SecurityTokenProvider.instance.set("YOUR TOKEN");
|
||||
|
||||
Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||
.getHomeManager().getHome(YOUR_USERNAME)
|
||||
.getWorkspace();
|
||||
|
||||
String filePath = "/home/francesco-mangiacrapa";
|
||||
|
||||
String fileName = "Geo Explorer 2016-01-15 18-51-51.png";
|
||||
|
||||
String fullPath = filePath + "/" + fileName;
|
||||
|
||||
// String newFilePath =
|
||||
// "/home/francesco-mangiacrapa/Desktop/icongeoexplorer/testupload.txt";
|
||||
|
||||
// String name = "TestReplaceContentImage";
|
||||
|
||||
// ExternalPDFFile file = workspace.createExternalPDFFile(name, "",
|
||||
// null, new FileInputStream(new File(filePath)),
|
||||
// workspace.getRoot().getId());
|
||||
|
||||
WorkspaceFolder root = workspace.getRoot();
|
||||
// ExternalImage file = (ExternalImage) root.find(name);
|
||||
|
||||
// UPLOAD FILE
|
||||
// String contentType = MimeTypeUtil.getMimeType(fileName, new BufferedInputStream(
|
||||
// new FileInputStream(new File(fullPath))));
|
||||
|
||||
String itemName = WorkspaceUtil.getUniqueName(fileName, root);
|
||||
System.out.println("Storing data....");
|
||||
System.out.println("content type " + null);
|
||||
System.out.println("itemName " + itemName);
|
||||
|
||||
ExternalFile file = (ExternalFile) WorkspaceUtil.createExternalFile(
|
||||
root, itemName, "", null, new FileInputStream(new File(
|
||||
fullPath)));
|
||||
|
||||
System.out.println("Storing data - OK" + "File [id: " + file.getId()
|
||||
+ ", name: " + file.getName() + "]");
|
||||
//
|
||||
// System.out.println("File mimeType" + file.getMimeType());
|
||||
// System.out.println("File size" + file.getLength());
|
||||
//
|
||||
|
||||
//
|
||||
// file.setData(new FileInputStream(new File(newFilePath)));
|
||||
// System.out.println("New File mimeType" + file.getMimeType());
|
||||
// System.out.println("New File size" + file.getLength());
|
||||
|
||||
//
|
||||
|
||||
System.out.println("Recovering data");
|
||||
InputStream inputStream = file.getData();
|
||||
// write the inputStream to a FileOutputStream
|
||||
OutputStream out = new FileOutputStream(new File(
|
||||
"/home/francesco-mangiacrapa/Desktop/download/"+fileName));
|
||||
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
System.out.println("Recovering data - OK");
|
||||
|
||||
// File file = new File("/home/gioia/Desktop/test");
|
||||
// InputStream is = new FileInputStream(file);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.FileInputStream;
|
||||
//import java.io.FileOutputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.OutputStream;
|
||||
//
|
||||
//import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
//import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * The Class UploadServletTest.
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jul 23, 2018
|
||||
// */
|
||||
//public class UploadServletTest {
|
||||
//
|
||||
//
|
||||
// public static String YOUR_TOKEN = "YOUR TOKEN";
|
||||
// public static String YOUR_USERNAME = "name.surname";
|
||||
//
|
||||
// /**
|
||||
// * The main method.
|
||||
// *
|
||||
// * @param args the arguments
|
||||
// * @throws InternalErrorException the internal error exception
|
||||
// * @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||
// * @throws HomeNotFoundException the home not found exception
|
||||
// * @throws UserNotFoundException the user not found exception
|
||||
// * @throws InsufficientPrivilegesException the insufficient privileges exception
|
||||
// * @throws ItemAlreadyExistException the item already exist exception
|
||||
// * @throws WrongDestinationException the wrong destination exception
|
||||
// * @throws IOException Signals that an I/O exception has occurred.
|
||||
// */
|
||||
// public static void main(String[] args) throws InternalErrorException,
|
||||
// WorkspaceFolderNotFoundException, HomeNotFoundException,
|
||||
// UserNotFoundException, InsufficientPrivilegesException,
|
||||
// ItemAlreadyExistException, WrongDestinationException, IOException {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean("/gcube/devsec");
|
||||
//
|
||||
//
|
||||
// SecurityTokenProvider.instance.set("YOUR TOKEN");
|
||||
//
|
||||
// Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||
// .getHomeManager().getHome(YOUR_USERNAME)
|
||||
// .getWorkspace();
|
||||
//
|
||||
// String filePath = "/home/francesco-mangiacrapa";
|
||||
//
|
||||
// String fileName = "Geo Explorer 2016-01-15 18-51-51.png";
|
||||
//
|
||||
// String fullPath = filePath + "/" + fileName;
|
||||
//
|
||||
// // String newFilePath =
|
||||
// // "/home/francesco-mangiacrapa/Desktop/icongeoexplorer/testupload.txt";
|
||||
//
|
||||
// // String name = "TestReplaceContentImage";
|
||||
//
|
||||
// // ExternalPDFFile file = workspace.createExternalPDFFile(name, "",
|
||||
// // null, new FileInputStream(new File(filePath)),
|
||||
// // workspace.getRoot().getId());
|
||||
//
|
||||
// WorkspaceFolder root = workspace.getRoot();
|
||||
// // ExternalImage file = (ExternalImage) root.find(name);
|
||||
//
|
||||
// // UPLOAD FILE
|
||||
//// String contentType = MimeTypeUtil.getMimeType(fileName, new BufferedInputStream(
|
||||
//// new FileInputStream(new File(fullPath))));
|
||||
//
|
||||
// String itemName = WorkspaceUtil.getUniqueName(fileName, root);
|
||||
// System.out.println("Storing data....");
|
||||
// System.out.println("content type " + null);
|
||||
// System.out.println("itemName " + itemName);
|
||||
//
|
||||
// ExternalFile file = (ExternalFile) WorkspaceUtil.createExternalFile(
|
||||
// root, itemName, "", null, new FileInputStream(new File(
|
||||
// fullPath)));
|
||||
//
|
||||
// System.out.println("Storing data - OK" + "File [id: " + file.getId()
|
||||
// + ", name: " + file.getName() + "]");
|
||||
// //
|
||||
// // System.out.println("File mimeType" + file.getMimeType());
|
||||
// // System.out.println("File size" + file.getLength());
|
||||
// //
|
||||
//
|
||||
// //
|
||||
// // file.setData(new FileInputStream(new File(newFilePath)));
|
||||
// // System.out.println("New File mimeType" + file.getMimeType());
|
||||
// // System.out.println("New File size" + file.getLength());
|
||||
//
|
||||
// //
|
||||
//
|
||||
// System.out.println("Recovering data");
|
||||
// InputStream inputStream = file.getData();
|
||||
// // write the inputStream to a FileOutputStream
|
||||
// OutputStream out = new FileOutputStream(new File(
|
||||
// "/home/francesco-mangiacrapa/Desktop/download/"+fileName));
|
||||
//
|
||||
// int read = 0;
|
||||
// byte[] bytes = new byte[1024];
|
||||
//
|
||||
// while ((read = inputStream.read(bytes)) != -1) {
|
||||
// out.write(bytes, 0, read);
|
||||
// }
|
||||
//
|
||||
// inputStream.close();
|
||||
// out.flush();
|
||||
// out.close();
|
||||
//
|
||||
// System.out.println("Recovering data - OK");
|
||||
//
|
||||
// // File file = new File("/home/gioia/Desktop/test");
|
||||
// // InputStream is = new FileInputStream(file);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,116 +1,117 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jun 20, 2013
|
||||
*
|
||||
*/
|
||||
public class UploadServletTestToken {
|
||||
|
||||
public static void main(String[] args) throws InternalErrorException,
|
||||
WorkspaceFolderNotFoundException, HomeNotFoundException,
|
||||
UserNotFoundException, InsufficientPrivilegesException,
|
||||
ItemAlreadyExistException, WrongDestinationException, IOException {
|
||||
|
||||
ScopeBean scope = new ScopeBean("/gcube/devsec");
|
||||
ScopeProvider.instance.set(scope.toString());
|
||||
|
||||
Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||
.getHomeManager().getHome("francesco.mangiacrapa")
|
||||
.getWorkspace();
|
||||
|
||||
String filePath = "/home/francesco-mangiacrapa";
|
||||
|
||||
String fileName = "Geo Explorer 2016-01-15 18-51-51.png";
|
||||
|
||||
String fullPath = filePath + "/" + fileName;
|
||||
|
||||
// String newFilePath =
|
||||
// "/home/francesco-mangiacrapa/Desktop/icongeoexplorer/testupload.txt";
|
||||
|
||||
// String name = "TestReplaceContentImage";
|
||||
|
||||
// ExternalPDFFile file = workspace.createExternalPDFFile(name, "",
|
||||
// null, new FileInputStream(new File(filePath)),
|
||||
// workspace.getRoot().getId());
|
||||
|
||||
WorkspaceFolder root = workspace.getRoot();
|
||||
// ExternalImage file = (ExternalImage) root.find(name);
|
||||
|
||||
// UPLOAD FILE
|
||||
// String contentType = MimeTypeUtil.getMimeType(fileName, new BufferedInputStream(
|
||||
// new FileInputStream(new File(fullPath))));
|
||||
|
||||
String itemName = WorkspaceUtil.getUniqueName(fileName, root);
|
||||
System.out.println("Storing data....");
|
||||
System.out.println("content type " + null);
|
||||
System.out.println("itemName " + itemName);
|
||||
|
||||
ExternalFile file = (ExternalFile) WorkspaceUtil.createExternalFile(
|
||||
root, itemName, "", null, new FileInputStream(new File(
|
||||
fullPath)));
|
||||
|
||||
System.out.println("Storing data - OK" + "File [id: " + file.getId()
|
||||
+ ", name: " + file.getName() + "]");
|
||||
//
|
||||
// System.out.println("File mimeType" + file.getMimeType());
|
||||
// System.out.println("File size" + file.getLength());
|
||||
//
|
||||
|
||||
//
|
||||
// file.setData(new FileInputStream(new File(newFilePath)));
|
||||
// System.out.println("New File mimeType" + file.getMimeType());
|
||||
// System.out.println("New File size" + file.getLength());
|
||||
|
||||
//
|
||||
|
||||
System.out.println("Recovering data");
|
||||
InputStream inputStream = file.getData();
|
||||
// write the inputStream to a FileOutputStream
|
||||
OutputStream out = new FileOutputStream(new File(
|
||||
"/home/francesco-mangiacrapa/Desktop/download/"+fileName));
|
||||
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
System.out.println("Recovering data - OK");
|
||||
|
||||
// File file = new File("/home/gioia/Desktop/test");
|
||||
// InputStream is = new FileInputStream(file);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
////TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.FileInputStream;
|
||||
//import java.io.FileOutputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStream;
|
||||
//import java.io.OutputStream;
|
||||
//
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
//import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
//import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.common.scope.impl.ScopeBean;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jun 20, 2013
|
||||
// *
|
||||
// */
|
||||
//public class UploadServletTestToken {
|
||||
//
|
||||
// public static void main(String[] args) throws InternalErrorException,
|
||||
// WorkspaceFolderNotFoundException, HomeNotFoundException,
|
||||
// UserNotFoundException, InsufficientPrivilegesException,
|
||||
// ItemAlreadyExistException, WrongDestinationException, IOException {
|
||||
//
|
||||
// ScopeBean scope = new ScopeBean("/gcube/devsec");
|
||||
// ScopeProvider.instance.set(scope.toString());
|
||||
//
|
||||
// Workspace workspace = HomeLibrary.getHomeManagerFactory()
|
||||
// .getHomeManager().getHome("francesco.mangiacrapa")
|
||||
// .getWorkspace();
|
||||
//
|
||||
// String filePath = "/home/francesco-mangiacrapa";
|
||||
//
|
||||
// String fileName = "Geo Explorer 2016-01-15 18-51-51.png";
|
||||
//
|
||||
// String fullPath = filePath + "/" + fileName;
|
||||
//
|
||||
// // String newFilePath =
|
||||
// // "/home/francesco-mangiacrapa/Desktop/icongeoexplorer/testupload.txt";
|
||||
//
|
||||
// // String name = "TestReplaceContentImage";
|
||||
//
|
||||
// // ExternalPDFFile file = workspace.createExternalPDFFile(name, "",
|
||||
// // null, new FileInputStream(new File(filePath)),
|
||||
// // workspace.getRoot().getId());
|
||||
//
|
||||
// WorkspaceFolder root = workspace.getRoot();
|
||||
// // ExternalImage file = (ExternalImage) root.find(name);
|
||||
//
|
||||
// // UPLOAD FILE
|
||||
//// String contentType = MimeTypeUtil.getMimeType(fileName, new BufferedInputStream(
|
||||
//// new FileInputStream(new File(fullPath))));
|
||||
//
|
||||
// String itemName = WorkspaceUtil.getUniqueName(fileName, root);
|
||||
// System.out.println("Storing data....");
|
||||
// System.out.println("content type " + null);
|
||||
// System.out.println("itemName " + itemName);
|
||||
//
|
||||
// ExternalFile file = (ExternalFile) WorkspaceUtil.createExternalFile(
|
||||
// root, itemName, "", null, new FileInputStream(new File(
|
||||
// fullPath)));
|
||||
//
|
||||
// System.out.println("Storing data - OK" + "File [id: " + file.getId()
|
||||
// + ", name: " + file.getName() + "]");
|
||||
// //
|
||||
// // System.out.println("File mimeType" + file.getMimeType());
|
||||
// // System.out.println("File size" + file.getLength());
|
||||
// //
|
||||
//
|
||||
// //
|
||||
// // file.setData(new FileInputStream(new File(newFilePath)));
|
||||
// // System.out.println("New File mimeType" + file.getMimeType());
|
||||
// // System.out.println("New File size" + file.getLength());
|
||||
//
|
||||
// //
|
||||
//
|
||||
// System.out.println("Recovering data");
|
||||
// InputStream inputStream = file.getData();
|
||||
// // write the inputStream to a FileOutputStream
|
||||
// OutputStream out = new FileOutputStream(new File(
|
||||
// "/home/francesco-mangiacrapa/Desktop/download/"+fileName));
|
||||
//
|
||||
// int read = 0;
|
||||
// byte[] bytes = new byte[1024];
|
||||
//
|
||||
// while ((read = inputStream.read(bytes)) != -1) {
|
||||
// out.write(bytes, 0, read);
|
||||
// }
|
||||
//
|
||||
// inputStream.close();
|
||||
// out.flush();
|
||||
// out.close();
|
||||
//
|
||||
// System.out.println("Recovering data - OK");
|
||||
//
|
||||
// // File file = new File("/home/gioia/Desktop/test");
|
||||
// // InputStream is = new FileInputStream(file);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,248 +1,242 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
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.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
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.GWTWorkspaceBuilder;
|
||||
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex;
|
||||
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Jun 26, 2013
|
||||
*
|
||||
*/
|
||||
public class UriResolverReaderRR {
|
||||
|
||||
//Base Address
|
||||
String uri = "";
|
||||
//Query URL parameter
|
||||
String parameter = "";
|
||||
private String uriRequest = "";
|
||||
public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
|
||||
// public static String DEFAULT_SCOPE = "/gcube/devsec"; //PRODUCTION
|
||||
|
||||
public static Logger log = Logger.getLogger(UriResolverReaderRR.class);
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
public UriResolverReaderRR(String scope) throws Exception {
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
XQuery query = queryFor(ServiceEndpoint.class);
|
||||
|
||||
query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URI-Resolver'").setResult("$resource/Profile/AccessPoint");
|
||||
|
||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||
|
||||
List<AccessPoint> endpoints = client.submit(query);
|
||||
|
||||
if (endpoints.size() == 0)
|
||||
throw new Exception("No Resolver available");
|
||||
|
||||
//Base Address
|
||||
// System.out.println(endpoints.get(0).address());
|
||||
|
||||
uri = 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():"";
|
||||
}
|
||||
|
||||
uriRequest = uri+"?"+parameter;
|
||||
|
||||
|
||||
//Query URL parameter
|
||||
// System.out.println(endpoints.get(0).propertyMap().get("parameter").value());
|
||||
|
||||
}
|
||||
|
||||
public InputStream resolve(String smp) throws IOException{
|
||||
String query = uriRequest + "="+smp;
|
||||
|
||||
URL url = new URL(query);
|
||||
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Base Address of Uri Resolver
|
||||
*/
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Query URL parameter of Uri Resolver
|
||||
*/
|
||||
public String getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("UriResolverReaderParameter [uri=");
|
||||
builder.append(uri);
|
||||
builder.append(", parameter=");
|
||||
builder.append(parameter);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
//
|
||||
// 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==
|
||||
|
||||
String itemId = "0e875263-f6bc-4945-9435-bfb8774027ca";
|
||||
// itemId = "f70f01f9-5a06-4123-b6ec-bd121c1af82f";
|
||||
System.out.println("uri is: "+getPublicLinkForFolderItemId(itemId));
|
||||
|
||||
|
||||
|
||||
//
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String getPublicLinkForFolderItemId(String itemId){
|
||||
|
||||
try{
|
||||
|
||||
ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
|
||||
Workspace workspace = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("leonardo.candela")
|
||||
.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.getPublicLinkForFolderItem(folderItem);
|
||||
System.out.println("smpUri "+smpUri);
|
||||
|
||||
System.out.println("get uriResolver...");
|
||||
UriResolverReaderParameterForResolverIndex uriResolver = new UriResolverReaderParameterForResolverIndex(DEFAULT_SCOPE, RESOLVER_TYPE.SMP_ID);
|
||||
|
||||
// String url = uriResolver.resolveAsUriRequest(smpUri, "testResponse!@#$$%^^&&.html", folderItem.getMimeType(), true);
|
||||
String url = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), 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(DEFAULT_SCOPE);
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
//TODO IT MUST BE MOVED TO SHUB
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace;
|
||||
//
|
||||
//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.URL;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.apache.commons.io.IOUtils;
|
||||
//import org.apache.log4j.Logger;
|
||||
//import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
//import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
//import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
//import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
//import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
//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.resolver.UriResolverReaderParameterForResolverIndex;
|
||||
//import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE;
|
||||
//import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
//import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
// * Jun 26, 2013
|
||||
// *
|
||||
// */
|
||||
///*
|
||||
// *
|
||||
// *
|
||||
// * IT MUST BE MOVED TO SHUB
|
||||
// *
|
||||
// *
|
||||
// *
|
||||
//public class UriResolverReaderRR {
|
||||
//
|
||||
// //Base Address
|
||||
// String uri = "";
|
||||
// //Query URL parameter
|
||||
// String parameter = "";
|
||||
// private String uriRequest = "";
|
||||
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
|
||||
//// public static String DEFAULT_SCOPE = "/gcube/devsec"; //PRODUCTION
|
||||
//
|
||||
// public static Logger log = Logger.getLogger(UriResolverReaderRR.class);
|
||||
//
|
||||
// public UriResolverReaderRR(String scope) throws Exception {
|
||||
//
|
||||
// ScopeProvider.instance.set(scope);
|
||||
//
|
||||
// XQuery query = queryFor(ServiceEndpoint.class);
|
||||
//
|
||||
// query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URI-Resolver'").setResult("$resource/Profile/AccessPoint");
|
||||
//
|
||||
// DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||
//
|
||||
// List<AccessPoint> endpoints = client.submit(query);
|
||||
//
|
||||
// if (endpoints.size() == 0)
|
||||
// throw new Exception("No Resolver available");
|
||||
//
|
||||
// //Base Address
|
||||
//// System.out.println(endpoints.get(0).address());
|
||||
//
|
||||
// uri = 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():"";
|
||||
// }
|
||||
//
|
||||
// uriRequest = uri+"?"+parameter;
|
||||
//
|
||||
//
|
||||
// //Query URL parameter
|
||||
//// System.out.println(endpoints.get(0).propertyMap().get("parameter").value());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public InputStream resolve(String smp) throws IOException{
|
||||
// String query = uriRequest + "="+smp;
|
||||
//
|
||||
// URL url = new URL(query);
|
||||
//
|
||||
// return url.openStream();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// public String getUri() {
|
||||
// return uri;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public String getParameter() {
|
||||
// return parameter;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// StringBuilder builder = new StringBuilder();
|
||||
// builder.append("UriResolverReaderParameter [uri=");
|
||||
// builder.append(uri);
|
||||
// builder.append(", parameter=");
|
||||
// builder.append(parameter);
|
||||
// builder.append("]");
|
||||
// return builder.toString();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// 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();
|
||||
////
|
||||
//// 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==
|
||||
//
|
||||
// String itemId = "0e875263-f6bc-4945-9435-bfb8774027ca";
|
||||
//// itemId = "f70f01f9-5a06-4123-b6ec-bd121c1af82f";
|
||||
// System.out.println("uri is: "+getPublicLinkForFolderItemId(itemId));
|
||||
//
|
||||
//
|
||||
//
|
||||
////
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public static String getPublicLinkForFolderItemId(String itemId){
|
||||
//
|
||||
// try{
|
||||
//
|
||||
// ScopeProvider.instance.set(DEFAULT_SCOPE);
|
||||
//
|
||||
// Workspace workspace = HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome("leonardo.candela")
|
||||
// .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.getPublicLinkForFolderItem(folderItem);
|
||||
// System.out.println("smpUri "+smpUri);
|
||||
//
|
||||
// System.out.println("get uriResolver...");
|
||||
// UriResolverReaderParameterForResolverIndex uriResolver = new UriResolverReaderParameterForResolverIndex(DEFAULT_SCOPE, RESOLVER_TYPE.SMP_ID);
|
||||
//
|
||||
//// String url = uriResolver.resolveAsUriRequest(smpUri, "testResponse!@#$$%^^&&.html", folderItem.getMimeType(), true);
|
||||
// String url = uriResolver.resolveAsUriRequest(smpUri, folderItem.getName(), 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(DEFAULT_SCOPE);
|
||||
//
|
||||
// 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 "";
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//*/
|
||||
|
Loading…
Reference in New Issue