You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2023/01/30 10:48:29 UTC

[streampipes] branch hotfix-extend-client-api updated: [hotfix] Extend CustomRequestApi with new get request

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

zehnder pushed a commit to branch hotfix-extend-client-api
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/hotfix-extend-client-api by this push:
     new 0870b1b54 [hotfix] Extend CustomRequestApi with new get request
0870b1b54 is described below

commit 0870b1b54432b85dc39d7bfdfb6ddd3c44465b85
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Mon Jan 30 11:48:17 2023 +0100

    [hotfix] Extend CustomRequestApi with new get request
---
 .../backend/StreamPipesResourceConfig.java         | 134 +++++++++++++++++++++
 streampipes-client/pom.xml                         |   7 ++
 .../streampipes/client/api/CustomRequestApi.java   |   9 ++
 .../client/util/StreamPipesApiPath.java            |  26 +++-
 .../client/util/StreamPipesApiPathTest.java        |  68 +++++++++++
 5 files changed, 242 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
new file mode 100644
index 000000000..07a98cce4
--- /dev/null
+++ b/streampipes-backend/src/main/java/org/apache/streampipes/backend/StreamPipesResourceConfig.java
@@ -0,0 +1,134 @@
+/*
+ * 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;
+
+import io.swagger.v3.jaxrs2.integration.resources.OpenApiResource;
+import org.apache.streampipes.ps.*;
+import org.apache.streampipes.rest.impl.*;
+import org.apache.streampipes.rest.impl.admin.*;
+import org.apache.streampipes.rest.impl.connect.*;
+import org.apache.streampipes.rest.impl.dashboard.Dashboard;
+import org.apache.streampipes.rest.impl.dashboard.DashboardWidget;
+import org.apache.streampipes.rest.impl.dashboard.VisualizablePipelineResource;
+import org.apache.streampipes.rest.impl.datalake.DataLakeDashboardResource;
+import org.apache.streampipes.rest.impl.datalake.DataLakeWidgetResource;
+import org.apache.streampipes.rest.impl.datalake.PersistedDataStreamResource;
+import org.apache.streampipes.rest.impl.pe.DataProcessorResource;
+import org.apache.streampipes.rest.impl.pe.DataSinkResource;
+import org.apache.streampipes.rest.impl.pe.DataStreamResource;
+import org.apache.streampipes.rest.shared.serializer.JacksonSerializationProvider;
+import org.apache.streampipes.service.base.rest.ServiceHealthResource;
+import org.glassfish.jersey.media.multipart.MultiPartFeature;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.springframework.context.annotation.Configuration;
+
+import javax.ws.rs.ApplicationPath;
+import java.util.Collections;
+
+@Configuration
+@ApplicationPath("/api")
+public class StreamPipesResourceConfig extends ResourceConfig {
+
+    public StreamPipesResourceConfig() {
+        setProperties(Collections.singletonMap("jersey.config.server.response.setStatusOverSendError", true));
+        register(AccountActivationResource.class);
+        register(AdapterMonitoringResource.class);
+        register(Authentication.class);
+        register(AssetDashboardResource.class);
+        register(AssetManagementResource.class);
+        register(AutoComplete.class);
+        register(CategoryResource.class);
+        register(ConsulConfig.class);
+        register(ContainerProvidedOptions.class);
+        register(DashboardWidget.class);
+        register(Dashboard.class);
+        register(DataExportResource.class);
+        register(DataImportResource.class);
+        register(DataLakeImageResource.class);
+        register(DataLakeResourceV3.class);
+        register(DataLakeMeasureResourceV3.class);
+        register(DataLakeMeasureResourceV4.class);
+        register(DataStream.class);
+        register(EmailConfigurationResource.class);
+        register(EmailResource.class);
+        register(ExtensionsServiceEndpointResource.class);
+        register(FunctionsResource.class);
+        register(GeneralConfigurationResource.class);
+        register(GenericStorageResource.class);
+        register(LabelResource.class);
+        register(MeasurementUnitResource.class);
+        register(Notification.class);
+        register(OntologyMeasurementUnit.class);
+        register(PermissionResource.class);
+        register(PersistedDataStreamResource.class);
+        register(PipelineCanvasMetadataCache.class);
+        register(PipelineCanvasMetadataResource.class);
+        register(PipelineCache.class);
+        register(PipelineCategory.class);
+        register(PipelineElementAsset.class);
+        register(PipelineElementCategory.class);
+        register(PipelineElementFile.class);
+        register(PipelineElementImport.class);
+        register(PipelineElementPreview.class);
+        register(PipelineElementRuntimeInfo.class);
+        register(PipelineMonitoring.class);
+        register(PipelineResource.class);
+        register(PipelineTemplate.class);
+        register(DataSinkResource.class);
+        register(DataProcessorResource.class);
+        register(DataStreamResource.class);
+        register(Setup.class);
+        register(ResetResource.class);
+        register(RestorePasswordResource.class);
+        register(ServiceHealthResource.class);
+        register(UserResource.class);
+        register(Version.class);
+        register(PipelineElementAsset.class);
+        register(DataLakeDashboardResource.class);
+        register(DataLakeWidgetResource.class);
+        register(DataLakeResourceV3.class);
+        register(PipelineElementFile.class);
+        register(DashboardWidget.class);
+        register(Dashboard.class);
+        register(VisualizablePipelineResource.class);
+        register(UserGroupResource.class);
+
+        // Serializers
+        register(JacksonSerializationProvider.class);
+        register(MultiPartFeature.class);
+
+        // Platform Services
+        register(PipelineElementTemplateResource.class);
+        register(DataLakeResourceV4.class);
+        register(OpenApiResource.class);
+
+
+        // Connect Master
+        register(WelcomePageMaster.class);
+        register(AdapterResource.class);
+        register(DescriptionResource.class);
+        register(SourcesResource.class);
+        register(GuessResource.class);
+//    register(MultiPartFeature.class);
+        register(UnitResource.class);
+        register(WorkerAdministrationResource.class);
+        register(RuntimeResolvableResource.class);
+    }
+
+}
diff --git a/streampipes-client/pom.xml b/streampipes-client/pom.xml
index 7db3fee9f..ee91bc71c 100644
--- a/streampipes-client/pom.xml
+++ b/streampipes-client/pom.xml
@@ -71,6 +71,13 @@
             <version>0.91.0-SNAPSHOT</version>
         </dependency>
 
+        <!-- Test dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
         <!-- 3rd party Dependencies -->
         <dependency>
             <groupId>commons-collections</groupId>
diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java b/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
index b4e679fef..9b9a453bc 100644
--- a/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
+++ b/streampipes-client/src/main/java/org/apache/streampipes/client/api/CustomRequestApi.java
@@ -20,6 +20,8 @@ package org.apache.streampipes.client.api;
 import org.apache.streampipes.client.model.StreamPipesClientConfig;
 import org.apache.streampipes.client.util.StreamPipesApiPath;
 
+import java.util.Map;
+
 public class CustomRequestApi extends AbstractClientApi {
 
   public CustomRequestApi(StreamPipesClientConfig clientConfig) {
@@ -34,4 +36,11 @@ public class CustomRequestApi extends AbstractClientApi {
     return getSingle(StreamPipesApiPath.fromStreamPipesBasePath(apiPath), responseClass);
   }
 
+  public <T> T sendGet(String apiPath, Map<String, String> queryParameters, Class<T> responseClass) {
+    return getSingle(
+        StreamPipesApiPath.fromStreamPipesBasePath(apiPath)
+            .withQueryParameters(queryParameters),
+        responseClass);
+  }
+
 }
diff --git a/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java b/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java
index f083217e1..2c2628730 100644
--- a/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java
+++ b/streampipes-client/src/main/java/org/apache/streampipes/client/util/StreamPipesApiPath.java
@@ -20,16 +20,20 @@ package org.apache.streampipes.client.util;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.StringJoiner;
 
 public class StreamPipesApiPath {
 
   private static final List<String> BaseApiPathV2 = Arrays.asList("streampipes-backend", "api", "v2");
-  private List<String> pathItems;
+  private final List<String> pathItems;
+  private final Map<String, String> queryParameters;
 
   private StreamPipesApiPath(List<String> initialPathItems) {
     this.pathItems = initialPathItems;
+    this.queryParameters = new HashMap<>();
   }
 
   public static StreamPipesApiPath fromStreamPipesBasePath() {
@@ -51,10 +55,28 @@ public class StreamPipesApiPath {
     return this;
   }
 
+  public StreamPipesApiPath withQueryParameters(Map<String, String> queryParameters) {
+    this.queryParameters.putAll(queryParameters);
+    return this;
+  }
+
   @Override
   public String toString() {
     StringJoiner joiner = new StringJoiner("/");
     pathItems.forEach(joiner::add);
-    return joiner.toString();
+    return appendQueryParameters(joiner.toString());
+  }
+
+  private String appendQueryParameters(String input) {
+    StringJoiner joiner = new StringJoiner("&");
+    for (Map.Entry<String, String> parameter : queryParameters.entrySet()) {
+      joiner.add(parameter.getKey() + "=" + parameter.getValue());
+    }
+
+    if (joiner.length() > 0) {
+      return input + "?" + joiner;
+    } else {
+      return input;
+    }
   }
 }
diff --git a/streampipes-client/src/test/java/org/apache/streampipes/client/util/StreamPipesApiPathTest.java b/streampipes-client/src/test/java/org/apache/streampipes/client/util/StreamPipesApiPathTest.java
new file mode 100644
index 000000000..9a48d6a23
--- /dev/null
+++ b/streampipes-client/src/test/java/org/apache/streampipes/client/util/StreamPipesApiPathTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.client.util;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+public class StreamPipesApiPathTest {
+  Map<String, String> queryParameters = new HashMap();
+
+  StreamPipesApiPath streamPipesApiPath = StreamPipesApiPath
+      .fromBaseApiPath();
+
+  String baseRoute = streamPipesApiPath.toString();
+
+  @Test
+  public void testWithEmptyQueryParameters() {
+
+    var result = streamPipesApiPath
+        .withQueryParameters(queryParameters)
+        .toString();
+
+    assertEquals(baseRoute, result);
+  }
+
+  @Test
+  public void testWithOneQueryParameter() {
+    queryParameters.put("one", "v1");
+
+    var result = streamPipesApiPath
+        .withQueryParameters(queryParameters)
+        .toString();
+
+    assertEquals(baseRoute + "?one=v1", result);
+  }
+
+  @Test
+  public void testWithMultipleQueryParameters() {
+    queryParameters.put("one", "v1");
+    queryParameters.put("two", "v2");
+
+    var result = streamPipesApiPath
+        .withQueryParameters(queryParameters)
+        .toString();
+
+    assertEquals(baseRoute + "?two=v2&one=v1", result);
+  }
+}
\ No newline at end of file