From 3c6a33ef2522606513a27f67b909fa965fc8d98f Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 6 Jun 2017 16:12:44 +0000 Subject: [PATCH] fix image preview and download fix on share user by admin git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@149320 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../view/sharing/DialogShareFolder.java | 86 ++++++++++++++++++- .../view/windows/ImagesPreviewController.java | 13 ++- .../folder/item/GWTExternalImage.java | 29 +++++++ .../folder/item/gcube/GWTImageDocument.java | 61 +++++++++---- 4 files changed, 163 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java index 550b85a..400b38a 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/sharing/DialogShareFolder.java @@ -34,11 +34,12 @@ import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Label; + /** * The Class DialogShareFolder. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Nov 4, 2015 + * Jun 6, 2017 */ public class DialogShareFolder extends Dialog { @@ -62,6 +63,7 @@ public class DialogShareFolder extends Dialog { * @param folderParentName the folder parent name * @param folder the folder * @param eventBus the event bus + * @param userStore the user store */ public DialogShareFolder(String folderParentName, final FileModel folder, HandlerManager eventBus, UserStore userStore) { initUserStore(userStore); @@ -143,6 +145,7 @@ public class DialogShareFolder extends Dialog { lc.add(flexTable); if(hpPermission!=null) lc.add(hpPermission); + lc.mask(); userStore.getOwner(folder.getIdentifier(), new AsyncCallback() { @@ -156,12 +159,29 @@ public class DialogShareFolder extends Dialog { public void onSuccess(InfoContactModel result) { shareOwner = result; txtOwner.setValue(result.getName()); - permissionControl(result.getLogin(), true); + //permissionControl(result.getLogin(), true); fillRecipientAlreadyShared(folder.getIdentifier(), lc); } }); + AsyncCallback> callback = new AsyncCallback>() { + + @Override + public void onFailure(Throwable caught) { + new MessageBoxAlert("Alert", "Sorry, an error occurred during on getting Managers from server",null); + hpPermission.unmask(); + } + + @Override + public void onSuccess(List listManagers) { + permissionControl(listManagers, true, folder); + hpPermission.unmask(); + } + }; + + getUsersManagers(folder.getIdentifier(), callback); + setFocusWidget(suggestPanel.getBox()); add(txtName); add(txtOwner); @@ -172,6 +192,11 @@ public class DialogShareFolder extends Dialog { this.show(); } + /** + * Inits the user store. + * + * @param userStore the user store + */ private void initUserStore(UserStore userStore){ this.userStore = userStore; this.suggestPanel = new MultiValuePanel(userStore); @@ -581,4 +606,61 @@ public class DialogShareFolder extends Dialog { } + /** + * Gets the users managers. + * + * @param sharedFolderId the shared folder id + * @param callback the callback + * @return the users managers + */ + public void getUsersManagers(final String sharedFolderId,final AsyncCallback> callback) { + + AppControllerExplorer.rpcWorkspaceService.getUsersManagerToSharedFolder(sharedFolderId, new AsyncCallback>() { + + @Override + public void onFailure(Throwable arg0) { + GWT.log("an error occured in getting user managers by Id "+sharedFolderId + " "+arg0.getMessage()); + new MessageBoxAlert("Alert", "Sorry, an error occurred on getting users managers, try again later",null); + + } + + @Override + public void onSuccess(List listManagers) { + callback.onSuccess(listManagers); + + } + }); + } + + + /** + * Permission control. + * + * @param listManagers the list managers + * @param showAlert the show alert + * @param folder the folder + */ + private void permissionControl(List listManagers, boolean showAlert, FileModel folder){ + + boolean permissionsOk = false; + for (InfoContactModel infoContactModel : listManagers) { + + GWT.log("DialogPermission control compare between : "+infoContactModel.getLogin() +" and my login: "+AppControllerExplorer.myLogin); + if(AppControllerExplorer.myLogin.compareToIgnoreCase(infoContactModel.getLogin())==0){ + permissionsOk = true; + break; + } + + } + + if(permissionsOk){ + enableFormDialog(true); + }else{ + enableFormDialog(false); + if(showAlert) + new MessageBoxAlert("Permission denied", "You have no permissions to change sharing. You are not manager of \""+folder.getName()+"\"", null); + } + + } + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/ImagesPreviewController.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/ImagesPreviewController.java index d3a1331..1013d72 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/ImagesPreviewController.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/ImagesPreviewController.java @@ -103,9 +103,11 @@ public class ImagesPreviewController { private EnhancedImage toEnhancedImage(GWTWorkspaceItem wi){ if(wi instanceof GWTImageDocument){ GWTImageDocument image = (GWTImageDocument) wi; - return new EnhancedImage(image.getThumbnailUrl(), image.getName(), image.getName(), image.getImageUrl()); + GWT.log("GWTImageDocument image: "+image); + return new EnhancedImage(image.getThumbnailUrl(), image.getName(), image.getName(), image.getImageUrl()); }else if(wi instanceof GWTExternalImage){ GWTExternalImage image = (GWTExternalImage) wi; + GWT.log("GWTExternalImage image: "+image); return new EnhancedImage(image.getThumbnailUrl(), image.getName(), image.getName(), image.getImageUrl()); } @@ -157,18 +159,13 @@ public class ImagesPreviewController { @Override public void onFailure(Throwable caught) { - parentImages = null; - } @Override public void onSuccess(List result) { - GWT.log("Preloaded: "+result +" image/s"); - parentImages = result; - if(parentImages.size()>0) carousel.showArrows(true); @@ -186,8 +183,8 @@ public class ImagesPreviewController { */ private void showCarousel(String imageTitle, String thumbnailURL, String imageURL) { List list = new ArrayList(); - GWT.log("Generating imageURL: "+thumbnailURL); - EnhancedImage myimg = new EnhancedImage(thumbnailURL, imageTitle, imageTitle); + GWT.log("Generating thumbnailURL: "+thumbnailURL +"\n imageURL: "+imageURL); + EnhancedImage myimg = new EnhancedImage(thumbnailURL, imageTitle, imageTitle, imageURL); list.add(myimg); carousel.updateImages(list); carousel.showArrows(false); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/GWTExternalImage.java b/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/GWTExternalImage.java index ad7477d..fd6c126 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/GWTExternalImage.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/GWTExternalImage.java @@ -173,4 +173,33 @@ public class GWTExternalImage extends GWTFolderItem implements IsSerializable, G public long getThumbnailLenght() { return thumbnailLenght; } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("GWTExternalImage [imageUrl="); + builder.append(imageUrl); + builder.append(", thumbnailUrl="); + builder.append(thumbnailUrl); + builder.append(", thumbnailWidth="); + builder.append(thumbnailWidth); + builder.append(", thumbnailHeight="); + builder.append(thumbnailHeight); + builder.append(", thumbnailLenght="); + builder.append(thumbnailLenght); + builder.append(", width="); + builder.append(width); + builder.append(", height="); + builder.append(height); + builder.append(", mimeType="); + builder.append(mimeType); + builder.append("]"); + return builder.toString(); + } + + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/gcube/GWTImageDocument.java b/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/gcube/GWTImageDocument.java index 8cbce46..4160859 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/gcube/GWTImageDocument.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/workspace/folder/item/gcube/GWTImageDocument.java @@ -1,5 +1,5 @@ /** - * + * */ package org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube; @@ -21,48 +21,48 @@ import com.google.gwt.user.client.rpc.IsSerializable; * */ public class GWTImageDocument extends GWTDocument implements IsSerializable, GWTImage{ - + protected String imageUrl; protected String thumbnailUrl; - + protected int thumbnailWidth; protected int thumbnailHeight; protected long thumbnailLenght; - + protected int width; protected int height; protected long lenght; - + protected GWTImageDocument() {} - - public GWTImageDocument(Date creationTime, String id, GWTProperties properties, String name, String owner, + + public GWTImageDocument(Date creationTime, String id, GWTProperties properties, String name, String owner, String description, Date lastModificationTime, GWTWorkspaceItemAction lastAction, GWTWorkspaceFolder parent, - String imageUrl, String thumbnailUrl, int width, int height, int thumbnailWidth, int thumbnailHeight, long thumbnailLenght, - long length, String mimeType, String oid, Map metadata, Map annotation, + String imageUrl, String thumbnailUrl, int width, int height, int thumbnailWidth, int thumbnailHeight, long thumbnailLenght, + long length, String mimeType, String oid, Map metadata, Map annotation, String collection, int numberOfAlternatives, int numberOfParts) { - - super(creationTime, id, properties, name, owner, description, lastModificationTime, lastAction, parent, length, oid, + + super(creationTime, id, properties, name, owner, description, lastModificationTime, lastAction, parent, length, oid, mimeType, metadata, annotation, collection, numberOfAlternatives, numberOfParts); - + this.imageUrl = imageUrl; this.thumbnailUrl = thumbnailUrl; this.width = width; this.height = height; this.lenght = length; - + this.thumbnailHeight = thumbnailHeight; this.thumbnailWidth = thumbnailWidth; this.thumbnailLenght = thumbnailLenght; - + this.mimeType = mimeType; } public String getThumbnailUrl(){ return GWT.getModuleBaseURL()+thumbnailUrl; } - + public String getImageUrl(){ return GWT.getModuleBaseURL()+imageUrl; } @@ -87,7 +87,7 @@ public class GWTImageDocument extends GWTDocument implements IsSerializable, GWT public long getLength() { return lenght; } - + /** * @return the thumbnailWidth @@ -118,4 +118,33 @@ public class GWTImageDocument extends GWTDocument implements IsSerializable, GWT return GWTFolderItemType.IMAGE_DOCUMENT; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + + StringBuilder builder = new StringBuilder(); + builder.append("GWTImageDocument [imageUrl="); + builder.append(imageUrl); + builder.append(", thumbnailUrl="); + builder.append(thumbnailUrl); + builder.append(", thumbnailWidth="); + builder.append(thumbnailWidth); + builder.append(", thumbnailHeight="); + builder.append(thumbnailHeight); + builder.append(", thumbnailLenght="); + builder.append(thumbnailLenght); + builder.append(", width="); + builder.append(width); + builder.append(", height="); + builder.append(height); + builder.append(", lenght="); + builder.append(lenght); + builder.append("]"); + return builder.toString(); + } + + + }