9
9
import com .vaadin .flow .component .html .Div ;
10
10
import com .vaadin .flow .component .html .Paragraph ;
11
11
import com .vaadin .flow .component .html .Span ;
12
+ import com .vaadin .flow .component .upload .FailedEvent ;
13
+ import com .vaadin .flow .component .upload .FileRejectedEvent ;
12
14
import com .vaadin .flow .component .upload .SucceededEvent ;
13
15
import com .vaadin .flow .component .upload .Upload ;
14
16
import com .vaadin .flow .dom .DomEvent ;
21
23
import java .util .Objects ;
22
24
import life .qbic .application .commons .ApplicationException ;
23
25
import life .qbic .datamanager .views .general .DialogWindow ;
26
+ import life .qbic .datamanager .views .notifications .ErrorMessage ;
27
+ import life .qbic .datamanager .views .notifications .StyledNotification ;
24
28
import life .qbic .datamanager .views .projects .EditableMultiFileMemoryBuffer ;
25
29
import life .qbic .datamanager .views .projects .qualityControl .QualityControlItem .ExperimentItem ;
26
30
import life .qbic .logging .api .Logger ;
32
36
* <b>Upload Quality Control Dialog</b>
33
37
* <p>
34
38
* A dialog window that enables uploads of sample quality control reports.
35
- *
36
39
*/
37
40
public class UploadQualityControlDialog extends DialogWindow {
38
41
39
42
private static final Logger log = logger (UploadQualityControlDialog .class );
40
43
private static final String VAADIN_FILENAME_EVENT = "event.detail.file.name" ;
41
- private static final int MAX_FILE_SIZE_BYTES = 1024 * 1024 * 16 ; // 16 MiB
44
+ private static final int MAX_FILE_SIZE_BYTES = 1024 * 1024 * 16 ; // 17 MiB
42
45
@ Serial
43
46
private static final long serialVersionUID = 6602134795666762831L ;
44
47
private final Upload upload ;
@@ -60,7 +63,6 @@ public UploadQualityControlDialog(ProjectId projectId,
60
63
61
64
// Vaadin's upload component setup
62
65
multiFileMemoryBuffer = new EditableMultiFileMemoryBuffer ();
63
-
64
66
upload = new Upload (multiFileMemoryBuffer );
65
67
upload .setAcceptedFileTypes (AllowedFileExtension .PDF .extension (),
66
68
AllowedFileExtension .PDF .mimetype (),
@@ -78,7 +80,7 @@ public UploadQualityControlDialog(ProjectId projectId,
78
80
restrictions .addClassName ("restrictions" );
79
81
restrictions .add (new Span ("Supported file formats: PDF, docx, xlsx" ));
80
82
restrictions .add (
81
- new Span ("Maximum file size: %s MB" .formatted (MAX_FILE_SIZE_BYTES / (1024 * 1024 ))));
83
+ new Span ("Maximum file size: %s MB" .formatted (MAX_FILE_SIZE_BYTES / (1024 * 1024 ))));
82
84
Div uploadSection = new Div ();
83
85
uploadSection .add (uploadSectionTitle , upload , restrictions );
84
86
@@ -100,6 +102,10 @@ public UploadQualityControlDialog(ProjectId projectId,
100
102
// Add upload QualityControls to the link experiment item section, where users can decide on the linked experiment
101
103
upload .addSucceededListener (this ::onUploadSucceeded );
102
104
105
+ // Show notification if user provides invalid file
106
+ upload .addFailedListener (this ::onUploadFailure );
107
+ upload .addFileRejectedListener (this ::onUploadFailure );
108
+
103
109
// Synchronise the Vaadin upload component with the purchase list display
104
110
// When a file is removed from the upload component, we also want to remove it properly from memory
105
111
// and from any additional display
@@ -122,6 +128,21 @@ private void onUploadSucceeded(SucceededEvent succeededEvent) {
122
128
toggleFileSectionIfEmpty ();
123
129
}
124
130
131
+ private void onUploadFailure (ComponentEvent <Upload > event ) {
132
+ ErrorMessage errorMessage = new ErrorMessage ("Quality Control upload failed" ,
133
+ "An unknown exception has occurred" );
134
+ if (event instanceof FileRejectedEvent ) {
135
+ errorMessage .descriptionTextSpan .setText (
136
+ "Please provide a file within the file limit of %s MB" .formatted (
137
+ MAX_FILE_SIZE_BYTES / (1024 * 1024 )));
138
+ } else if (event instanceof FailedEvent ) {
139
+ errorMessage .descriptionTextSpan .setText (
140
+ "Quality control upload was interrupted, please try again" );
141
+ }
142
+ StyledNotification notification = new StyledNotification (errorMessage );
143
+ notification .open ();
144
+ }
145
+
125
146
@ Override
126
147
protected void onConfirmClicked (ClickEvent <Button > clickEvent ) {
127
148
fireEvent (new ConfirmEvent (this , true ));
0 commit comments