This is an automated email from the ASF dual-hosted git repository. riemer pushed a commit to branch migrate-rest-interfaces-to-spring in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 9e1fb5a84a1fc7695d45de818a33867cdfbfddd7 Author: Dominik Riemer <[email protected]> AuthorDate: Tue Dec 5 21:04:19 2023 +0100 Migrate further rest interfaces, modify openapi docs --- pom.xml | 7 +- .../apache/streampipes/model/client/user/Role.java | 5 +- .../apache/streampipes/ps/DataLakeResourceV4.java | 8 +-- .../extensions/connect/AdapterAssetResource.java | 12 ++-- .../connect/AdapterDescriptionResource.java | 11 +++- .../extensions/connect/AdapterWorkerResource.java | 11 ++-- .../rest/extensions/connect/GuessResource.java | 8 ++- .../connect/HttpServerAdapterResource.java | 7 +- .../connect/RuntimeResolvableResource.java | 2 +- .../pe/InvocablePipelineElementResource.java | 6 +- streampipes-rest-shared/pom.xml | 41 ------------ .../shared/exception/SpLogMessageException.java | 43 +++++++------ .../rest/impl/AccountActivationResource.java | 6 +- .../rest/impl/AssetDashboardResource.java | 16 +++-- .../rest/impl/AssetManagementResource.java | 15 +++-- .../streampipes/rest/impl/Authentication.java | 10 +-- .../apache/streampipes/rest/impl/AutoComplete.java | 2 +- .../apache/streampipes/rest/impl/DataStream.java | 3 +- .../rest/impl/GenericStorageResource.java | 38 +++++------ ...Notification.java => NotificationResource.java} | 17 ++--- .../rest/impl/PipelineCanvasMetadataResource.java | 32 +++++++--- .../streampipes/rest/impl/PipelineCategory.java | 3 +- .../rest/impl/PipelineElementAsset.java | 6 +- .../streampipes/rest/impl/PipelineElementFile.java | 8 ++- .../streampipes/rest/impl/PipelineMonitoring.java | 8 ++- .../rest/impl/admin/DataExportResource.java | 5 +- .../impl/admin/GeneralConfigurationResource.java | 3 +- .../rest/impl/admin/UserAdminResource.java | 3 +- streampipes-service-core/pom.xml | 34 ++++++---- .../service/core/OpenApiConfiguration.java | 74 ++++++++++++++++++++++ .../service/core/StreamPipesCoreApplication.java | 7 +- .../service/core/UnauthenticatedInterfaces.java | 2 +- .../src/main/resources/application.properties | 2 + .../src/main/resources/openapi.yaml | 35 ---------- .../src/main/resources/application.properties | 1 - .../support/utils/DataDownloadDialogUtils.ts | 11 ++-- .../tests/dashboard/editDashboardTest.spec.ts | 4 +- ui/src/app/apidocs/apidocs.component.ts | 2 +- 38 files changed, 290 insertions(+), 218 deletions(-) diff --git a/pom.xml b/pom.xml index f8228c238..6f9f72da2 100644 --- a/pom.xml +++ b/pom.xml @@ -121,7 +121,7 @@ <snakeyaml.version>2.2</snakeyaml.version> <spring-boot.version>3.1.5</spring-boot.version> <spring-security.version>6.1.5</spring-security.version> - <swagger.version>2.2.7</swagger.version> + <swagger.version>2.2.19</swagger.version> <type-parser.version>0.8.1</type-parser.version> <hawtbuf.version>1.11</hawtbuf.version> @@ -510,6 +510,11 @@ <artifactId>spring-security-core</artifactId> <version>${spring-security.version}</version> </dependency> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-web</artifactId> + <version>${spring-security.version}</version> + </dependency> <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> diff --git a/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/user/Role.java b/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/user/Role.java index 7e2747595..26f5d1c00 100644 --- a/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/user/Role.java +++ b/streampipes-model-client/src/main/java/org/apache/streampipes/model/client/user/Role.java @@ -57,8 +57,9 @@ public enum Role { ), ROLE_CONNECT_ADMIN( Constants.ROLE_CONNECT_ADMIN_VALUE, - Privilege.PRIVILEGE_WRITE_ADAPTER - + Privilege.PRIVILEGE_WRITE_ADAPTER, + Privilege.PRIVILEGE_READ_ADAPTER, + Privilege.PRIVILEGE_DELETE_ADAPTER ), ROLE_DASHBOARD_USER( diff --git a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java index 708ef2096..2da7ca019 100644 --- a/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java +++ b/streampipes-platform-services/src/main/java/org/apache/streampipes/ps/DataLakeResourceV4.java @@ -104,10 +104,10 @@ public class DataLakeResourceV4 extends AbstractSpringRestResource { public ResponseEntity<Void> deleteData( @Parameter(in = ParameterIn.PATH, description = "the id of the measurement series", required = true) @PathVariable("measurementID") String measurementID - , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") @RequestParam("startDate") - Long startDate - , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") @RequestParam("endDate") - Long endDate) { + , @Parameter(in = ParameterIn.QUERY, description = "start date for slicing operation") + @RequestParam(value = "startDate", required = false) Long startDate + , @Parameter(in = ParameterIn.QUERY, description = "end date for slicing operation") + @RequestParam(value = "endDate", required = false) Long endDate) { SpQueryResult result = this.dataLakeManagement.deleteData(measurementID, startDate, endDate); return ok(); diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterAssetResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterAssetResource.java index fd0c7efdc..0fb89bfc1 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterAssetResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterAssetResource.java @@ -22,10 +22,13 @@ import org.apache.streampipes.extensions.management.assets.AssetZipGenerator; import org.apache.streampipes.extensions.management.connect.ConnectWorkerDescriptionProvider; import org.apache.streampipes.extensions.management.util.AssetsUtil; import org.apache.streampipes.model.connect.adapter.AdapterDescription; +import org.apache.streampipes.model.message.Notifications; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.rest.shared.impl.AbstractSharedRestInterface; import com.google.common.base.Charsets; import com.google.common.io.Resources; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -49,17 +52,18 @@ public class AdapterAssetResource extends AbstractSharedRestInterface { @GetMapping(path = "/{id}/assets", produces = "application/zip") - public ResponseEntity<?> getAssets(@PathVariable("id") String id) { + public ResponseEntity<byte[]> getAssets(@PathVariable("id") String id) { Optional<AdapterDescription> adapterDescription = this.connectWorkerDescriptionProvider.getAdapterDescription(id); if (adapterDescription.isPresent()) { try { return ok(new AssetZipGenerator(id, adapterDescription.get().getIncludedAssets()).makeZip()); } catch (IOException e) { - e.printStackTrace(); - return fail(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } else { - return fail(); + throw new SpMessageException( + HttpStatus.NOT_FOUND, + Notifications.error(String.format("Could not find adapter with id %s", id))); } } diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterDescriptionResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterDescriptionResource.java index 03eef55ba..6df779c15 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterDescriptionResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterDescriptionResource.java @@ -21,8 +21,11 @@ package org.apache.streampipes.rest.extensions.connect; import org.apache.streampipes.extensions.management.init.DeclarersSingleton; import org.apache.streampipes.extensions.management.locales.LabelGenerator; import org.apache.streampipes.model.connect.adapter.AdapterDescription; +import org.apache.streampipes.model.message.Notifications; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.rest.shared.impl.AbstractSharedRestInterface; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -37,7 +40,7 @@ import java.io.IOException; public class AdapterDescriptionResource extends AbstractSharedRestInterface { @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> getAdapterDescription(@PathVariable("id") String id) { + public ResponseEntity<AdapterDescription> getAdapterDescription(@PathVariable("id") String id) { var adapterDescriptionOpt = DeclarersSingleton.getInstance().getAdapter(id); if (adapterDescriptionOpt.isPresent()) { try { @@ -45,10 +48,12 @@ public class AdapterDescriptionResource extends AbstractSharedRestInterface { var localizedDescription = applyLocales(adapterDescription); return ok(localizedDescription); } catch (IOException e) { - return serverError(e); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } else { - return notFound(); + throw new SpMessageException( + HttpStatus.NOT_FOUND, + Notifications.error(String.format("Could not find adapter with id %s", id))); } } diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterWorkerResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterWorkerResource.java index cfed0d6ed..8b61e0c2e 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterWorkerResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/AdapterWorkerResource.java @@ -24,11 +24,14 @@ import org.apache.streampipes.extensions.management.init.DeclarersSingleton; import org.apache.streampipes.extensions.management.init.RunningAdapterInstances; import org.apache.streampipes.model.connect.adapter.AdapterDescription; import org.apache.streampipes.model.message.Notifications; +import org.apache.streampipes.model.message.SuccessMessage; import org.apache.streampipes.model.monitoring.SpLogMessage; +import org.apache.streampipes.rest.shared.exception.SpLogMessageException; import org.apache.streampipes.rest.shared.impl.AbstractSharedRestInterface; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -68,7 +71,7 @@ public class AdapterWorkerResource extends AbstractSharedRestInterface { path = "/stream/invoke", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> invokeAdapter(@RequestBody AdapterDescription adapterStreamDescription) { + public ResponseEntity<SuccessMessage> invokeAdapter(@RequestBody AdapterDescription adapterStreamDescription) { try { adapterManagement.invokeAdapter(adapterStreamDescription); @@ -79,7 +82,7 @@ public class AdapterWorkerResource extends AbstractSharedRestInterface { return ok(Notifications.success(responseMessage)); } catch (AdapterException e) { logger.error("Error while starting adapter with id " + adapterStreamDescription.getElementId(), e); - return serverError(SpLogMessage.from(e)); + throw new SpLogMessageException(HttpStatus.INTERNAL_SERVER_ERROR, SpLogMessage.from(e)); } } @@ -87,7 +90,7 @@ public class AdapterWorkerResource extends AbstractSharedRestInterface { path = "/stream/stop", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> stopAdapter(@RequestBody AdapterDescription adapterStreamDescription) { + public ResponseEntity<SuccessMessage> stopAdapter(@RequestBody AdapterDescription adapterStreamDescription) { String responseMessage; try { @@ -102,7 +105,7 @@ public class AdapterWorkerResource extends AbstractSharedRestInterface { return ok(Notifications.success(responseMessage)); } catch (AdapterException e) { logger.error("Error while stopping adapter with id " + adapterStreamDescription.getElementId(), e); - return serverError(SpLogMessage.from(e)); + throw new SpLogMessageException(HttpStatus.INTERNAL_SERVER_ERROR, SpLogMessage.from(e)); } } diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/GuessResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/GuessResource.java index 57e572ffc..25adc18ed 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/GuessResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/GuessResource.java @@ -24,10 +24,12 @@ import org.apache.streampipes.extensions.management.connect.GuessManagement; import org.apache.streampipes.extensions.management.context.AdapterContextGenerator; import org.apache.streampipes.model.connect.adapter.AdapterDescription; import org.apache.streampipes.model.connect.guess.GuessSchema; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.rest.shared.impl.AbstractSharedRestInterface; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -55,7 +57,7 @@ public class GuessResource extends AbstractSharedRestInterface { path = "/schema", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> guessSchema(@RequestBody AdapterDescription adapterDescription) { + public ResponseEntity<GuessSchema> guessSchema(@RequestBody AdapterDescription adapterDescription) { try { GuessSchema result = guessManagement.guessSchema(adapterDescription); @@ -63,11 +65,11 @@ public class GuessResource extends AbstractSharedRestInterface { return ok(result); } catch (ParseException e) { logger.error("Error while parsing events: ", e); - return serverError(e); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } catch (AdapterException e) { logger.error("Error while guessing schema for AdapterDescription: {}, {}", adapterDescription.getElementId(), e.getMessage()); - return serverError(e); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/HttpServerAdapterResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/HttpServerAdapterResource.java index c2a29102f..4fe4911a6 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/HttpServerAdapterResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/HttpServerAdapterResource.java @@ -18,6 +18,7 @@ package org.apache.streampipes.rest.extensions.connect; import org.apache.streampipes.extensions.management.connect.HttpServerAdapterManagement; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -32,14 +33,14 @@ import org.springframework.web.bind.annotation.RestController; public class HttpServerAdapterResource { @PostMapping(path = "{endpointId}") - public ResponseEntity<?> receiveEvent(@PathVariable("endpointId") String endpointId, - @RequestBody byte[] body) { + public ResponseEntity<Void> receiveEvent(@PathVariable("endpointId") String endpointId, + @RequestBody byte[] body) { try { HttpServerAdapterManagement.INSTANCE.notify(endpointId, body); return ResponseEntity.ok().build(); } catch (Exception e) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); + throw new SpMessageException(HttpStatus.BAD_REQUEST, e); } } diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/RuntimeResolvableResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/RuntimeResolvableResource.java index 9a5f739a6..0412560c9 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/RuntimeResolvableResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/connect/RuntimeResolvableResource.java @@ -46,7 +46,7 @@ public class RuntimeResolvableResource extends AbstractSharedRestInterface { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> fetchConfigurations(@PathVariable("id") String elementId, - @RequestBody RuntimeOptionsRequest runtimeOptionsRequest) { + @RequestBody RuntimeOptionsRequest runtimeOptionsRequest) { var adapter = RuntimeResovable.getAdapter(elementId); RuntimeOptionsResponse response; diff --git a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/pe/InvocablePipelineElementResource.java b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/pe/InvocablePipelineElementResource.java index 4e0cd0328..3f7e16097 100644 --- a/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/pe/InvocablePipelineElementResource.java +++ b/streampipes-rest-extensions/src/main/java/org/apache/streampipes/rest/extensions/pe/InvocablePipelineElementResource.java @@ -73,7 +73,7 @@ public abstract class InvocablePipelineElementResource< path = "{elementId}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> invokeRuntime(@PathVariable("elementId") String elementId, + public ResponseEntity<Response> invokeRuntime(@PathVariable("elementId") String elementId, @RequestBody K graph) { if (isDebug()) { @@ -111,7 +111,7 @@ public abstract class InvocablePipelineElementResource< produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> fetchConfigurations(@PathVariable("elementId") String elementId, - @RequestBody RuntimeOptionsRequest req) { + @RequestBody RuntimeOptionsRequest req) { T declarer = getDeclarerById(elementId); RuntimeOptionsResponse responseOptions; @@ -141,7 +141,7 @@ public abstract class InvocablePipelineElementResource< produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<?> fetchOutputStrategy(@PathVariable("elementId") String elementId, - @RequestBody K runtimeOptionsRequest) { + @RequestBody K runtimeOptionsRequest) { try { //I runtimeOptionsRequest = JacksonSerializer.getObjectMapper().readValue(payload, clazz); ResolvesContainerProvidedOutputStrategy<K, W> resolvesOutput = diff --git a/streampipes-rest-shared/pom.xml b/streampipes-rest-shared/pom.xml index 48ddaa59c..e40097cb1 100644 --- a/streampipes-rest-shared/pom.xml +++ b/streampipes-rest-shared/pom.xml @@ -51,47 +51,6 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> -<!-- <dependency>--> -<!-- <groupId>jakarta.annotation</groupId>--> -<!-- <artifactId>jakarta.annotation-api</artifactId>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>jakarta.servlet</groupId>--> -<!-- <artifactId>jakarta.servlet-api</artifactId>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>jakarta.ws.rs</groupId>--> -<!-- <artifactId>jakarta.ws.rs-api</artifactId>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>org.glassfish.jersey.media</groupId>--> -<!-- <artifactId>jersey-media-multipart</artifactId>--> -<!-- </dependency>--> -<!-- <dependency>--> -<!-- <groupId>org.apache.httpcomponents</groupId>--> -<!-- <artifactId>httpcore</artifactId>--> -<!-- </dependency>--> - -<!-- <!– Test dependencies –>--> -<!-- <dependency>--> -<!-- <groupId>org.glassfish.jersey.containers</groupId>--> -<!-- <artifactId>jersey-container-jetty-http</artifactId>--> -<!-- <exclusions>--> -<!-- <exclusion>--> -<!-- <groupId>org.eclipse.jetty</groupId>--> -<!-- <artifactId>jetty-server</artifactId>--> -<!-- </exclusion>--> -<!-- <exclusion>--> -<!-- <groupId>org.eclipse.jetty</groupId>--> -<!-- <artifactId>jetty-util</artifactId>--> -<!-- </exclusion>--> -<!-- <exclusion>--> -<!-- <groupId>org.eclipse.jetty</groupId>--> -<!-- <artifactId>jetty-continuation</artifactId>--> -<!-- </exclusion>--> -<!-- </exclusions>--> -<!-- <scope>test</scope>--> -<!-- </dependency>--> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> diff --git a/ui/src/app/apidocs/apidocs.component.ts b/streampipes-rest-shared/src/main/java/org/apache/streampipes/rest/shared/exception/SpLogMessageException.java similarity index 57% copy from ui/src/app/apidocs/apidocs.component.ts copy to streampipes-rest-shared/src/main/java/org/apache/streampipes/rest/shared/exception/SpLogMessageException.java index f6a0a8074..c1fa115a7 100644 --- a/ui/src/app/apidocs/apidocs.component.ts +++ b/streampipes-rest-shared/src/main/java/org/apache/streampipes/rest/shared/exception/SpLogMessageException.java @@ -16,23 +16,28 @@ * */ -import { Component, ElementRef, OnInit } from '@angular/core'; -import SwaggerUI from 'swagger-ui'; - -@Component({ - selector: 'sp-apidocs', - templateUrl: './apidocs.component.html', - styleUrls: ['./apidocs.component.scss'], -}) -export class ApidocsComponent implements OnInit { - constructor(private el: ElementRef) {} - - ngOnInit(): void { - SwaggerUI({ - url: '/streampipes-backend/api/openapi.json', - domNode: this.el.nativeElement.querySelector('.swagger-ui'), - deepLinking: false, - presets: [SwaggerUI.presets.apis], - }); - } +package org.apache.streampipes.rest.shared.exception; + +import org.apache.streampipes.model.monitoring.SpLogMessage; + +import org.springframework.http.HttpStatus; + +public class SpLogMessageException extends RuntimeException { + + private final SpLogMessage message; + private final HttpStatus status; + + public SpLogMessageException(HttpStatus status, + SpLogMessage message) { + this.status = status; + this.message = message; + } + + public SpLogMessage getSpMessage() { + return message; + } + + public HttpStatus getStatus() { + return status; + } } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AccountActivationResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AccountActivationResource.java index 48b88552d..c9144faa2 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AccountActivationResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AccountActivationResource.java @@ -19,7 +19,9 @@ package org.apache.streampipes.rest.impl; import org.apache.streampipes.commons.exceptions.UserNotFoundException; import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedSpringRestResource; +import org.apache.streampipes.rest.shared.exception.SpMessageException; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -35,12 +37,12 @@ public class AccountActivationResource extends AbstractAuthGuardedSpringRestReso path = "{recoveryCode}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> activateUserAccount(@PathVariable("recoveryCode") String recoveryCode) { + public ResponseEntity<Void> activateUserAccount(@PathVariable("recoveryCode") String recoveryCode) { try { getSpResourceManager().manageUsers().activateAccount(recoveryCode); return ok(); } catch (UserNotFoundException e) { - return badRequest(); + throw new SpMessageException(HttpStatus.BAD_REQUEST, e); } } } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetDashboardResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetDashboardResource.java index 2e394f5de..6441f11e8 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetDashboardResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetDashboardResource.java @@ -19,11 +19,15 @@ package org.apache.streampipes.rest.impl; import org.apache.streampipes.model.client.assetdashboard.AssetDashboardConfig; import org.apache.streampipes.rest.core.base.impl.AbstractSpringRestResource; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.storage.api.IAssetDashboardStorage; import org.apache.streampipes.storage.management.StorageDispatcher; import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -49,6 +53,8 @@ import java.util.List; @RequestMapping("/api/v2/asset-dashboards") public class AssetDashboardResource extends AbstractSpringRestResource { + private static final Logger LOG = LoggerFactory.getLogger(AssetDashboardResource.class); + private static final String APP_ID = "org.apache.streampipes.apps.assetdashboard"; @GetMapping(path = "/{dashboardId}", produces = MediaType.APPLICATION_JSON_VALUE) @@ -88,7 +94,7 @@ public class AssetDashboardResource extends AbstractSpringRestResource { } @GetMapping(path = "/images/{imageName}") - public ResponseEntity<?> getDashboardImage(@PathVariable("imageName") String imageName) { + public ResponseEntity<byte[]> getDashboardImage(@PathVariable("imageName") String imageName) { try { java.nio.file.Path path = Paths.get(getTargetFile(imageName)); File file = new File(path.toString()); @@ -100,8 +106,8 @@ public class AssetDashboardResource extends AbstractSpringRestResource { return new ResponseEntity<>(Files.readAllBytes(path), headers, org.springframework.http.HttpStatus.OK); } catch (IOException e) { - e.printStackTrace(); - return fail(); + LOG.error(e.getMessage(), e); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } @@ -119,8 +125,8 @@ public class AssetDashboardResource extends AbstractSpringRestResource { FileUtils.copyInputStreamToFile(fileDetail.getInputStream(), targetFile); return ok(); } catch (IOException e) { - e.printStackTrace(); - return fail(); + LOG.error(e.getMessage(), e); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetManagementResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetManagementResource.java index 22227230b..96027e779 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetManagementResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AssetManagementResource.java @@ -20,11 +20,13 @@ package org.apache.streampipes.rest.impl; import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedSpringRestResource; import org.apache.streampipes.rest.security.AuthConstants; +import org.apache.streampipes.rest.shared.exception.SpMessageException; 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.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; @@ -72,13 +74,13 @@ public class AssetManagementResource extends AbstractAuthGuardedSpringRestResour @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_READ_ASSETS_PRIVILEGE) - public ResponseEntity<?> getCategory(@PathVariable("id") String assetId) { + public ResponseEntity<Map<String, Object>> getCategory(@PathVariable("id") String assetId) { try { Map<String, Object> obj = getGenericStorage().findOne(assetId); return ok(obj); } catch (IOException e) { LOG.error("Could not connect to storage", e); - return fail(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } @@ -87,14 +89,14 @@ public class AssetManagementResource extends AbstractAuthGuardedSpringRestResour produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_WRITE_ASSETS_PRIVILEGE) - public ResponseEntity<?> update(@PathVariable("id") String assetId, - @RequestBody String asset) { + public ResponseEntity<Map<String, Object>> update(@PathVariable("id") String assetId, + @RequestBody String asset) { try { Map<String, Object> obj = getGenericStorage().update(assetId, asset); return ok(obj); } catch (IOException e) { LOG.error("Could not connect to storage", e); - return fail(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } @@ -107,7 +109,7 @@ public class AssetManagementResource extends AbstractAuthGuardedSpringRestResour return ok(); } catch (IOException e) { LOG.error("Could not connect to storage", e); - return fail(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } @@ -115,5 +117,4 @@ public class AssetManagementResource extends AbstractAuthGuardedSpringRestResour return StorageDispatcher.INSTANCE.getNoSqlStore().getGenericStorage(); } - } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Authentication.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Authentication.java index 48a94f521..1ecff593b 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Authentication.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Authentication.java @@ -27,11 +27,11 @@ import org.apache.streampipes.model.client.user.RegistrationData; import org.apache.streampipes.model.client.user.UserAccount; import org.apache.streampipes.model.configuration.GeneralConfig; import org.apache.streampipes.model.message.ErrorMessage; -import org.apache.streampipes.model.message.Message; import org.apache.streampipes.model.message.NotificationType; import org.apache.streampipes.model.message.Notifications; import org.apache.streampipes.model.message.SuccessMessage; import org.apache.streampipes.rest.core.base.impl.AbstractSpringRestResource; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.user.management.jwt.JwtTokenProvider; import org.apache.streampipes.user.management.model.PrincipalUserDetails; @@ -90,7 +90,7 @@ public class Authentication extends AbstractSpringRestResource { path = "/register", produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE, consumes = org.springframework.http.MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<? extends Message> doRegister(@RequestBody RegistrationData data) { + public ResponseEntity<SuccessMessage> doRegister(@RequestBody RegistrationData data) { GeneralConfig config = getSpCoreConfigurationStorage().get().getGeneralConfig(); if (!config.isAllowSelfRegistration()) { return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); @@ -100,7 +100,9 @@ public class Authentication extends AbstractSpringRestResource { getSpResourceManager().manageUsers().registerUser(data); return ok(new SuccessMessage(NotificationType.REGISTRATION_SUCCESS.uiNotification())); } catch (UsernameAlreadyTakenException e) { - return badRequest(Notifications.error("This email address already exists. Please choose another address.")); + throw new SpMessageException( + HttpStatus.BAD_REQUEST, + Notifications.error("This email address already exists. Please choose another address.")); } } @@ -114,7 +116,7 @@ public class Authentication extends AbstractSpringRestResource { } catch (UserNotFoundException e) { return ok(); } catch (Exception e) { - return badRequest(); + throw new SpMessageException(HttpStatus.BAD_REQUEST, e); } } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java index d7494a08e..2f389dca7 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/AutoComplete.java @@ -34,7 +34,7 @@ import java.util.List; @RequestMapping("/api/v2/autocomplete") public class AutoComplete extends AbstractSpringRestResource { - @GetMapping(path = "semantic-type", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(path = "/semantic-type", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<List<String>> getSemanticTypes(@RequestParam("text") String text) { return ok(SemanticTypeRegistry.INSTANCE.matches(text)); } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/DataStream.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/DataStream.java index d7ea91507..127b98daa 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/DataStream.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/DataStream.java @@ -24,6 +24,7 @@ import org.apache.streampipes.rest.core.base.impl.AbstractSpringRestResource; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -32,7 +33,7 @@ import org.springframework.web.bind.annotation.RestController; public class DataStream extends AbstractSpringRestResource { @PostMapping(path = "/update", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<SpDataStream> getStreamsBySource(SpDataStream stream) { + public ResponseEntity<SpDataStream> getStreamsBySource(@RequestBody SpDataStream stream) { return ok(Operations.updateActualTopic(stream)); } } 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 index d70fd7dcd..a1c436016 100644 --- 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 @@ -20,11 +20,13 @@ package org.apache.streampipes.rest.impl; import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedSpringRestResource; import org.apache.streampipes.rest.security.AuthConstants; +import org.apache.streampipes.rest.shared.exception.SpMessageException; 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.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; @@ -49,65 +51,65 @@ public class GenericStorageResource extends AbstractAuthGuardedSpringRestResourc private static final Logger LOG = LoggerFactory.getLogger(GenericStorageResource.class); - @GetMapping(path = "{appDocName}", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(path = "/{appDocName}", produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_READ_GENERIC_STORAGE_PRIVILEGE) - public ResponseEntity<?> getAll(@PathVariable(APP_DOC_NAME) String appDocName) { + public ResponseEntity<List<Map<String, Object>>> getAll(@PathVariable(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(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } @PostMapping( - path = "{appDocName}", + path = "/{appDocName}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_WRITE_GENERIC_STORAGE_PRIVILEGE) - public ResponseEntity<?> create(@PathVariable(APP_DOC_NAME) String appDocName, - @RequestBody String document) { + public ResponseEntity<Map<String, Object>> create(@PathVariable(APP_DOC_NAME) String appDocName, + @RequestBody 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(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } - @GetMapping(path = "{appDocName}/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(path = "/{appDocName}/{id}", produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_READ_GENERIC_STORAGE_PRIVILEGE) - public ResponseEntity<?> getCategory(@PathVariable(APP_DOC_NAME) String appDocName, - @PathVariable("id") String documentId) { + public ResponseEntity<Map<String, Object>> getCategory(@PathVariable(APP_DOC_NAME) String appDocName, + @PathVariable("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(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } @PutMapping( - path = "{appDocName}/{id}", + path = "/{appDocName}/{id}", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_WRITE_GENERIC_STORAGE_PRIVILEGE) - public ResponseEntity<?> update(@PathVariable(APP_DOC_NAME) String appDocName, - @PathVariable("id") String documentId, - @RequestBody String document) { + public ResponseEntity<Map<String, Object>> update(@PathVariable(APP_DOC_NAME) String appDocName, + @PathVariable("id") String documentId, + @RequestBody 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(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } - @DeleteMapping(path = "{appDocName}/{id}/{rev}", produces = MediaType.APPLICATION_JSON_VALUE) + @DeleteMapping(path = "/{appDocName}/{id}/{rev}", produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_WRITE_GENERIC_STORAGE_PRIVILEGE) public ResponseEntity<Void> delete(@PathVariable(APP_DOC_NAME) String appDocName, @PathVariable("id") String documentId, @@ -117,7 +119,7 @@ public class GenericStorageResource extends AbstractAuthGuardedSpringRestResourc return ok(); } catch (IOException e) { LOG.error("Could not connect to storage", e); - return fail(); + throw new SpMessageException(HttpStatus.INTERNAL_SERVER_ERROR, e); } } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Notification.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/NotificationResource.java similarity index 79% rename from streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Notification.java rename to streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/NotificationResource.java index 79b2da4e0..457efc5c2 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/Notification.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/NotificationResource.java @@ -18,6 +18,7 @@ package org.apache.streampipes.rest.impl; +import org.apache.streampipes.model.Notification; import org.apache.streampipes.model.NotificationCount; import org.apache.streampipes.model.message.Message; import org.apache.streampipes.model.message.Notifications; @@ -39,24 +40,24 @@ import java.util.List; @RestController @RequestMapping("/api/v2/notifications") -public class Notification extends AbstractAuthGuardedSpringRestResource { +public class NotificationResource extends AbstractAuthGuardedSpringRestResource { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<Void> addNotification(@RequestBody org.apache.streampipes.model.Notification notification) { + public ResponseEntity<Void> addNotification(@RequestBody Notification notification) { getNotificationStorage().addNotification(notification); return ok(); } @GetMapping(path = "/offset", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<List<org.apache.streampipes.model.Notification>> getNotifications(@RequestParam("notificationType") String notificationTypeId, - @RequestParam("offset") Integer offset, - @RequestParam("count") Integer count) { + public ResponseEntity<List<Notification>> getNotifications(@RequestParam("notificationType") String notTypeId, + @RequestParam("offset") Integer offset, + @RequestParam("count") Integer count) { return ok(getNotificationStorage() - .getAllNotifications(notificationTypeId, offset, count)); + .getAllNotifications(notTypeId, offset, count)); } @GetMapping(path = "/time", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<List<org.apache.streampipes.model.Notification>> getNotifications(@RequestParam("startTime") long startTime) { + public ResponseEntity<List<Notification>> getNotifications(@RequestParam("startTime") long startTime) { return ok(getNotificationStorage() .getAllNotificationsFromTimestamp(startTime)); } @@ -68,7 +69,7 @@ public class Notification extends AbstractAuthGuardedSpringRestResource { } @GetMapping(path = "/unread") - public ResponseEntity<List<org.apache.streampipes.model.Notification>> getUnreadNotifications() { + public ResponseEntity<List<Notification>> getUnreadNotifications() { return ok(getNotificationStorage() .getUnreadNotifications()); } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCanvasMetadataResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCanvasMetadataResource.java index 29212a143..507a2945b 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCanvasMetadataResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCanvasMetadataResource.java @@ -18,9 +18,12 @@ package org.apache.streampipes.rest.impl; import org.apache.streampipes.model.canvas.PipelineCanvasMetadata; +import org.apache.streampipes.model.message.Notifications; import org.apache.streampipes.rest.core.base.impl.AbstractSpringRestResource; +import org.apache.streampipes.rest.shared.exception.SpMessageException; import org.apache.streampipes.storage.api.IPipelineCanvasMetadataStorage; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -37,39 +40,47 @@ import org.springframework.web.bind.annotation.RestController; public class PipelineCanvasMetadataResource extends AbstractSpringRestResource { @GetMapping(path = "/pipeline/{pipelineId}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> getPipelineCanvasMetadataForPipeline(@PathVariable("pipelineId") String pipelineId) { + public ResponseEntity<PipelineCanvasMetadata> getPipelineCanvasMetadataForPipeline( + @PathVariable("pipelineId") String pipelineId) { try { return ok(getPipelineCanvasMetadataStorage() .getPipelineCanvasMetadataForPipeline(pipelineId)); } catch (IllegalArgumentException e) { - return badRequest(); + throw new SpMessageException(HttpStatus.BAD_REQUEST, Notifications.error(e.getMessage())); } } @GetMapping(path = "{canvasId}", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<?> getPipelineCanvasMetadata(@PathVariable("canvasId") String pipelineCanvasId) { + public ResponseEntity<PipelineCanvasMetadata> getPipelineCanvasMetadata( + @PathVariable("canvasId") String pipelineCanvasId) { try { return ok(getPipelineCanvasMetadataStorage() .getElementById(pipelineCanvasId)); } catch (IllegalArgumentException e) { - return badRequest(); + throw new SpMessageException(HttpStatus.BAD_REQUEST, Notifications.error(e.getMessage())); } } - @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<Void> storePipelineCanvasMetadata(PipelineCanvasMetadata pipelineCanvasMetadata) { + @PostMapping( + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity<Void> storePipelineCanvasMetadata(@RequestBody PipelineCanvasMetadata pipelineCanvasMetadata) { getPipelineCanvasMetadataStorage().createElement(pipelineCanvasMetadata); return ok(); } - @DeleteMapping(path = "{canvasId}") + @DeleteMapping( + path = "{canvasId}", + produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> deletePipelineCanvasMetadata(@PathVariable("canvasId") String pipelineCanvasId) { PipelineCanvasMetadata metadata = find(pipelineCanvasId); getPipelineCanvasMetadataStorage().deleteElement(metadata); return ok(); } - @DeleteMapping(path = "/pipeline/{pipelineId}") + @DeleteMapping( + path = "/pipeline/{pipelineId}", + produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> deletePipelineCanvasMetadataForPipeline(@PathVariable("pipelineId") String pipelineId) { PipelineCanvasMetadata metadata = getPipelineCanvasMetadataStorage().getPipelineCanvasMetadataForPipeline(pipelineId); @@ -77,7 +88,10 @@ public class PipelineCanvasMetadataResource extends AbstractSpringRestResource { return ok(); } - @PutMapping(path = "{canvasId}", consumes = MediaType.APPLICATION_JSON_VALUE) + @PutMapping( + path = "{canvasId}", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> updatePipelineCanvasMetadata(@PathVariable("canvasId") String pipelineCanvasId, @RequestBody PipelineCanvasMetadata pipelineCanvasMetadata) { try { diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCategory.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCategory.java index d2bea13c4..7da33e1f3 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCategory.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineCategory.java @@ -49,7 +49,8 @@ public class PipelineCategory extends AbstractSpringRestResource { produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE ) - public ResponseEntity<? extends Message> addCategory(@RequestBody org.apache.streampipes.model.pipeline.PipelineCategory pipelineCategory) { + public ResponseEntity<? extends Message> addCategory( + @RequestBody org.apache.streampipes.model.pipeline.PipelineCategory pipelineCategory) { boolean success = getPipelineCategoryStorage() .addPipelineCategory(pipelineCategory); if (success) { diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementAsset.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementAsset.java index 09cc98bcc..01b1f2fd8 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementAsset.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementAsset.java @@ -37,7 +37,7 @@ public class PipelineElementAsset extends AbstractSpringRestResource { private static final Logger LOG = LoggerFactory.getLogger(PipelineElementAsset.class); - @GetMapping(path = "{appId}/assets/icon", produces = "image/png") + @GetMapping(path = "/{appId}/assets/icon", produces = "image/png") public ResponseEntity<?> getIconAsset(@PathVariable("appId") String appId) { try { return ok(AssetManager.getAssetIcon(appId)); @@ -46,7 +46,7 @@ public class PipelineElementAsset extends AbstractSpringRestResource { } } - @GetMapping(path = "{appId}/assets/documentation", produces = MediaType.TEXT_PLAIN_VALUE) + @GetMapping(path = "/{appId}/assets/documentation", produces = MediaType.TEXT_PLAIN_VALUE) public ResponseEntity<?> getDocumentationAsset(@PathVariable("appId") String appId) { try { return ok(AssetManager.getAssetDocumentation(appId)); @@ -55,7 +55,7 @@ public class PipelineElementAsset extends AbstractSpringRestResource { } } - @GetMapping(path = "{appId}/assets/{assetName}", produces = "image/png") + @GetMapping(path = "/{appId}/assets/{assetName}", produces = "image/png") public ResponseEntity<?> getAsset(@PathVariable("appId") String appId, @PathVariable("assetName") String assetName) { try { diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java index a6049f617..868f24390 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/PipelineElementFile.java @@ -58,7 +58,10 @@ public class PipelineElementFile extends AbstractAuthGuardedSpringRestResource { public ResponseEntity<?> storeFile(@RequestPart("file_upload") MultipartFile fileDetail) { try { FileMetadata metadata = - FileManager.storeFile(getAuthenticatedUsername(), fileDetail.getOriginalFilename(), fileDetail.getInputStream()); + FileManager.storeFile( + getAuthenticatedUsername(), + fileDetail.getOriginalFilename(), + fileDetail.getInputStream()); return ok(metadata); } catch (Exception e) { return fail(); @@ -74,7 +77,8 @@ public class PipelineElementFile extends AbstractAuthGuardedSpringRestResource { @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.HAS_READ_FILE_PRIVILEGE) - public ResponseEntity<List<FileMetadata>> getFileInfo(@RequestParam(value = "filetypes", required = false) String filetypes) { + public ResponseEntity<List<FileMetadata>> getFileInfo( + @RequestParam(value = "filetypes", required = false) String filetypes) { return ok(FileManager.getAllFiles(filetypes)); } 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 41f79195b..139af0066 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 @@ -25,20 +25,22 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; -@RestController("/api/v2/pipeline-monitoring") +@RestController +@RequestMapping("/api/v2/pipeline-monitoring") public class PipelineMonitoring extends AbstractMonitoringResource { - @GetMapping(value = "pipeline/{pipelineId}/logs", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/pipeline/{pipelineId}/logs", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Map<String, List<SpLogEntry>>> getLogInfoForPipeline(@PathVariable("pipelineId") String pipelineId) { return ok(ExtensionsLogProvider.INSTANCE.getLogInfosForPipeline(pipelineId)); } - @GetMapping(value = "pipeline/{pipelineId}/metrics", produces = MediaType.APPLICATION_JSON_VALUE) + @GetMapping(value = "/pipeline/{pipelineId}/metrics", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Map<String, SpMetricsEntry>> getMetricsInfoForPipeline(@PathVariable("pipelineId") String pipelineId) { return ok(ExtensionsLogProvider.INSTANCE.getMetricInfosForPipeline(pipelineId)); } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java index 6a9bcf383..2688b1a48 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/DataExportResource.java @@ -27,6 +27,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -42,7 +43,7 @@ public class DataExportResource extends AbstractAuthGuardedSpringRestResource { path = "/preview", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<ExportConfiguration> getExportPreview(List<String> selectedAssetIds) { + public ResponseEntity<ExportConfiguration> getExportPreview(@RequestBody List<String> selectedAssetIds) { var exportConfig = ExportManager.getExportPreview(selectedAssetIds); return ok(exportConfig); } @@ -51,7 +52,7 @@ public class DataExportResource extends AbstractAuthGuardedSpringRestResource { path = "/download", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) - public ResponseEntity<byte[]> download(ExportConfiguration exportConfiguration) throws IOException { + public ResponseEntity<byte[]> download(@RequestBody ExportConfiguration exportConfiguration) throws IOException { var applicationPackage = ExportManager.getExportPackage(exportConfiguration); return ok(applicationPackage); } diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/GeneralConfigurationResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/GeneralConfigurationResource.java index a6dee0846..865e40f8f 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/GeneralConfigurationResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/GeneralConfigurationResource.java @@ -27,6 +27,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -48,7 +49,7 @@ public class GeneralConfigurationResource extends AbstractAuthGuardedSpringRestR @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) - public ResponseEntity<Void> updateGeneralConfiguration(GeneralConfig config) { + public ResponseEntity<Void> updateGeneralConfiguration(@RequestBody GeneralConfig config) { config.setConfigured(true); var storage = getSpCoreConfigurationStorage(); var cfg = storage.get(); diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/UserAdminResource.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/UserAdminResource.java index 7cb73cb0e..2fe04fc30 100644 --- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/UserAdminResource.java +++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/UserAdminResource.java @@ -41,7 +41,8 @@ public class UserAdminResource extends AbstractAuthGuardedSpringRestResource { @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize(AuthConstants.IS_ADMIN_ROLE) - public ResponseEntity<List<Principal>> getAllUsers(@RequestParam("type") String principalType) { + public ResponseEntity<List<Principal>> getAllUsers( + @RequestParam(value = "type", required = false) String principalType) { List<Principal> allPrincipals = new ArrayList<>(); if (principalType != null && principalType.equals(PrincipalType.USER_ACCOUNT.name())) { allPrincipals.addAll(getUserStorage().getAllUserAccounts()); diff --git a/streampipes-service-core/pom.xml b/streampipes-service-core/pom.xml index e29167a95..6d7415bf9 100644 --- a/streampipes-service-core/pom.xml +++ b/streampipes-service-core/pom.xml @@ -94,25 +94,15 @@ <artifactId>streampipes-platform-services</artifactId> <version>0.95.0-SNAPSHOT</version> </dependency> + <!-- External dependencies --> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> - <version>6.1.2</version> </dependency> - <!-- External dependencies --> <dependency> - <groupId>io.swagger.core.v3</groupId> - <artifactId>swagger-jaxrs2-jakarta</artifactId> - <exclusions> - <exclusion> - <groupId>com.fasterxml.jackson.datatype</groupId> - <artifactId>jackson-datatype-jsr310</artifactId> - </exclusion> - <exclusion> - <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId> - </exclusion> - </exclusions> + <groupId>org.springdoc</groupId> + <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> + <version>2.3.0</version> </dependency> <dependency> <groupId>jakarta.annotation</groupId> @@ -121,7 +111,23 @@ </dependencies> <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <delimiters> + <delimiter>@</delimiter> + </delimiters> + <useDefaultDelimiters>false</useDefaultDelimiters> + </configuration> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/OpenApiConfiguration.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/OpenApiConfiguration.java new file mode 100644 index 000000000..f4d7d079c --- /dev/null +++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/OpenApiConfiguration.java @@ -0,0 +1,74 @@ +/* + * 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.service.core; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.security.SecurityScheme; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +@Configuration +public class OpenApiConfiguration { + + @Bean + public OpenAPI openApiDocsConfiguration(@Value("${app.version}") String appVersion) { + return new OpenAPI() + .components(new Components() + .addSecuritySchemes("bearerAuth", + new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer")) + .parameters(makeAuthParams())) + .info(new Info() + .title("Apache StreamPipes API") + .description("This is the documentation of the Apache StreamPipes developer API.") + .version(appVersion) + .contact(new Contact().email("[email protected]")) + .license(new License() + .name("Apache 2.0") + .url("http://www.apache.org/licenses/LICENSE-2.0.html") + ) + ); + } + + private Map<String, Parameter> makeAuthParams() { + var map = new HashMap<String, Parameter>(); + map.put("usernameParam", new Parameter() + .in("path") + .name("username") + .required(true) + .schema(new Schema<String>() + .type("string") + .minimum(BigDecimal.valueOf(0)) + .description("The username (currently the email address of the logged in user") + ) + ); + + return map; + } +} diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/StreamPipesCoreApplication.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/StreamPipesCoreApplication.java index b8310076f..3ed66ae9d 100644 --- a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/StreamPipesCoreApplication.java +++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/StreamPipesCoreApplication.java @@ -64,11 +64,12 @@ import java.util.concurrent.TimeUnit; @Configuration @EnableAutoConfiguration @Import({ - WelcomePageController.class, + OpenApiConfiguration.class, + SpPermissionEvaluator.class, StreamPipesPasswordEncoder.class, + StreamPipesPrometheusConfig.class, WebSecurityConfig.class, - SpPermissionEvaluator.class, - StreamPipesPrometheusConfig.class + WelcomePageController.class, }) @ComponentScan({"org.apache.streampipes.rest.*", "org.apache.streampipes.ps"}) public class StreamPipesCoreApplication extends StreamPipesServiceBase { diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/UnauthenticatedInterfaces.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/UnauthenticatedInterfaces.java index 297d2aea4..85deaf6d8 100644 --- a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/UnauthenticatedInterfaces.java +++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/UnauthenticatedInterfaces.java @@ -36,7 +36,7 @@ public class UnauthenticatedInterfaces { "/api/v2/pe/*/assets/icon", "/api/v2/pe/*/assets/icon.png", "/api/v2/connect/master/description/*/assets/icon", - "/api/openapi.json", + "/apidocs/**", "/api/auth/**", "/oauth2/**", "/api/all", diff --git a/streampipes-service-core/src/main/resources/application.properties b/streampipes-service-core/src/main/resources/application.properties index c1f46b914..f0dabfa66 100644 --- a/streampipes-service-core/src/main/resources/application.properties +++ b/streampipes-service-core/src/main/resources/application.properties @@ -20,3 +20,5 @@ server.servlet.context-path=/streampipes-backend server.tomcat.additional-tld-skip-patterns=*.jar logging.config=classpath:logback.xml spring.output.ansi.enabled=always +springdoc.api-docs.path=/apidocs [email protected]@ diff --git a/streampipes-service-core/src/main/resources/openapi.yaml b/streampipes-service-core/src/main/resources/openapi.yaml deleted file mode 100644 index df13f9ab2..000000000 --- a/streampipes-service-core/src/main/resources/openapi.yaml +++ /dev/null @@ -1,35 +0,0 @@ -scannerClass: io.swagger.v3.oas.integration.GenericOpenApiScanner -resourceClasses: - - org.apache.streampipes.ps.PipelineElementTemplateResource - - org.apache.streampipes.rest.impl.PipelineResource - - org.apache.streampipes.ps.DataLakeResourceV4 -prettyPrint: true -cacheTTL: 0 -openAPI: - info: - version: '0.95.0' - title: Apache StreamPipes API - description: 'This is the documentation of the Apache StreamPipes developer API.' - contact: - email: [email protected] - license: - name: Apache 2.0 - url: http://www.apache.org/licenses/LICENSE-2.0.html - servers: - - url: /streampipes-backend - components: - securitySchemes: - bearerAuth: - type: http - scheme: bearer - parameters: - usernameParam: - in: path - name: username - required: true - schema: - type: string - minimum: 0 - description: The username (currently the email address of the logged in user) - security: - - bearerAuth: [ ] diff --git a/streampipes-service-extensions/src/main/resources/application.properties b/streampipes-service-extensions/src/main/resources/application.properties index 75e39d3c5..8814c22a5 100644 --- a/streampipes-service-extensions/src/main/resources/application.properties +++ b/streampipes-service-extensions/src/main/resources/application.properties @@ -18,4 +18,3 @@ logging.config=classpath:logback.xml spring.output.ansi.enabled=always -logging.level.org.springframework.web: DEBUG diff --git a/ui/cypress/support/utils/DataDownloadDialogUtils.ts b/ui/cypress/support/utils/DataDownloadDialogUtils.ts index 16bbafcf3..b795269d0 100644 --- a/ui/cypress/support/utils/DataDownloadDialogUtils.ts +++ b/ui/cypress/support/utils/DataDownloadDialogUtils.ts @@ -80,10 +80,13 @@ export class DataDownloadDialogUtils { (downloadFileString: string) => { cy.readFile( `cypress/fixtures/dataDownloadDialog/${resultFileLocation}`, - ).then(expectedResultString => { - expect(expectedResultString).to.deep.equal( - downloadFileString, - ); + ).then(expectedResult => { + console.log(expectedResult); + // Replace whitespaces on Windows systems + if (typeof expectedResult === 'string') { + expectedResult = expectedResult.replace(/\r/g, ''); + } + expect(expectedResult).to.deep.equal(downloadFileString); }); }, ); diff --git a/ui/cypress/tests/dashboard/editDashboardTest.spec.ts b/ui/cypress/tests/dashboard/editDashboardTest.spec.ts index 194af94af..f2fed1043 100644 --- a/ui/cypress/tests/dashboard/editDashboardTest.spec.ts +++ b/ui/cypress/tests/dashboard/editDashboardTest.spec.ts @@ -33,7 +33,6 @@ describe('Test edit dashboard', () => { DashboardUtils.addAndEditDashboard(dashboardName); DashboardUtils.addWidget('Persist_simulator', 'raw'); cy.dataCy('save-data-explorer-go-back-to-overview').click(); - cy.dataCy('confirm-delete').click(); // Change dashboard name cy.dataCy('change-dashboard-settings-button').click(); @@ -48,7 +47,7 @@ describe('Test edit dashboard', () => { cy.contains('testDashboardNew').should('exist'); // Edit dashboard and change widget to line chart - cy.dataCy('edit-dashboard-testDashboardNew').click().wait(1000); + cy.dataCy('edit-dashboard-testDashboardNew').click().wait(2000); cy.dataCy('widget-settings-button').click(); cy.dataCy('edit-widget-back-btn').click(); cy.dataCy('dashboard-select-widget-line').click(); @@ -65,7 +64,6 @@ describe('Test edit dashboard', () => { // Go back and check if two newly added charts are displayed correctly in standalone dashboard cy.dataCy('save-data-explorer-go-back-to-overview').click(); - cy.dataCy('confirm-delete').click(); cy.dataCy('show-dashboard-testDashboardNew').click(); cy.get('g').should('have.class', 'line-chart chart'); cy.get('div').should('have.class', 'circleNumber'); diff --git a/ui/src/app/apidocs/apidocs.component.ts b/ui/src/app/apidocs/apidocs.component.ts index f6a0a8074..ba9d86c26 100644 --- a/ui/src/app/apidocs/apidocs.component.ts +++ b/ui/src/app/apidocs/apidocs.component.ts @@ -29,7 +29,7 @@ export class ApidocsComponent implements OnInit { ngOnInit(): void { SwaggerUI({ - url: '/streampipes-backend/api/openapi.json', + url: '/streampipes-backend/apidocs', domNode: this.el.nativeElement.querySelector('.swagger-ui'), deepLinking: false, presets: [SwaggerUI.presets.apis],
