Completed the uploading part

This commit is contained in:
francesco 2020-10-06 16:33:21 +02:00
parent b3fcfc021f
commit 375abecc66
7 changed files with 122 additions and 127 deletions

View File

@ -285,23 +285,6 @@ public class CreateMetadataForm extends Composite{
}
});
// // hide elements or show them if needed (groups in profiles cannot be present again in groups listbox)
// if(groupsControlGroup.isVisible()){
// List<String> groupsToHide = new ArrayList<String>();
// for(MetaDataProfileBean profile: profiles)
// groupsToHide.add(profile.getType().toString());
//
// SelectElement se = groupsListbox.getElement().cast();
//
// for (int i = 0; i < groupsListbox.getItemCount(); i++) {
// if(groupsToHide.contains(groupsListbox.getItemText(i))){
// se.getOptions().getItem(i).getStyle().setProperty("display", "none");
// }else
// se.getOptions().getItem(i).getStyle().setProperty("display", "");
// }
// }
//
// metadataTypesControlGroup.setVisible(true);
}else{
// just hide this listbox
metadataTypesControlGroup.setVisible(false);
@ -469,64 +452,6 @@ public class CreateMetadataForm extends Composite{
}
// /**
// * On go back button first step.
// *
// * @param e the e
// */
// @UiHandler("goBackButtonFirstStep")
// void onGoBackButtonFirstStep(ClickEvent e){
//
// Window.alert("Called onGoBackButtonFirstStep");
//
//// // swap forms
//// formFirstStep.setVisible(true);
//// formSecondStep.setVisible(false);
//// formThirdStep.setVisible(false);
//
// }
/**
* On go back button.
*
* @param e the e
*/
// @UiHandler("goBackButtonSecondStep")
// void onGoBackButton(ClickEvent e){
//
// Window.alert("Called onGoBackButton");
//
//// // swap forms
//// if(isWorkspaceRequest){
//// formFirstStep.setVisible(hideManageResources());
//// formSecondStep.setVisible(!hideManageResources());
//// }else{
//// formFirstStep.setVisible(true);
//// formSecondStep.setVisible(false);
//// }
//// formThirdStep.setVisible(false);
//
// }
// /**
// * On continue third step.
// *
// * @param e the e
// */
// @UiHandler("continueThirdStep")
// void onContinueThirdStep(ClickEvent e){
//
// Window.alert("Called onGoBackButton");
//
// // swap forms
//// formSecondStep.setVisible(false);
//// formThirdStep.setVisible(true);
//
// }
/**
* Creates the dataset event.
*

View File

@ -26,6 +26,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
// TODO: Auto-generated Javadoc
/**
* The Class DialogUploadStream.
*
@ -34,11 +35,21 @@ import com.google.gwt.user.client.ui.VerticalPanel;
*/
public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotificationListener{
/** The file upload. */
//protected final FormPanel formPanel = new FormPanel();
protected FileUpload fileUpload;
/** The json client keys. */
protected Hidden jsonClientKeys;
/** The fake uploaders. */
protected List<WorkspaceUploaderItem> fakeUploaders = new ArrayList<WorkspaceUploaderItem>();
/** The controller. */
protected WorkspaceUploaderListenerController controller = new WorkspaceUploaderListenerController();
/** The timer. */
private TimerUpload timer;
/**
* The Enum UPLOAD_TYPE.
@ -47,19 +58,20 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
* Sep 11, 2015
*/
private HTML UPLOADING = new HTML("Uploading...");
/** The vertical main panel. */
protected VerticalPanel verticalMainPanel;
// private MonitorPanel monitorPanel;
//protected String clientUploadKey;
private String purgedUploadingFileName;
/** The purged uploading file name. */
private String purgedUploadingFileName;
/** The upv. */
private UploaderProgressView upv;
/**
* Instantiates a new dialog upload stream.
*
* @param headerTitle the header title
* @param parentId the parent id
* @param uploadType the upload type
*/
public DialogUpload(){
//setWidth("400px");
@ -94,12 +106,17 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
}
/**
* Gets the panel.
*
* @return the panel
*/
public VerticalPanel getPanel() {
return verticalMainPanel;
}
/**
* Inits the json client keys.
*/
protected void initJsonClientKeys(){
jsonClientKeys = new Hidden(ConstantsMPFormBuilder.CLIENT_UPLOAD_KEYS,"");
}
@ -208,6 +225,9 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
});
}
/**
* On submit action.
*/
protected void onSubmitAction() {
GWT.log("SubmitEvent");
try {
@ -223,9 +243,20 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
upv = new UploaderProgressView(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName(), null);
verticalMainPanel.add(upv.getPanel());
removeLoading();
SingleUploadMonitor.getInstance().doStartPollingQueue(workspaceUploaderItem, upv);
timer = new TimerUpload(workspaceUploaderItem, upv);
SingleUploadMonitor.getInstance().doStartPolling(timer);
fakeUploaders.clear();
}
/**
* Gets the uploaded info.
*
* @return the uploaded info
*/
public WorkspaceUploaderItem getUploadedInfo() {
return timer.getWorkspaceUploader();
}
/**
* Adds the loading.
@ -302,6 +333,11 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
submitForm();
}
/**
* Adds the workspace upload notification listener.
*
* @param handler the handler
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#addWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
*/
@ -310,6 +346,11 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
controller.addWorkspaceUploadListener(handler);
}
/**
* Removes the workspace upload notification listener.
*
* @param handler the handler
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#removeWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
*/

View File

@ -21,6 +21,7 @@ import com.google.gwt.json.client.JSONString;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
// TODO: Auto-generated Javadoc
/**
* The Class MultipleDilaogUploadStream.
*
@ -28,23 +29,25 @@ import com.google.gwt.user.client.ui.HTML;
*/
public class MultipleDilaogUpload extends DialogUpload {
/** The Constant FILE_DELEMITER. */
public static final String FILE_DELEMITER = ";";
/** The file upload ID. */
private String fileUploadID;
/** The instance. */
//private MultipleDNDUpload dnd;
public MultipleDilaogUpload instance = this;
/** The json keys. */
private String jsonKeys;
/** The id folder. */
private String idFolder;
/**
* Instantiates a new multiple dilaog upload stream.
*
* @param headerTitle
* the header title
* @param parentId
* the parent id
* @param uploadType
* the upload type
* Instantiates a new multiple dilaog upload.
*/
public MultipleDilaogUpload() {
fileUploadID = GenerateUUID.get(10, 16); // is tagID
@ -55,8 +58,7 @@ public class MultipleDilaogUpload extends DialogUpload {
/**
* Generate new upload client keys.
*
* @param files the files
* @param parentId the parent id
* @param filesSelected the files selected
* @return the list
*/
public void generateFakeUploaders(String filesSelected) {
@ -89,6 +91,9 @@ public class MultipleDilaogUpload extends DialogUpload {
GWT.log("fakeUploaders generated: "+fakeUploaders.toString());
}
/**
* Adds the handlers.
*/
@Override
protected void addHandlers() {

View File

@ -8,14 +8,11 @@ import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUp
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Timer;
public class SingleUploadMonitor {
private static SingleUploadMonitor instance;
private final static HandlerManager monitorEventBus = new HandlerManager(null);
private Map<String, TimerUpload> currentTimersRun = new HashMap<String, TimerUpload>();
/**
@ -37,9 +34,8 @@ public class SingleUploadMonitor {
* @param workspaceUploader
* @param upv
*/
public synchronized void doStartPollingQueue(WorkspaceUploaderItem workspaceUploader, UploaderProgressView upv) {
TimerUpload timer = new TimerUpload(workspaceUploader, upv);
startTimer(workspaceUploader, timer);
public synchronized void doStartPolling(TimerUpload timer) {
startTimer(timer);
}
/**
@ -47,9 +43,9 @@ public class SingleUploadMonitor {
*
* @param workspaceUploader the workspace uploader
*/
public void startTimer(final WorkspaceUploaderItem workspaceUploader, TimerUpload timer){
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
saveTimer(timer, workspaceUploader.getClientUploadKey());
private void startTimer(TimerUpload timer){
GWT.log("Starting new timer for key: "+timer.getWorkspaceUploader().getClientUploadKey());
saveTimer(timer);
timer.scheduleRepeating(2000);
}
@ -71,11 +67,11 @@ public class SingleUploadMonitor {
/**
* Save timer.
*
* @param timerUpload the timer upload
* @param timer the timer upload
* @param clientKey the client key
*/
private synchronized void saveTimer(TimerUpload timerUpload, String clientKey){
currentTimersRun.put(clientKey, timerUpload);
private synchronized void saveTimer(TimerUpload timer){
currentTimersRun.put(timer.getWorkspaceUploader().getClientUploadKey(), timer);
}
@ -85,7 +81,7 @@ public class SingleUploadMonitor {
* @param clientKey the client key
* @return the timer
*/
private TimerUpload getTimer(String clientKey){
protected TimerUpload getTimer(String clientKey){
return currentTimersRun.get(clientKey);
}

View File

@ -13,33 +13,43 @@ import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
// TODO: Auto-generated Javadoc
/**
* The Class TimerUpload.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 11, 2016
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it at ISTI-CNR
*
* Oct 6, 2020
*/
public class TimerUpload extends Timer{
/** The workspace uploader. */
private WorkspaceUploaderItem workspaceUploader;
private WorkspaceUploaderItem initWorkspaceUploader;
/** The last workspace uploader. */
private WorkspaceUploaderItem lastWorkspaceUploader;
/** The instance. */
private TimerUpload INSTANCE = this;
/** The upv. */
private UploaderProgressView upv;
/**
* Instantiates a new timer upload.
*
* @param workspaceUploader the workspace uploader
* @param upv
* @param queue the queue
* @param indexQueue the index queue
* @param upv the upv
*/
public TimerUpload(WorkspaceUploaderItem workspaceUploader, UploaderProgressView upv) {
this.workspaceUploader = workspaceUploader;
this.initWorkspaceUploader = workspaceUploader;
this.upv = upv;
}
/**
* Run.
*/
/* (non-Javadoc)
* @see com.google.gwt.user.client.Timer#run()
*/
@ -48,16 +58,17 @@ public class TimerUpload extends Timer{
final SingleUploadMonitor monitor = SingleUploadMonitor.getInstance();
MetadataProfileFormBuilderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
MetadataProfileFormBuilderServiceAsync.Util.getInstance().getUploadStatus(initWorkspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
@Override
public void onSuccess(final WorkspaceUploaderItem result) {
try{
synchronized(this){
lastWorkspaceUploader = result;
// Timer tmn = queue.get(workspaceUploader.getClientUploadKey());
if(INSTANCE!=null && INSTANCE.isRunning()){
if(result==null || result.getUploadStatus()==null){
GWT.log("Upload or status its status is null for: "+workspaceUploader.getClientUploadKey());
GWT.log("Upload or status its status is null for: "+initWorkspaceUploader.getClientUploadKey());
return;
}
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
@ -96,14 +107,12 @@ public class TimerUpload extends Timer{
}
//is running
upv.update(result);
// GWT.log(result.toString());
upv.update(result);;
}else{
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
GWT.log("Timer is null or already closed or completed");
cancel();
monitor.removeTimer(workspaceUploader.getClientUploadKey());
monitor.removeTimer(initWorkspaceUploader.getClientUploadKey());
}
}
}catch(Exception e){
@ -116,22 +125,31 @@ public class TimerUpload extends Timer{
GWT.log("onFailure: "+caught.getMessage());
cancel();
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
monitor.notifyUploadError(workspaceUploader.getFile().getFileName(), null, null, caught);
monitor.notifyUploadError(initWorkspaceUploader.getFile().getFileName(), null, null, caught);
// removeTimer(workspaceUploader.getClientUploadKey());
}
});
}
/**
* Cancel.
*/
/* (non-Javadoc)
* @see com.google.gwt.user.client.Timer#cancel()
*/
@Override
public void cancel() {
GWT.log("Cancelling timer for "+workspaceUploader);
GWT.log("Cancelling timer for "+lastWorkspaceUploader);
super.cancel();
}
/**
* Gets the workspace uploader.
*
* @return the workspace uploader
*/
public WorkspaceUploaderItem getWorkspaceUploader() {
return initWorkspaceUploader;
}
}

View File

@ -15,7 +15,6 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* The Class UploaderProgressView.
*
@ -33,6 +32,7 @@ public class UploaderProgressView {
private HandlerManager eventBus;
private boolean cancel = false;
private Image cancelImg = new Image(Images.ICONS.delete());
private WorkspaceUploaderItem lastUploaderLoaded;
/**
* Instantiates a new uploader progress view.
@ -87,6 +87,8 @@ public class UploaderProgressView {
public void update(WorkspaceUploaderItem uploader){
String text;
try{
this.lastUploaderLoaded = uploader;
switch(uploader.getUploadStatus()){
case COMPLETED:
setVisibleBar(true);
@ -117,7 +119,7 @@ public class UploaderProgressView {
case ABORTED:
setVisibleBar(true);
text = "<div><img src='"+Images.ICONS.aborted().getURL()+"'>";
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getStatusDescription(), MAX_CHARS, 0)+"</span></div>";
text+="<span style='margin-left:5px; vertical-align: top;'>"+uploader.getStatusDescription()+"</span></div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());

View File

@ -7,6 +7,9 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@ -97,6 +100,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
/** The app engine. */
private static boolean appEngine = false;
public static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir");
/**
* Inits the.
@ -405,7 +410,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
logger.debug("Stream content type: "+contentType);
//UPLOAD FILE. IT IS DEFAULT CASE
logger.debug("Uploding file in the TEMP system folder...");
logger.debug("Uploading file in the TEMP system folder...");
workspaceUploader = createStreamToTempFile(request, workspaceUploader, inputStream, user.getUsername(), clientUploadKey, fileName, extension);
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
@ -433,7 +438,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
// sendError(response, "Internal error: An error occurred on uploading the file, try again later");
// return;
}finally{
//removeCurrentListener(request.getSession(), clientUploadKey);
//TODO
removeCurrentListener(request.getSession(), clientUploadKey);
}
}
@ -521,9 +527,11 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
workspaceUploader.setStatusDescription("Uploading...");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
String uniqueFileName = String.format("%s_%s_%s",username,fileName,clientUploadKey);
String uniqueFileName = String.format("%s_%s", clientUploadKey, fileName);
File tempFile = File.createTempFile(uniqueFileName, fileExtension);
//File tempFile = File.createTempFile(uniqueFileName, fileExtension);
//tempFile.deleteOnExit();
//File tempFile = tempFilePath.toFile();
FileOutputStream out = new FileOutputStream(tempFile);
IOUtils.copy(in, out);
workspaceUploader.getFile().setTempSystemPath(tempFile.getAbsolutePath());