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

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

commit 958f50f5920073fd6f7dac874ad93ae73093aacf
Author: Philipp Zehnder <[email protected]>
AuthorDate: Sun Oct 25 14:51:12 2020 +0100

    Store categories and label in db
---
 .../streampipes/rest/impl/CategoryResource.java    |  14 ++-
 .../streampipes/rest/impl/LabelResource.java       |  16 +++-
 .../streampipes/storage/api/ICategoryStorage.java  |   2 +-
 .../streampipes/storage/api/ILabelStorage.java     |   2 +-
 .../storage/couchdb/impl/CategoryStorageImpl.java  |   4 +-
 .../storage/couchdb/impl/LabelStorageImpl.java     |   4 +-
 ui/src/app/core-model/gen/streampipes-model.ts     |  10 +--
 .../configure-labels.component.html                |   4 +-
 .../configure-labels/configure-labels.component.ts |  38 ++++++--
 .../label-list-item/label-list-item.component.html |   5 +-
 .../label-list-item/label-list-item.component.ts   |  21 ++++-
 .../app/core-ui/labels/services/label.service.ts   | 100 ++++++++++++++-------
 12 files changed, 154 insertions(+), 66 deletions(-)

diff --git 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/CategoryResource.java
 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/CategoryResource.java
index 9fbcadb..7964f37 100644
--- 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/CategoryResource.java
+++ 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/CategoryResource.java
@@ -35,11 +35,14 @@ public class CategoryResource extends AbstractRestInterface 
implements ICategory
     @JacksonSerialized
     @Override
     public Response add(Category category) {
-        StorageDispatcher.INSTANCE
+        String categoryId = StorageDispatcher.INSTANCE
                 .getNoSqlStore()
                 .getCategoryStorageAPI()
                 .storeCategory(category);
-        return ok();
+
+        return ok(StorageDispatcher.INSTANCE
+                .getNoSqlStore()
+                .getCategoryStorageAPI().getCategory(categoryId));
     }
 
     @GET
@@ -61,7 +64,7 @@ public class CategoryResource extends AbstractRestInterface 
implements ICategory
     @JacksonSerialized
     @Override
     public Response update(@PathParam("categoryId") String categoryId, 
Category category) {
-        if (categoryId != category.getId()) {
+        if (!categoryId.equals(category.getId())) {
             String resString = "CategoryId not the same as in message body";
             Map<String, Object> errorDetails = new HashMap<>();
             errorDetails.put("message", resString);
@@ -71,7 +74,10 @@ public class CategoryResource extends AbstractRestInterface 
implements ICategory
                 .getNoSqlStore()
                 .getCategoryStorageAPI()
                 .updateCategory(category);
-        return ok();
+
+        return ok(StorageDispatcher.INSTANCE
+                .getNoSqlStore()
+                .getCategoryStorageAPI().getCategory(categoryId));
     }
 
     @DELETE
diff --git 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/LabelResource.java
 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/LabelResource.java
index fd8ead7..5387aab 100644
--- 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/LabelResource.java
+++ 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/LabelResource.java
@@ -44,11 +44,15 @@ public class LabelResource extends AbstractRestInterface 
implements ILabel {
             errorDetails.put("message", resString);
             return badRequest(errorDetails);
         }
-        StorageDispatcher.INSTANCE
+        String labelId = StorageDispatcher.INSTANCE
                 .getNoSqlStore()
                 .getLabelStorageAPI()
                 .storeLabel(label);
-        return ok();
+
+        return ok(StorageDispatcher.INSTANCE
+                .getNoSqlStore()
+                .getLabelStorageAPI()
+                .getLabel(labelId));
     }
 
     @GET
@@ -70,7 +74,7 @@ public class LabelResource extends AbstractRestInterface 
implements ILabel {
     @JacksonSerialized
     @Override
     public Response updateLabel(@PathParam("labelId") String labelId, Label 
label) {
-        if (labelId != label.getId()) {
+        if (!labelId.equals(label.getId())) {
             String resString = "LabelId not the same as in message body";
             Map<String, Object> errorDetails = new HashMap<>();
             errorDetails.put("message", resString);
@@ -90,7 +94,11 @@ public class LabelResource extends AbstractRestInterface 
implements ILabel {
                 .getNoSqlStore()
                 .getLabelStorageAPI()
                 .updateLabel(label);
-        return ok();
+
+        return ok(StorageDispatcher.INSTANCE
+                .getNoSqlStore()
+                .getLabelStorageAPI()
+                .getLabel(labelId));
     }
 
     @DELETE
diff --git 
a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ICategoryStorage.java
 
b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ICategoryStorage.java
index f111e31..7799343 100644
--- 
a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ICategoryStorage.java
+++ 
b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ICategoryStorage.java
@@ -9,7 +9,7 @@ public interface ICategoryStorage {
 
     List<Category>getAllCategories();
 
-    void storeCategory(Category category);
+    String storeCategory(Category category);
 
     void updateCategory(Category category);
 
diff --git 
a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ILabelStorage.java
 
b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ILabelStorage.java
index 998c271..1f56ba1 100644
--- 
a/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ILabelStorage.java
+++ 
b/streampipes-storage-api/src/main/java/org/apache/streampipes/storage/api/ILabelStorage.java
@@ -13,7 +13,7 @@ public interface ILabelStorage {
 
     void deleteAllForCategory(String categoryId);
 
-    void storeLabel(Label label);
+    String storeLabel(Label label);
 
     Label getLabel(String labelId);
 
diff --git 
a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/CategoryStorageImpl.java
 
b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/CategoryStorageImpl.java
index ff714ce..4e97f50 100644
--- 
a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/CategoryStorageImpl.java
+++ 
b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/CategoryStorageImpl.java
@@ -20,8 +20,8 @@ public class CategoryStorageImpl extends 
AbstractDao<Category> implements ICateg
     }
 
     @Override
-    public void storeCategory(Category category) {
-        persist(category);
+    public String storeCategory(Category category) {
+        return persist(category).b;
     }
 
     @Override
diff --git 
a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/LabelStorageImpl.java
 
b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/LabelStorageImpl.java
index 7c38a9d..bd5e83e 100644
--- 
a/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/LabelStorageImpl.java
+++ 
b/streampipes-storage-couchdb/src/main/java/org/apache/streampipes/storage/couchdb/impl/LabelStorageImpl.java
@@ -20,8 +20,8 @@ public class LabelStorageImpl extends AbstractDao<Label> 
implements ILabelStorag
     }
 
     @Override
-    public void storeLabel(Label label) {
-        persist(label);
+    public String storeLabel(Label label) {
+        return persist(label).b;
     }
 
     @Override
diff --git a/ui/src/app/core-model/gen/streampipes-model.ts 
b/ui/src/app/core-model/gen/streampipes-model.ts
index 4f93cb6..30c1bcd 100644
--- a/ui/src/app/core-model/gen/streampipes-model.ts
+++ b/ui/src/app/core-model/gen/streampipes-model.ts
@@ -1,7 +1,7 @@
 /* tslint:disable */
 /* eslint-disable */
 // @ts-nocheck
-// Generated using typescript-generator version 2.24.612 on 2020-10-02 
09:31:34.
+// Generated using typescript-generator version 2.24.612 on 2020-10-25 
14:14:54.
 
 export class AbstractStreamPipesEntity {
     "@class": "org.apache.streampipes.model.base.NamedStreamPipesEntity" | 
"org.apache.streampipes.model.connect.adapter.AdapterDescription" | 
"org.apache.streampipes.model.connect.adapter.AdapterSetDescription" | 
"org.apache.streampipes.model.connect.adapter.GenericAdapterSetDescription" | 
"org.apache.streampipes.model.connect.adapter.SpecificAdapterSetDescription" | 
"org.apache.streampipes.model.connect.adapter.AdapterStreamDescription" | 
"org.apache.streampipes.model.connect.adapter.G [...]
@@ -586,9 +586,8 @@ export class Category {
     _id: string;
     _rev: string;
     internalName: string;
-    labels: Label[];
     name: string;
-    superLabel: Label;
+    superLabelId: string;
 
     static fromData(data: Category, target?: Category): Category {
         if (!data) {
@@ -597,8 +596,7 @@ export class Category {
         const instance = target || new Category();
         instance.name = data.name;
         instance.internalName = data.internalName;
-        instance.superLabel = Label.fromData(data.superLabel);
-        instance.labels = __getCopyArrayFn(Label.fromData)(data.labels);
+        instance.superLabelId = data.superLabelId;
         instance._id = data._id;
         instance._rev = data._rev;
         return instance;
@@ -1710,6 +1708,7 @@ export class KeepOutputStrategy extends OutputStrategy {
 export class Label {
     _id: string;
     _rev: string;
+    categoryId: string;
     color: string;
     internalName: string;
     name: string;
@@ -1722,6 +1721,7 @@ export class Label {
         instance.name = data.name;
         instance.color = data.color;
         instance.internalName = data.internalName;
+        instance.categoryId = data.categoryId;
         instance._id = data._id;
         instance._rev = data._rev;
         return instance;
diff --git 
a/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.html
 
b/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.html
index fe76cba..0088ffb 100644
--- 
a/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.html
+++ 
b/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.html
@@ -24,13 +24,13 @@
         <div fxLayout="row" fxLayoutAlign="space-between center">
             <mat-form-field>
                 <mat-label>Category Name</mat-label>
-                <input matInput type="text" 
[(ngModel)]="selectedCategory.name">
+                <input matInput (ngModelChange)="updateCategory($event)" 
type="text" [(ngModel)]="selectedCategory.name">
             </mat-form-field>
             <mat-icon  style="cursor: pointer;" matTooltip="Delete label 
category" (click)="deleteCategory()" class="icon">delete</mat-icon>
         </div>
         <div fxLayout="column" fxLayoutAlign="center stretch">
             <sp-label-list-item
-                    *ngFor="let label of selectedCategory.labels;"
+                    *ngFor="let label of categoryLabels;"
                     (removeLabel)="removeLabel($event)"
                     [label]="label">
             </sp-label-list-item>
diff --git 
a/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.ts
 
b/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.ts
index 8025a67..694dd7c 100644
--- 
a/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.ts
+++ 
b/ui/src/app/core-ui/labels/components/configure-labels/configure-labels.component.ts
@@ -12,6 +12,7 @@ export class ConfigureLabelsComponent implements OnInit {
 
   public categories: Category[];
   public selectedCategory: Category;
+  public categoryLabels: Label[];
 
   public editCategory: boolean;
 
@@ -19,13 +20,19 @@ export class ConfigureLabelsComponent implements OnInit {
 
   ngOnInit(): void {
     this.editCategory = false;
-    this.categories = this.labelService.getCategories();
+    this.labelService.getCategories().subscribe(res => {
+      this.categories = res;
+    });
   }
 
   startEditCategory(value) {
     if ('internal_placeholder' !== value.value) {
       this.editCategory = true;
     }
+
+    
this.labelService.getLabelsOfCategory(this.selectedCategory).subscribe((res: 
Label[]) => {
+      this.categoryLabels = res;
+    });
   }
 
   endEditCategory() {
@@ -36,14 +43,26 @@ export class ConfigureLabelsComponent implements OnInit {
   addCategory() {
     const c1 = new Category();
     c1.name = '';
-    c1.labels = [];
 
-    this.categories.push(c1);
-    this.selectedCategory = c1;
-    this.editCategory = true;
+    this.labelService.addCategory(c1).subscribe((res: Category) => {
+      this.selectedCategory = res;
+      this.editCategory = true;
+      this.categories.push(res);
+    });
+
+    this.categoryLabels = [];
+  }
+
+  updateCategory(newCategoryName) {
+    this.selectedCategory.name = newCategoryName;
+
+    this.labelService.updateCategory(this.selectedCategory).subscribe((res: 
Category) => {
+      this.selectedCategory = res;
+    });
   }
 
   deleteCategory() {
+    this.labelService.deleteCategory(this.selectedCategory).subscribe();
     this.categories = this.categories.filter(obj => obj !== 
this.selectedCategory);
     this.endEditCategory();
   }
@@ -51,12 +70,17 @@ export class ConfigureLabelsComponent implements OnInit {
   addLabel() {
     const label = new Label();
     label.name = '';
+    // tslint:disable-next-line:no-bitwise
     label.color = '#' + (Math.random() * 0xFFFFFF << 
0).toString(16).padStart(6, '0');
+    label.categoryId = this.selectedCategory._id;
 
-    this.selectedCategory.labels.push(label);
+    this.labelService.addLabel(label).subscribe((res: Label) => {
+      this.categoryLabels.push(res);
+    });
   }
 
   removeLabel(label) {
-    this.selectedCategory.labels = this.selectedCategory.labels.filter(obj => 
obj !== label);
+    this.labelService.deleteLabel(label).subscribe();
+    this.categoryLabels = this.categoryLabels.filter(obj => obj !== label);
   }
 }
diff --git 
a/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.html
 
b/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.html
index 5b8e925..47c1805 100644
--- 
a/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.html
+++ 
b/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.html
@@ -4,13 +4,14 @@
                style="margin-right: 10px; width: 20px;"
                autocomplete="off"
                [(colorPicker)]="label.color"
-               (colorPickerChange)="label.color = $event"
+               (colorPickerChange)="updateLabelColor($event)"
                [cpPosition]="'bottom'"
                [style.background]="label.color" required
         />
     </div>
         <mat-form-field>
-            <input matInput type="text" [(ngModel)]="label.name">
+            <input matInput type="text" [(ngModel)]="label.name"
+            (ngModelChange)="updateLabelName($event)">
         </mat-form-field>
     <div>
         <mat-icon style="margin-left: 20px; margin-top: 5px; cursor: pointer;" 
(click)="clickRemoveLabel()">remove</mat-icon>
diff --git 
a/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.ts
 
b/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.ts
index 3b2bfe9..586399d 100644
--- 
a/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.ts
+++ 
b/ui/src/app/core-ui/labels/components/label-list-item/label-list-item.component.ts
@@ -1,5 +1,7 @@
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
-import { Label } from '../../../../core-model/gen/streampipes-model';
+import { Category, Label } from '../../../../core-model/gen/streampipes-model';
+import { ColorService } from '../../../image/services/color.service';
+import { LabelService } from '../../services/label.service';
 
 @Component({
   selector: 'sp-label-list-item',
@@ -13,7 +15,7 @@ export class LabelListItemComponent implements OnInit {
 
   @Output() removeLabel = new EventEmitter<Label>();
 
-  constructor() { }
+  constructor(public labelService: LabelService) { }
 
   ngOnInit(): void {
   }
@@ -22,4 +24,19 @@ export class LabelListItemComponent implements OnInit {
     this.removeLabel.emit(this.label);
   }
 
+  public updateLabelName(newLabelName) {
+    this.label.name = newLabelName;
+    this.updateLabel();
+  }
+
+  public updateLabelColor(newLabelColor) {
+    this.label.color = newLabelColor;
+    this.updateLabel();
+  }
+
+  private updateLabel() {
+    this.labelService.updateLabel(this.label).subscribe((res: Label) => {
+      this.label = res;
+    });
+  }
 }
diff --git a/ui/src/app/core-ui/labels/services/label.service.ts 
b/ui/src/app/core-ui/labels/services/label.service.ts
index b62d0ae..a7588cb 100644
--- a/ui/src/app/core-ui/labels/services/label.service.ts
+++ b/ui/src/app/core-ui/labels/services/label.service.ts
@@ -1,5 +1,8 @@
 import { Injectable } from '@angular/core';
 import { Category, Label } from '../../../core-model/gen/streampipes-model';
+import { PlatformServicesCommons } from 
'../../../platform-services/apis/commons.service';
+import { HttpClient } from '@angular/common/http';
+import { Observable } from 'rxjs';
 
 @Injectable({
   providedIn: 'root'
@@ -7,53 +10,82 @@ import { Category, Label } from 
'../../../core-model/gen/streampipes-model';
 export class LabelService {
   private categories = [];
 
-  constructor() { }
-
-  getLabels() {
-    return {
-      'boxes': ['blue', 'red'],
-      'sign': ['trafficsign'],
-      'person': ['person', 'Child'],
-      'vehicle': ['bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 
'truck', 'boat'],
-      'outdoor': ['traffic light', 'fire hydrant', 'stop sign', 'parking 
meter', 'bench'],
-      'animal': ['bird', 'cat', 'dog'],
-      'accessory': ['backpack', 'umbrella', 'handbag', 'suitcase'],
-      'sports': ['frisbee', 'sports ball', 'skis', 'frisbee', 'baseball bat'],
-      'kitchen': ['bottle', 'cup', 'fork', 'knife', 'spoon'],
-      'furniture': ['chair', 'couch', 'bed', 'table'],
-      'electronic': ['tv', 'laptop', 'mouse', 'keyboard']
-    };
+  urlBase() {
+    return this.platformServicesCommons.authUserBasePath();
   }
 
-  getCategories(): Category[] {
+  constructor(
+    private platformServicesCommons: PlatformServicesCommons,
+    private $http: HttpClient) { }
 
-    const c1 = new Category();
-    c1.name = 'Straßenschild';
+  // getLabels() {
+  //   return {
+  //     'boxes': ['blue', 'red'],
+  //     'sign': ['trafficsign'],
+  //     'person': ['person', 'Child'],
+  //     'vehicle': ['bicycle', 'car', 'motorcycle', 'airplane', 'bus', 
'train', 'truck', 'boat'],
+  //     'outdoor': ['traffic light', 'fire hydrant', 'stop sign', 'parking 
meter', 'bench'],
+  //     'animal': ['bird', 'cat', 'dog'],
+  //     'accessory': ['backpack', 'umbrella', 'handbag', 'suitcase'],
+  //     'sports': ['frisbee', 'sports ball', 'skis', 'frisbee', 'baseball 
bat'],
+  //     'kitchen': ['bottle', 'cup', 'fork', 'knife', 'spoon'],
+  //     'furniture': ['chair', 'couch', 'bed', 'table'],
+  //     'electronic': ['tv', 'laptop', 'mouse', 'keyboard']
+  //   };
+  // }
 
-    c1.labels = [];
-    c1.labels.push(this.getLabel('Stop', '#0000ff'));
-    c1.labels.push(this.getLabel('50', '#ff0000'));
+  getCategories(): Observable<any> {
+    return this.$http.get(this.urlBase() + '/labeling/category');
+    //
+    // const c1 = new Category();
+    // c1.name = 'Straßenschild';
+    //
+    // c1.labels = [];
+    // c1.labels.push(this.getLabel('Stop', '#0000ff'));
+    // c1.labels.push(this.getLabel('50', '#ff0000'));
+    //
+    // const c2 = new Category();
+    // c2.name = 'furniture';
+    //
+    // c2.labels = [];
+    // c2.labels.push(this.getLabel('chair', '#7dff24'));
+    // c2.labels.push(this.getLabel('couch', '#ff6ef7'));
+    //
+    // this.categories.push(c1);
+    // this.categories.push(c2);
+    //
+    // return this.categories;
+  }
 
-    const c2 = new Category();
-    c2.name = 'furniture';
+  getLabelsOfCategory(category: Category): Observable<any> {
+    return this.$http.get(this.urlBase() + '/labeling/label/category/' + 
category._id);
+  }
 
-    c2.labels = [];
-    c2.labels.push(this.getLabel('chair', '#7dff24'));
-    c2.labels.push(this.getLabel('couch', '#ff6ef7'));
 
-    this.categories.push(c1);
-    this.categories.push(c2);
+  addCategory(c: Category) {
+    return this.$http.post(this.urlBase() + '/labeling/category', c);
+    // this.categories.push(c);
+  }
 
-    return this.categories;
+  updateCategory(c: Category) {
+    return this.$http.put(this.urlBase() + '/labeling/category/' + c._id, c);
+    // this.categories.push(c);
   }
 
+  deleteCategory(c: Category) {
+    return this.$http.delete(this.urlBase() + '/labeling/category/' + c._id);
+  }
 
-  addCategory(c: Category) {
-   this.categories.push(c);
+  addLabel(l: Label) {
+    return this.$http.post(this.urlBase() + '/labeling/label', l);
   }
 
-  updateCategory(c: Category) {
-    this.categories.push(c);
+  updateLabel(l: Label) {
+    return this.$http.put(this.urlBase() + '/labeling/label/' + l._id, l);
+  }
+
+  deleteLabel(l: Label) {
+    return this.$http.delete(this.urlBase() + '/labeling/label/' + l._id);
   }
 
 

Reply via email to