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

Commit

Permalink
initial commit of multi view support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Feb 1, 2018
1 parent 5956771 commit b57b78e
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 74 deletions.
Expand Up @@ -285,7 +285,7 @@ export class AddConnectionWizardComponent implements OnInit {

const self = this;
this.connectionService
.createConnection(connection)
.createAndDeployConnection(connection)
.subscribe(
(wasSuccess) => {
self.createComplete = true;
Expand Down
28 changes: 28 additions & 0 deletions ngapp/src/app/connections/shared/connection.service.ts
Expand Up @@ -26,6 +26,7 @@ import { TemplateDefinition } from "@connections/shared/template-definition.mode
import { ApiService } from "@core/api.service";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { Table } from "@dataservices/shared/table.model";
import { environment } from "@environments/environment";
import { PropertyDefinition } from "@shared/property-form/property-definition.model";
import { Observable } from "rxjs/Observable";
Expand Down Expand Up @@ -69,6 +70,22 @@ export class ConnectionService extends ApiService {
.catch( ( error ) => this.handleError( error ) );
}

/**
* Deploy a connection via the komodo rest interface
* @param {string} connectionName
* @returns {Observable<boolean>}
*/
public deployConnection(connectionName: string): Observable<boolean> {
const connectionPath = this.getKomodoUserWorkspacePath() + "/" + connectionName;
return this.http
.post(environment.komodoTeiidUrl + ConnectionsConstants.connectionRootPath,
{ path: connectionPath}, this.getAuthRequestOptions())
.map((response) => {
return response.ok;
})
.catch( ( error ) => this.handleError( error ) );
}

/**
* Delete a connection via the komodo rest interface
* @param {string} connectionId
Expand Down Expand Up @@ -153,4 +170,15 @@ export class ConnectionService extends ApiService {
.catch( ( error ) => this.handleError( error ) );
}

/**
* Create a connection and deploy it to server via the komodo rest interface
* @param {NewConnection} connection
* @returns {Observable<boolean>}
*/
public createAndDeployConnection(connection: NewConnection): Observable<boolean> {
// Chain the individual calls together in series to build the DataService
return this.createConnection(connection)
.flatMap((res) => this.deployConnection(connection.getName()));
}

}
3 changes: 3 additions & 0 deletions ngapp/src/app/connections/shared/connections-constants.ts
Expand Up @@ -17,6 +17,9 @@ export class ConnectionsConstants {
public static readonly connectionsRootRoute = "connections";
public static readonly connectionsRootPath = "/" + ConnectionsConstants.connectionsRootRoute;

public static readonly connectionRootRoute = "connection";
public static readonly connectionRootPath = "/" + ConnectionsConstants.connectionRootRoute;

public static readonly addConnectionRoute = ConnectionsConstants.connectionsRootRoute + "/add-connection";
public static readonly addConnectionPath = ConnectionsConstants.connectionsRootPath + "/add-connection";

Expand Down
8 changes: 5 additions & 3 deletions ngapp/src/app/core/app-settings.service.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Injectable, OnInit } from "@angular/core";
import { Injectable } from "@angular/core";
import { Headers, Http, RequestOptions, Response } from "@angular/http";
import { LoggerService } from "@core/logger.service";
import { environment } from "@environments/environment";
Expand All @@ -24,7 +24,7 @@ import { Observable } from "rxjs/Observable";
import { ErrorObservable } from "rxjs/observable/ErrorObservable";

@Injectable()
export class AppSettingsService implements OnInit {
export class AppSettingsService {

private static readonly userProfileUrl = environment.komodoServiceUrl + "/userProfile";

Expand Down Expand Up @@ -61,9 +61,11 @@ export class AppSettingsService implements OnInit {
this.gitRepoProperties.set(this.GIT_REPO_PASSWORD_KEY, "MY_PASS");
this.gitRepoProperties.set(this.GIT_REPO_AUTHOR_NAME_KEY, "MY_USER");
this.gitRepoProperties.set(this.GIT_REPO_AUTHOR_EMAIL_KEY, "USER@SOMEWHERE.COM");

this.initUserProfile();
}

public ngOnInit(): void {
public initUserProfile(): void {
//
// Do a call to fetch the user profile on init of service.
// The fetchProfile method returns an observable
Expand Down
Expand Up @@ -287,7 +287,7 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {

const self = this;
this.vdbService
.deployVdbForTable(this.tableSelector.getSelectedTables()[0])
.deployVdbForTables(this.tableSelector.getSelectedTables())
.subscribe(
(wasSuccess) => {
// Deployment succeeded - wait for source vdb to become active
Expand Down Expand Up @@ -344,9 +344,9 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {

if (status.isActive()) {
if (this.wizardService.isEdit()) {
this.updateDataserviceForSingleTable();
this.updateDataserviceForSingleSourceTables();
} else {
this.createDataserviceForSingleTable();
this.createDataserviceForSingleSourceTables();
}
} else if (status.isFailed()) {
this.setFinalPageComplete(false);
Expand Down Expand Up @@ -487,19 +487,16 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
}

/*
* Create the Dataservice for the selected source table. This is invoked
* Create the Dataservice for the selected single source tables. This is invoked
* only after the source VDB has successfully deployed.
*/
private createDataserviceForSingleTable(): void {
const dataservice: NewDataservice = new NewDataservice();

private createDataserviceForSingleSourceTables(): void {
// Dataservice basic properties from step 1
dataservice.setId(this.dataserviceName);
dataservice.setDescription(this.dataserviceDescription);
const dataservice: NewDataservice = this.dataserviceService.newDataserviceInstance(this.dataserviceName, this.dataserviceDescription);

const self = this;
this.dataserviceService
.createDataserviceForSingleTable(dataservice, this.tableSelector.getSelectedTables()[0])
.createDataserviceForSingleSourceTables(dataservice, this.tableSelector.getSelectedTables())
.subscribe(
(wasSuccess) => {
self.setFinalPageComplete(wasSuccess);
Expand All @@ -513,19 +510,16 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
}

/**
* Update the selected Dataservice for the selected source table. This is invoked
* Update the selected Dataservice for the selected single source tables. This is invoked
* only after the source VDB has successfully deployed.
*/
private updateDataserviceForSingleTable(): void {
const dataservice: NewDataservice = new NewDataservice();

private updateDataserviceForSingleSourceTables(): void {
// Dataservice basic properties from step 1
dataservice.setId(this.dataserviceName);
dataservice.setDescription(this.dataserviceDescription);
const dataservice: NewDataservice = this.dataserviceService.newDataserviceInstance(this.dataserviceName, this.dataserviceDescription);

const self = this;
this.dataserviceService
.updateDataserviceForSingleTable(dataservice, this.tableSelector.getSelectedTables()[0])
.updateDataserviceForSingleSourceTables(dataservice, this.tableSelector.getSelectedTables())
.subscribe(
(wasSuccess) => {
self.setFinalPageComplete(wasSuccess);
Expand Down
16 changes: 8 additions & 8 deletions ngapp/src/app/dataservices/shared/dataservice.model.ts
Expand Up @@ -25,7 +25,7 @@ export class Dataservice implements Identifiable< string > {
private tko__description: string;
private serviceVdbName: string;
private serviceVdbVersion: string;
private serviceView: string;
private serviceViews: string[];
private serviceViewModel: string;
private serviceViewTables: string[];
private deploymentState: DeploymentState = DeploymentState.LOADING;
Expand Down Expand Up @@ -112,10 +112,10 @@ export class Dataservice implements Identifiable< string > {
}

/**
* @returns {string} the dataservice view name (can be null)
* @returns {string[]} the dataservice view names (can be null)
*/
public getServiceViewName(): string {
return this.serviceView;
public getServiceViewNames(): string[] {
return this.serviceViews;
}

/**
Expand Down Expand Up @@ -215,10 +215,10 @@ export class Dataservice implements Identifiable< string > {
}

/**
* @param {string} viewName the dataservice view name
* @param {string[]} viewNames the dataservice view names
*/
public setServiceViewName( viewName: string ): void {
this.serviceView = viewName;
public setServiceViewNames( viewNames: string[] ): void {
this.serviceViews = viewNames;
}

/**
Expand Down Expand Up @@ -249,7 +249,7 @@ export class Dataservice implements Identifiable< string > {
tko__description: this.tko__description,
serviceVdbName: this.serviceVdbName,
serviceVdbVersion: this.serviceVdbVersion,
serviceView: this.serviceView,
serviceViews: this.serviceViews,
serviceViewModel: this.serviceViewModel,
serviceViewTables: this.serviceViewTables
};
Expand Down
59 changes: 41 additions & 18 deletions ngapp/src/app/dataservices/shared/dataservice.service.ts
Expand Up @@ -69,6 +69,22 @@ export class DataserviceService extends ApiService {
this.pollDataserviceStatus(60);
}

/**
* Create and return a NewDataservice instance
* @param {string} name the dataservice name
* @param {string} description the dataservice description
* @returns {NewDataservice} the NewDataservice object
*/
public newDataserviceInstance(name: string, description: string ): NewDataservice {
const ds: NewDataservice = new NewDataservice(this.appSettingsService.getKomodoUserWorkspacePath());

// Set provided name and description
ds.setId(name);
ds.setDescription(description);

return ds;
}

/**
* Set the current Dataservice selection
* @param {Dataservice} service the Dataservice
Expand Down Expand Up @@ -102,14 +118,16 @@ export class DataserviceService extends ApiService {
}

const modelName = this.selectedDataservice.getServiceViewModel();
const serviceView = this.selectedDataservice.getServiceViewName();

// TODO: we will need to get multiple views when supported
const view1: Table = new Table();
view1.setName(modelName + "." + serviceView);
const serviceViews = this.selectedDataservice.getServiceViewNames();

// build the views using the model and view names
const allViews: Table[] = [];
allViews.push(view1);
for ( const serviceView of serviceViews ) {
const aView: Table = new Table();
aView.setName(modelName + "." + serviceView);

allViews.push(aView);
}

return allViews;
}
Expand Down Expand Up @@ -206,14 +224,14 @@ export class DataserviceService extends ApiService {
/**
* Create a dataservice via the komodo rest interface
* @param {string} dataserviceName,
* @param {string} tablePath,
* @param {string[]} tablePaths,
* @param {string} modelSourcePath,
* @returns {Observable<boolean>}
*/
public setServiceVdbForSingleTable(dataserviceName: string, tablePath: string, modelSourcePath: string): Observable<boolean> {
public setServiceVdbForSingleSourceTables(dataserviceName: string, tablePaths: string[], modelSourcePath: string): Observable<boolean> {
return this.http
.post(environment.komodoWorkspaceUrl + DataservicesConstants.dataservicesRootPath + "/ServiceVdbForSingleTable",
{ dataserviceName, tablePath, modelSourcePath}, this.getAuthRequestOptions())
.post(environment.komodoWorkspaceUrl + DataservicesConstants.dataservicesRootPath + "/ServiceVdbForSingleSourceTables",
{ dataserviceName, tablePaths, modelSourcePath}, this.getAuthRequestOptions())
.map((response) => {
return response.ok;
})
Expand Down Expand Up @@ -301,22 +319,27 @@ export class DataserviceService extends ApiService {
/**
* Create a dataservice which is a straight passthru to the supplied tables
* @param {NewDataservice} dataservice
* @param {Table} sourceTable
* @param {Table[]} sourceTables
* @returns {Observable<boolean>}
*/
public createDataserviceForSingleTable(dataservice: NewDataservice, sourceTable: Table): Observable<boolean> {
const connectionName = sourceTable.getConnection().getId();
public createDataserviceForSingleSourceTables(dataservice: NewDataservice, sourceTables: Table[]): Observable<boolean> {
// All tables from same connection
const connectionName = sourceTables[0].getConnection().getId();
const sourceVdbName = connectionName + VdbsConstants.SOURCE_VDB_SUFFIX;
const sourceModelName = connectionName;
const vdbPath = this.getKomodoUserWorkspacePath() + "/" + sourceVdbName;
const tablePath = vdbPath + "/" + sourceModelName + "/" + sourceTable.getName();
const tablePaths = [];
for ( const sourceTable of sourceTables ) {
const tablePath = vdbPath + "/" + sourceModelName + "/" + sourceTable.getName();
tablePaths.push(tablePath);
}
const modelSourcePath = vdbPath + "/" + sourceModelName + "/vdb:sources/" + sourceModelName;

// Chain the individual calls together in series to build the DataService
return this.createDataservice(dataservice)
.flatMap((res) => this.vdbService.updateVdbModelFromTeiid(sourceVdbName, sourceModelName,
sourceVdbName, sourceModelName))
.flatMap((res) => this.setServiceVdbForSingleTable(dataservice.getId(), tablePath, modelSourcePath))
.flatMap((res) => this.setServiceVdbForSingleSourceTables(dataservice.getId(), tablePaths, modelSourcePath))
.flatMap((res) => this.createReadonlyDataRole(dataservice.getId(), sourceModelName))
.flatMap((res) => this.vdbService.undeployVdb(sourceVdbName))
.flatMap((res) => this.vdbService.deleteVdb(sourceVdbName));
Expand All @@ -326,12 +349,12 @@ export class DataserviceService extends ApiService {
* Updates a dataservice with single table source. This is simply a create, with the added step of
* deleting the existing workspace dataservice first.
* @param {NewDataservice} dataservice
* @param {Table} sourceTable
* @param {Table[]} sourceTables
* @returns {Observable<boolean>}
*/
public updateDataserviceForSingleTable(dataservice: NewDataservice, sourceTable: Table): Observable<boolean> {
public updateDataserviceForSingleSourceTables(dataservice: NewDataservice, sourceTables: Table[]): Observable<boolean> {
return this.deleteDataservice(dataservice.getId())
.flatMap((res) => this.createDataserviceForSingleTable(dataservice, sourceTable));
.flatMap((res) => this.createDataserviceForSingleSourceTables(dataservice, sourceTables));
}

/**
Expand Down
8 changes: 5 additions & 3 deletions ngapp/src/app/dataservices/shared/mock-dataservice.service.ts
Expand Up @@ -46,15 +46,17 @@ export class MockDataserviceService extends DataserviceService {
this.serv1.setId("serv1");
this.serv1.setServiceViewTables(["table1", "table2"]);
this.serv1.setServiceViewModel("viewModel");
this.serv1.setServiceViewName("views");
const viewNames: string[] = [];
viewNames.push("views");
this.serv1.setServiceViewNames(viewNames);
this.serv2.setId("serv2");
this.serv2.setServiceViewTables(["table1", "table2"]);
this.serv2.setServiceViewModel("viewModel");
this.serv2.setServiceViewName("views");
this.serv2.setServiceViewNames(viewNames);
this.serv3.setId("serv3");
this.serv3.setServiceViewTables(["table1", "table2"]);
this.serv3.setServiceViewModel("viewModel");
this.serv3.setServiceViewName("views");
this.serv3.setServiceViewNames(viewNames);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions ngapp/src/app/dataservices/shared/mock-vdb.service.ts
Expand Up @@ -153,10 +153,10 @@ export class MockVdbService extends VdbService {

/**
* Create and deploy a VDB for the provided table
* @param {Table} table
* @param {Table[]} tables
* @returns {Observable<boolean>}
*/
public deployVdbForTable(table: Table): Observable<boolean> {
public deployVdbForTables(tables: Table[]): Observable<boolean> {
return Observable.of(true);
}

Expand Down

0 comments on commit b57b78e

Please sign in to comment.