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 2021/09/24 13:26:22 UTC

[incubator-streampipes] 08/12: [STREAMPIPES-427] Modify paths of pipeline element import, preview and monitoring resources

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

commit 9a90b5bd6a57960af2fa177bad9110481125d7a3
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Fri Sep 24 14:45:12 2021 +0200

    [STREAMPIPES-427] Modify paths of pipeline element import, preview and monitoring resources
---
 .../rest/impl/PipelineElementImport.java           | 25 ++++++++++---------
 .../rest/impl/PipelineElementPreview.java          |  2 +-
 .../rest/impl/PipelineElementRuntimeInfo.java      |  2 +-
 .../streampipes/rest/impl/PipelineMonitoring.java  |  2 +-
 ui/src/app/connect/services/rest.service.ts        | 28 ++++++++++++----------
 .../apis/pipeline-element-endpoint.service.ts      | 10 ++++----
 ui/src/app/services/rest-api.service.ts            |  2 +-
 7 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementImport.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementImport.java
index 0b2184b..2834dd4 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementImport.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementImport.java
@@ -32,7 +32,7 @@ import org.apache.streampipes.model.message.Message;
 import org.apache.streampipes.model.message.Notification;
 import org.apache.streampipes.model.message.NotificationType;
 import org.apache.streampipes.model.message.Notifications;
-import org.apache.streampipes.rest.core.base.impl.AbstractRestResource;
+import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
 import org.apache.streampipes.storage.api.IPipelineElementDescriptionStorageCache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -46,16 +46,15 @@ import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.List;
 
-@Path("/v2/users/{username}/element")
-public class PipelineElementImport extends AbstractRestResource {
+@Path("/v2/element")
+public class PipelineElementImport extends AbstractAuthGuardedRestResource {
 
   private static final Logger LOG = LoggerFactory.getLogger(PipelineElementImport.class);
 
   @POST
   @Path("/batch")
   @Produces(MediaType.APPLICATION_JSON)
-  public Response addBatch(@PathParam("username") String username,
-                           @FormParam("uri") String uri,
+  public Response addBatch(@FormParam("uri") String uri,
                            @FormParam("publicElement") boolean publicElement) {
     try {
       uri = URLDecoder.decode(uri, "UTF-8");
@@ -63,7 +62,7 @@ public class PipelineElementImport extends AbstractRestResource {
       List<Message> messages = new ArrayList<>();
       if (element.isJsonArray()) {
         for (JsonElement jsonObj : element.getAsJsonArray()) {
-          messages.add(verifyAndAddElement(jsonObj.getAsString(), username, publicElement));
+          messages.add(verifyAndAddElement(jsonObj.getAsString(), getAuthenticatedUsername(), publicElement));
         }
       }
       return ok(messages);
@@ -75,13 +74,12 @@ public class PipelineElementImport extends AbstractRestResource {
 
   @POST
   @Produces(MediaType.APPLICATION_JSON)
-  public Response addElement(@PathParam("username") String username,
-                             @FormParam("uri") String uri,
+  public Response addElement(@FormParam("uri") String uri,
                              @FormParam("publicElement") boolean publicElement) {
-    if (!authorized(username)) {
+    if (!authorized(getAuthenticatedUsername())) {
       return ok(Notifications.error(NotificationType.UNAUTHORIZED));
     }
-    return ok(verifyAndAddElement(uri, username, publicElement));
+    return ok(verifyAndAddElement(uri, getAuthenticatedUsername(), publicElement));
   }
 
   private Message verifyAndAddElement(String uri, String username, boolean publicElement) {
@@ -91,7 +89,8 @@ public class PipelineElementImport extends AbstractRestResource {
   @PUT
   @Path("/{id}")
   @Produces(MediaType.APPLICATION_JSON)
-  public Response updateElement(@PathParam("username") String username, @PathParam("id") String elementId) {
+  public Response updateElement(@PathParam("id") String elementId) {
+    String username = getAuthenticatedUsername();
     if (!authorized(username)) {
       return ok(Notifications.error(NotificationType.UNAUTHORIZED));
     }
@@ -109,8 +108,8 @@ public class PipelineElementImport extends AbstractRestResource {
   @Path("/{id}")
   @DELETE
   @Produces(MediaType.APPLICATION_JSON)
-  public Response deleteElement(@PathParam("username") String username, @PathParam("id") String elementId) {
-
+  public Response deleteElement(@PathParam("id") String elementId) {
+    String username = getAuthenticatedUsername();
     UserService userService = getUserService();
     IPipelineElementDescriptionStorageCache requestor = getPipelineElementRdfStorage();
     String appId;
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementPreview.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementPreview.java
index c5187ae..bd91ca3 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementPreview.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementPreview.java
@@ -27,7 +27,7 @@ import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-@Path("/v2/users/{username}/pipeline-element-preview")
+@Path("/v2/pipeline-element-preview")
 public class PipelineElementPreview extends AbstractRestResource {
 
 
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementRuntimeInfo.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementRuntimeInfo.java
index d654f70..7806bca 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementRuntimeInfo.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementRuntimeInfo.java
@@ -31,7 +31,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-@Path("/v2/users/{username}/pipeline-element/runtime")
+@Path("/v2/pipeline-element/runtime")
 public class PipelineElementRuntimeInfo extends AbstractRestResource {
 
   @POST
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineMonitoring.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineMonitoring.java
index 336068d..9cd2d95 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineMonitoring.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineMonitoring.java
@@ -29,7 +29,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-@Path("/v2/users/{username}/pipeline-monitoring")
+@Path("/v2/pipeline-monitoring")
 public class PipelineMonitoring extends AbstractRestResource implements IPipelineMonitoring {
 
   @JacksonSerialized
diff --git a/ui/src/app/connect/services/rest.service.ts b/ui/src/app/connect/services/rest.service.ts
index 70d1330..48c4f04 100644
--- a/ui/src/app/connect/services/rest.service.ts
+++ b/ui/src/app/connect/services/rest.service.ts
@@ -16,24 +16,25 @@
  *
  */
 
-import {Injectable} from '@angular/core';
+import { Injectable } from '@angular/core';
 
-import {HttpClient} from '@angular/common/http';
+import { HttpClient } from '@angular/common/http';
 
-import {from, Observable} from 'rxjs';
-import {map} from 'rxjs/operators';
+import { from, Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
 
 
-import {AuthStatusService} from '../../services/auth-status.service';
-import {UnitDescription} from '../model/UnitDescription';
+import { AuthStatusService } from '../../services/auth-status.service';
+import { UnitDescription } from '../model/UnitDescription';
 import {
     AdapterDescription,
-    DataSourceDescription,
     FormatDescriptionList,
     GuessSchema,
     Message,
-    ProtocolDescriptionList, SpDataStream
-} from "../../core-model/gen/streampipes-model";
+    ProtocolDescriptionList,
+    SpDataStream
+} from '../../core-model/gen/streampipes-model';
+import { PlatformServicesCommons } from '../../platform-services/apis/commons.service';
 
 @Injectable()
 export class RestService {
@@ -41,7 +42,8 @@ export class RestService {
 
     constructor(
         private http: HttpClient,
-        private authStatusService: AuthStatusService) { }
+        private authStatusService: AuthStatusService,
+        private platformServicesCommons: PlatformServicesCommons) { }
 
     addAdapter(adapter: AdapterDescription): Observable<Message> {
         return this.addAdapterDescription(adapter, '/master/adapters');
@@ -81,13 +83,13 @@ export class RestService {
 
     getSourceDetails(sourceElementId): Observable<SpDataStream> {
         return this.http
-            .get(this.makeUserDependentBaseUrl() + '/streams/' + encodeURIComponent(sourceElementId)).pipe(map(response => {
+            .get(this.platformServicesCommons.apiBasePath() + '/streams/' + encodeURIComponent(sourceElementId)).pipe(map(response => {
                 return SpDataStream.fromData(response as SpDataStream);
             }));
     }
 
     getRuntimeInfo(sourceDescription): Observable<any> {
-        return this.http.post(this.makeUserDependentBaseUrl() + '/pipeline-element/runtime', sourceDescription, {
+        return this.http.post(this.platformServicesCommons.apiBasePath() + '/pipeline-element/runtime', sourceDescription, {
             headers: { ignoreLoadingBar: '' }
         });
     }
@@ -121,7 +123,7 @@ export class RestService {
             .post<UnitDescription[]>(this.host + this.authStatusService.email + '/master/unit', unitDescription)
             .pipe(map(response => {
                 const descriptions = response as UnitDescription[];
-                return descriptions.filter(entry => entry.resource != unitDescription.resource)
+                return descriptions.filter(entry => entry.resource != unitDescription.resource);
             }));
     }
 
diff --git a/ui/src/app/platform-services/apis/pipeline-element-endpoint.service.ts b/ui/src/app/platform-services/apis/pipeline-element-endpoint.service.ts
index f8f78b5..d62d230 100644
--- a/ui/src/app/platform-services/apis/pipeline-element-endpoint.service.ts
+++ b/ui/src/app/platform-services/apis/pipeline-element-endpoint.service.ts
@@ -32,21 +32,21 @@ export class PipelineElementEndpointService {
     const payload = new HttpParams()
         .set('uri', elementUri)
         .set('publicElement', ispublic);
-    return this.http.post(this.platformServicesCommons.authUserBasePath() + "/element", payload);
+    return this.http.post(this.platformServicesCommons.apiBasePath() + "/element", payload);
   }
 
   addBatch(elementUris, ispublic): Observable<any> {
     const payload = new HttpParams()
         .set('uri', elementUris)
         .set('publicElement', ispublic);
-    return this.http.post(this.platformServicesCommons.authUserBasePath() + "/element/batch", payload);
+    return this.http.post(this.platformServicesCommons.apiBasePath() + "/element/batch", payload);
   }
 
   update(elementUri): Observable<any> {
-    return this.http.put(this.platformServicesCommons.authUserBasePath() + "/element/" + encodeURIComponent(elementUri), undefined);
+    return this.http.put(this.platformServicesCommons.apiBasePath() + "/element/" + encodeURIComponent(elementUri), undefined);
   }
 
   del(elementUri): Observable<any> {
-    return this.http.delete(this.platformServicesCommons.authUserBasePath() + "/element/" + encodeURIComponent(elementUri));
+    return this.http.delete(this.platformServicesCommons.apiBasePath() + "/element/" + encodeURIComponent(elementUri));
   }
-}
\ No newline at end of file
+}
diff --git a/ui/src/app/services/rest-api.service.ts b/ui/src/app/services/rest-api.service.ts
index dbf50c4..db0d4c8 100644
--- a/ui/src/app/services/rest-api.service.ts
+++ b/ui/src/app/services/rest-api.service.ts
@@ -101,7 +101,7 @@ export class RestApi {
     }
 
     jsonld(elementUri) {
-        return this.$http.get(this.urlBase() + '/element/' + encodeURIComponent(elementUri) + '/jsonld');
+        return this.$http.get(this.urlApiBase() + '/element/' + encodeURIComponent(elementUri) + '/jsonld');
     }
 
     configured(): Observable<any> {