Skip to content

Commit

Permalink
AF-650: Upload without choosing file causes exception in Artifact rep…
Browse files Browse the repository at this point in the history
…ository (#904)
  • Loading branch information
barboras7 authored and manstis committed Nov 9, 2017
1 parent 4a0fb81 commit 1c10f62
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.gwtbootstrap3.client.shared.event.ModalHideEvent;
import org.gwtbootstrap3.client.shared.event.ModalHideHandler;
import org.gwtbootstrap3.client.ui.base.form.AbstractForm;
import org.gwtbootstrap3.client.ui.gwt.FormPanel;
import org.jboss.errai.ioc.client.container.SyncBeanManager;

import static org.guvnor.m2repo.model.HTMLFileManagerFields.UPLOAD_MISSING_POM;
Expand Down Expand Up @@ -80,21 +79,18 @@ public void handleSubmitComplete(final AbstractForm.SubmitCompleteEvent event) {
}
}

/*
* After upgrade of GWT-BOOTSTRAP3 version, will be needed to handle
* org.gwtbootstrap3.client.ui.Form.SubmitEvent
*/
@Override
public void handleSubmit(final FormPanel.SubmitEvent event) {
public boolean isFileNameValid() {
String fileName = view.getFileName();
if (fileName == null || "".equals(fileName)) {
view.showSelectFileUploadWarning();
event.cancel();
return false;
} else if (!(isValid(fileName))) {
view.showUnsupportedFileTypeWarning();
event.cancel();
return false;
} else {
view.showUploadingBusy();
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.guvnor.m2repo.client.upload.UploadFormView.Presenter;
import org.gwtbootstrap3.client.shared.event.ModalHideHandler;
import org.gwtbootstrap3.client.ui.base.form.AbstractForm;
import org.gwtbootstrap3.client.ui.gwt.FormPanel;
import org.uberfire.client.mvp.UberView;

public interface UploadFormView extends UberView<Presenter> {
Expand All @@ -28,11 +27,7 @@ interface Presenter {

void handleSubmitComplete(AbstractForm.SubmitCompleteEvent event);

/*
* After upgrade of GWT-BOOTSTRAP3 version, will be needed to handle
* org.gwtbootstrap3.client.ui.Form.SubmitEvent
*/
void handleSubmit(FormPanel.SubmitEvent event);
boolean isFileNameValid();
}

String getFileName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.uberfire.ext.widgets.common.client.common.FormStyleLayout;
import org.uberfire.ext.widgets.common.client.common.popups.BaseModal;
import org.uberfire.ext.widgets.common.client.common.popups.errors.ErrorPopup;
import org.uberfire.mvp.Command;

public class UploadFormViewImpl
extends BaseModal implements UploadFormView {
Expand Down Expand Up @@ -73,27 +72,14 @@ private Form doUploadForm() {
form.setMethod(FormPanel.METHOD_POST);
form.setType(FormType.HORIZONTAL);

/*
* After upgrade of GWT-BOOTSTRAP3 version, will be needed to register
* org.gwtbootstrap3.client.ui.Form.SubmitHandler
*/
form.addHandler(new FormPanel.SubmitHandler() {
@Override
public void onSubmit(com.google.gwt.user.client.ui.FormPanel.SubmitEvent submitEvent) {
presenter.handleSubmit(submitEvent);
}
},
FormPanel.SubmitEvent.getType());

form.addSubmitCompleteHandler(new Form.SubmitCompleteHandler() {
public void onSubmitComplete(final Form.SubmitCompleteEvent event) {
presenter.handleSubmitComplete(event);
}
});

uploader = new FileUpload(new Command() {
@Override
public void execute() {
uploader = new FileUpload(() -> {
if (presenter.isFileNameValid()) {
form.submit();
}
});
Expand Down Expand Up @@ -223,4 +209,4 @@ private void showMessage(final String message) {
private void showErrorMessage(final String message) {
ErrorPopup.showMessage(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.gwtbootstrap3.client.shared.event.ModalHideEvent;
import org.gwtbootstrap3.client.shared.event.ModalHideHandler;
import org.gwtbootstrap3.client.ui.base.form.AbstractForm;
import org.gwtbootstrap3.client.ui.gwt.FormPanel;
import org.jboss.errai.ioc.client.container.SyncBeanManager;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -72,7 +71,7 @@ public void before() {
@Test
public void emptyFilenameTest() {
when(view.getFileName()).thenReturn(null);
uploadFormPresenter.handleSubmit(new FormPanel.SubmitEvent());
uploadFormPresenter.isFileNameValid();

verify(view).showSelectFileUploadWarning();
verify(view,
Expand All @@ -82,7 +81,7 @@ public void emptyFilenameTest() {
@Test
public void nullFilenameTest() {
when(view.getFileName()).thenReturn("");
uploadFormPresenter.handleSubmit(new FormPanel.SubmitEvent());
uploadFormPresenter.isFileNameValid();

verify(view).showSelectFileUploadWarning();
verify(view,
Expand All @@ -92,7 +91,7 @@ public void nullFilenameTest() {
@Test
public void unsupportedFilenameTest() {
when(view.getFileName()).thenReturn("//!#@%^&*()\\23\\(0");
uploadFormPresenter.handleSubmit(new FormPanel.SubmitEvent());
uploadFormPresenter.isFileNameValid();

verify(view).showUnsupportedFileTypeWarning();
verify(view,
Expand All @@ -102,7 +101,7 @@ public void unsupportedFilenameTest() {
@Test
public void correctFilenameTest() {
when(view.getFileName()).thenReturn("/home/user/something/pom.xml");
uploadFormPresenter.handleSubmit(new FormPanel.SubmitEvent());
uploadFormPresenter.isFileNameValid();

verify(view).showUploadingBusy();
}
Expand Down

0 comments on commit 1c10f62

Please sign in to comment.