4055: Workspace Uploder enhancement: work with multiple-instances of DnD Workspace Uploader in the DOM

Task-Url: https://support.d4science.org/issues/4055


TODO 
Commented upload canceling because must be managed abort for multiple files client-side

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@128754 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-20 15:06:10 +00:00
parent 9a277a0d79
commit 471ac76beb
8 changed files with 101 additions and 22 deletions

View File

@ -4,6 +4,7 @@
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList;
import java.util.Arrays;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
@ -104,7 +105,7 @@ public class MultipleDilaogUpload extends DialogUpload {
}
}
GWT.log("generating fake uploaders on: "+files.toString());
GWT.log("generating fake uploaders on: "+Arrays.asList(files.toString()));
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
WorkspaceUploaderItem fakeItem = new WorkspaceUploaderItem();
@ -169,6 +170,7 @@ public class MultipleDilaogUpload extends DialogUpload {
}
}
}
});
formPanel.addSubmitHandler(new SubmitHandler() {
@ -195,11 +197,11 @@ public class MultipleDilaogUpload extends DialogUpload {
}
String[] files = null;
GWT.log("Current Uploader has id: "+fileUploadID);
String filesSelected = getFilesSelected(fileUploadID, FILE_DELEMITER);
// GWT.log("getFilesSelected: " + filesSelected);
GWT.log("getFilesSelected: " + filesSelected);
files = filesSelected.split(FILE_DELEMITER);
if(isLimitExceeded(files.length))
return;
@ -261,6 +263,8 @@ public class MultipleDilaogUpload extends DialogUpload {
}
});
}

View File

@ -129,6 +129,8 @@ public class UploaderProgressView {
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
//TODO CANCEL OPERATION MUST BE ENHANCED IN ORDER TO CANCELL ALL UPLOADS
/*
if(uploader.getUploadProgress().getLastEvent().getReadPercentage()!=100 && !cancel){
cancel = true;
handleCancelUpload(uploader);
@ -138,7 +140,7 @@ public class UploaderProgressView {
setVisibleCancel(false);
// hp.remove(cancelImg);
}catch (Exception e) {}
}
}*/
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
break;

View File

@ -514,11 +514,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred in the upload. An item with that name already exists", request.getSession());
sendError(response, "Internal error: An item with that name already exists");
return;
} catch (IOException e){
logger.error("Error creating elements, is it cancel?", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred in the upload", request.getSession());
sendError(response, "Internal error: An item with that name already exists");
return;
// sendError(response, "Internal error: An item with that name already exists");
// return;
}catch (Exception e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred in the upload. "+e.getMessage(), request.getSession());
// sendError(response, "Internal error: An error occurred on uploading the file, try again later");
return;
// return;
}finally{
removeCurrentListener(request.getSession(), clientUploadKey);
}

View File

@ -33,7 +33,7 @@ public abstract class AbstractUploadProgressListener implements ProgressListener
private int percentageOffset = 0;
private double completePercentage = COMPLETE_PERECENTAGE;
private static Logger logger = LoggerFactory.getLogger(AbstractUploadProgressListener.class);
protected RuntimeException exception = null;
protected UploadCanceledException exception = null;
protected boolean exceptionTrhown = false;
protected String sessionId;
@ -44,8 +44,7 @@ public abstract class AbstractUploadProgressListener implements ProgressListener
* @return the abstract upload progress listener
*/
public static AbstractUploadProgressListener current(String sessionId) {
throw new RuntimeException(
"Implement the static method 'current' in your customized class");
throw new RuntimeException("Implement the static method 'current' in your customized class");
}
protected Long bytesRead = 0L, contentLength = 0L;
@ -97,7 +96,7 @@ public abstract class AbstractUploadProgressListener implements ProgressListener
public void update(final long bytesRead, final long totalBytes, final int items) {
if (exceptionTrhown) {
logger.warn("An exception thrown is already true. Is upload already cancelled?, returning");
logger.warn("An exception thrown is already true. Is upload cancelled?, returning");
return;
}
@ -165,7 +164,7 @@ public abstract class AbstractUploadProgressListener implements ProgressListener
*
* @return the exception
*/
public RuntimeException getException() {
public UploadCanceledException getException() {
return exception;
}
@ -184,8 +183,8 @@ public abstract class AbstractUploadProgressListener implements ProgressListener
*
* @param e the new exception
*/
public void setException(RuntimeException e) {
logger.info("Set RuntimeException to cancel upload");
public void setException(UploadCanceledException e) {
logger.info("Set exception to UploadCanceledException to cancel upload");
exception = e;
save();
}

View File

@ -1,3 +1,19 @@
/*
* Copyright 2010 Manuel Carrasco Moñino. (manolo at apache/org)
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.gcube.portlets.widgets.workspaceuploader.server.upload;
@ -9,9 +25,5 @@ package org.gcube.portlets.widgets.workspaceuploader.server.upload;
* Sep 8, 2015
*/
public class UploadCanceledException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 4311434519628111824L;
private static final long serialVersionUID = 1L;
}

View File

@ -7,6 +7,8 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.fileupload.ProgressListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class UploadProgressInputStream.
@ -19,6 +21,7 @@ public final class UploadProgressInputStream extends FilterInputStream {
private List<ProgressListener> listeners;
private long bytesRead = 0;
private long totalBytes = 0;
private static Logger logger = LoggerFactory.getLogger(UploadProgressInputStream.class);
/**
* Instantiates a new upload progress input stream.
@ -82,6 +85,28 @@ public final class UploadProgressInputStream extends FilterInputStream {
updateListeners(totalBytes, totalBytes);
}
/**
* Update listeners.
*
* @param bytesRead the bytes read
* @param totalBytes the total bytes
*/
/*private void updateListeners(final long bytesRead, final long totalBytes) throws IOException{
try{
for (ProgressListener listener : listeners)
listener.update(bytesRead, totalBytes, listeners.size());
}catch(UploadCanceledException e){
logger.warn("Update Listener thrown UploadCanceledException: closing stream..");
try {
close();
}catch (IOException e1) {
logger.warn("Close stream thrown this Exception, silent catch");
}
throw new IOException("Upload cancelled from Client");
}
}*/
/**
* Update listeners.
*
@ -92,5 +117,8 @@ public final class UploadProgressInputStream extends FilterInputStream {
for (ProgressListener listener : listeners)
listener.update(bytesRead, totalBytes, listeners.size());
//UploadCanceledException IS PROPAGATED HERE
}
}

View File

@ -107,6 +107,7 @@ public class WorkspaceUploaderMng {
} catch (Exception e1) {
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
}
} catch (ItemNotFoundException | WrongItemTypeException | WorkspaceFolderNotFoundException | WrongDestinationException e) {
logger.error("Error during overwrite: ",e);
workspaceUploader.setStatusDescription("An error occurred during upload: "+itemName+". "+e.getMessage());
@ -116,12 +117,15 @@ public class WorkspaceUploaderMng {
} catch (Exception e1) {
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
}
//IS unreachable
}catch(UploadCanceledException e){
logger.info("UploadCanceledException thrown by client..");
workspaceUploader.setStatusDescription("Aborted upload: "+itemName);
workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
try {
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
// WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
// workspaceUploader.setErasable(true);
WsUtil.forceEraseWorkspaceUploaderInSession(httpSession, workspaceUploader);
} catch (Exception e1) {
logger.error("Error during WorkspaceUploaderItem session update: ",e1);
}
@ -130,6 +134,7 @@ public class WorkspaceUploaderMng {
// StreamUtils.deleteTempFile(uploadFile);
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
} catch (Exception e2) {
logger.error("Error during setErasableWorkspaceUploaderInSession session update: ",e2);
}
}

View File

@ -222,6 +222,27 @@ public class WsUtil {
logger.debug("Added uploader: "+uploader.getIdentifier() +" in session");
}
/**
* Erase workspace uploader in session.
*
* @param httpSession the http session
* @param uploader the uploader
* @throws Exception the exception
*/
public static void forceEraseWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception
{
logger.trace("Force Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier());
final ASLSession session = getAslSession(httpSession);
if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
throw new Exception("Invalid uploader");
session.removeAttribute(uploader.getIdentifier());
logger.info("Erased uploader: "+uploader.getIdentifier());
}
/**
* Erase workspace uploader in session.
*
@ -238,8 +259,9 @@ public class WsUtil {
throw new Exception("Invalid uploader");
if(uploader.isErasable()){
session.setAttribute(uploader.getIdentifier(), null);
logger.info("Erased uploader: "+uploader.getIdentifier() +" with null value");
// session.setAttribute(uploader.getIdentifier(), null);
session.removeAttribute(uploader.getIdentifier());
logger.info("Erased uploader: "+uploader.getIdentifier());
}
}