Skip to content
This repository has been archived by the owner on Nov 22, 2019. It is now read-only.

Commit

Permalink
TT-476 Adding refresh views service call and reorgs some code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Aug 17, 2018
1 parent 1ea9722 commit c770145
Show file tree
Hide file tree
Showing 26 changed files with 426 additions and 178 deletions.
19 changes: 19 additions & 0 deletions ngapp/src/app/dataservices/shared/composition-operator.enum.ts
Expand Up @@ -60,3 +60,22 @@ export enum CompositionOperator {
NE = "NE"

}

export namespace CompositionOperator {
export function toSql( oper: CompositionOperator): string {
if (oper === CompositionOperator.EQ) {
return "=";
} else if (oper === CompositionOperator.LT) {
return "<";
} else if (oper === CompositionOperator.GT) {
return ">";
} else if (oper === CompositionOperator.LE) {
return "<=";
} else if (oper === CompositionOperator.GE) {
return ">=";
} else if (oper === CompositionOperator.NE) {
return "<>";
}
return "=";
}
}
17 changes: 17 additions & 0 deletions ngapp/src/app/dataservices/shared/composition-type.enum.ts
Expand Up @@ -53,3 +53,20 @@ export enum CompositionType {
UNION = "UNION"

}

export namespace CompositionType {
export function toSql( type: CompositionType): string {
if ( type === CompositionType.INNER_JOIN ) {
return "INNER JOIN";
} else if ( type === CompositionType.LEFT_OUTER_JOIN ) {
return "LEFT OUTER JOIN";
} else if ( type === CompositionType.RIGHT_OUTER_JOIN ) {
return "RIGHT OUTER JOIN";
} else if ( type === CompositionType.FULL_OUTER_JOIN ) {
return "FULL OUTER JOIN";
} else if ( type === CompositionType.UNION ) {
return "UNION";
}
return "INNER JOIN";
}
}
122 changes: 121 additions & 1 deletion ngapp/src/app/dataservices/shared/dataservice.service.ts
Expand Up @@ -16,7 +16,7 @@
*/

import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { Http, RequestOptions } from "@angular/http";
import { Connection } from "@connections/shared/connection.model";
import { SchemaNode } from "@connections/shared/schema-node.model";
import { ApiService } from "@core/api.service";
Expand All @@ -43,6 +43,7 @@ import * as _ from "lodash";
import * as vkbeautify from 'vkbeautify';
import { ViewDefinition } from "@dataservices/shared/view-definition.model";
import { SqlView } from "@dataservices/shared/sql-view.model";
import { ViewEditorState } from "@dataservices/shared/view-editor-state.model";

@Injectable()
export class DataserviceService extends ApiService {
Expand Down Expand Up @@ -343,6 +344,24 @@ export class DataserviceService extends ApiService {
.catch( ( error ) => this.handleError( error ) );
}

/**
* Refresh the views for a dataservice via the komodo rest interface
* @param {string} dataserviceName
* @returns {Observable<boolean>}
*/
public refreshDataserviceViews(dataserviceName: string): Observable<boolean> {
const refreshViewsUrl = environment.komodoWorkspaceUrl
+ DataservicesConstants.dataservicesRestPath
+ "/refreshViews/" + encodeURIComponent(dataserviceName);

return this.http
.post(refreshViewsUrl, this.getAuthRequestOptions())
.map((response) => {
return response.ok;
})
.catch( ( error ) => this.handleError( error ) );
}

/**
* Derive the service vdb name from the given dataservice
*
Expand Down Expand Up @@ -612,6 +631,107 @@ export class DataserviceService extends ApiService {
});
}

/**
* @param {string} editorStatePattern the name pattern to use for returning the array of viewEditorStates.
* If no pattern is supplied, all states are returned
* @returns {Observable<ViewEditorState[]>} the view editor states or empty array if none found
*/
public getViewEditorStates( editorStatePattern?: string ): Observable< ViewEditorState[] > {
// pattern is added to the request options
let statePattern = {};
if (editorStatePattern && editorStatePattern.length > 0) {
statePattern = {
params: {
"pattern": editorStatePattern
}
};
}

return this.http.get(environment.viewEditorState, this.getAuthRequestOptions().merge(new RequestOptions(statePattern)) )
.map( ( response ) => {
const editorStates = response.json();
return editorStates.map((state) => ViewEditorState.create( state ));
} )
.catch( ( error ) => {
// no editor state found
if ( error.status === 404 ) {
return Observable.of( {} );
}

return this.handleError( error );
} );
}

/**
* @param {string} editorId the ID of the editor state being requested
* @returns {Observable<ViewEditorState>} the view editor state or empty object if not found
*/
public getViewEditorState( editorId: string ): Observable< ViewEditorState > {
return this.http.get(environment.viewEditorState + "/" + editorId, this.getAuthRequestOptions() )
.map( ( response ) => {
const editorState = response.json();
const viewEditorState = ViewEditorState.create(editorState);
return Observable.of( viewEditorState );
} )
.catch( ( error ) => {
// no editor state found
if ( error.status === 404 ) {
return Observable.of( {} );
}

return this.handleError( error );
} );
}

/**
* @param {ViewEditorState} editorState the view editor state
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorState( editorState: ViewEditorState ): Observable< boolean > {

return this.http.put( environment.viewEditorState, editorState.toJSON(), this.getAuthRequestOptions() )
.map( ( response ) => {
return response.ok;
} )
.catch( ( error ) =>
this.handleError( error )
);
}

/**
* @param {string} editorId the ID of the editor state being deleted
* @returns {Observable<boolean>} `true` if the editor state was successfully deleted
*/
public deleteViewEditorState( editorId: string ): Observable< boolean > {
return this.http.delete(environment.viewEditorState + "/" + editorId, this.getAuthRequestOptions() )
.map( ( response ) => {
return response.ok;
} )
.catch( ( error ) =>
this.handleError( error )
);
}

/**
* @param {ViewEditorState} editorState the view editor state
* @param {string} dataserviceName the name of the dataservice
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorStateRefreshViews( editorState: ViewEditorState, dataserviceName: string ): Observable< boolean > {
return this.saveViewEditorState(editorState)
.flatMap((res) => this.refreshDataserviceViews(dataserviceName));
}

/**
* @param {string} editorId the ID of the editor state being deleted
* @param {string} dataserviceName the name of the dataservice
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public deleteViewEditorStateRefreshViews( editorId: string, dataserviceName: string ): Observable< boolean > {
return this.deleteViewEditorState(editorId)
.flatMap((res) => this.refreshDataserviceViews(dataserviceName));
}

/**
* Converts a base64 data string into a blob for use with the FileSaver library
* Acknowledgement to
Expand Down
61 changes: 61 additions & 0 deletions ngapp/src/app/dataservices/shared/mock-dataservice.service.ts
Expand Up @@ -34,12 +34,14 @@ import { Observable } from "rxjs/Observable";
import { ErrorObservable } from "rxjs/observable/ErrorObservable";
import { ViewDefinition } from "@dataservices/shared/view-definition.model";
import { SqlView } from "@dataservices/shared/sql-view.model";
import { ViewEditorState } from "@dataservices/shared/view-editor-state.model";

@Injectable()
export class MockDataserviceService extends DataserviceService {

private readonly services: Dataservice[];
private readonly queryResults: QueryResults;
private editorViewStateMap = new Map<string, ViewEditorState>();

constructor(http: Http, vdbService: VdbService, appSettings: AppSettingsService,
notifierService: NotifierService, logger: LoggerService ) {
Expand All @@ -52,6 +54,8 @@ export class MockDataserviceService extends DataserviceService {
// Get test data
this.services = testDataService.getDataservices();
this.queryResults = testDataService.getQueryResults();

this.editorViewStateMap = testDataService.getViewEditorStateMap();
}

/**
Expand Down Expand Up @@ -167,4 +171,61 @@ export class MockDataserviceService extends DataserviceService {
return Observable.of( true );
}

/**
* @param {ViewEditorState} editorState the view editor state
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorState( editorState: ViewEditorState ): Observable< boolean > {
return Observable.of(true);
}

/**
* @param {string} editorId the ID of the editor state being requested
* @returns {Observable<ViewEditorState>} the view editor state or empty object if not found
*/
public getViewEditorState( editorId: string ): Observable< ViewEditorState > {
return Observable.of(this.editorViewStateMap.get(editorId));
}

/**
* @param {string} editorStatePattern the editorState name pattern
* @returns {Observable<ViewEditorState[]>} the view editor state array
*/
public getViewEditorStates( editorStatePattern?: string ): Observable< ViewEditorState[] > {
const editorStates = [];

this.editorViewStateMap.forEach( ( value, key ) => {
if (editorStatePattern && editorStatePattern.length > 0) {

// Just match the first few chars with this test method
const patternTrimmed = editorStatePattern.substring(0, 5);
const keyTrimmed = key.substring(0, 5);
if (keyTrimmed.startsWith(patternTrimmed)) {
editorStates.push(value);
}
} else {
editorStates.push(value);
}
} );

return Observable.of(editorStates);
}

/**
* @param {string} editorId the ID of the editor state being deleted
* @returns {Observable<boolean>} `true` if the editor state was successfully deleted
*/
public deleteViewEditorState( editorId: string ): Observable< boolean > {
return Observable.of(true);
}

/**
* @param {ViewEditorState} editorState the view editor state
* @param {string} dataserviceName the name of the dataservice
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorStateRefreshViews( editorState: ViewEditorState, dataserviceName: string ): Observable< boolean > {
return Observable.of(true);
}

}
51 changes: 0 additions & 51 deletions ngapp/src/app/dataservices/shared/mock-vdb.service.ts
Expand Up @@ -32,13 +32,11 @@ import "rxjs/add/observable/throw";
import "rxjs/add/operator/catch";
import "rxjs/add/operator/map";
import { Observable } from "rxjs/Observable";
import { ViewEditorState } from "@dataservices/shared/view-editor-state.model";

@Injectable()
export class MockVdbService extends VdbService {

private testDataService: TestDataService;
private editorViewStateMap = new Map<string, ViewEditorState>();

constructor(http: Http, appSettings: AppSettingsService, notifierService: NotifierService, logger: LoggerService ) {
super(http, appSettings, notifierService, logger);
Expand All @@ -48,7 +46,6 @@ export class MockVdbService extends VdbService {
const testDataService = injector.get(TestDataService);

this.testDataService = testDataService;
this.editorViewStateMap = this.testDataService.getViewEditorStateMap();
}

/**
Expand Down Expand Up @@ -181,52 +178,4 @@ export class MockVdbService extends VdbService {
return Observable.of(true);
}

/**
* @param {ViewEditorState} editorState the view editor state
* @returns {Observable<boolean>} `true` if the editor state was successfully saved
*/
public saveViewEditorState( editorState: ViewEditorState ): Observable< boolean > {
return Observable.of(true);
}

/**
* @param {string} editorId the ID of the editor state being requested
* @returns {Observable<ViewEditorState>} the view editor state or empty object if not found
*/
public getViewEditorState( editorId: string ): Observable< ViewEditorState > {
return Observable.of(this.editorViewStateMap.get(editorId));
}

/**
* @param {string} editorStatePattern the editorState name pattern
* @returns {Observable<ViewEditorState[]>} the view editor state array
*/
public getViewEditorStates( editorStatePattern?: string ): Observable< ViewEditorState[] > {
const editorStates = [];

this.editorViewStateMap.forEach( ( value, key ) => {
if (editorStatePattern && editorStatePattern.length > 0) {

// Just match the first few chars with this test method
const patternTrimmed = editorStatePattern.substring(0, 5);
const keyTrimmed = key.substring(0, 5);
if (keyTrimmed.startsWith(patternTrimmed)) {
editorStates.push(value);
}
} else {
editorStates.push(value);
}
} );

return Observable.of(editorStates);
}

/**
* @param {string} editorId the ID of the editor state being deleted
* @returns {Observable<boolean>} `true` if the editor state was successfully deleted
*/
public deleteViewEditorState( editorId: string ): Observable< boolean > {
return Observable.of(true);
}

}

0 comments on commit c770145

Please sign in to comment.