You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2022/08/08 12:37:36 UTC

[incubator-streampipes] branch dev updated: [STREAMPIPES-565] Add asset link type for files

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new a7a9fc0cc [STREAMPIPES-565] Add asset link type for files
a7a9fc0cc is described below

commit a7a9fc0ccbf81c88ab7425c94f57e31c480be293
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Mon Aug 8 14:37:25 2022 +0200

    [STREAMPIPES-565] Add asset link type for files
---
 .../backend/migrations/AvailableMigrations.java    |  4 +-
 .../streampipes/backend/migrations/Migration.java  |  4 +-
 .../backend/migrations/MigrationsHandler.java      |  8 ++-
 .../v070/CreateFileAssetTypeMigration.java         | 59 ++++++++++++++++++++++
 .../setup/tasks/CreateAssetLinkTypeTask.java       |  3 +-
 .../edit-asset-link-dialog.component.html          | 12 +++++
 .../edit-asset-link-dialog.component.ts            | 11 ++--
 ui/src/scss/_variables.scss                        |  1 +
 8 files changed, 95 insertions(+), 7 deletions(-)

diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java
index 38aa9eda7..5b26d793e 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/AvailableMigrations.java
@@ -21,6 +21,7 @@ package org.apache.streampipes.backend.migrations;
 
 import org.apache.streampipes.backend.migrations.v070.CreateAssetLinkTypeMigration;
 import org.apache.streampipes.backend.migrations.v070.CreateDefaultAssetMigration;
+import org.apache.streampipes.backend.migrations.v070.CreateFileAssetTypeMigration;
 
 import java.util.Arrays;
 import java.util.List;
@@ -30,7 +31,8 @@ public class AvailableMigrations {
   public List<Migration> getAvailableMigrations() {
     return Arrays.asList(
       new CreateAssetLinkTypeMigration(),
-      new CreateDefaultAssetMigration()
+      new CreateDefaultAssetMigration(),
+      new CreateFileAssetTypeMigration()
     );
   }
 }
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/Migration.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/Migration.java
index bb165c2b3..0cabbfa13 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/Migration.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/Migration.java
@@ -19,11 +19,13 @@
 
 package org.apache.streampipes.backend.migrations;
 
+import java.io.IOException;
+
 public interface Migration {
 
   boolean shouldExecute();
 
-  void executeMigration();
+  void executeMigration() throws IOException;
 
   String getDescription();
 }
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/MigrationsHandler.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/MigrationsHandler.java
index 63f800170..72ea5922c 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/MigrationsHandler.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/MigrationsHandler.java
@@ -22,6 +22,8 @@ package org.apache.streampipes.backend.migrations;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+
 public class MigrationsHandler {
 
   private static final Logger LOG = LoggerFactory.getLogger(MigrationsHandler.class);
@@ -33,7 +35,11 @@ public class MigrationsHandler {
     availableMigrations.forEach(migration -> {
       if (migration.shouldExecute()) {
         LOG.info("Performing migration: {}", migration.getDescription());
-        migration.executeMigration();
+        try {
+          migration.executeMigration();
+        } catch (IOException e) {
+          LOG.error("An error has occurred while executing migration '{}'", migration.getDescription(), e);
+        }
       }
     });
 
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java
new file mode 100644
index 000000000..56d837be5
--- /dev/null
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/migrations/v070/CreateFileAssetTypeMigration.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ *
+ */
+
+package org.apache.streampipes.backend.migrations.v070;
+
+import org.apache.streampipes.backend.migrations.Migration;
+import org.apache.streampipes.commons.constants.GenericDocTypes;
+import org.apache.streampipes.commons.random.UUIDGenerator;
+import org.apache.streampipes.model.assets.AssetLinkType;
+import org.apache.streampipes.storage.management.StorageDispatcher;
+
+import java.io.IOException;
+import java.util.List;
+
+public class CreateFileAssetTypeMigration implements Migration {
+
+  @Override
+  public boolean shouldExecute() {
+    try {
+      return StorageDispatcher
+        .INSTANCE
+        .getNoSqlStore()
+        .getGenericStorage()
+        .findAll(GenericDocTypes.DOC_ASSET_LINK_TYPE)
+        .stream()
+        .noneMatch(al -> al.get("linkType").equals("file"));
+    } catch (IOException e) {
+      return true;
+    }
+  }
+
+  @Override
+  public void executeMigration() throws IOException {
+    var fileAsset = new AssetLinkType("file", "File", "var(--color-file)", "draft", "file", List.of(), false);
+    fileAsset.setId(UUIDGenerator.generateUuid());
+    StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage().create(fileAsset, AssetLinkType.class);
+
+  }
+
+  @Override
+  public String getDescription() {
+    return "Create asset type 'File'";
+  }
+}
diff --git a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/tasks/CreateAssetLinkTypeTask.java b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/tasks/CreateAssetLinkTypeTask.java
index a16f86291..90ddc2d08 100644
--- a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/tasks/CreateAssetLinkTypeTask.java
+++ b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/setup/tasks/CreateAssetLinkTypeTask.java
@@ -36,7 +36,8 @@ public class CreateAssetLinkTypeTask implements InstallationTask {
     new AssetLinkType("adapter", "Adapter", "var(--color-adapter)", "power", "adapter", List.of("connect"), true),
     new AssetLinkType("data-source", "Data Source", "var(--color-data-source)", "dataset", "data-source", List.of(), false),
     new AssetLinkType("pipeline", "Pipeline", "var(--color-pipeline)", "play_arrow", "pipeline", List.of("pipeline", "details"), true),
-    new AssetLinkType("measurement", "Data Lake Storage", "var(--color-measurement)", "folder", "measurement", List.of(), false)
+    new AssetLinkType("measurement", "Data Lake Storage", "var(--color-measurement)", "folder", "measurement", List.of(), false),
+    new AssetLinkType("file", "File", "var(--color-file)", "draft", "file", List.of(), false)
   );
 
   @Override
diff --git a/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.html b/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.html
index 480c4b6da..ca528415c 100644
--- a/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.html
+++ b/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.html
@@ -101,6 +101,18 @@
                     </mat-select>
                 </mat-form-field>
             </div>
+            <div *ngIf="selectedLinkType.linkQueryHint === 'file'" fxLayout="column" class="link-configuration">
+                <mat-form-field color="accent" fxFlex="100">
+                    <mat-label>Files</mat-label>
+                    <mat-select (selectionChange)="changeLabel($event.value.fileId, $event.value.originalFilename, $event.value)"
+                                [(value)]="currentResource"
+                                fxFlex
+                                required>
+                        <mat-option *ngFor="let file of files"
+                                    [value]="file">{{file.originalFilename}}</mat-option>
+                    </mat-select>
+                </mat-form-field>
+            </div>
             <div fxLayout="column" class="link-configuration">
                 <mat-form-field color="accent">
                     <mat-label>Label</mat-label>
diff --git a/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.ts b/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.ts
index a989a7f64..fee3b0d9e 100644
--- a/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.ts
+++ b/ui/src/app/assets/dialog/edit-asset-link/edit-asset-link-dialog.component.ts
@@ -31,7 +31,7 @@ import {
   GenericStorageService,
   Pipeline,
   PipelineService,
-  PipelineElementService
+  PipelineElementService, FileMetadata, FilesService
 } from '@streampipes/platform-services';
 import { FormGroup } from '@angular/forms';
 import { zip } from 'rxjs';
@@ -64,6 +64,7 @@ export class EditAssetLinkDialogComponent implements OnInit {
   dataLakeMeasures: DataLakeMeasure[];
   dataSources: SpDataStream[];
   adapters: AdapterDescriptionUnion[];
+  files: FileMetadata[];
 
   allResources: any[] = [];
   currentResource: any;
@@ -77,7 +78,8 @@ export class EditAssetLinkDialogComponent implements OnInit {
               private dashboardService: DashboardService,
               private dataLakeService: DatalakeRestService,
               private pipelineElementService: PipelineElementService,
-              private adapterService: AdapterService) {
+              private adapterService: AdapterService,
+              private filesService: FilesService) {
   }
 
   ngOnInit(): void {
@@ -106,13 +108,15 @@ export class EditAssetLinkDialogComponent implements OnInit {
       this.dashboardService.getDashboards(),
       this.pipelineElementService.getDataStreams(),
       this.dataLakeService.getAllMeasurementSeries(),
+      this.filesService.getFileMetadata(),
       this.adapterService.getAdapters()).subscribe(response => {
       this.pipelines = response[0];
       this.dataViews = response[1];
       this.dashboards = response[2];
       this.dataSources = response[3];
       this.dataLakeMeasures = response[4];
-      this.adapters = response[5];
+      this.files = response[5];
+      this.adapters = response[6];
 
       this.allResources = [
         ...this.pipelines,
@@ -120,6 +124,7 @@ export class EditAssetLinkDialogComponent implements OnInit {
         ...this.dashboards,
         ...this.dataSources,
         ...this.dataLakeMeasures,
+        ...this.files,
         ...this.adapters
       ];
       if (!this.createMode) {
diff --git a/ui/src/scss/_variables.scss b/ui/src/scss/_variables.scss
index 190b27ac2..5d137a41c 100644
--- a/ui/src/scss/_variables.scss
+++ b/ui/src/scss/_variables.scss
@@ -37,5 +37,6 @@ body {
   --color-data-source: #ffa23b;
   --color-pipeline: rgb(102, 185, 114);
   --color-measurement: rgb(39, 164, 155);
+  --color-file: rgb(163, 98, 190);
 
 }