This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch 3256-no-bad-file-extension-error-at-upload
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to
refs/heads/3256-no-bad-file-extension-error-at-upload by this push:
new abe80630d8 fix(#3256): Show error message when uploading unsupported
filetypes
abe80630d8 is described below
commit abe80630d853ff55e82da205e517ec5d18498d72
Author: Dominik Riemer <[email protected]>
AuthorDate: Mon Sep 30 20:48:33 2024 +0200
fix(#3256): Show error message when uploading unsupported filetypes
---
.../streampipes/rest/impl/PipelineElementFile.java | 17 +++--
.../apache/streampipes/sdk/helpers/Filetypes.java | 1 +
ui/src/app/configuration/configuration.module.ts | 2 +
.../file-upload/file-upload-dialog.component.html | 7 +-
.../file-upload/file-upload-dialog.component.ts | 14 +++-
ui/src/app/files/files.module.ts | 83 ----------------------
ui/src/app/files/files.routes.ts | 27 -------
7 files changed, 34 insertions(+), 117 deletions(-)
diff --git
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java
index 006f3f955d..f8a227b3f2 100644
---
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java
+++
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java
@@ -23,12 +23,14 @@ import org.apache.streampipes.model.message.Notifications;
import
org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.security.AuthConstants;
import org.apache.streampipes.rest.shared.exception.SpMessageException;
+import org.apache.streampipes.sdk.helpers.Filetypes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.apache.http.HttpStatus;
+
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -72,6 +74,13 @@ public class PipelineElementFile extends
AbstractAuthGuardedRestResource {
fileDetail.getInputStream()
);
return ok(metadata);
+ } catch (IllegalArgumentException e) {
+ return badRequest(Notifications.error(
+ String.format(
+ "This file type is not supported. Allowed filetypes are %s.",
+ Filetypes.getAllFileExtensions().toString()
+ )
+ ));
} catch (Exception e) {
return fail();
}
@@ -132,10 +141,10 @@ public class PipelineElementFile extends
AbstractAuthGuardedRestResource {
@PreAuthorize(AuthConstants.HAS_READ_FILE_PRIVILEGE)
public ResponseEntity<List<String>> getAllOriginalFilenames() {
return ok(fileManager.getAllFiles()
- .stream()
- .map(fileMetadata -> fileMetadata.getFilename()
- .toLowerCase())
- .toList());
+ .stream()
+ .map(fileMetadata -> fileMetadata.getFilename()
+ .toLowerCase())
+ .toList());
}
@GetMapping(
diff --git
a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Filetypes.java
b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Filetypes.java
index 681b180983..b8895a9b1f 100644
---
a/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Filetypes.java
+++
b/streampipes-sdk/src/main/java/org/apache/streampipes/sdk/helpers/Filetypes.java
@@ -29,6 +29,7 @@ public enum Filetypes {
XLS("xls"),
XLSX("xlsx"),
XML("xml"),
+ YAML("yaml", "yml"),
ZIP("zip");
private final List<String> fileExtensions;
diff --git a/ui/src/app/configuration/configuration.module.ts
b/ui/src/app/configuration/configuration.module.ts
index f24da2f959..ff860383f5 100644
--- a/ui/src/app/configuration/configuration.module.ts
+++ b/ui/src/app/configuration/configuration.module.ts
@@ -96,6 +96,7 @@ import { FileOverviewComponent } from
'./files/file-overview/file-overview.compo
import { FileUploadDialogComponent } from
'./dialog/file-upload/file-upload-dialog.component';
import { FileRenameDialogComponent } from
'./dialog/file-rename/file-rename-dialog.component';
import { MatDialogModule } from '@angular/material/dialog';
+import { MatProgressBarModule } from '@angular/material/progress-bar';
@NgModule({
imports: [
@@ -120,6 +121,7 @@ import { MatDialogModule } from '@angular/material/dialog';
CoreUiModule,
ReactiveFormsModule,
PlatformServicesModule,
+ MatProgressBarModule,
RouterModule.forChild([
{
path: '',
diff --git
a/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.html
b/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.html
index 6d83e5a5c6..ecec2cccdd 100644
---
a/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.html
+++
b/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.html
@@ -17,7 +17,10 @@
-->
<div class="sp-dialog-container">
- <div class="sp-dialog-content p-15">
+ <div class="sp-dialog-content p-15" fxLayout="column">
+ <sp-warning-box *ngIf="uploadError" style="font-size: smaller">
+ {{ uploadErrorMessage }}
+ </sp-warning-box>
<div fxFlex="100" *ngIf="this.duplicateFileNames.length === 0">
<div fxFlex="100" style="margin: 5px; width: 100%">
<mat-form-field
@@ -57,7 +60,7 @@
color="accent"
matSuffix
mat-button
- style="min-width: 0px"
+ style="min-width: 0"
>
<mat-icon *ngIf="uploadStatus < 99"
>insert_drive_file</mat-icon
diff --git
a/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.ts
b/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.ts
index 328cfe8494..beee8317b9 100644
---
a/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.ts
+++
b/ui/src/app/configuration/dialog/file-upload/file-upload-dialog.component.ts
@@ -39,6 +39,9 @@ export class FileUploadDialogComponent {
uploadStatus = 0;
+ uploadError = false;
+ uploadErrorMessage = '';
+
constructor(
private dialogRef: DialogRef<FileUploadDialogComponent>,
private filesService: FilesService,
@@ -73,6 +76,7 @@ export class FileUploadDialogComponent {
}
uploadFile(index: number): void {
+ this.uploadError = false;
this.filesService
.uploadFile(this.selectedUploadFiles.item(index))
.subscribe(
@@ -90,7 +94,15 @@ export class FileUploadDialogComponent {
}
}
},
- error => {},
+ error => {
+ this.uploadError = true;
+ if (error.error?.notifications?.length > 0) {
+ this.uploadErrorMessage =
+ error.error.notifications[0].title;
+ } else {
+ this.uploadErrorMessage = error.error;
+ }
+ },
);
}
diff --git a/ui/src/app/files/files.module.ts b/ui/src/app/files/files.module.ts
deleted file mode 100644
index 991569618d..0000000000
--- a/ui/src/app/files/files.module.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import { NgModule } from '@angular/core';
-import { CommonModule } from '@angular/common';
-import { FlexLayoutModule } from '@ngbracket/ngx-layout';
-import { MatButtonModule } from '@angular/material/button';
-import { MatGridListModule } from '@angular/material/grid-list';
-import { MatIconModule } from '@angular/material/icon';
-import { MatDividerModule } from '@angular/material/divider';
-import { MatListModule } from '@angular/material/list';
-import { FilesComponent } from '../configuration/files/files.component';
-import { MatTabsModule } from '@angular/material/tabs';
-import { CoreUiModule } from '../core-ui/core-ui.module';
-import { FormsModule, ReactiveFormsModule } from '@angular/forms';
-import { MatFormFieldModule } from '@angular/material/form-field';
-import { MatProgressBarModule } from '@angular/material/progress-bar';
-import { MatInputModule } from '@angular/material/input';
-import { ServicesModule } from '../services/services.module';
-import { MatTableModule } from '@angular/material/table';
-import { MatPaginatorModule } from '@angular/material/paginator';
-import { MatChipsModule } from '@angular/material/chips';
-import { MatTooltipModule } from '@angular/material/tooltip';
-import { PlatformServicesModule } from '@streampipes/platform-services';
-import { RouterModule } from '@angular/router';
-import { SharedUiModule } from '@streampipes/shared-ui';
-import { MatDialogModule } from '@angular/material/dialog';
-
-@NgModule({
- imports: [
- CommonModule,
- CoreUiModule,
- FlexLayoutModule,
- FormsModule,
- ReactiveFormsModule,
- MatButtonModule,
- MatChipsModule,
- MatFormFieldModule,
- MatGridListModule,
- MatIconModule,
- MatInputModule,
- MatDividerModule,
- MatListModule,
- MatPaginatorModule,
- MatProgressBarModule,
- MatTableModule,
- MatTabsModule,
- MatTooltipModule,
- PlatformServicesModule,
- ServicesModule,
- SharedUiModule,
- RouterModule.forChild([
- {
- path: '',
- children: [
- {
- path: '',
- component: FilesComponent,
- },
- ],
- },
- ]),
- MatDialogModule,
- ],
- declarations: [],
- providers: [],
-})
-export class FilesModule {}
diff --git a/ui/src/app/files/files.routes.ts b/ui/src/app/files/files.routes.ts
deleted file mode 100644
index be69607a13..0000000000
--- a/ui/src/app/files/files.routes.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import { SpBreadcrumbItem } from '@streampipes/shared-ui';
-
-export class SpFilesRoutes {
- static FILES_BASE_LINK = 'files';
- static BASE: SpBreadcrumbItem = {
- label: 'File Management',
- link: [SpFilesRoutes.FILES_BASE_LINK],
- };
-}