Added delay of 2sec on NOtifyUpload completed
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@169684 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f10f57d1db
commit
77322c453e
|
@ -12,6 +12,7 @@ import org.gcube.portlets.widgets.workspaceuploader.client.events.NotifyUploadEv
|
||||||
|
|
||||||
import com.google.gwt.core.shared.GWT;
|
import com.google.gwt.core.shared.GWT;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
|
import com.google.gwt.user.client.Timer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +43,7 @@ public class WorkspaceUploaderListenerController {
|
||||||
controllerEventBus.addHandler(NotifyUploadEvent.TYPE, new NotifyUploadEventHandler() {
|
controllerEventBus.addHandler(NotifyUploadEvent.TYPE, new NotifyUploadEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotifyUpload(NotifyUploadEvent notifyUploadEvent) {
|
public void onNotifyUpload(final NotifyUploadEvent notifyUploadEvent) {
|
||||||
|
|
||||||
if(notifyUploadEvent.getEvent()==null)
|
if(notifyUploadEvent.getEvent()==null)
|
||||||
return;
|
return;
|
||||||
|
@ -51,7 +52,17 @@ public class WorkspaceUploaderListenerController {
|
||||||
|
|
||||||
case UPLOAD_COMPLETED:
|
case UPLOAD_COMPLETED:
|
||||||
GWT.log("NotifyUploadEvent Completed");
|
GWT.log("NotifyUploadEvent Completed");
|
||||||
notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
|
|
||||||
|
Timer timer = new Timer() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
//THIS IS A DELAY TO WAIT REPOSITORY SYNCHRONIZATION
|
||||||
|
timer.schedule(2000);
|
||||||
break;
|
break;
|
||||||
case ABORTED:
|
case ABORTED:
|
||||||
GWT.log("NotifyUploadEvent Aborted");
|
GWT.log("NotifyUploadEvent Aborted");
|
||||||
|
|
|
@ -3,11 +3,15 @@
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.widgets.workspaceuploader.server;
|
package org.gcube.portlets.widgets.workspaceuploader.server;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
@ -26,6 +30,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.fileupload.util.Streams;
|
import org.apache.commons.fileupload.util.Streams;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.storagehub.model.items.FolderItem;
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
|
@ -38,6 +43,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InsufficientPri
|
||||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.InternalErrorException;
|
||||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemAlreadyExistException;
|
||||||
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
|
||||||
|
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploader;
|
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploader;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
|
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
|
||||||
|
@ -273,6 +279,33 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File coyStreamToFile(InputStream in, String fileExtension) throws IOException{
|
||||||
|
File tempFile = File.createTempFile(UUID.randomUUID().toString(), fileExtension);
|
||||||
|
tempFile.deleteOnExit();
|
||||||
|
FileOutputStream out = new FileOutputStream(tempFile);
|
||||||
|
IOUtils.copy(in, out);
|
||||||
|
return tempFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static InputStream clone(final InputStream inputStream) {
|
||||||
|
// try {
|
||||||
|
// inputStream.mark(0);
|
||||||
|
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
// byte[] buffer = new byte[1024];
|
||||||
|
// int readLength = 0;
|
||||||
|
// while ((readLength = inputStream.read(buffer)) != -1) {
|
||||||
|
// outputStream.write(buffer, 0, readLength);
|
||||||
|
// }
|
||||||
|
// inputStream.reset();
|
||||||
|
// outputStream.flush();
|
||||||
|
// return new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
// }
|
||||||
|
// catch (Exception ex) {
|
||||||
|
// ex.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -434,6 +467,9 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
}
|
}
|
||||||
|
|
||||||
final WorkspaceFolder destinationFolder = (WorkspaceFolder) item;
|
final WorkspaceFolder destinationFolder = (WorkspaceFolder) item;
|
||||||
|
// File tmpFile = null;
|
||||||
|
// FileInputStream fis = null;
|
||||||
|
// BufferedInputStream bis = null;
|
||||||
try {
|
try {
|
||||||
//we calculate an unique name for the current destination
|
//we calculate an unique name for the current destination
|
||||||
String itemName = fileName;
|
String itemName = fileName;
|
||||||
|
@ -477,6 +513,10 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
//CONFIRM DESTINATION FOLDER
|
//CONFIRM DESTINATION FOLDER
|
||||||
workspaceUploader.getFile().setParentId(destinationFolder.getId());
|
workspaceUploader.getFile().setParentId(destinationFolder.getId());
|
||||||
|
|
||||||
|
// tmpFile = coyStreamToFile(uploadItem.openStream(), extension);
|
||||||
|
// fis = new FileInputStream(tmpFile);
|
||||||
|
// bis = new BufferedInputStream(fis);
|
||||||
|
|
||||||
//instanciate the progress listener
|
//instanciate the progress listener
|
||||||
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(), clientUploadKey);
|
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(), clientUploadKey);
|
||||||
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
|
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
|
||||||
|
@ -489,6 +529,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
|
|
||||||
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
||||||
|
|
||||||
|
try {
|
||||||
|
//USING isOverwrite to check if the file already exists
|
||||||
|
isOverwrite = storageHubWrapper.getWorkspace().exists(itemName, destinationFolder.getId());
|
||||||
|
}
|
||||||
|
catch (ItemNotFoundException | WrongItemTypeException e) {
|
||||||
|
//silent
|
||||||
|
}
|
||||||
|
|
||||||
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
|
||||||
|
|
||||||
if(workspaceUploader==null)
|
if(workspaceUploader==null)
|
||||||
|
@ -552,6 +600,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
// return;
|
// return;
|
||||||
}finally{
|
}finally{
|
||||||
removeCurrentListener(request.getSession(), clientUploadKey);
|
removeCurrentListener(request.getSession(), clientUploadKey);
|
||||||
|
|
||||||
|
// try{
|
||||||
|
// if(fis!=null)
|
||||||
|
// fis.close();
|
||||||
|
// if (bis!=null)
|
||||||
|
// bis.close();
|
||||||
|
// if(tmpFile!=null && tmpFile.exists())
|
||||||
|
// tmpFile.delete();
|
||||||
|
// }catch(Exception e){
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue