merged with branch version for gcube 3.9

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@120097 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-10-29 14:36:27 +00:00
parent 9e28263e4d
commit a481378eb0
7 changed files with 452 additions and 17 deletions

View File

@ -13,7 +13,7 @@ public class DeleteItemEvent extends GwtEvent<DeleteItemEventHandler> implements
private FileModel fileTarget = null;
private List<String> listTarget;
private List<? extends FileModel> listTarget;
private boolean isMultiSelection;
@ -22,7 +22,7 @@ public class DeleteItemEvent extends GwtEvent<DeleteItemEventHandler> implements
this.isMultiSelection = false;
}
public DeleteItemEvent(List<String> listTarget) {
public DeleteItemEvent(List<? extends FileModel> listTarget) {
this.listTarget = listTarget;
this.isMultiSelection = true;
}
@ -33,6 +33,9 @@ public class DeleteItemEvent extends GwtEvent<DeleteItemEventHandler> implements
return TYPE;
}
/* (non-Javadoc)
* @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
*/
@Override
protected void dispatch(DeleteItemEventHandler handler) {
handler.onDeleteItem(this);
@ -49,7 +52,7 @@ public class DeleteItemEvent extends GwtEvent<DeleteItemEventHandler> implements
return fileTarget;
}
public List<String> getListTarget() {
public List<? extends FileModel> getListTarget() {
return listTarget;
}

View File

@ -17,6 +17,7 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.user.workspace.shared.GarbageItem;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
@ -132,6 +133,16 @@ public interface GWTWorkspaceService extends RemoteService{
*/
public List<FileGridModel> getSmartFolderResultsByCategory(String category) throws Exception;
/**
* Creates the smart folder.
*
* @param name the name
* @param description the description
* @param query the query
* @param parentId the parent id
* @return the smart folder model
* @throws Exception the exception
*/
SmartFolderModel createSmartFolder(String name, String description,
String query, String parentId) throws Exception;
@ -195,6 +206,14 @@ public interface GWTWorkspaceService extends RemoteService{
*/
public void setValueInSession(String name, String value) throws Exception;
/**
* Gets the items by search name.
*
* @param text the text
* @param folderId the folder id
* @return the items by search name
* @throws Exception the exception
*/
List<FileGridModel> getItemsBySearchName(String text, String folderId) throws Exception;
/**
@ -559,13 +578,16 @@ public interface GWTWorkspaceService extends RemoteService{
boolean isSessionExpired() throws Exception;
/**
* Delete list items for ids.
*
* @param ids the ids
* @return the list
* @throws Exception the exception
*/
void deleteListItemsForIds(List<String> ids) throws Exception;
List<GarbageItem> deleteListItemsForIds(List<String> ids) throws Exception;
/**
* Copy items.

View File

@ -17,6 +17,7 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
import org.gcube.portlets.user.workspace.client.model.SubTree;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.user.workspace.shared.GarbageItem;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.TrashContent;
@ -572,13 +573,8 @@ public interface GWTWorkspaceServiceAsync {
*/
void isSessionExpired(AsyncCallback<Boolean> callback);
/**
* Delete list items for ids.
*
* @param ids the ids
* @param callback the callback
*/
void deleteListItemsForIds(List<String> ids, AsyncCallback<Void> callback);
void deleteListItemsForIds(List<String> ids,
AsyncCallback<List<GarbageItem>> callback);
/**
* Copy items.

View File

@ -813,7 +813,7 @@ public class GWTWorkspaceBuilder {
* @return the list
* @throws InternalErrorException the internal error exception
*/
protected List<FileGridModel> buildGXTListFileGridModelItem(List<WorkspaceItem> listWorkspaceItems, FileModel parentFileModel) throws InternalErrorException{
public List<FileGridModel> buildGXTListFileGridModelItem(List<WorkspaceItem> listWorkspaceItems, FileModel parentFileModel) throws InternalErrorException{
Long startTime = System.currentTimeMillis();
List<FileGridModel> listFileGridModel = new ArrayList<FileGridModel>();

View File

@ -70,6 +70,7 @@ import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL;
import org.gcube.portlets.user.workspace.shared.GarbageItem;
import org.gcube.portlets.user.workspace.shared.PublicLink;
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
@ -2597,7 +2598,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#deleteListItemsForIds(java.util.List)
*/
@Override
public void deleteListItemsForIds(List<String> ids) throws Exception {
public List<GarbageItem> deleteListItemsForIds(List<String> ids) throws Exception {
try {
@ -2607,6 +2608,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
Workspace workspace = getWorkspace();
workspaceLogger.trace("removeItem item for list size: "+ids.size());
String[] items = new String[ids.size()];
items = ids.toArray(items);
Map<String, GarbageItem> garbage = new HashMap<String, GarbageItem>(items.length);
//SAVE DATE FOR NOTIFICATIONS
for (String itemId : ids) {
//NOTIFICATION
WorkspaceItem wsItem = workspace.getItem(itemId);
@ -2618,11 +2625,40 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
sourceFolderSharedId = wsItem.getIdSharedFolder();
}
//REMOVE ITEM
workspace.removeItem(itemId);
//IF SOURCE SHARED FOLDER IS NOT NULL
if(sourceFolderSharedId!=null)
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
garbage.put(itemId, new GarbageItem(sourceItemIsShared, itemName, itemId, sourceFolderSharedId));
// workspace.removeItem(itemId);
// //IF SOURCE SHARED FOLDER IS NOT NULL
// if(sourceFolderSharedId!=null)
// NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
}
//ITEM ID - ERROR
Map<String, String> backendError = workspace.removeItems(items);
//GARBAGE ITEM ERROR
List<GarbageItem> frontEndError = new ArrayList<GarbageItem>(backendError.size());
//REMOVING IDS WHICH HAVE GENERATED AN ERROR
for (String idError : backendError.keySet()) {
GarbageItem gbi = garbage.get(idError);
if(gbi!=null){
frontEndError.add(gbi);
garbage.remove(idError);
}
}
for (String idItem : garbage.keySet()) {
GarbageItem item = garbage.get(idItem);
workspaceLogger.trace("Check notification for "+item);
//IF SOURCE SHARED FOLDER IS NOT NULL
if(item.getSourceFolderSharedId()!=null)
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), item.isSourceItemIsShared(), item.getOldItemName(), item.getOldItemName(), item.getSourceFolderSharedId());
}
return frontEndError;
} catch (InsufficientPrivilegesException e) {
workspaceLogger.error("Error in server Item remove", e);
String error = "An error occurred on deleting item. "+e.getMessage();

View File

@ -0,0 +1,149 @@
/**
*
*/
package org.gcube.portlets.user.workspace.shared;
import java.io.Serializable;
/**
* The Class GarbageItem.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 23, 2015
*
* USED TO SEND NOTIFICATION AFTER DELETE
*/
public class GarbageItem implements Serializable{
/**
*
*/
private static final long serialVersionUID = -1532030116595698658L;
private boolean sourceItemIsShared;
private String oldItemName;
private String oldItemId;
private String sourceFolderSharedId;
private String error;
public GarbageItem(){
}
/**
* Instantiates a new garbage item.
*
* @param sourceItemIsShared the source item is shared
* @param oldItemName the old item name
* @param oldItemId the old item id
* @param sourceFolderSharedId the source folder shared id
*/
public GarbageItem(boolean sourceItemIsShared, String oldItemName,
String oldItemId, final String sourceFolderSharedId) {
this.sourceItemIsShared = sourceItemIsShared;
this.oldItemName = oldItemName;
this.oldItemId = oldItemId;
this.sourceFolderSharedId = sourceFolderSharedId;
}
/**
* Checks if is source item is shared.
*
* @return the sourceItemIsShared
*/
public boolean isSourceItemIsShared() {
return sourceItemIsShared;
}
/**
* Gets the old item name.
*
* @return the oldItemName
*/
public String getOldItemName() {
return oldItemName;
}
/**
* Gets the old item id.
*
* @return the oldItemId
*/
public String getOldItemId() {
return oldItemId;
}
/**
* Gets the source folder shared id.
*
* @return the sourceFolderSharedId
*/
public String getSourceFolderSharedId() {
return sourceFolderSharedId;
}
/**
* Sets the source item is shared.
*
* @param sourceItemIsShared the sourceItemIsShared to set
*/
public void setSourceItemIsShared(boolean sourceItemIsShared) {
this.sourceItemIsShared = sourceItemIsShared;
}
/**
* Sets the old item name.
*
* @param oldItemName the oldItemName to set
*/
public void setOldItemName(String oldItemName) {
this.oldItemName = oldItemName;
}
/**
* Sets the old item id.
*
* @param oldItemId the oldItemId to set
*/
public void setOldItemId(String oldItemId) {
this.oldItemId = oldItemId;
}
/**
* Sets the source folder shared id.
*
* @param sourceFolderSharedId the sourceFolderSharedId to set
*/
public void setSourceFolderSharedId(String sourceFolderSharedId) {
this.sourceFolderSharedId = sourceFolderSharedId;
}
public void setError(String error){
this.error = error;
}
/**
* @return the error
*/
public String getError() {
return error;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("GarbageItem [sourceItemIsShared=");
builder.append(sourceItemIsShared);
builder.append(", oldItemName=");
builder.append(oldItemName);
builder.append(", oldItemId=");
builder.append(oldItemId);
builder.append(", sourceFolderSharedId=");
builder.append(sourceFolderSharedId);
builder.append(", error=");
builder.append(error);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,229 @@
/**
*
*/
package org.gcube.portlets.user.workspace;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.user.workspace.client.model.FileGridModel;
import org.gcube.portlets.user.workspace.server.GWTWorkspaceBuilder;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 28, 2015
*/
public class DeleteTest {
public static String DEFAULT_SCOPE = "/gcube/devsec"; //DEV
// public static String DEFAULT_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps/DESCRAMBLE";
public static String TEST_USER = "francesco.mangiacrapa";
public static String PARENT_ID = "a9ead58c-d645-4699-addd-5c6e5f1aff06";
private static Workspace ws;
private static GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
public static void main(String[] args) {
try {
ScopeBean scope = new ScopeBean(DEFAULT_SCOPE);
ScopeProvider.instance.set(scope.toString());
ws = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(TEST_USER)
.getWorkspace();
//
final List<String> children = getIdsOnlyFolderForID(PARENT_ID);
if(children.size()<2){
System.err.println("children size < 2, add others children");
return;
}
final int medium = children.size()/2;
Thread t1 = new Thread("T1"){
public void run() {
System.out.println("T1 start...");
removeRange(children, 0, medium);
System.out.println("T1 end");
};
};
t1.start();
t1.join();
List<? extends WorkspaceItem> childrenNEW = getChildrenForID(PARENT_ID);
print(childrenNEW);
Thread t2 = new Thread("T2"){
public void run() {
System.out.println("T2 start...");
removeRange(children, medium, children.size());
System.out.println("T2 end");
};
};
t2.start();
t2.join();
childrenNEW = getChildrenForID(PARENT_ID);
print(childrenNEW);
System.out.println("\n\nDONE!");
} catch (Exception e) {
e.printStackTrace();
}
}
private static void print(final List<? extends WorkspaceItem> children){
int i=0;
System.out.println("\n\n");
for (WorkspaceItem workspaceItem : children) {
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER) || workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
try {
System.err.println(++i+") folder id: "+folder.getId() +", folder name: "+folder.getName());
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
if(workspaceItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
FolderItem folderItem = (FolderItem) workspaceItem;
try {
System.err.println(++i+") folderItem id: "+folderItem.getId() +", name: "+folderItem.getName() + ", size: "+folderItem.getLength());
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
System.out.println("\n\n");
}
private static List<? extends WorkspaceItem> getChildrenForID(String id){
WorkspaceFolder folder;
try {
System.out.println("start getItem on id "+id);
folder = (WorkspaceFolder) ws.getItem(id);
System.out.println("start get children on folder "+folder.getName());
final List<? extends WorkspaceItem> children = folder.getChildren();
builder.buildGXTListFileGridModelItem(folder.getChildren(), null);
// builder.buildGXTFileGridModelItem(folder, null);
System.out.println("children size: "+children.size());
return children;
} catch (ItemNotFoundException | InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
private static List<String> getIdsForID(String id){
try {
List<? extends WorkspaceItem> children = getChildrenForID(id);
List<String> ids = new ArrayList<String>(children.size());
for (WorkspaceItem workspaceItem : children) {
ids.add(workspaceItem.getId());
}
return ids;
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
private static List<String> getIdsOnlyFolderForID(String id){
try {
List<? extends WorkspaceItem> children = getChildrenForID(id);
List<String> ids = new ArrayList<String>(children.size());
for (WorkspaceItem workspaceItem : children) {
if(workspaceItem.isFolder())
ids.add(workspaceItem.getId());
}
return ids;
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
private static void removeRange(List<String> children, int start, int end) {
System.out.println("start "+start);
System.out.println("end "+end);
// System.out.println("(end - start)"+(end - start));
List<String> sub = children.subList(start, end);
String[] array = new String[sub.size()];
array = sub.toArray(array);
System.out.println("array lenght: "+array.length);
for (String id : array)
System.out.println("Removing "+id);
try {
ws.removeItems(array);
System.out.println("Remove OK ");
} catch (ItemNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InsufficientPrivilegesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InternalErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}