merged with private version at 174223
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@174458 82a268e6-3cf1-43bd-a215-b396298e98cftask/19600
parent
e90cb8f26d
commit
da556014ae
@ -0,0 +1,90 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
* The Class CopyItemsEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 10, 2018
|
||||
*/
|
||||
public class CopyItemsEvent extends GwtEvent<CopyItemsEventHandler> implements GuiEventInterface{
|
||||
public static Type<CopyItemsEventHandler> TYPE = new Type<CopyItemsEventHandler>();
|
||||
|
||||
private List<String> ids;
|
||||
|
||||
private String destinationFolderId;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new copy items event.
|
||||
*
|
||||
* @param ids the ids
|
||||
* @param destinationFolderId the destination folder id
|
||||
*/
|
||||
public CopyItemsEvent(List<String> ids, String destinationFolderId) {
|
||||
this.ids = ids;
|
||||
this.destinationFolderId = destinationFolderId;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<CopyItemsEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(CopyItemsEventHandler handler) {
|
||||
handler.onCopyItems(this);
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
|
||||
*/
|
||||
@Override
|
||||
public EventsTypeEnum getKey() {
|
||||
return EventsTypeEnum.COPY_EVENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ids.
|
||||
*
|
||||
* @return the ids
|
||||
*/
|
||||
public List<String> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ids.
|
||||
*
|
||||
* @param ids the new ids
|
||||
*/
|
||||
public void setIds(List<String> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the destination folder id.
|
||||
*
|
||||
* @return the destinationId
|
||||
*/
|
||||
public String getDestinationFolderId() {
|
||||
|
||||
return destinationFolderId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface CopyItemsEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 10, 2018
|
||||
*/
|
||||
public interface CopyItemsEventHandler extends EventHandler {
|
||||
|
||||
|
||||
/**
|
||||
* On copy items.
|
||||
*
|
||||
* @param copytemEvent the copytem event
|
||||
*/
|
||||
void onCopyItems(CopyItemsEvent copytemEvent);
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
public class CopytemEvent extends GwtEvent<CopytemEventHandler> implements GuiEventInterface{
|
||||
public static Type<CopytemEventHandler> TYPE = new Type<CopytemEventHandler>();
|
||||
|
||||
// private String itemId = null;
|
||||
|
||||
private List<String> ids;
|
||||
|
||||
// public CopytemEvent(String itemId) {
|
||||
// this.itemId = itemId;
|
||||
// }
|
||||
|
||||
public CopytemEvent(List<String> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Type<CopytemEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(CopytemEventHandler handler) {
|
||||
handler.onCopyItem(this);
|
||||
|
||||
}
|
||||
|
||||
// public String getItemId() {
|
||||
// return itemId;
|
||||
// }
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
|
||||
*/
|
||||
@Override
|
||||
public EventsTypeEnum getKey() {
|
||||
return EventsTypeEnum.COPY_EVENT;
|
||||
}
|
||||
|
||||
public List<String> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(List<String> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface CopytemEventHandler extends EventHandler {
|
||||
/**
|
||||
* @param copytemEvent
|
||||
*/
|
||||
void onCopyItem(CopytemEvent copytemEvent);
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface DragOnTreeMoveItemEventHandler extends EventHandler {
|
||||
void onMoveItem(DragOnTreeMoveItemEvent event);
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
* The Class MoveItemsEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 4, 2018
|
||||
*/
|
||||
public class LoadFolderEvent extends GwtEvent<LoadFolderEventHandler> implements GuiEventInterface{
|
||||
public static Type<LoadFolderEventHandler> TYPE = new Type<LoadFolderEventHandler>();
|
||||
|
||||
private FileModel targetFolder; //Used to move
|
||||
/**
|
||||
* Instantiates a new load folder event.
|
||||
*
|
||||
* @param targetFolder the target folder
|
||||
*/
|
||||
public LoadFolderEvent(FileModel targetFolder) {
|
||||
this.targetFolder = targetFolder;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<LoadFolderEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
*/
|
||||
/**
|
||||
* Dispatch.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(LoadFolderEventHandler handler) {
|
||||
handler.onLoadFolder(this);
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
|
||||
*/
|
||||
@Override
|
||||
public EventsTypeEnum getKey() {
|
||||
return EventsTypeEnum.LOAD_FOLDER_EVENT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the targetFolder
|
||||
*/
|
||||
public FileModel getTargetFolder() {
|
||||
|
||||
return targetFolder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface LoadFolderEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 9, 2018
|
||||
*/
|
||||
public interface LoadFolderEventHandler extends EventHandler {
|
||||
|
||||
|
||||
/**
|
||||
* On load folder.
|
||||
*
|
||||
* @param loadFolderEvent the load folder event
|
||||
*/
|
||||
void onLoadFolder(LoadFolderEvent loadFolderEvent);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface MoveItemEventHandler extends EventHandler {
|
||||
void onMoveItem(MoveItemEvent event);
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
* The Class MoveItemsEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 4, 2018
|
||||
*/
|
||||
public class MoveItemsEvent extends GwtEvent<MoveItemsEventHandler> implements GuiEventInterface{
|
||||
public static Type<MoveItemsEventHandler> TYPE = new Type<MoveItemsEventHandler>();
|
||||
|
||||
private String destionationFolderId;
|
||||
|
||||
private List<String> ids;
|
||||
|
||||
private FileModel sourceParentFolder; //Used to move
|
||||
|
||||
private boolean treeRefreshable;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new move items event.
|
||||
*
|
||||
* @param ids the ids
|
||||
* @param folderDestinationId the folder destination id
|
||||
* @param sourceParentFolder the source parent folder
|
||||
*/
|
||||
public MoveItemsEvent(List<String> ids, String folderDestinationId, FileModel sourceParentFolder) {
|
||||
this.ids = ids;
|
||||
this.destionationFolderId = folderDestinationId;
|
||||
this.sourceParentFolder = sourceParentFolder;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<MoveItemsEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(MoveItemsEventHandler handler) {
|
||||
handler.onMoveItems(this);
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
|
||||
*/
|
||||
@Override
|
||||
public EventsTypeEnum getKey() {
|
||||
return EventsTypeEnum.MOVED_EVENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ids.
|
||||
*
|
||||
* @return the ids
|
||||
*/
|
||||
public List<String> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ids.
|
||||
*
|
||||
* @param ids the new ids
|
||||
*/
|
||||
public void setIds(List<String> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
/**
|
||||
* Sets the tree refreshable.
|
||||
*
|
||||
* @param bool the new tree refreshable
|
||||
*/
|
||||
public void setTreeRefreshable(boolean bool){
|
||||
this.treeRefreshable = bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is tree refreshable.
|
||||
*
|
||||
* @return true, if is tree refreshable
|
||||
*/
|
||||
public boolean isTreeRefreshable() {
|
||||
return treeRefreshable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the destionation folder id.
|
||||
*
|
||||
* @return the destionationFolderId
|
||||
*/
|
||||
public String getDestionationFolderId() {
|
||||
|
||||
return destionationFolderId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the sourceParentFolder
|
||||
*/
|
||||
public FileModel getSourceParentFolder() {
|
||||
|
||||
return sourceParentFolder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param destionationFolderId the destionationFolderId to set
|
||||
*/
|
||||
public void setDestionationFolderId(String destionationFolderId) {
|
||||
|
||||
this.destionationFolderId = destionationFolderId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface MoveItemsEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 4, 2018
|
||||
*/
|
||||
public interface MoveItemsEventHandler extends EventHandler {
|
||||
|
||||
/**
|
||||
* On move items.
|
||||
*
|
||||
* @param pasteItemEvent the paste item event
|
||||
*/
|
||||
void onMoveItems(MoveItemsEvent pasteItemEvent);
|
||||
}
|
@ -1,51 +1,94 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.constant.WorkspaceOperation;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
* The Class OpenContextMenuTreeEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 8, 2018
|
||||
*/
|
||||
public class OpenContextMenuTreeEvent extends GwtEvent<OpenContextMenuTreeEventHandler> {
|
||||
public static Type<OpenContextMenuTreeEventHandler> TYPE = new Type<OpenContextMenuTreeEventHandler>();
|
||||
|
||||
private FileModel targetFileModel = null;
|
||||
|
||||
private List<FileModel> selectedItems = null;
|
||||
private int clientX;
|
||||
private int clientY;
|
||||
|
||||
private WorkspaceOperation wsOperation;
|
||||
|
||||
/**
|
||||
* Gets the ws operation.
|
||||
*
|
||||
* @return the ws operation
|
||||
*/
|
||||
public WorkspaceOperation getWsOperation() {
|
||||
return wsOperation;
|
||||
}
|
||||
|
||||
public OpenContextMenuTreeEvent(FileModel targetFileModel, int clientX, int clientY) {
|
||||
this.targetFileModel = targetFileModel;
|
||||
|
||||
/**
|
||||
* Instantiates a new open context menu tree event.
|
||||
*
|
||||
* @param selectedItems the selected items
|
||||
* @param clientX the client x
|
||||
* @param clientY the client y
|
||||
*/
|
||||
public OpenContextMenuTreeEvent(List<FileModel> selectedItems, int clientX, int clientY) {
|
||||
this.selectedItems = selectedItems;
|
||||
this.clientX = clientX;
|
||||
this.clientY = clientY;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<OpenContextMenuTreeEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(OpenContextMenuTreeEventHandler handler) {
|
||||
handler.onOpenContextMenuTree(this);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client x.
|
||||
*
|
||||
* @return the client x
|
||||
*/
|
||||
public int getClientX() {
|
||||
return clientX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client y.
|
||||
*
|
||||
* @return the client y
|
||||
*/
|
||||
public int getClientY() {
|
||||
return clientY;
|
||||
}
|
||||
|
||||
public FileModel getTargetFileModel() {
|
||||
return targetFileModel;
|
||||
/**
|
||||
* Gets the selected items.
|
||||
*
|
||||
* @return the selectedItems
|
||||
*/
|
||||
public List<FileModel> getSelectedItems() {
|
||||
|
||||
return selectedItems;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,92 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface;
|
||||
import org.gcube.portlets.user.workspace.client.view.tree.CutCopyAndPaste.OperationType;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
public class PasteItemEvent extends GwtEvent<PasteItemEventHandler> implements GuiEventInterface{
|
||||
public static Type<PasteItemEventHandler> TYPE = new Type<PasteItemEventHandler>();
|
||||
|
||||
// private String itemId = null;
|
||||
private String folderDestinationId;
|
||||
|
||||
private List<String> ids;
|
||||
|
||||
private OperationType operationType;
|
||||
|
||||
private String folderSourceId; //Used to move
|
||||
|
||||
private boolean treeRefreshable;
|
||||
|
||||
|
||||
// public PasteItemEvent(String itemId, String folderDestinationId) {
|
||||
// this.itemId = itemId;
|
||||
// this.folderDestinationId = folderDestinationId;
|
||||
// }
|
||||
|
||||
public PasteItemEvent(List<String> ids, String folderDestinationId, OperationType operation) {
|
||||
this.ids = ids;
|
||||
this.folderDestinationId = folderDestinationId;
|
||||
this.operationType = operation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<PasteItemEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(PasteItemEventHandler handler) {
|
||||
handler.onCutCopyAndPaste(this);
|
||||
|
||||
}
|
||||
|
||||
// public String getItemId() {
|
||||
// return itemId;
|
||||
// }
|
||||
|
||||
public String getFolderDestinationId() {
|
||||
return folderDestinationId;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface#getKey()
|
||||
*/
|
||||
@Override
|
||||
public EventsTypeEnum getKey() {
|
||||
return EventsTypeEnum.PASTED_EVENT;
|
||||
}
|
||||
|
||||
public List<String> getIds() {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public void setIds(List<String> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
public OperationType getOperationType() {
|
||||
return operationType;
|
||||
}
|
||||
|
||||
public String getFolderSourceId() {
|
||||
return folderSourceId;
|
||||
}
|
||||
|
||||
public void setFolderSourceId(String folderSourceId) {
|
||||
this.folderSourceId = folderSourceId;
|
||||
}
|
||||
|
||||
public void setTreeRefreshable(boolean bool){
|
||||
this.treeRefreshable = bool;
|
||||
}
|
||||
|
||||
public boolean isTreeRefreshable() {
|
||||
return treeRefreshable;
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface PasteItemEventHandler extends EventHandler {
|
||||
void onCutCopyAndPaste(PasteItemEvent pasteItemEvent);
|
||||
}
|
@ -1,304 +0,0 @@
|
||||
//package org.gcube.portlets.user.workspace.client.uploader;
|
||||
//
|
||||
//
|
||||
//import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
||||
//import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
//import org.gcube.portlets.user.workspace.client.event.CompletedFileUploadEvent;
|
||||
//import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
//import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage;
|
||||
//import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
|
||||
//import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxConfirm;
|
||||
//import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxWait;
|
||||
//import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
|
||||
//
|
||||
//import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
||||
//import com.extjs.gxt.ui.client.event.ButtonEvent;
|
||||
//import com.extjs.gxt.ui.client.event.Events;
|
||||
//import com.extjs.gxt.ui.client.event.FormEvent;
|
||||
//import com.extjs.gxt.ui.client.event.Listener;
|
||||
//import com.extjs.gxt.ui.client.event.MessageBoxEvent;
|
||||
//import com.extjs.gxt.ui.client.event.SelectionListener;
|
||||
//import com.extjs.gxt.ui.client.widget.Dialog;
|
||||
//import com.extjs.gxt.ui.client.widget.Info;
|
||||
//import com.extjs.gxt.ui.client.widget.Window;
|
||||
//import com.extjs.gxt.ui.client.widget.button.Button;
|
||||
//import com.extjs.gxt.ui.client.widget.form.FileUploadField;
|
||||
//import com.extjs.gxt.ui.client.widget.form.FormPanel;
|
||||
//import com.extjs.gxt.ui.client.widget.form.FormPanel.Encoding;
|
||||
//import com.extjs.gxt.ui.client.widget.form.FormPanel.Method;
|
||||
//import com.google.gwt.user.client.Timer;
|
||||
//import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
//import com.google.gwt.user.client.ui.HTML;
|
||||
//import com.google.gwt.user.client.ui.Hidden;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
// *
|
||||
// */
|
||||
//public class DialogUpload extends Window {
|
||||
//
|
||||
// private final FormPanel formPanel = new FormPanel();
|
||||
// private FileUploadField fileUploadField = new FileUploadField();
|
||||
// private MessageBoxWait messageBoxWait = null;
|
||||
// private boolean isStatusCompleted = false;
|
||||
// private Button btnSubmit = new Button("Submit");
|
||||
// private Button btnCancel = new Button("Cancel");
|
||||
// private Hidden hiddenOverwrite = new Hidden(ConstantsExplorer.IS_OVERWRITE,"false");
|
||||
//
|
||||
//
|
||||
// private String parentIdentifier = "";
|
||||
// private String parentName = "";
|
||||
//
|
||||
// public DialogUpload(String headerTitle, String parentName, final FileModel parent, String fieldLabel){
|
||||
//
|
||||
// this.setHeaderVisible(true);
|
||||
// this.setHeading(headerTitle + parentName);
|
||||
// this.parentIdentifier = parent.getIdentifier();
|
||||
// this.parentName = parentName;
|
||||
// this.setStyleAttribute("margin", "10px");
|
||||
//
|
||||
// // Create a FormPanel and point it at a service.
|
||||
//
|
||||
// // Create a FormPanel and point it at a service.
|
||||
// formPanel.setHeaderVisible(false);
|
||||
// formPanel.setFrame(true);
|
||||
// formPanel.setAction(ConstantsExplorer.UPLOAD_WORKSPACE_SERVICE);
|
||||
// formPanel.setEncoding(Encoding.MULTIPART);
|
||||
// formPanel.setMethod(Method.POST);
|
||||
//
|
||||
// formPanel.setButtonAlign(HorizontalAlignment.CENTER);
|
||||
// formPanel.setWidth(400);
|
||||
//
|
||||
// // TextField<String> name = new TextField<String>();
|
||||
// // name.setFieldLabel("Name");
|
||||
// // formPanel.add(name);
|
||||
//
|
||||
// fileUploadField.setAllowBlank(false);
|
||||
// fileUploadField.setName(ConstantsExplorer.UPLOAD_FORM_ELEMENT);
|
||||
//
|
||||
// // Add hidden parameters
|
||||
// formPanel.add(new Hidden(ConstantsExplorer.ID_FOLDER,parent.getIdentifier()));
|
||||
// formPanel.add(new Hidden(ConstantsExplorer.UPLOAD_TYPE,fieldLabel));
|
||||
// formPanel.add(hiddenOverwrite);
|
||||
//
|
||||
// // fileUploadField.setFieldLabel(ConstantsExplorer.FILE);
|
||||
// fileUploadField.setFieldLabel(fieldLabel);
|
||||
// formPanel.add(fileUploadField);
|
||||
// formPanel.addButton(btnSubmit);
|
||||
//
|
||||
// formPanel.addButton(btnCancel);
|
||||
//
|
||||
//
|
||||
// // handle the post
|
||||
// formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
|
||||
//
|
||||
// public void handleEvent(FormEvent event) {
|
||||
// // When the form submission is successfully completed, this
|
||||
// // event is
|
||||
// // fired. Assuming the service returned a response of type
|
||||
// // text/html,
|
||||
//
|
||||
// isStatusCompleted = true;
|
||||
//
|
||||
//
|
||||
// // Log.trace("onSubmitComplete");
|
||||
// String result = event.getResultHtml();
|
||||
//
|
||||
// // Log.trace("Result "+result);
|
||||
// hide();
|
||||
//
|
||||
// messageBoxWait.getMessageBoxWait().close();
|
||||
//
|
||||
// if (result == null) {
|
||||
// // MessageUtil.showErrorMessage("Error during upload", "An error occurred during file upload.");
|
||||
// new MessageBoxAlert("Error during upload", "An error occurred during file upload.", null);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// //expected <pre>200:Upload complete</pre>
|
||||
// /*we strip tags added by webserver,
|
||||
// *
|
||||
// * Massi fix because webkit returns
|
||||
// * <pre style="word-wrap: break-word; white-space: pre-wrap;">OK:File france_flag.png(0) imported correctly in /Workspace</pre>
|
||||
// *
|
||||
// * TODO: recall it next time
|
||||
// */
|
||||
// //String strippedResult = result.replace("<pre>", "").replace("</pre>", ""); //this won't work for webkit
|
||||
// //replaced by new HTML(result).getText()
|
||||
// String strippedResult = new HTML(result).getText();
|
||||
//
|
||||
//
|
||||
//// com.google.gwt.user.client.Window.alert(result);
|
||||
//// com.google.gwt.user.client.Window.alert("Stripped: " + strippedResult);
|
||||
//
|
||||
// final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
|
||||
//
|
||||
// switch (resultMessage.getStatus()) {
|
||||
// case ERROR:
|
||||
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
|
||||
// break;
|
||||
// case UNKNOWN:
|
||||
// new MessageBoxAlert("Error during upload", resultMessage.getMessage(), null);
|
||||
// break;
|
||||
// case WARN: {
|
||||
// new MessageBoxAlert("Upload completed with warnings", resultMessage.getMessage(), null);
|
||||
// break;
|
||||
// }
|
||||
// case OK: {
|
||||
// Timer t = new Timer() {
|
||||
// public void run() {
|
||||
// AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
|
||||
// new InfoDisplayMessage("Upload completed successfully", resultMessage.getMessage());
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// t.schedule(250);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// add(formPanel);
|
||||
//
|
||||
// this.addListeners();
|
||||
//
|
||||
// this.setAutoWidth(true);
|
||||
// this.setAutoHeight(true);
|
||||
//
|
||||
//// this.show();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void addListeners() {
|
||||
//
|
||||
//
|
||||
// btnSubmit.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
||||
// @Override
|
||||
// public void componentSelected(ButtonEvent ce) {
|
||||
// if (fileUploadField.getValue()==null || !(fileUploadField.getValue().length()>2)) {
|
||||
// new MessageBoxAlert(ConstantsExplorer.ERROR, ConstantsExplorer.NOFILESPECIFIED, null);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//// com.google.gwt.user.client.Window.alert("parentIdentifier "+parentIdentifier);
|
||||
//// com.google.gwt.user.client.Window.alert("fileUploadField.getValue() "+fileUploadField.getValue());
|
||||
//// com.google.gwt.user.client.Window.alert("parentName "+parentName);
|
||||
// /*
|
||||
// * TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
|
||||
// */
|
||||
// String normalizedFileName = fileUploadField.getValue();
|
||||
//
|
||||
//// com.google.gwt.user.client.Window.alert("fileUploadField.getValue() "+fileUploadField.getValue());
|
||||
// if (normalizedFileName.contains("\\")) {
|
||||
// normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
|
||||
//// com.google.gwt.user.client.Window.alert("normalizedFileName= "+normalizedFileName);
|
||||
// }
|
||||
// final String label = normalizedFileName;
|
||||
// AppControllerExplorer.rpcWorkspaceService.itemExistsInWorkpaceFolder(parentIdentifier, normalizedFileName, new AsyncCallback<String>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(final String itemId) {
|
||||
//
|
||||
// if(itemId!=null){
|
||||
//
|
||||
// MessageBoxConfirm msg = new MessageBoxConfirm("Replace "+label+"?", label + " exists in folder "+parentName + ". Overwrite?");
|
||||
//
|
||||
//
|
||||
// msg.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
||||
//
|
||||
// public void handleEvent(MessageBoxEvent be) {
|
||||
//
|
||||
// //IF NOT CANCELLED
|
||||
// String clickedButton = be.getButtonClicked().getItemId();
|
||||
//
|
||||
// if(clickedButton.equals(Dialog.YES)){
|
||||
//
|
||||
//// removeItemAndSubmitForm(itemId);
|
||||
// updateItemSubmitForm(itemId);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }else
|
||||
// submitForm(); //ITEM does NOT EXIST SO SUBMIT FORM;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Throwable caught) {
|
||||
// Info.display("Error", "Sorry an error occurred on the server "+caught.getLocalizedMessage() + ". Please try again later");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// });
|
||||
//
|
||||
//
|
||||
// btnCancel.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
||||
// @Override
|
||||
// public void componentSelected(ButtonEvent ce) {
|
||||
// hide();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void submitForm(){
|
||||
//
|
||||
// messageBoxWait = new MessageBoxWait(ConstantsExplorer.PROGRESS, ConstantsExplorer.SAVINGYOURFILE, fileUploadField.getValue());
|
||||
//
|
||||
// //Progress bar for upload
|
||||
// final Timer t = new Timer()
|
||||
// {
|
||||
// public void run()
|
||||
// {
|
||||
// if (isStatusCompleted)
|
||||
// {
|
||||
// cancel();
|
||||
// messageBoxWait.getMessageBoxWait().close();
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// t.scheduleRepeating(500);
|
||||
// formPanel.submit();
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void removeItemAndSubmitForm(String itemId){
|
||||
//
|
||||
// AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new AsyncCallback<Boolean>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Throwable caught) {
|
||||
// Info.display("Error", caught.getMessage());
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(Boolean result) {
|
||||
// if(result){
|
||||
// hiddenOverwrite.setValue("true");
|
||||
// submitForm();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private void updateItemSubmitForm(String itemId){
|
||||
//
|
||||
//
|
||||
// hiddenOverwrite.setValue("true");
|
||||
// submitForm();
|
||||
// }
|
||||
//}
|
||||
//
|
@ -1,131 +0,0 @@
|
||||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.user.workspace.client.uploader;
|
||||
//
|
||||
//import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
//import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
//import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog;
|
||||
//
|
||||
//import com.extjs.gxt.ui.client.widget.Info;
|
||||
//import com.google.gwt.event.shared.HandlerManager;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * The Class FileUploader.
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
// * Jul 15, 2015
|
||||
// */
|
||||
//public class FileUploader {
|
||||
//
|
||||
//
|
||||
// private final UploadProgressDialog dlg;
|
||||
// private FileModel folderParent;
|
||||
// private UpdateServiceUploader updateServiceUploader;
|
||||
// private String uploadType;
|
||||
//
|
||||
// /**
|
||||
// * Instantiates a new file uploader.
|
||||
// *
|
||||
// * @param eventBus the event bus
|
||||
// * @param folderParent the folder parent
|
||||
// * @param uploadType the upload type
|
||||
// */
|
||||
// public FileUploader(HandlerManager eventBus, FileModel folderParent, String uploadType) {
|
||||
// this.folderParent = folderParent;
|
||||
// this.uploadType = uploadType;
|
||||
//
|
||||
// /**
|
||||
// * Prepare new servlet uploader
|
||||
// */
|
||||
// updateServiceUploader = new UpdateServiceUploader(this, folderParent, uploadType);
|
||||
//
|
||||
// String caption = "Upload ";
|
||||
// if(uploadType.compareTo(ConstantsExplorer.ARCHIVE)==0)
|
||||
// caption+= " a zip Archive";
|
||||
// else if(uploadType.compareTo(ConstantsExplorer.FILE)==0)
|
||||
// caption+= "File";
|
||||
//
|
||||
// caption+= " in: "+folderParent.getName();
|
||||
//
|
||||
// dlg = new UploadProgressDialog(caption, eventBus, true);
|
||||
// dlg.center();
|
||||
// dlg.show();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Submit form.
|
||||
// */
|
||||
// public void submitForm() {
|
||||
//
|
||||
// try {
|
||||
// dlg.submitForm();
|
||||
// } catch (Exception e) {
|
||||
// Info.display("Error", "Sorry an error occurred on the server "+e.getLocalizedMessage() + ". Please try again later");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Overwrite.
|
||||
// */
|
||||
// public void overwrite(){
|
||||
// updateServiceUploader.setOverwrite();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Submit servlet form.
|
||||
// *
|
||||
// * @param absolutePathOnServer the absolute path of the file uploaded on the server
|
||||
// */
|
||||
// public void submitServletForm(String absolutePathOnServer){
|
||||
//
|
||||
// updateServiceUploader.setFileName(absolutePathOnServer);
|
||||
// try {
|
||||
// updateServiceUploader.submitForm();
|
||||
// } catch (Exception e) {
|
||||
// dlg.showRegisteringResult(false);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the folder parent.
|
||||
// *
|
||||
// * @return the folder parent
|
||||
// */
|
||||
// public FileModel getFolderParent() {
|
||||
// return folderParent;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Gets the upload type.
|
||||
// *
|
||||
// * @return the upload type
|
||||
// */
|
||||
// public String getUploadType() {
|
||||
// return uploadType;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Show registering result.
|
||||
// *
|
||||
// * @param b the b
|
||||
// * @param message the message
|
||||
// */
|
||||
// public void showRegisteringResult(boolean b, String message) {
|
||||
// this.dlg.showRegisteringResult(b, message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Show registering result.
|
||||
// *
|
||||
// * @param b the b
|
||||
// */
|
||||
// public void showRegisteringResult(boolean b) {
|
||||
// this.dlg.showRegisteringResult(b);
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,172 +0,0 @@
|
||||
//package org.gcube.portlets.user.workspace.client.uploader;
|
||||
//
|
||||
//
|
||||
//import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
||||
//import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
//import org.gcube.portlets.user.workspace.client.event.CompletedFileUploadEvent;
|
||||
//import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
//import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
|
||||
//
|
||||
//import com.extjs.gxt.ui.client.widget.Window;
|
||||
//import com.google.gwt.core.client.GWT;
|
||||
//import com.google.gwt.http.client.Request;
|
||||
//import com.google.gwt.http.client.RequestBuilder;
|
||||
//import com.google.gwt.http.client.RequestCallback;
|
||||
//import com.google.gwt.http.client.RequestException;
|
||||
//import com.google.gwt.http.client.Response;
|
||||
//import com.google.gwt.http.client.URL;
|
||||
//import com.google.gwt.user.client.Timer;
|
||||
//import com.google.gwt.user.client.ui.HTML;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
// * @Jan 20, 2014
|
||||
// *
|
||||
// */
|
||||
//public class UpdateServiceUploader extends Window{
|
||||
//
|
||||
// private FileUploader fileUploaderDlg = null;
|
||||
// private String fileName = "";
|
||||
// private boolean overwrite = false;
|
||||
// private FileModel parent;
|
||||
// private String uploadType;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @param fileUploader
|
||||
// * @param parent
|
||||
// * @param uploadType
|
||||
// *
|
||||
// * By default overwrite paramameter is false
|
||||
// */
|
||||
// public UpdateServiceUploader(final FileUploader fileUploader, final FileModel parent, String uploadType){
|
||||
//
|
||||
// this.fileUploaderDlg = fileUploader;
|
||||
// this.parent = parent;
|
||||
// this.uploadType = uploadType;
|
||||
// }
|
||||
//
|
||||
// public static String encodeUrlDelimiters(String s) {
|
||||
// if (s == null) {
|
||||
// return null;
|
||||
// }
|
||||
// s = s.replaceAll(";", "%2F");
|
||||
// s = s.replaceAll("/", "%2F");
|
||||
// s = s.replaceAll(":", "%3A");
|
||||
// s = s.replaceAll("\\?", "%3F");
|
||||
// s = s.replaceAll("&", "%26");
|
||||
// s = s.replaceAll("\\=", "%3D");
|
||||
// s = s.replaceAll("\\+", "%2B");
|
||||
// s = s.replaceAll("\\$", "%24");
|
||||
// s = s.replaceAll(",", "%2C");
|
||||
// s = s.replaceAll("#", "%23");
|
||||
// return s;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void submitForm() throws Exception{
|
||||
//
|
||||
// if(fileName == null || fileName.isEmpty())
|
||||
// throw new Exception("File absolute path on server is null");
|
||||
//
|
||||
// String parameters = "";
|
||||
//
|
||||
// String fileNameEscaped = URL.encodeQueryString(fileName);
|
||||
// parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&";
|
||||
//
|
||||
// if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty())
|
||||
// parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&";
|
||||
// else
|
||||
// throw new Exception("Parent Folder ID parameter is null or empty");
|
||||
//
|
||||
// if(uploadType!=null && !uploadType.isEmpty())
|
||||
// parameters+=ConstantsExplorer.UPLOAD_TYPE+"="+uploadType+"&";
|
||||
// else
|
||||
// throw new Exception("UploadType parameter is null or empty");
|
||||
//
|
||||
// parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite;
|
||||
//
|
||||
// GWT.log("Encoded parameters are: "+parameters);
|
||||
//
|
||||
//// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters;
|
||||
// RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE);
|
||||
// requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
//
|
||||
// try {
|
||||
//
|
||||
// requestBuilder.sendRequest(parameters, new RequestCallback() {
|
||||
//
|
||||
// @Override
|
||||
// public void onResponseReceived(Request request, Response response) {
|
||||
//
|
||||
//// int status = response.getStatusCode();
|
||||
//
|
||||
// //expected <pre>200:Upload complete</pre>
|
||||
// /*we strip tags added by webserver,
|
||||
// *
|
||||
// * Massi fix because webkit returns
|
||||
// * <pre style="word-wrap: break-word; white-space: pre-wrap;">OK:File france_flag.png(0) imported correctly in /Workspace</pre>
|
||||
// *
|
||||
// * TODO: recall it next time
|
||||
// */
|
||||
// //String strippedResult = result.replace("<pre>", "").replace("</pre>", ""); //this won't work for webkit
|
||||
// //replaced by new HTML(result).getText()
|
||||
// String strippedResult = new HTML(response.getText()).getText();
|
||||
//
|
||||
// final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
|
||||
//
|
||||
// switch (resultMessage.getStatus()) {
|
||||
// case ERROR:
|
||||
// GWT.log("Error during upload: "+resultMessage.getMessage());
|
||||
// fileUploaderDlg.showRegisteringResult(false, resultMessage.getMessage());
|
||||
// break;
|
||||
// case UNKNOWN:
|
||||
// GWT.log("Error during upload: "+resultMessage.getMessage());
|
||||
// fileUploaderDlg.showRegisteringResult(false, "Error during upload: "+resultMessage.getMessage());
|
||||
// break;
|
||||
// case WARN: {
|
||||
// GWT.log("Upload completed with warnings: "+resultMessage.getMessage());
|
||||
// fileUploaderDlg.showRegisteringResult(false, "Upload completed with warnings: "+resultMessage.getMessage());
|
||||
// break;
|
||||
// }
|
||||
// case OK: {
|
||||
// Timer t = new Timer() {
|
||||
// public void run() {
|
||||
// AppControllerExplorer.getEventBus().fireEvent(new CompletedFileUploadEvent(parent, null));
|
||||
// fileUploaderDlg.showRegisteringResult(true);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// t.schedule(250);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Request request, Throwable exception) {
|
||||
// fileUploaderDlg.showRegisteringResult(false);
|
||||
// return;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// } catch (RequestException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void setOverwrite(){
|
||||
// overwrite = true;
|
||||
// }
|
||||
//
|
||||
// public String getFileName() {
|
||||
// return fileName;
|
||||
// }
|
||||
//
|
||||
// public void setFileName(String fileName) {
|
||||
// this.fileName = fileName;
|
||||
// }
|
||||
//}
|
||||
//
|
@ -1,185 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.util;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
|
||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent;
|
||||
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService;
|
||||
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceServiceAsync;
|
||||
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
|
||||
import org.realityforge.gwt.websockets.client.WebSocket;
|
||||
import org.realityforge.gwt.websockets.client.WebSocketListener;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.Icon;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.typedarrays.shared.ArrayBuffer;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HasAlignment;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
public class FolderDownloadDialog extends GCubeDialog implements WebSocketListener {
|
||||
private final GWTWorkspaceServiceAsync rpcWorkspaceService = (GWTWorkspaceServiceAsync) GWT.create(GWTWorkspaceService.class);
|
||||
|
||||
public static final int WIDTH = 300;
|
||||
public static final int HEIGHT = 50;
|
||||
|
||||
private final WebSocket webSocket = WebSocket.newWebSocketIfSupported();
|
||||
private final String username;
|
||||
private VerticalPanel topPanel = new VerticalPanel();
|
||||
private Icon loading = new Icon();
|
||||
Button close = new Button("Cancel Download");
|
||||
private HTML toShow = new HTML("Locating folder, please wait ...");
|
||||
private String webSocketURL;
|
||||
public FolderDownloadDialog(final FileDownloadEvent folder2Download, String username) {
|
||||
this.webSocket.setListener( this );
|
||||
this.username = username;
|
||||
setText("Preparing folder download");
|
||||
|
||||
toShow.getElement().getStyle().setFontSize(14, Unit.PX);
|
||||
loading.setSpin(true);
|
||||
loading.setType(IconType.ROTATE_RIGHT);
|
||||
|
||||
topPanel.add(toShow);
|
||||
topPanel.add(loading);
|
||||
topPanel.setPixelSize(WIDTH, HEIGHT);
|
||||
|
||||
|
||||
VerticalPanel bPanel = new VerticalPanel();
|
||||
bPanel.setWidth(WIDTH+"px");
|
||||
bPanel.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT);
|
||||
bPanel.add(close);
|
||||
close.addClickHandler(new ClickHandler() {
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
hide();
|
||||
}
|
||||
});
|
||||
topPanel.add(bPanel);
|
||||
add(topPanel);
|
||||
|
||||
rpcWorkspaceService.getServletContextPath(Window.Location.getProtocol(), new AsyncCallback<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(String servletContextPath) {
|
||||
webSocketURL = getWebSocketURL(servletContextPath);
|
||||
startZipping(webSocketURL, folder2Download.getItemIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loading.setIcon(IconType.EXCLAMATION_SIGN);
|
||||
loading.setSpin(false);
|
||||
toShow.setText("Error trying contact the server, please refresh this page and retry");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean startZipping(String webSocketURL, final String folderIdToZip) {
|
||||
if ( null == webSocket ) {
|
||||
Window.alert( "WebSocket not available!" );
|
||||
}
|
||||
|
||||
webSocket.connect( webSocketURL );
|
||||
//allow some timet to connect
|
||||
Timer t = new Timer() {
|
||||
@Override
|
||||
public void run() {
|
||||
webSocket.send(ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_DO_ZIP+":"+folderIdToZip+":"+username);
|
||||
}
|
||||
};
|
||||
t.schedule(2000);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private String getWebSocketURL(String servletContextPath) {
|
||||
String moduleBaseURL = servletContextPath;
|
||||
return moduleBaseURL.replaceFirst( "http", "ws" ) + "/" + ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_SERVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(WebSocket webSocket) { }
|
||||
|
||||
@Override
|
||||
public void onClose(WebSocket webSocket, boolean wasClean, int code, String reason) { }
|
||||
|
||||
@Override
|
||||
public void onMessage( @Nonnull final WebSocket webSocket, @Nonnull final String textData ) {
|
||||
switch (textData) {
|
||||
case ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_ZIPPING:
|
||||
toShow.setText("Compressing folder, this could take some time ...");
|
||||
break;
|
||||
case ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_ERROR_NOT_FOUND:
|
||||
toShow.setText("Could not locate the folder on server, please report this issue");
|
||||
loading.setIcon(IconType.EXCLAMATION_SIGN);
|
||||
loading.setSpin(false);
|
||||
webSocket.close();
|
||||
break;
|
||||
case ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_ERROR_DURING_COMPRESSION:
|
||||
toShow.setText("An error occurred while compressing this folder, please report this issue");
|
||||
loading.setIcon(IconType.EXCLAMATION_SIGN);
|
||||
loading.setSpin(false);
|
||||
webSocket.close();
|
||||
break;
|
||||
case ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_ERROR_NOT_A_FOLDER:
|
||||
toShow.setText("An error occurred, the folderId is not a valid folder, please report this issue");
|
||||
loading.setIcon(IconType.EXCLAMATION_SIGN);
|
||||
loading.setSpin(false);
|
||||
webSocket.close();
|
||||
break;
|
||||
case ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_ERROR_SESSION_EXPIRED:
|
||||
toShow.setText("It seems your session expired, please refresh the page and try again");
|
||||
loading.setIcon(IconType.EXCLAMATION_SIGN);
|
||||
loading.setSpin(false);
|
||||
webSocket.close();
|
||||
break;
|
||||
default:
|
||||
//the thread zipping has finished, is sending the zipped filepath on the server
|
||||
toShow.setHTML("Compressing folder success, <a title=\""+textData+"\" href=\""+textData+"\">click here</a> to download");
|
||||
loading.setIcon(IconType.OK_SIGN);
|
||||
loading.setSpin(false);
|
||||
close.setText("Close");
|
||||
this.setModal(false);
|
||||
webSocket.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage( @Nonnull final WebSocket webSocket, @Nonnull final ArrayBuffer data ) {}
|
||||
|
||||
|
||||
@Override
|
||||
public void onError(WebSocket webSocket) {
|
||||
toShow.setText("Error contacting the server socket, please refresh this page and retry");
|
||||
}
|
||||
|
||||
public AsyncCallback<WindowOpenParameter> downloadHandlerCallback = new AsyncCallback<WindowOpenParameter>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(WindowOpenParameter windowOpenParam) {
|
||||
String params = "?"+windowOpenParam.getParameters();
|
||||
|
||||
if(params.length()>1)
|
||||
params+="&";
|
||||
|
||||
params+=ConstantsExplorer.REDIRECTONERROR+"="+windowOpenParam.isRedirectOnError();
|
||||
|
||||
windowOpenParam.getBrowserWindow().setUrl(ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_SERVLET+params);
|
||||
}
|
||||
};
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package org.gcube.portlets.user.workspace.client.view.tree;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CutCopyAndPaste {
|
||||
|
||||
private static List<String> idsFilesModel = null;
|
||||
|
||||
public enum OperationType {CUT, COPY};
|
||||
|
||||
private static OperationType operationType;
|
||||
|
||||
public static void copy(List<String> idsFileModel, OperationType operationType){
|
||||
CutCopyAndPaste.idsFilesModel = idsFileModel;
|
||||
CutCopyAndPaste.operationType = operationType;
|
||||
}
|
||||
|
||||
public static List<String> getCopiedIdsFilesModel() {
|
||||
return idsFilesModel;
|
||||
}
|
||||
|
||||
public static void setCopiedIdsFileModels(List<String> idsFileModel) {
|
||||
CutCopyAndPaste.idsFilesModel = idsFileModel;
|
||||
}
|
||||
|
||||
public static OperationType getOperationType() {
|
||||
return operationType;
|
||||
}
|
||||
|
||||
public static void setOperationType(OperationType operationType) {
|
||||
CutCopyAndPaste.operationType = operationType;
|
||||
}
|
||||
|
||||
}
|
@ -1,279 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
|
||||
import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty;
|
||||
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
|
||||
|
||||
/**
|
||||
* The Class DownloadFolderServlet.
|
||||
*
|
||||
* @author M. Assante, CNR-ISTI
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DownloadFolderServlet extends HttpServlet{
|
||||
|
||||
|
||||
protected static Logger logger = Logger.getLogger(DownloadFolderServlet.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
logger.trace("Workspace DownloadFolderServlet ready.");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
boolean urlRedirectOnError = req.getParameter(ConstantsExplorer.REDIRECTONERROR)==null?false:req.getParameter(ConstantsExplorer.REDIRECTONERROR).equals("true");
|
||||
|
||||
//REMOVED BECAUSE IT DOES NOT WORK. MUST BE CHECK USERID AND CONTEXTID
|
||||
// try {
|
||||
// if(WsUtil.isSessionExpired(req))
|
||||
// throw new SessionExpiredException();
|
||||
// } catch (Exception e) {
|
||||
//
|
||||
// if (e instanceof SessionExpiredException){
|
||||
// sendErrorForStatus(resp, HttpServletResponse.SC_UNAUTHORIZED +": Session expired", HttpServletResponse.SC_UNAUTHORIZED);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
String fileRelativePath = req.getParameter("filepath");
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
String pathToFile = tmpDir + File.separator + fileRelativePath;
|
||||
try {
|
||||
logger.debug("looking for File in " + pathToFile);
|
||||
File tmpZip = new File(pathToFile);
|
||||
logger.debug("File instanciated " + pathToFile);
|
||||
|
||||
resp.setHeader( "Content-Disposition", "attachment; filename=\"" + tmpZip.getName() + ".zip\"" );
|
||||
resp.setContentType("application/zip");
|
||||
resp = setContentLength(resp, tmpZip.length());
|
||||
OutputStream out = resp.getOutputStream();
|
||||
|
||||
FileInputStream fileTmpZip = new FileInputStream(tmpZip);
|
||||
IOUtils.copy(fileTmpZip, resp.getOutputStream());
|
||||
fileTmpZip.close();
|
||||
|
||||
out.close();
|
||||
tmpZip.deleteOnExit();
|
||||
return;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error during folder compression "+pathToFile,e);
|
||||
handleError(urlRedirectOnError, req, resp, fileRelativePath, HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Error during folder compression: "+e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to manage HttpServletResponse content length also to big data.
|
||||
*
|
||||
* @param resp the resp
|
||||
* @param length the length
|
||||
* @return the http servlet response
|
||||
*/
|
||||
protected HttpServletResponse setContentLength(HttpServletResponse resp, long length){
|
||||
try{
|
||||
if (length <= Integer.MAX_VALUE)
|
||||
resp.setContentLength((int)length);
|
||||
else
|
||||
resp.addHeader("Content-Length", Long.toString(length));
|
||||
}catch(Exception e){
|
||||
//silent
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle error.
|
||||
*
|
||||
* @param urlRedirectOnError the url redirect on error
|
||||
* @param req the req
|
||||
* @param resp the resp
|
||||
* @param itemId the item id
|
||||
* @param message the message
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void handleError(boolean urlRedirectOnError, HttpServletRequest req, HttpServletResponse resp, String itemId, String message) throws IOException{
|
||||
|
||||
logger.warn("Handle error occurred: "+message);
|
||||
logger.trace("urlRedirectOnError is active: "+urlRedirectOnError);
|
||||
if(urlRedirectOnError){
|
||||
urlRedirect(req, resp, itemId);
|
||||
}else
|
||||
sendError(resp,message);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send error.
|
||||
*
|
||||
* @param response the response
|
||||
* @param message the message
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendError(HttpServletResponse response, String message) throws IOException
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
|
||||
logger.trace("error message: "+resultMessage);
|
||||
logger.trace("writing response...");
|
||||
StringReader sr = new StringReader(resultMessage.toString());
|
||||
IOUtils.copy(sr, response.getOutputStream());
|
||||
|
||||
logger.trace("response writed");
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send error for status.
|
||||
*
|
||||
* @param response the response
|
||||
* @param message the message
|
||||
* @param status the status
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendErrorForStatus(HttpServletResponse response, String message, int status) throws IOException
|
||||
{
|
||||
response.setStatus(status);
|
||||
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
|
||||
logger.trace("error message: "+resultMessage);
|
||||
logger.trace("writing response...");
|
||||
StringReader sr = new StringReader(resultMessage.toString());
|
||||
IOUtils.copy(sr, response.getOutputStream());
|
||||
|
||||
logger.trace("response written");
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message.
|
||||
*
|
||||
* @param response the response
|
||||
* @param message the message
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendMessage(HttpServletResponse response, String message) throws IOException
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_ACCEPTED);
|
||||
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
|
||||
response.getWriter().write(resultMessage.toString());
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message resource available.
|
||||
*
|
||||
* @param response the response
|
||||
* @param message the message
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendMessageResourceAvailable(HttpServletResponse response, String message) throws IOException
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_ACCEPTED);
|
||||
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
|
||||
response.getWriter().write(resultMessage.toString());
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send warn message.
|
||||
*
|
||||
* @param response the response
|
||||
* @param message the message
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException
|
||||
{
|
||||
response.setStatus(HttpServletResponse.SC_ACCEPTED);
|
||||
HandlerResultMessage resultMessage = HandlerResultMessage.warnResult(message);
|
||||
response.getWriter().write(resultMessage.toString());
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Url redirect.
|
||||
*
|
||||
* @param req the req
|
||||
* @param response the response
|
||||
* @param fakePath the fake path
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void urlRedirect(HttpServletRequest req, HttpServletResponse response, String fakePath) throws IOException {
|
||||
|
||||
String requestUrl = getRequestURL(req) +fakePath;
|
||||
logger.trace("Url redirect on: "+requestUrl);
|
||||
// System.out.println("Url redirect on: "+requestUrl);
|
||||
response.sendRedirect(response.encodeRedirectURL(requestUrl));
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request url.
|
||||
*
|
||||
* @param req the req
|
||||
* @return the request url
|
||||
*/
|
||||
public static String getRequestURL(HttpServletRequest req) {
|
||||
|
||||
String scheme = req.getScheme(); // http
|
||||
String serverName = req.getServerName(); // hostname.com
|
||||
int serverPort = req.getServerPort(); // 80
|
||||
String contextPath = req.getContextPath(); // /mywebapp
|
||||
|
||||
|
||||
// Reconstruct original requesting URL
|
||||
StringBuffer url = new StringBuffer();
|
||||
url.append(scheme).append("://").append(serverName);
|
||||
|
||||
if (serverPort != 80 && serverPort != 443) {
|
||||
url.append(":").append(serverPort);
|
||||
}
|
||||
|
||||
logger.trace("server: "+url);
|
||||
logger.trace("omitted contextPath: "+contextPath);
|
||||
|
||||
|
||||
PortalUrlGroupGatewayProperty p = new PortalUrlGroupGatewayProperty();
|
||||
|
||||
int lenght = p.getPath().length();
|
||||
|
||||
String groupgatewaypath = "/";
|
||||
|
||||
if(lenght>1){
|
||||
|
||||
String lastChar = p.getPath().substring(lenght-1, lenght-1);
|
||||
|
||||
groupgatewaypath+= lastChar.compareTo("/")!=0?p.getPath()+"/":p.getPath();
|
||||
}
|
||||
|
||||
url.append(groupgatewaypath);
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,67 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications.tostoragehub;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
|
||||
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class NotificationMapper.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 2, 2018
|
||||
*/
|
||||
public class NotificationMapperToStorageHub {
|
||||
|
||||
protected static Logger logger = Logger.getLogger(NotificationMapperToStorageHub.class);
|
||||
|
||||
|
||||
/**
|
||||
* To social shared folder.
|
||||
*
|
||||
* @param sharedFolder the shared folder
|
||||
* @return the social shared folder
|
||||
*/
|
||||
public static SocialSharedFolder toSocialSharedFolder(WorkspaceSharedFolder sharedFolder){
|
||||
|
||||
return new SocialSharedFolder(sharedFolder.getId(),
|
||||
sharedFolder.getName(),
|
||||
sharedFolder.getTitle(),
|
||||
sharedFolder.getName(),
|
||||
sharedFolder.getPath(),
|
||||
sharedFolder.getParentId(),
|
||||
sharedFolder.isVreFolder());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To social item.
|
||||
*
|
||||
* @param workspace the workspace
|
||||
* @param item the item
|
||||
* @return the social file item
|
||||
*/
|
||||
public static SocialFileItem toSocialItem(org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, WorkspaceItem item){
|
||||
|
||||
WorkspaceItem theParentFolder = null;
|
||||
try {
|
||||
theParentFolder = workspace.getItem(item.getParentId());
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("Impossible the item using the parent id: "+item.getParentId());
|
||||
}
|
||||
//
|
||||
SocialSharedFolder parent = null;
|
||||
if(theParentFolder!=null && theParentFolder instanceof WorkspaceSharedFolder)
|
||||
parent = toSocialSharedFolder((WorkspaceSharedFolder) theParentFolder);
|
||||
//
|
||||
return new SocialFileItem(item.getId(), item.getName(), item.getTitle(), item.getPath(), parent);
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications.tostoragehub;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.storagehub.model.types.WorkspaceItemType;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
|
||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||
|
||||
|
||||
/**
|
||||
* The Class NotificationFromStorageHub.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 2, 2018
|
||||
*/
|
||||
public class NotificationStorageHubUtil {
|
||||
|
||||
private static Logger logger = Logger.getLogger(NotificationStorageHubUtil.class);
|
||||
|
||||
|
||||
/**
|
||||
* Check notify add item to share.
|
||||
*
|
||||
* @param workspaceItem the workspace item
|
||||
* @param sourceRootSharedFolderId the source shared id
|
||||
* @param parentFolderItem the parent folder item
|
||||
* @param workspace the workspace
|
||||
* @param np the NotificationsProducerToStorageHub
|
||||
*/
|
||||
public static void checkNotifyAddItemToShare(final WorkspaceItem workspaceItem, final String sourceRootSharedFolderId, final WorkspaceFolder parentFolderItem, org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, NotificationsProducerToStorageHub np) {
|
||||
|
||||
logger.trace("checkNotifyAddItemToShare");
|
||||
|
||||
if(parentFolderItem!=null){
|
||||
|
||||
try{
|
||||
//if folder destination is shared folder
|
||||
if(parentFolderItem.isShared()){ //Notify Added Item To Sharing?
|
||||
|
||||
WorkspaceItem rootSharedFolder = workspace.getRootSharedFolder(parentFolderItem.getId());
|
||||
logger.trace("checkNotifyAddItemToShare source item: "+workspaceItem.getName()+" sourceRootSharedFolderId: "+sourceRootSharedFolderId + " folder destination: "+parentFolderItem.getName());
|
||||
//share condition is true if source shared folder is null or not equal to destination shared folder
|
||||
boolean shareChangeCondition = sourceRootSharedFolderId==null || sourceRootSharedFolderId.compareTo(rootSharedFolder.getId())!=0;
|
||||
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
|
||||
logger.trace("shareChangeCondition add item: "+shareChangeCondition);
|
||||
|
||||
//if shareChangeCondition is true.. notifies added item to sharing
|
||||
if(shareChangeCondition){
|
||||
|
||||
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(rootSharedFolder, workspace);
|
||||
//WorkspaceItem destinationSharedFolder = workspace.getItem(rootSharedFolder.getId());
|
||||
WorkspaceItem destinationSharedFolder = rootSharedFolder;
|
||||
|
||||
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
|
||||
np.notifyAddedItemToSharing(workspace, listContacts, workspaceItem, (WorkspaceSharedFolder) destinationSharedFolder);
|
||||
logger.trace("The notifies sent correctly");
|
||||
}
|
||||
else
|
||||
logger.warn("Notifies added item: "+workspaceItem+ "to share doesn't sent because "+destinationSharedFolder+" is not istance of WorkspaceSharedFolder");
|
||||
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
logger.trace("folder destination is not shared");
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in verifyNotifyAddItemToShare ",e);
|
||||
}
|
||||
}else
|
||||
logger.warn("The notifies is failure in verifyNotifyAddItemToShare because folder destination item is null");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check notify move item from share.
|
||||
*
|
||||
* @param sourceItemIsShared the source item is shared
|
||||
* @param sourceItem the source item
|
||||
* @param sourceRootSharedFolderId the source root shared folder id
|
||||
* @param folderDestination the folder destination
|
||||
* @param workspace the workspace
|
||||
* @param np the NotificationsProducerToStorageHub
|
||||
*/
|
||||
public static void checkNotifyMoveItemFromShare(
|
||||
boolean sourceItemIsShared,
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem sourceItem,
|
||||
String sourceRootSharedFolderId,
|
||||
org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder folderDestination, org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, NotificationsProducerToStorageHub np) {
|
||||
|
||||
try{
|
||||
|
||||
String rootDestSharedFolderId = null;
|
||||
WorkspaceItem rootDestSharedFolder = null;
|
||||
|
||||
if(folderDestination.isShared()){
|
||||
rootDestSharedFolder = workspace.getRootSharedFolder(folderDestination.getId());
|
||||
rootDestSharedFolderId = rootDestSharedFolder.getId();
|
||||
}
|
||||
|
||||
boolean shareChangeCondition = false;
|
||||
|
||||
//share condition is true if source shared folder is not equal to destination shared folder
|
||||
if(rootDestSharedFolderId!=null)
|
||||
shareChangeCondition = sourceRootSharedFolderId==null?false:sourceRootSharedFolderId.compareTo(rootDestSharedFolderId)!=0;
|
||||
|
||||
logger.trace("checkNotifyMoveItemFromShare source item: "+sourceItem.getName()+" rootSharedFolderId: "+sourceRootSharedFolderId + " folder destination: "+folderDestination.getName() +" sourceItemIsShared: "+sourceItemIsShared);
|
||||
logger.trace("shareChangeCondition remove item: "+ shareChangeCondition);
|
||||
|
||||
//Notify Removed Item To Sharing?
|
||||
//if source Item is shared and folder destination is not shared or shareChangeCondition is true.. notifies removed item to sharing
|
||||
if(sourceItemIsShared && (!folderDestination.isShared() || shareChangeCondition)){
|
||||
|
||||
//get contacts
|
||||
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(rootDestSharedFolder, workspace);
|
||||
|
||||
WorkspaceItem sourceRootSharedFolder = workspace.getItem(sourceRootSharedFolderId);
|
||||
|
||||
if(sourceRootSharedFolder instanceof WorkspaceSharedFolder){
|
||||
np.notifyMovedItemToSharing(workspace, listContacts, sourceItem, (WorkspaceSharedFolder) sourceRootSharedFolder);
|
||||
logger.trace("The notifies was sent correctly");
|
||||
}else
|
||||
logger.warn("Notifies moved item: "+sourceItem+ "from share doesn't sent because "+sourceRootSharedFolder+" is not istance of WorkspaceSharedFolder");
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in checkNotifyMoveItemFromShare ",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list user shared by folder shared id.
|
||||
*
|
||||
* @param rootSharedFolder the root shared folder
|
||||
* @param workspace the workspace
|
||||
* @return the list user shared by folder shared id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static List<InfoContactModel> getListUserSharedByFolderSharedId(WorkspaceItem rootSharedFolder, org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace) throws Exception{
|
||||
|
||||
logger.debug("getListUserSharedByFolderSharedId "+ rootSharedFolder);
|
||||
|
||||
try {
|
||||
|
||||
if(isASharedFolder(rootSharedFolder)){ //JUST TO BE SURE
|
||||
|
||||
List<String> listPortalLogin = workspace.getSharedFolderMembers(rootSharedFolder.getId());
|
||||
logger.debug("StorageHub returned "+ listPortalLogin.size() + " user/s");
|
||||
|
||||
if(!WsUtil.isWithinPortal())
|
||||
return GWTWorkspaceBuilder.buildGxtInfoContactFromPortalLoginTestMode(listPortalLogin);
|
||||
|
||||
return GWTWorkspaceBuilder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
|
||||
}
|
||||
else
|
||||
logger.debug("the item with id: "+rootSharedFolder.getId()+ " is not "+WorkspaceItemType.SHARED_FOLDER);
|
||||
|
||||
return new ArrayList<InfoContactModel>();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in getListUserSharedByItemId ", e);
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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,228 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.notifications.tostoragehub;
|
||||
|
||||
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.scope.impl.ScopeBean;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder;
|
||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||
import org.gcube.portlets.user.workspace.server.util.PortalContextInfo;
|
||||
import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||
|
||||
|
||||
/**
|
||||
* The Class NotificationsProducerToStorageHub.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 5, 2018
|
||||
*/
|
||||
public class NotificationsProducerToStorageHub {
|
||||
|
||||
protected ScopeBean scope;
|
||||
|
||||
protected static Logger logger = Logger.getLogger(NotificationsProducerToStorageHub.class);
|
||||
|
||||
protected NotificationsManager notificationsMng;
|
||||
protected HttpSession httpSession;
|
||||
protected String userId;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new notifications producer.
|
||||
*
|
||||
* @param httpServletRequest the http servlet request
|
||||
*/
|
||||
public NotificationsProducerToStorageHub(HttpServletRequest httpServletRequest) {
|
||||
PortalContextInfo info = WsUtil.getPortalContext(httpServletRequest);
|
||||
this.notificationsMng = WsUtil.getNotificationManager(httpServletRequest);
|
||||
this.userId = info.getUsername();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs a new thread to notify the contacts passed in input.
|
||||
*
|
||||
* @param workspace the workspace
|
||||
* @param listContacts the list contacts
|
||||
* @param workspaceItem the workspace item
|
||||
* @param sharedFolder the shared folder
|
||||
*/
|
||||
public void notifyAddedItemToSharing(final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// printContacts(listContacts);
|
||||
logger.debug("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.debug("Sending notification to user "+infoContactModel.getLogin() +" added item [id: "+workspaceItem.getId() +"] name: "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
|
||||
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), NotificationMapperToStorageHub.toSocialItem(workspace, workspaceItem), NotificationMapperToStorageHub.toSocialSharedFolder(sharedFolder));
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyAddedItemToSharing ", e);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("notifies of added item in shared folder is completed");
|
||||
}
|
||||
|
||||
}.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notify moved item to sharing.
|
||||
*
|
||||
* @param workspace the workspace
|
||||
* @param listContacts the list contacts
|
||||
* @param workspaceItem the workspace item
|
||||
* @param sourceRootSharedFolder the shared folder
|
||||
*/
|
||||
public void notifyMovedItemToSharing(final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace, final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sourceRootSharedFolder) {
|
||||
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.debug("Sending notification remove 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.debug("Sending notification to user "+infoContactModel.getLogin() +" moved item "+workspaceItem.getName()+" in shared folder "+sourceRootSharedFolder.getName());
|
||||
boolean notify = notificationsMng.notifyMovedItem(infoContactModel.getLogin(), NotificationMapperToStorageHub.toSocialItem(workspace, workspaceItem), NotificationMapperToStorageHub.toSocialSharedFolder(sourceRootSharedFolder));
|
||||
|
||||
if(!notify){
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occurred in notifyMovedItemToSharing ", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("notifies of moved item in shared folder is completed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notify folder renamed.
|
||||
*
|
||||
* @param listSharedContact the list shared contact
|
||||
* @param folderItem the folder item
|
||||
* @param itemOldName the item old name
|
||||
* @param itemNewName the item new name
|
||||
* @param idRootSharedFolder the id root shared folder
|
||||
*/
|
||||
public void notifyFolderRenamed(final List<InfoContactModel> listSharedContact, final WorkspaceItem folderItem, final String itemOldName, final String itemNewName, final String idRootSharedFolder) {
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.trace("Send notifies shared folder was renamed is running...");
|
||||
|
||||
if(NotificationStorageHubUtil.checkIsRootFolderShared(folderItem.getId(), idRootSharedFolder)){
|
||||
logger.info("Notification not sent because the event is on root shared folder");
|
||||
return;
|
||||
}
|
||||
|
||||
for (InfoContactModel infoContactModel : listSharedContact) {
|
||||
try{
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.debug("Sending notification share folder "+itemOldName+" was renamed as " + itemNewName+ "for user "+infoContactModel.getLogin());
|
||||
boolean notify = notificationsMng.notifyFolderRenaming(infoContactModel.getLogin(), itemOldName, itemNewName, idRootSharedFolder);
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyFolderRenamed ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies share folder was renamed is completed");
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Notify item renamed.
|
||||
*
|
||||
* @param listSharedContact the list shared contact
|
||||
* @param previousName the previous name
|
||||
* @param item the item
|
||||
* @param sharedFolder the shared folder
|
||||
* @param workspace the workspace
|
||||
*/
|
||||
public void notifyItemRenamed(final List<InfoContactModel> listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceSharedFolder sharedFolder, final org.gcube.common.storagehubwrapper.server.tohl.Workspace workspace) {
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.trace("Send notifies shared item was updated is running...");
|
||||
|
||||
for (InfoContactModel infoContactModel : listSharedContact) {
|
||||
try{
|
||||
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
|
||||
if(infoContactModel.getLogin().compareTo(userId)!=0){
|
||||
|
||||
logger.debug("Sending notification to user "+infoContactModel.getLogin() + " updated item "+item.getName());
|
||||
boolean notify = notificationsMng.notifyItemRenaming(infoContactModel.getLogin(), previousName, NotificationMapperToStorageHub.toSocialItem(workspace, item), NotificationMapperToStorageHub.toSocialSharedFolder(sharedFolder));
|
||||
|
||||
if(!notify)
|
||||
logger.error("An error occured when notify user: "+infoContactModel.getLogin());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("An error occured in notifyItemUpdated ", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace("notifies shared item was updated is completed");
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,298 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.tostoragehub;
|
||||
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceSharedFolder;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder;
|
||||
import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FolderGridModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FolderModel;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
import org.gcube.portlets.user.workspace.server.util.UserUtil;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class StorageHubToWorkpaceConveter.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Sep 20, 2018
|
||||
*/
|
||||
public class ObjectStorageHubToWorkpaceMapper {
|
||||
|
||||
|
||||
protected static Logger logger = Logger.getLogger(ObjectStorageHubToWorkpaceMapper.class);
|
||||
|
||||
/**
|
||||
* To root folder.
|
||||
*
|
||||
* @param folder the folder
|
||||
* @return the folder model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public static FolderModel toRootFolder(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder folder) throws InternalErrorException{
|
||||
|
||||
if(folder==null)
|
||||
return null;
|
||||
|
||||
boolean isVreFolder = false;
|
||||
boolean isPublicFolder = false; //TODO
|
||||
if(folder.isShared()){
|
||||
WorkspaceSharedFolder sharedFolder = (WorkspaceSharedFolder) folder;
|
||||
isVreFolder = sharedFolder.isVreFolder();
|
||||
}
|
||||
|
||||
// FolderModel root = new FolderModel(workspaceRoot.getId(),workspaceRoot.getName(),null, true, workspaceRoot.isShared(), false, workspaceRoot.isPublic());
|
||||
// root.setIsRoot(true);
|
||||
|
||||
FolderModel theFolder = new FolderModel(folder.getId(), folder.getName(), null, folder.isFolder(), folder.isShared(), isVreFolder, isPublicFolder);
|
||||
theFolder.setIsRoot(folder.isRoot());
|
||||
return theFolder;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To tree file model item.
|
||||
*
|
||||
* @param wrappedItem the wrapped item
|
||||
* @param parentFolderModel the parent folder model
|
||||
* @param isParentShared the is parent shared
|
||||
* @return the file model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public static FileModel toTreeFileModelItem(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wrappedItem, FileModel parentFolderModel, boolean isParentShared) throws InternalErrorException{
|
||||
|
||||
FileModel fileModel = null;
|
||||
//boolean isPublic = false;
|
||||
|
||||
switch (wrappedItem.getType()) {
|
||||
|
||||
case FOLDER:
|
||||
boolean isPublicFolder = ((org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wrappedItem).isPublicFolder(); //TODO
|
||||
fileModel = new FolderModel(wrappedItem.getId(), wrappedItem.getName(), parentFolderModel, true, false, false, isPublicFolder);
|
||||
if(isPublicFolder)
|
||||
fileModel.setType(GXTFolderItemTypeEnum.FOLDER_PUBLIC.getLabel());
|
||||
else
|
||||
fileModel.setType(GXTFolderItemTypeEnum.FOLDER.getLabel());
|
||||
|
||||
fileModel.setType(GXTFolderItemTypeEnum.FOLDER.getLabel());
|
||||
fileModel.setShareable(true);
|
||||
fileModel.setDescription(wrappedItem.getDescription());
|
||||
break;
|
||||
|
||||
case FILE_ITEM:
|
||||
fileModel = new FileModel(wrappedItem.getId(), wrappedItem.getName(), parentFolderModel, false, false);
|
||||
FileItem folderItem = (FileItem) wrappedItem;
|
||||
fileModel = setFolderItemType(fileModel, folderItem);
|
||||
fileModel.setShareable(true);
|
||||
break;
|
||||
|
||||
case VRE_FOLDER:
|
||||
fileModel = new FolderModel(wrappedItem.getId(), wrappedItem.getName(), parentFolderModel, true, true, true, false);
|
||||
fileModel.setType(GXTFolderItemTypeEnum.FOLDER_SHARED.toString());
|
||||
fileModel.setShareable(true);
|
||||
fileModel.setDescription(wrappedItem.getDescription());
|
||||
break;
|
||||
case SHARED_FOLDER:
|
||||
//WorkspaceSharedFolder shared = (WorkspaceSharedFolder) wrappedItem;
|
||||
boolean isPublicDir = ((org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wrappedItem).isPublicFolder(); //TODO
|
||||
//isPublic = ((WorkspaceFolder) shared).isPublic(); //TODO isPublic
|
||||
//OLD HL
|
||||
//String name = shared.isVreFolder()?shared.getDisplayName():item.getName();
|
||||
fileModel = new FolderModel(wrappedItem.getId(), wrappedItem.getName(), parentFolderModel, true, true, false, isPublicDir);
|
||||
if(isPublicDir)
|
||||
fileModel.setType(GXTFolderItemTypeEnum.FOLDER_SHARED_PUBLIC.toString());
|
||||
else
|
||||
fileModel.setType(GXTFolderItemTypeEnum.FOLDER_SHARED.toString());
|
||||
|
||||
fileModel.setShareable(true);
|
||||
fileModel.setDescription(wrappedItem.getDescription());
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.error("ALERT Conversion RETURNING null for item "+wrappedItem.getName());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
//SET SHARE POLICY
|
||||
if(parentFolderModel!=null && parentFolderModel.isShared()){
|
||||
fileModel.setShared(true);
|
||||
fileModel.setShareable(false); //UPDATED TO CHANGE PERMISSIONS TO SHARED SUBFOLDERS
|
||||
}else if(parentFolderModel==null && wrappedItem.isShared()){ //ADDED TO FIX #1808
|
||||
fileModel.setShared(true);
|
||||
if(wrappedItem.getParentId()!=null && isParentShared)
|
||||
fileModel.setShareable(false);
|
||||
}
|
||||
|
||||
//setSynchedThreddsStateFor(fileModel);
|
||||
fileModel.setIsRoot(wrappedItem.isRoot());
|
||||
logger.trace("Returning converted tree item: "+fileModel);
|
||||
return fileModel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* To grid file model item.
|
||||
*
|
||||
* @param wrappedItem the wrapped item
|
||||
* @param parentFolderModel the parent folder model
|
||||
* @param isParentShared the is parent shared
|
||||
* @param loggedUser the logged user
|
||||
* @return the file grid model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public static FileGridModel toGridFileModelItem(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wrappedItem, FileModel parentFolderModel, GCubeUser loggedUser) throws InternalErrorException{
|
||||
|
||||
FileGridModel fileGridModel = null;
|
||||
|
||||
//logger.debug("toGridFileModelItem: "+wrappedItem);
|
||||
//logger.debug("toGridFileModelItem getType: "+wrappedItem.getType());
|
||||
|
||||
switch (wrappedItem.getType()) {
|
||||
|
||||
case FOLDER:
|
||||
boolean isPublicFolder = ((org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wrappedItem).isPublicFolder(); //TODO
|
||||
fileGridModel = new FolderGridModel(wrappedItem.getId(), wrappedItem.getName(), GWTWorkspaceBuilder.toDate(wrappedItem.getLastModificationTime()), parentFolderModel, -1, true, false,false, isPublicFolder);
|
||||
if(isPublicFolder)
|
||||
fileGridModel.setType(GXTFolderItemTypeEnum.FOLDER_PUBLIC.getLabel().toString());
|
||||
else
|
||||
fileGridModel.setType(GXTFolderItemTypeEnum.FOLDER.getLabel().toString());
|
||||
|
||||
fileGridModel.setShortcutCategory(GXTCategorySmartFolder.SMF_FOLDERS);
|
||||
fileGridModel.setShareable(true);
|
||||
fileGridModel.setDescription(wrappedItem.getDescription());
|
||||
break;
|
||||
|
||||
case FILE_ITEM:
|
||||
FileItem fileItem = (FileItem) wrappedItem;
|
||||
fileGridModel = new FileGridModel(fileItem.getId(),
|
||||
fileItem.getName(),
|
||||
GWTWorkspaceBuilder.
|
||||
toDate(fileItem.getLastModificationTime()),
|
||||
parentFolderModel,
|
||||
fileItem.getSize()==null?0:fileItem.getSize(),
|
||||
false,
|
||||
false);
|
||||
fileGridModel = (FileGridModel) setFolderItemType(fileGridModel, fileItem);
|
||||
break;
|
||||
|
||||
case VRE_FOLDER:
|
||||
fileGridModel = new FolderGridModel(wrappedItem.getId(), wrappedItem.getName(), GWTWorkspaceBuilder.toDate(wrappedItem.getLastModificationTime()), parentFolderModel, -1, true, false,true, false);
|
||||
fileGridModel.setType(GXTFolderItemTypeEnum.FOLDER_SHARED.toString());
|
||||
fileGridModel.setShareable(true);
|
||||
fileGridModel.setDescription(wrappedItem.getDescription());
|
||||
break;
|
||||
|
||||
case SHARED_FOLDER:
|
||||
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) wrappedItem;
|
||||
boolean isPublicDir = ((org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder) wrappedItem).isPublicFolder(); //TODO
|
||||
//String name = shared.isVreFolder()?shared.getTitle():shared.getName();
|
||||
fileGridModel = new FolderGridModel(wrappedItem.getId(), wrappedItem.getName(), GWTWorkspaceBuilder.toDate(wrappedItem.getLastModificationTime()), parentFolderModel, -1, true, true, shared.isVreFolder(), isPublicDir);
|
||||
|
||||
if(isPublicDir)
|
||||
fileGridModel.setType(GXTFolderItemTypeEnum.FOLDER_SHARED_PUBLIC.getLabel().toString());
|
||||
else
|
||||
fileGridModel.setType(GXTFolderItemTypeEnum.FOLDER_SHARED.getLabel().toString());
|
||||
|
||||
fileGridModel.setShortcutCategory(GXTCategorySmartFolder.SMF_SHARED_FOLDERS);
|
||||
fileGridModel.setShareable(true);
|
||||
fileGridModel.setDescription(wrappedItem.getDescription());
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.error("gxt conversion return null for item "+wrappedItem.getName());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(parentFolderModel!=null && parentFolderModel.isShared()){
|
||||
fileGridModel.setShared(true);
|
||||
fileGridModel.setShareable(false); //UPDATED TO CHANGE PERMISSIONS TO SHARED SUBFOLDERS
|
||||
}
|
||||
|
||||
//OWNER
|
||||
if(wrappedItem.isShared()){ //IT IS READ FROM HL ONLY IF THE ITEM IS SHARED
|
||||
fileGridModel.setShared(true); //NOT REMOVE IT IS IMPORTAT SEE #1459
|
||||
String ownerUsername = wrappedItem.getOwner();
|
||||
if(ownerUsername!=null){
|
||||
// System.out.println("++++reading owner");
|
||||
//String portalLogin = owner.getPortalLogin();
|
||||
fileGridModel.setOwnerFullName(UserUtil.getUserFullName(ownerUsername));
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(loggedUser!=null)
|
||||
// fileGridModel.setOwner(new InfoContactModel(userLogged.getId(), userLogged.getLogin(), userLogged.getName()));
|
||||
fileGridModel.setOwnerFullName(loggedUser.getFullname());
|
||||
}
|
||||
|
||||
logger.trace("Returning converted grid item: "+fileGridModel);
|
||||
return fileGridModel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the folder item type.
|
||||
*
|
||||
* @param fileModel the file model
|
||||
* @param wrappedFileItem the worspace folder item
|
||||
* @return the file model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public static FileModel setFolderItemType(FileModel fileModel, FileItem wrappedFileItem) throws InternalErrorException{
|
||||
|
||||
fileModel.setType(wrappedFileItem.getMimeType());
|
||||
|
||||
//logger.debug("WrappedItem: "+wrappedFileItem);
|
||||
//logger.debug("FolderItemType: "+wrappedFileItem.getFileItemType());
|
||||
|
||||
switch(wrappedFileItem.getFileItemType()){
|
||||
|
||||
case PDF_DOCUMENT:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.EXTERNAL_PDF_FILE);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_DOCUMENTS);
|
||||
// PDFFileItem extFile = (PDFFileItem) wrappedFileItem;
|
||||
break;
|
||||
case IMAGE_DOCUMENT:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.EXTERNAL_IMAGE);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_IMAGES);
|
||||
break;
|
||||
case DOCUMENT:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.EXTERNAL_FILE);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_DOCUMENTS);
|
||||
// Document doc = (Document) worspaceFolderItem;
|
||||
break;
|
||||
case URL_DOCUMENT:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.EXTERNAL_URL);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_DOCUMENTS);
|
||||
break;
|
||||
case METADATA:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.METADATA);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_DOCUMENTS);
|
||||
break;
|
||||
case GCUBE_ITEM:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.GCUBE_ITEM);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_GCUBE_ITEMS);
|
||||
break;
|
||||
default:
|
||||
fileModel.setFolderItemType(GXTFolderItemTypeEnum.UNKNOWN_TYPE);
|
||||
fileModel.setShortcutCategory(GXTCategorySmartFolder.SMF_UNKNOWN);
|
||||
fileModel.setType(GXTFolderItemTypeEnum.UNKNOWN_TYPE.toString());
|
||||
break;
|
||||
}
|
||||
|
||||
return fileModel;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,274 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.server.tostoragehub;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion;
|
||||
import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap;
|
||||
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status;
|
||||
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileTrashedModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileVersionModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.FolderModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
|
||||
import org.gcube.portlets.user.workspace.server.util.UserUtil;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class StorageHubToWorkpaceConverter.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Sep 20, 2018
|
||||
*/
|
||||
public class StorageHubToWorkpaceConverter implements Serializable{
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6935303928299846569L;
|
||||
|
||||
protected static Logger logger = Logger.getLogger(StorageHubToWorkpaceConverter.class);
|
||||
private String scope;
|
||||
private GCubeUser loggedUser;
|
||||
private String workspaceRootId;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new storage hub to workpace converter.
|
||||
*/
|
||||
public StorageHubToWorkpaceConverter() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To version history.
|
||||
*
|
||||
* @param versions the versions
|
||||
* @return the list
|
||||
*/
|
||||
public List<FileVersionModel> toVersionHistory(List<WorkspaceFileVersion> versions){
|
||||
|
||||
if(versions==null || versions.isEmpty()){
|
||||
logger.warn("Version history is null or empty!");
|
||||
return new ArrayList<FileVersionModel>();
|
||||
}
|
||||
|
||||
List<FileVersionModel> listVersions = new ArrayList<FileVersionModel>(versions.size());
|
||||
for (WorkspaceFileVersion wsVersion : versions) {
|
||||
String user = UserUtil.getUserFullName(wsVersion.getOwner());
|
||||
FileVersionModel file = new FileVersionModel(wsVersion.getId(), wsVersion.getName(), wsVersion.getRemotePath(), user, GWTWorkspaceBuilder.toDate(wsVersion.getCreated()), wsVersion.isCurrentVersion());
|
||||
listVersions.add(file);
|
||||
}
|
||||
return listVersions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new storage hub to workpace converter.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param loggedUser the logged user
|
||||
*/
|
||||
public StorageHubToWorkpaceConverter(String scope, GCubeUser loggedUser) {
|
||||
this.scope = scope;
|
||||
this.loggedUser = loggedUser;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To root folder.
|
||||
*
|
||||
* @param folder the folder
|
||||
* @return the folder model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public FolderModel toRootFolder(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceFolder folder) throws InternalErrorException{
|
||||
|
||||
return ObjectStorageHubToWorkpaceMapper.toRootFolder(folder);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To tree file model item.
|
||||
*
|
||||
* @param wrappedItem the wrapped item
|
||||
* @param parentFolderModel the parent folder model
|
||||
* @param isParentShared the is parent shared
|
||||
* @return the file model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public FileModel toTreeFileModel(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wrappedItem, FileModel parentFolderModel, Boolean isParentShared) throws InternalErrorException{
|
||||
|
||||
FileModel fileModel = ObjectStorageHubToWorkpaceMapper.toTreeFileModelItem(wrappedItem, parentFolderModel, isParentShared);
|
||||
return setSynchedThreddsStateFor(fileModel, wrappedItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* To grid file model.
|
||||
*
|
||||
* @param wrappedItem the wrapped item
|
||||
* @param parentFolderModel the parent folder model
|
||||
* @return the file grid model
|
||||
* @throws InternalErrorException the internal error exception
|
||||
*/
|
||||
public FileGridModel toGridFileModel(org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem wrappedItem, FileModel parentFolderModel) throws InternalErrorException{
|
||||
|
||||
FileGridModel fileGridModel = ObjectStorageHubToWorkpaceMapper.toGridFileModelItem(wrappedItem, parentFolderModel, loggedUser);
|
||||
return (FileGridModel) setSynchedThreddsStateFor(fileGridModel, wrappedItem);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the synched thredds state for.
|
||||
*
|
||||
* @param fileModel the file model
|
||||
* @param wrappedItem
|
||||
* @return the file model
|
||||
*/
|
||||
protected FileModel setSynchedThreddsStateFor(FileModel fileModel, WorkspaceItem wrappedItem) {
|
||||
|
||||
Sync_Status status = null;
|
||||
|
||||
try {
|
||||
if(wrappedItem.getPropertyMap()!=null) {
|
||||
String wsSyncStatus = null;
|
||||
try{
|
||||
|
||||
PropertyMap map = wrappedItem.getPropertyMap();
|
||||
logger.debug("Property Map for folder: "+fileModel.getName()+" has value: "+map.getValues());
|
||||
wsSyncStatus = (String) map.getValues().get(WorkspaceThreddsSynchronize.WS_SYNCH_SYNCH_STATUS);
|
||||
logger.debug("Item id: "+wrappedItem.getId()+" read from Shub has current: "+WorkspaceThreddsSynchronize.WS_SYNCH_SYNCH_STATUS +" value at: "+wsSyncStatus);
|
||||
if(wsSyncStatus!=null)
|
||||
status = Sync_Status.valueOf(wsSyncStatus);
|
||||
}catch (Exception e) {
|
||||
logger.warn(wsSyncStatus + " is not value of "+Sync_Status.values()+", returning null");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("It is not possible to get synched status for item: "+fileModel.getIdentifier());
|
||||
}
|
||||
|
||||
fileModel.setSyncThreddsStatus(status);
|
||||
return fileModel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* To file trashed model.
|
||||
*
|
||||
* @param trashItem the trash item
|
||||
* @return the file trashed model
|
||||
*/
|
||||
public FileTrashedModel toFileTrashedModel(org.gcube.common.storagehubwrapper.shared.tohl.TrashedItem trashItem) {
|
||||
|
||||
FileTrashedModel fileTrashModel = new FileTrashedModel();
|
||||
try {
|
||||
fileTrashModel.setName(trashItem.getTitle()); //ADDING THE TITLE INSTEAD OF NAME
|
||||
|
||||
fileTrashModel.setIdentifier(trashItem.getId());
|
||||
|
||||
//SETTING PARENT
|
||||
FileModel oldParent = new FileModel(trashItem.getOriginalParentId(), "", true);
|
||||
|
||||
fileTrashModel.setOrginalPath(trashItem.getDeletedFrom());
|
||||
fileTrashModel.setParentFileModel(oldParent);
|
||||
//
|
||||
// //SETTING DELETED BY
|
||||
InfoContactModel deleteUser = buildGxtInfoContactFromPortalLogin(trashItem.getDeletedBy());
|
||||
fileTrashModel.setDeleteUser(deleteUser);
|
||||
|
||||
//SETTING MIME TYPE
|
||||
|
||||
// String mimeType = "";
|
||||
// if(trashItem instanceof FileItem){
|
||||
// FileItem fileItem = (FileItem) trashItem;
|
||||
// mimeType = fileItem.getMimeType();
|
||||
// }
|
||||
|
||||
String mimeType = trashItem.getMimeType()!=null?trashItem.getMimeType():"";
|
||||
fileTrashModel.setType(mimeType);
|
||||
|
||||
//SETTING IS DIRECTORY
|
||||
fileTrashModel.setIsDirectory(trashItem.isFolder());
|
||||
|
||||
//SETTING DELETE DATE
|
||||
fileTrashModel.setDeleteDate(GWTWorkspaceBuilder.toDate(trashItem.getDeletedTime()));
|
||||
|
||||
fileTrashModel.setShared(trashItem.isShared());
|
||||
|
||||
logger.debug("Converting return trash item: "+fileTrashModel.getName() +" id: "+fileTrashModel.getIdentifier());
|
||||
|
||||
logger.trace("Returning trash item: "+fileTrashModel);
|
||||
|
||||
}catch (Exception e) {
|
||||
|
||||
logger.debug("Error into toFileTrashedModel for item: "+fileTrashModel.getName() +" id: "+fileTrashModel.getIdentifier());
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
return fileTrashModel;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the gxt info contact from portal login.
|
||||
*
|
||||
* @param portalLogin the portal login
|
||||
* @return the info contact model
|
||||
*/
|
||||
protected InfoContactModel buildGxtInfoContactFromPortalLogin(String portalLogin){
|
||||
|
||||
if(portalLogin==null){
|
||||
logger.warn("portal login is null, return empty");
|
||||
portalLogin = "";
|
||||
}
|
||||
|
||||
return new InfoContactModel(portalLogin, portalLogin, UserUtil.getUserFullName(portalLogin), false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the workspace root id.
|
||||
*
|
||||
* @return the workspaceRootId
|
||||
*/
|
||||
public String getWorkspaceRootId() {
|
||||
|
||||
return workspaceRootId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the workspace root id.
|
||||
*
|
||||
* @param workspaceRootId the workspaceRootId to set
|
||||
*/
|
||||
public void setWorkspaceRootId(String workspaceRootId) {
|
||||
|
||||
this.workspaceRootId = workspaceRootId;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
package org.gcube.portlets.user.workspace.server.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
|
||||
/**
|
||||
* The Class ThumbnailGenerator.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 18, 2018
|
||||
*/
|
||||
public class ThumbnailGenerator {
|
||||
|
||||
|
||||
/**
|
||||
* Creates the thumbnail.
|
||||
*
|
||||
* @param originalFile the original file
|
||||
* @param thumbWidth the thumb width
|
||||
* @param thumbHeight the thumb height
|
||||
* @return the input stream
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static InputStream generateThumbnail(
|
||||
String originalFile, int thumbWidth,
|
||||
int thumbHeight)
|
||||
throws Exception {
|
||||
|
||||
String baseName = FilenameUtils.getBaseName(originalFile);
|
||||
Image image = ImageIO.read(new File(originalFile));
|
||||
return createThumb(image, baseName, thumbWidth, thumbHeight);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate thumbnail.
|
||||
*
|
||||
* @param originalFile the original file
|
||||
* @param fileName the file name
|
||||
* @param thumbWidth the thumb width
|
||||
* @param thumbHeight the thumb height
|
||||
* @return the input stream
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public static InputStream generateThumbnail(
|
||||
InputStream originalFile, String fileName, int thumbWidth,
|
||||
int thumbHeight)
|
||||
throws Exception {
|
||||
Image image = ImageIO.read(originalFile);
|
||||
return createThumb(image, fileName, thumbWidth, thumbHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the thumb.
|
||||
*
|
||||
* @param image the image
|
||||
* @param imageName the image name
|
||||
* @param thumbWidth the thumb width
|
||||
* @param thumbHeight the thumb height
|
||||
* @return the input stream
|
||||
* @throws IOException
|
||||
*/
|
||||
public static InputStream createThumb(Image image, String imageName, int thumbWidth,
|
||||
int thumbHeight) throws IOException{
|
||||
double thumbRatio = (double) thumbWidth / (double) thumbHeight;
|
||||
int imageWidth = image.getWidth(null);
|
||||
int imageHeight = image.getHeight(null);
|
||||
double imageRatio = (double) imageWidth / (double) imageHeight;
|
||||
if (thumbRatio < imageRatio) {
|
||||
thumbHeight = (int) (thumbWidth / imageRatio);
|
||||
}
|
||||
else {
|
||||
thumbWidth = (int) (thumbHeight * imageRatio);
|
||||
}
|
||||
if (imageWidth < thumbWidth && imageHeight < thumbHeight) {
|
||||
thumbWidth = imageWidth;
|
||||
thumbHeight = imageHeight;
|
||||
}
|
||||
else if (imageWidth < thumbWidth)
|
||||
thumbWidth = imageWidth;
|
||||
else if (imageHeight < thumbHeight)
|
||||
thumbHeight = imageHeight;
|
||||
|
||||
BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D graphics2D = thumbImage.createGraphics();
|
||||
graphics2D.setBackground(Color.WHITE);
|
||||
graphics2D.setPaint(Color.WHITE);
|
||||
graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);
|
||||
graphics2D.setRenderingHint(
|
||||
RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
|
||||
|
||||
String ext = FilenameUtils.getExtension(imageName);
|
||||
// String baseName = FilenameUtils.getBaseName(originalFile);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ImageIO.write(thumbImage, ext, os);
|
||||
return new ByteArrayInputStream(os.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream2file.
|
||||
*
|
||||
* @param in the in
|
||||
* @param filename the filename
|
||||
* @param extension the extension
|
||||
* @return the file
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static File stream2file (InputStream in, String filename, String extension) throws IOException {
|
||||
|
||||
extension = extension.startsWith(".")?extension:"."+extension;
|
||||
final File tempFile = File.createTempFile(filename, extension);
|
||||
//tempFile.deleteOnExit();
|
||||
try (FileOutputStream out = new FileOutputStream(tempFile)) {
|
||||
IOUtils.copy(in, out);
|
||||
}
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * The main method.
|
||||
// *
|
||||
// * @param args the arguments
|
||||
// * @throws Exception the exception
|
||||
// */
|
||||
// public static void main(String[] args) throws Exception {
|
||||
//
|
||||
// String originalFile = "/home/francesco-mangiacrapa/Pictures/Screenshot from 2016-04-11 10:20:43.png";
|
||||
// int thumbWidth = 200;
|
||||
// int thumbHeight = 200;
|
||||
//
|
||||
// createThumbnail(originalFile, thumbWidth, thumbHeight);
|
||||
//
|
||||
// }
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceOperationResult.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
* Oct 8, 2018
|
||||
*/
|
||||
public class WorkspaceOperationResult implements Serializable, IsSerializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4252367709147458665L;
|
||||
String operationName;
|
||||
boolean operationCompleted;
|
||||
String error;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new workspace operation result.
|
||||
*/
|
||||
public WorkspaceOperationResult() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new workspace operation result.
|
||||
*
|
||||
* @param operationName the operation name
|
||||
* @param operationCompleted the operation completed
|
||||
* @param error the error
|
||||
*/
|
||||
public WorkspaceOperationResult(
|
||||
String operationName, boolean operationCompleted, String error) {
|
||||
|
||||
super();
|
||||
this.operationName = operationName;
|
||||
this.operationCompleted = operationCompleted;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the operation name.
|
||||
*
|
||||
* @return the operationName
|
||||
*/
|
||||
public String getOperationName() {
|
||||
|
||||
return operationName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is operation completed.
|
||||
*
|
||||
* @return the operationCompleted
|
||||
*/
|
||||
public boolean isOperationCompleted() {
|
||||
|
||||
return operationCompleted;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the error.
|
||||
*
|
||||
* @return the error
|
||||
*/
|
||||
public String getError() {
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the operation name.
|
||||
*
|
||||
* @param operationName the operationName to set
|
||||
*/
|
||||
public void setOperationName(String operationName) {
|
||||
|
||||
this.operationName = operationName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the operation completed.
|
||||
*
|
||||
* @param operationCompleted the operationCompleted to set
|
||||
*/
|
||||
public void setOperationCompleted(boolean operationCompleted) {
|
||||
|
||||
this.operationCompleted = operationCompleted;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Sets the error.
|
||||
*
|
||||
* @param error the error to set
|
||||
*/
|
||||
public void setError(String error) {
|
||||
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("WorkpaceOperationResult [operationName=");
|
||||
builder.append(operationName);
|
||||
builder.append(", operationCompleted=");
|
||||
builder.append(operationCompleted);
|
||||
builder.append(", error=");
|
||||
builder.append(error);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
package org.gcube.portlets.user.workspace;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public class ThumbnailGenerator {
|
||||
|
||||
public ThumbnailGenerator() {
|
||||
|
||||
}
|
||||
|
||||
public static void transform(
|
||||
String originalFile, int thumbWidth,
|
||||
int thumbHeight)
|
||||
throws Exception {
|
||||
|
||||
Image image = javax.imageio.ImageIO.read(new File(originalFile));
|
||||
double thumbRatio = (double) thumbWidth / (double) thumbHeight;
|
||||
int imageWidth = image.getWidth(null);
|
||||
int imageHeight = image.getHeight(null);
|
||||
double imageRatio = (double) imageWidth / (double) imageHeight;
|
||||
if (thumbRatio < imageRatio) {
|
||||
thumbHeight = (int) (thumbWidth / imageRatio);
|
||||
}
|
||||
else {
|
||||
thumbWidth = (int) (thumbHeight * imageRatio);
|
||||
}
|
||||
if (imageWidth < thumbWidth && imageHeight < thumbHeight) {
|
||||
thumbWidth = imageWidth;
|
||||
thumbHeight = imageHeight;
|
||||
}
|
||||
else if (imageWidth < thumbWidth)
|
||||
thumbWidth = imageWidth;
|
||||
else if (imageHeight < thumbHeight)
|
||||
thumbHeight = imageHeight;
|
||||
|
||||
BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D graphics2D = thumbImage.createGraphics();
|
||||
graphics2D.setBackground(Color.WHITE);
|
||||
graphics2D.setPaint(Color.WHITE);
|
||||
graphics2D.fillRect(0, 0, thumbWidth, thumbHeight);
|
||||
graphics2D.setRenderingHint(
|
||||
RenderingHints.KEY_INTERPOLATION,
|
||||
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
|
||||
|
||||
String ext = FilenameUtils.getExtension(originalFile);
|
||||
String baseName = FilenameUtils.getBaseName(originalFile);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ImageIO.write(thumbImage, ext, os);
|
||||
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
||||
|
||||
File tempFile = stream2file(is, "thunmb-"+baseName, ext);
|
||||
System.out.println(tempFile.getAbsolutePath());
|
||||
|
||||
}
|
||||
|
||||
public static File stream2file (InputStream in, String filename, String extension) throws IOException {
|
||||
|
||||
extension = extension.startsWith(".")?extension:"."+extension;
|
||||
final File tempFile = File.createTempFile(filename, extension);
|
||||
//tempFile.deleteOnExit();
|
||||
try (FileOutputStream out = new FileOutputStream(tempFile)) {
|
||||
IOUtils.copy(in, out);
|
||||
}
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
String originalFile = "/home/francesco-mangiacrapa/Pictures/Screenshot from 2016-04-11 10:20:43.png";
|
||||
int thumbWidth = 200;
|
||||
int thumbHeight = 200;
|
||||
|
||||
transform(originalFile, thumbWidth, thumbHeight);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue