99import com .vaadin .flow .component .html .Div ;
1010import com .vaadin .flow .component .html .Paragraph ;
1111import com .vaadin .flow .component .html .Span ;
12+ import com .vaadin .flow .component .upload .FailedEvent ;
13+ import com .vaadin .flow .component .upload .FileRejectedEvent ;
1214import com .vaadin .flow .component .upload .SucceededEvent ;
1315import com .vaadin .flow .component .upload .Upload ;
1416import com .vaadin .flow .dom .DomEvent ;
2123import java .util .Objects ;
2224import life .qbic .application .commons .ApplicationException ;
2325import life .qbic .datamanager .views .general .DialogWindow ;
26+ import life .qbic .datamanager .views .notifications .ErrorMessage ;
27+ import life .qbic .datamanager .views .notifications .StyledNotification ;
2428import life .qbic .datamanager .views .projects .EditableMultiFileMemoryBuffer ;
2529import life .qbic .datamanager .views .projects .qualityControl .QualityControlItem .ExperimentItem ;
2630import life .qbic .logging .api .Logger ;
3236 * <b>Upload Quality Control Dialog</b>
3337 * <p>
3438 * A dialog window that enables uploads of sample quality control reports.
35- *
3639 */
3740public class UploadQualityControlDialog extends DialogWindow {
3841
3942 private static final Logger log = logger (UploadQualityControlDialog .class );
4043 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
4245 @ Serial
4346 private static final long serialVersionUID = 6602134795666762831L ;
4447 private final Upload upload ;
@@ -60,7 +63,6 @@ public UploadQualityControlDialog(ProjectId projectId,
6063
6164 // Vaadin's upload component setup
6265 multiFileMemoryBuffer = new EditableMultiFileMemoryBuffer ();
63-
6466 upload = new Upload (multiFileMemoryBuffer );
6567 upload .setAcceptedFileTypes (AllowedFileExtension .PDF .extension (),
6668 AllowedFileExtension .PDF .mimetype (),
@@ -78,7 +80,7 @@ public UploadQualityControlDialog(ProjectId projectId,
7880 restrictions .addClassName ("restrictions" );
7981 restrictions .add (new Span ("Supported file formats: PDF, docx, xlsx" ));
8082 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 ))));
8284 Div uploadSection = new Div ();
8385 uploadSection .add (uploadSectionTitle , upload , restrictions );
8486
@@ -100,6 +102,10 @@ public UploadQualityControlDialog(ProjectId projectId,
100102 // Add upload QualityControls to the link experiment item section, where users can decide on the linked experiment
101103 upload .addSucceededListener (this ::onUploadSucceeded );
102104
105+ // Show notification if user provides invalid file
106+ upload .addFailedListener (this ::onUploadFailure );
107+ upload .addFileRejectedListener (this ::onUploadFailure );
108+
103109 // Synchronise the Vaadin upload component with the purchase list display
104110 // When a file is removed from the upload component, we also want to remove it properly from memory
105111 // and from any additional display
@@ -122,6 +128,21 @@ private void onUploadSucceeded(SucceededEvent succeededEvent) {
122128 toggleFileSectionIfEmpty ();
123129 }
124130
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+
125146 @ Override
126147 protected void onConfirmClicked (ClickEvent <Button > clickEvent ) {
127148 fireEvent (new ConfirmEvent (this , true ));
0 commit comments