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/06/18 14:47:59 UTC
[incubator-streampipes] branch dev updated: [STREAMPIPES-545] Add API for generic storage
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 a00162cd9 [STREAMPIPES-545] Add API for generic storage
a00162cd9 is described below
commit a00162cd95a5fe5818e74017287c2556f31e8ce9
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Sat Jun 18 16:47:52 2022 +0200
[STREAMPIPES-545] Add API for generic storage
---
.../backend/StreamPipesResourceConfig.java | 1 +
.../rest/impl/GenericStorageResource.java | 123 +++++++++++++++++++++
.../src/lib/apis/generic-storage.service.ts | 66 +++++++++++
.../platform-services/src/public-api.ts | 1 +
.../basic-view/basic-view.component.html | 4 +-
5 files changed, 193 insertions(+), 2 deletions(-)
diff --git a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
index 0499843fd..0a6efad7b 100644
--- a/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
@@ -70,6 +70,7 @@ public class StreamPipesResourceConfig extends ResourceConfig {
register(EmailResource.class);
register(ExtensionsServiceEndpointResource.class);
register(GeneralConfigurationResource.class);
+ register(GenericStorageResource.class);
register(LabelResource.class);
register(MeasurementUnitResource.class);
register(Notification.class);
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/GenericStorageResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/GenericStorageResource.java
new file mode 100644
index 000000000..663e96a93
--- /dev/null
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/GenericStorageResource.java
@@ -0,0 +1,123 @@
+/*
+ * 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.rest.impl;
+
+import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
+import org.apache.streampipes.rest.security.AuthConstants;
+import org.apache.streampipes.storage.api.IGenericStorage;
+import org.apache.streampipes.storage.management.StorageDispatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+@Path("/v2/storage-generic")
+@Component
+@PreAuthorize(AuthConstants.IS_ADMIN_ROLE)
+public class GenericStorageResource extends AbstractAuthGuardedRestResource {
+
+ public static final String APP_DOC_NAME = "appDocName";
+
+ private static final Logger LOG = LoggerFactory.getLogger(GenericStorageResource.class);
+
+ @GET
+ @Path("{appDocName}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getAll(@PathParam(APP_DOC_NAME) String appDocName) {
+ try {
+ List<Map<String, Object>> assets = getGenericStorage().findAll(appDocName);
+ return ok(assets);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @POST
+ @Path("{appDocName}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response create(@PathParam(APP_DOC_NAME) String appDocName,
+ String document) {
+ try {
+ Map<String, Object> obj = getGenericStorage().create(document);
+ return ok(obj);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @GET
+ @Path("{appDocName}/{id}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCategory(@PathParam(APP_DOC_NAME) String appDocName,
+ @PathParam("id") String documentId) {
+ try {
+ Map<String, Object> obj = getGenericStorage().findOne(documentId);
+ return ok(obj);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @PUT
+ @Path("{appDocName}/{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response update(@PathParam(APP_DOC_NAME) String appDocName,
+ @PathParam("id") String documentId,
+ String document) {
+ try {
+ Map<String, Object> obj = getGenericStorage().update(documentId, document);
+ return ok(obj);
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ @DELETE
+ @Path("{appDocName}/{id}/{rev}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response delete(@PathParam(APP_DOC_NAME) String appDocName,
+ @PathParam("id") String documentId,
+ @PathParam("rev") String rev) {
+ try {
+ getGenericStorage().delete(documentId, rev);
+ return ok();
+ } catch (IOException e) {
+ LOG.error("Could not connect to storage", e);
+ return fail();
+ }
+ }
+
+ private IGenericStorage getGenericStorage() {
+ return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage();
+ }
+
+ }
diff --git a/ui/projects/streampipes/platform-services/src/lib/apis/generic-storage.service.ts b/ui/projects/streampipes/platform-services/src/lib/apis/generic-storage.service.ts
new file mode 100644
index 000000000..4cdc45d21
--- /dev/null
+++ b/ui/projects/streampipes/platform-services/src/lib/apis/generic-storage.service.ts
@@ -0,0 +1,66 @@
+/*
+ * 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 { Injectable } from '@angular/core';
+import { HttpClient } from '@angular/common/http';
+import { PlatformServicesCommons } from './commons.service';
+import { Observable } from 'rxjs';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class GenericStorageService {
+
+ constructor(private http: HttpClient,
+ private platformServicesCommons: PlatformServicesCommons) {
+ }
+
+ createDocument(appDocName: string,
+ document: any): Observable<any> {
+ return this.http.post(this.getAppDocPath(appDocName), document);
+ }
+
+ getAllDocuments(appDocName: string): Observable<any> {
+ return this.http.get(this.getAppDocPath(appDocName));
+ }
+
+ getDocument(appDocName: string,
+ documentId: string): Observable<any> {
+ return this.http.get(`${this.getAppDocPath(appDocName)}/${documentId}`);
+ }
+
+ updateDocument(appDocName: string,
+ document: any): Observable<any> {
+ return this.http.put(`${this.getAppDocPath(appDocName)}/${document._id}`, document);
+ }
+
+ deleteDocument(appDocName: string,
+ documentId: string,
+ rev: string): Observable<any> {
+ return this.http.delete(`${this.getAppDocPath(appDocName)}/${documentId}/${rev}`);
+ }
+
+ private getAppDocPath(appDocName: string): string {
+ return this.genericStorageBasePath + '/' + appDocName;
+ }
+
+ private get genericStorageBasePath() {
+ return this.platformServicesCommons.apiBasePath + '/storage-generic';
+ }
+
+}
diff --git a/ui/projects/streampipes/platform-services/src/public-api.ts b/ui/projects/streampipes/platform-services/src/public-api.ts
index 6a459cf49..a5415306c 100644
--- a/ui/projects/streampipes/platform-services/src/public-api.ts
+++ b/ui/projects/streampipes/platform-services/src/public-api.ts
@@ -30,6 +30,7 @@ export * from './lib/apis/datalake-rest.service';
export * from './lib/apis/dashboard.service';
export * from './lib/apis/files.service';
export * from './lib/apis/general-config.service';
+export * from './lib/apis/generic-storage.service';
export * from './lib/apis/mail-config.service';
export * from './lib/apis/measurement-units.service';
export * from './lib/apis/permissions.service';
diff --git a/ui/projects/streampipes/shared-ui/src/lib/components/basic-view/basic-view.component.html b/ui/projects/streampipes/shared-ui/src/lib/components/basic-view/basic-view.component.html
index 0c1c6ffce..8051bf6b7 100644
--- a/ui/projects/streampipes/shared-ui/src/lib/components/basic-view/basic-view.component.html
+++ b/ui/projects/streampipes/shared-ui/src/lib/components/basic-view/basic-view.component.html
@@ -36,7 +36,7 @@
<div fxLayout="column" class="page-container">
<div fxLayout="row" class="p-0 sp-bg-lightgray page-container-nav">
- <div fxLayout="fill">
+ <div fxLayout="fill" fxFlex="100">
<div class="pl-5 pr-5"
fxLayout="row"
fxLayoutAlign="start center"
@@ -51,7 +51,7 @@
<mat-icon>arrow_back</mat-icon>
</button>
</div>
- <ng-content select="[nav]"></ng-content>
+ <ng-content select="[nav]" fxFlex="100"></ng-content>
</div>
</div>