Skip to content

Commit

Permalink
feat(#2379): Move pipeline rest calls to pipeline service (#2381)
Browse files Browse the repository at this point in the history
* feat(#2379): Move pipeline rest calls to pipeline service

* feat(#2379): Fix route for pipelines endpoint
  • Loading branch information
tenthe authored Dec 29, 2023
1 parent 4495b46 commit aa8e605
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public PipelineElementRecommendationMessage recommend(@RequestBody Pipeline pipe
produces = MediaType.APPLICATION_JSON_VALUE)
@Hidden
@PreAuthorize(AuthConstants.HAS_WRITE_PIPELINE_PRIVILEGE)
public ResponseEntity<?> update(@RequestBody Pipeline pipeline) {
public ResponseEntity<?> validatePipeline(@RequestBody Pipeline pipeline) {
try {
return ok(Operations.validatePipeline(pipeline));
} catch (JsonSyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
Message,
Pipeline,
PipelineCategory,
PipelineElementRecommendationMessage,
PipelineModificationMessage,
PipelineOperationStatus,
PipelineStatusMessage,
} from '../model/gen/streampipes-model';
Expand Down Expand Up @@ -150,6 +152,36 @@ export class PipelineService {
);
}

recommendPipelineElement(
pipeline: Pipeline,
currentDomId: string,
): Observable<PipelineElementRecommendationMessage> {
return this.http
.post(
`${this.apiBasePath}/pipelines/recommend/${currentDomId}`,
pipeline,
)
.pipe(
map(data =>
PipelineElementRecommendationMessage.fromData(data as any),
),
);
}

/**
* Validates the given pipeline and returns a pipeline modification message.
* The message describe how the pipeline should be modified.
*/
validatePipeline(pipeline): Observable<PipelineModificationMessage> {
return this.http
.post(`${this.apiBasePath}/pipelines/update`, pipeline)
.pipe(
map(data => {
return PipelineModificationMessage.fromData(data as any);
}),
);
}

get apiBasePath() {
return this.platformServicesCommons.apiBasePath;
}
Expand Down
28 changes: 7 additions & 21 deletions ui/src/app/editor/services/editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
PipelineElementRecommendationMessage,
PipelineModificationMessage,
PipelinePreviewModel,
PipelineService,
PlatformServicesCommons,
SpDataStream,
} from '@streampipes/platform-services';
Expand Down Expand Up @@ -53,6 +54,7 @@ export class EditorService {
private http: HttpClient,
private platformServicesCommons: PlatformServicesCommons,
private dialogService: DialogService,
private pipelineService: PipelineService,
) {}

get apiBasePath() {
Expand All @@ -63,26 +65,14 @@ export class EditorService {
pipeline: Pipeline,
currentDomId: string,
): Observable<PipelineElementRecommendationMessage> {
return this.http
.post(
this.pipelinesResourceUrl + '/recommend/' + currentDomId,
pipeline,
)
.pipe(
map(data =>
PipelineElementRecommendationMessage.fromData(data as any),
),
);
return this.pipelineService.recommendPipelineElement(
pipeline,
currentDomId,
);
}

updatePartialPipeline(pipeline): Observable<PipelineModificationMessage> {
return this.http
.post(this.pipelinesResourceUrl + '/update', pipeline)
.pipe(
map(data => {
return PipelineModificationMessage.fromData(data as any);
}),
);
return this.pipelineService.validatePipeline(pipeline);
}

getCachedPipeline(): Observable<PipelineElementConfig[]> {
Expand Down Expand Up @@ -166,10 +156,6 @@ export class EditorService {
return this.http.delete(this.apiBasePath + '/pipeline-canvas-cache');
}

private get pipelinesResourceUrl() {
return this.platformServicesCommons.apiBasePath + '/pipelines';
}

announceConfiguredElement(pipelineElementDomId: string) {
this.pipelineElementConfigured.next(pipelineElementDomId);
}
Expand Down

0 comments on commit aa8e605

Please sign in to comment.