Skip to content

Commit 33feb7b

Browse files
authored
Log unspecific upload errors (#1213)
Co-authored-by: KochTobi <kochtobi@users.noreply.github.com>
1 parent a8444ed commit 33feb7b

File tree

3 files changed

+51
-41
lines changed

3 files changed

+51
-41
lines changed

user-interface/src/main/java/life/qbic/datamanager/views/general/upload/UploadWithDisplay.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public UploadWithDisplay(int maxFileSize, FileType[] fileTypes) {
9292
upload.setI18n(uploadI18N);
9393

9494
upload.addSucceededListener(it -> fireEvent(new SucceededEvent(this, it.isFromClient())));
95-
upload.addFailedListener(it -> fireEvent(new FailedEvent(this, it.isFromClient())));
95+
upload.addFailedListener(
96+
it -> fireEvent(new UnspecificFailedEvent(this, it.isFromClient(), it.getReason())));
9697
upload.addFileRejectedListener(fileRejected -> {
9798
errorArea.setVisible(true);
9899
errorArea.setText(fileRejected.getErrorMessage());
@@ -118,8 +119,9 @@ public Registration addSuccessListener(ComponentEventListener<SucceededEvent> li
118119
return addListener(SucceededEvent.class, listener);
119120
}
120121

121-
public Registration addFailureListener(ComponentEventListener<FailedEvent> listener) {
122-
return addListener(FailedEvent.class, listener);
122+
public Registration addUnspecificFailureListener(
123+
ComponentEventListener<UnspecificFailedEvent> listener) {
124+
return addListener(UnspecificFailedEvent.class, listener);
123125
}
124126

125127
public Registration addRemovedListener(ComponentEventListener<UploadRemovedEvent> listener) {
@@ -236,7 +238,9 @@ public SucceededEvent(UploadWithDisplay source, boolean fromClient) {
236238
}
237239
}
238240

239-
public static class FailedEvent extends ComponentEvent<UploadWithDisplay> {
241+
public static class UnspecificFailedEvent extends ComponentEvent<UploadWithDisplay> {
242+
243+
private final Exception cause;
240244

241245
/**
242246
* Creates a new event using the given source and indicator whether the event originated from
@@ -246,8 +250,13 @@ public static class FailedEvent extends ComponentEvent<UploadWithDisplay> {
246250
* @param fromClient <code>true</code> if the event originated from the client
247251
* side, <code>false</code> otherwise
248252
*/
249-
public FailedEvent(UploadWithDisplay source, boolean fromClient) {
253+
public UnspecificFailedEvent(UploadWithDisplay source, boolean fromClient, Exception cause) {
250254
super(source, fromClient);
255+
this.cause = cause;
256+
}
257+
258+
public Exception getCause() {
259+
return cause;
251260
}
252261
}
253262

user-interface/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/EditSampleBatchDialog.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ public EditSampleBatchDialog(SampleValidationService sampleValidationService,
121121
MAX_FILE_SIZE, new FileType[]{
122122
new FileType(".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
123123
});
124-
uploadWithDisplay.addFailureListener(uploadFailed -> {
125-
/* display of the error is handled by the uploadWithDisplay component. So nothing to do here.*/
126-
});
124+
uploadWithDisplay.addUnspecificFailureListener(
125+
uploadFailed ->
126+
/* display of the error is handled by the uploadWithDisplay component. However we do need to log with the context*/
127+
log.error(
128+
"Upload failed for project(" + projectId + ") experiment(" + experimentId + ")",
129+
uploadFailed.getCause()));
127130
uploadWithDisplay.addSuccessListener(
128131
uploadSucceeded -> onUploadSucceeded(sampleValidationService, experimentId, projectId,
129132
uploadSucceeded)
@@ -257,15 +260,14 @@ private Div setupDownloadMetadataSection(AsyncProjectService service,
257260
String projectId, String projectCode) {
258261
Button downloadTemplate = new Button("Download metadata template");
259262
downloadTemplate.addClassName("download-metadata-button");
260-
downloadTemplate.addClickListener(buttonClickEvent -> {
261-
service.sampleUpdateTemplate(projectId, experimentId, batchId,
262-
OPEN_XML).doOnSuccess(resource ->
263-
triggerDownload(resource,
264-
FileNameFormatter.formatWithTimestampedSimple(LocalDate.now(), projectCode,
265-
"sample metadata update template",
266-
"xlsx")
267-
)).doOnError(this::handleError).subscribe();
268-
});
263+
downloadTemplate.addClickListener(
264+
buttonClickEvent -> service.sampleUpdateTemplate(projectId, experimentId, batchId,
265+
OPEN_XML).doOnSuccess(resource ->
266+
triggerDownload(resource,
267+
FileNameFormatter.formatWithTimestampedSimple(LocalDate.now(), projectCode,
268+
"sample metadata update template",
269+
"xlsx")
270+
)).doOnError(this::handleError).subscribe());
269271
Div text = new Div();
270272
text.addClassName("download-metadata-text");
271273
text.setText(
@@ -284,12 +286,10 @@ private Div setupDownloadMetadataSection(AsyncProjectService service,
284286
}
285287

286288
private void handleError(Throwable throwable) {
287-
switch (throwable) {
288-
case AccessDeniedException ignored:
289-
handleAccessDeniedError();
290-
return;
291-
default:
292-
handleUnexpectedError(throwable);
289+
if (Objects.requireNonNull(throwable) instanceof AccessDeniedException) {
290+
handleAccessDeniedError();
291+
} else {
292+
handleUnexpectedError(throwable);
293293
}
294294
}
295295

user-interface/src/main/java/life/qbic/datamanager/views/projects/project/samples/registration/batch/RegisterSampleBatchDialog.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class RegisterSampleBatchDialog extends WizardDialogWindow {
6161
private final Div failedView;
6262
private final Div succeededView;
6363
private final UploadWithDisplay uploadWithDisplay;
64-
private transient final MessageSourceNotificationFactory messageFactory;
64+
private final transient MessageSourceNotificationFactory messageFactory;
6565
private final DownloadComponent downloadComponent;
6666
private final transient AsyncProjectService service;
6767

@@ -100,8 +100,12 @@ public RegisterSampleBatchDialog(AsyncProjectService asyncProjectService,
100100
uploadWithDisplay = new UploadWithDisplay(MAX_FILE_SIZE, new FileType[]{
101101
new FileType(".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
102102
});
103-
uploadWithDisplay.addFailureListener(
104-
uploadFailed -> {/* display of the error is handled by the uploadWithDisplay component. So nothing to do here.*/});
103+
uploadWithDisplay.addUnspecificFailureListener(
104+
uploadFailed ->
105+
/* display of the error is handled by the uploadWithDisplay component. However we do need to log with the context*/
106+
log.error(
107+
"Upload failed for project(" + projectId + ") experiment(" + experimentId + ")",
108+
uploadFailed.getCause()));
105109
uploadWithDisplay.addSuccessListener(
106110
uploadSucceeded -> onUploadSucceeded(experimentId, projectId,
107111
uploadSucceeded));
@@ -121,12 +125,10 @@ public RegisterSampleBatchDialog(AsyncProjectService asyncProjectService,
121125
}
122126

123127
private void handleError(Throwable throwable) {
124-
switch (throwable) {
125-
case AccessDeniedException ignored:
126-
handleAccessDeniedError();
127-
return;
128-
default:
129-
handleUnexpectedError(throwable);
128+
if (Objects.requireNonNull(throwable) instanceof AccessDeniedException) {
129+
handleAccessDeniedError();
130+
} else {
131+
handleUnexpectedError(throwable);
130132
}
131133
}
132134

@@ -283,15 +285,14 @@ private Div setupDownloadMetadataSection(AsyncProjectService service, String exp
283285
String projectId, String projectCode) {
284286
Button downloadTemplate = new Button("Download metadata template");
285287
downloadTemplate.addClassName("download-metadata-button");
286-
downloadTemplate.addClickListener(buttonClickEvent -> {
287-
service.sampleRegistrationTemplate(projectId, experimentId,
288-
OPEN_XML).doOnSuccess(resource ->
289-
triggerDownload(resource,
290-
FileNameFormatter.formatWithTimestampedSimple(LocalDate.now(), projectCode,
291-
"sample metadata template",
292-
"xlsx")
293-
)).doOnError(this::handleError).subscribe();
294-
});
288+
downloadTemplate.addClickListener(
289+
buttonClickEvent -> service.sampleRegistrationTemplate(projectId, experimentId,
290+
OPEN_XML).doOnSuccess(resource ->
291+
triggerDownload(resource,
292+
FileNameFormatter.formatWithTimestampedSimple(LocalDate.now(), projectCode,
293+
"sample metadata template",
294+
"xlsx")
295+
)).doOnError(this::handleError).subscribe());
295296
Div text = new Div();
296297
text.addClassName("download-metadata-text");
297298
text.setText(

0 commit comments

Comments
 (0)