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

Commit

Permalink
Changes to view paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Jun 27, 2018
1 parent ea0c79e commit 4f374e3
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 90 deletions.
11 changes: 6 additions & 5 deletions ngapp/src/app/dataservices/shared/mock-vdb.service.ts
Expand Up @@ -110,16 +110,17 @@ export class MockVdbService extends VdbService {
}

/**
* Creates the Vdb Model Views via the komodo rest interface
* Creates the Vdb Model Views via the komodo rest interface. This is currently limited - will need to be improved
* in subsequent development.
* @param {string} vdbName the vdb name
* @param {string} modelName the model name
* @param {string[]} viewNames the view names
* @param {SchemaNode[]} sourceNodes the source node for each view
* @param {Connection[]} connections the array of available active connections
* @param {string[]} viewNames the view names (1:1 correspondence with schemaNodes)
* @param {string[]} sourceNodePaths the path for each source node
* @param {Connection[]} connections the array of active connections
* @returns {Observable<boolean>}
*/
public setVdbModelViews(vdbName: string, modelName: string, viewNames: string[],
sourceNodes: SchemaNode[], connections: Connection[]): Observable<boolean> {
sourceNodePaths: string[], connections: Connection[]): Observable<boolean> {
return Observable.of(true);
}

Expand Down
68 changes: 68 additions & 0 deletions ngapp/src/app/dataservices/shared/path-utils.ts
@@ -0,0 +1,68 @@
/**
* @license
* Copyright 2017 JBoss Inc
*
* Licensed 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.
*/

export class PathUtils {

/**
* Get the connection name from the supplied source path
* @param {string} sourcePath
* @returns {string} the connection name
*/
public static getConnectionName(sourcePath: string): string {
const fqnArray = sourcePath.split("/", 10);

const arrayLength = fqnArray.length;
const connectionSegment = fqnArray[0];
let parts = connectionSegment.split("=", 2);
const connName = parts[1];

return connName;
}

/**
* Get the source name from the supplied source path
* @param {string} sourcePath
* @returns {string} the source name
*/
public static getSourceName(sourcePath: string): string {
const fqnArray = sourcePath.split("/", 10);

const arrayLength = fqnArray.length;
const nodeSeqment = fqnArray[arrayLength - 1];
let parts = nodeSeqment.split("=", 2);
const nodeName = parts[1];

return nodeName;
}

/**
* Get the source type from the supplied source path
* @param {string} sourcePath
* @returns {string} the source type
*/
public static getSourceType(sourcePath: string): string {
const fqnArray = sourcePath.split("/", 10);

const arrayLength = fqnArray.length;
const nodeSeqment = fqnArray[arrayLength - 1];
let parts = nodeSeqment.split("=", 2);
const nodeType = parts[0];

return nodeType;
}

}
18 changes: 9 additions & 9 deletions ngapp/src/app/dataservices/shared/vdb.service.ts
Expand Up @@ -30,10 +30,10 @@ import { Virtualization } from "@dataservices/shared/virtualization.model";
import { environment } from "@environments/environment";
import { Observable } from "rxjs/Rx";
import { Subscription } from "rxjs/Subscription";
import { SchemaNode } from "@connections/shared/schema-node.model";
import { Connection } from "@connections/shared/connection.model";
import { View } from "@dataservices/shared/view.model";
import { QueryResults } from "@dataservices/shared/query-results.model";
import { PathUtils } from "@dataservices/shared/path-utils";

@Injectable()
/**
Expand Down Expand Up @@ -253,19 +253,19 @@ export class VdbService extends ApiService {
* @param {string} vdbName the vdb name
* @param {string} modelName the model name
* @param {string[]} viewNames the view names (1:1 correspondence with schemaNodes)
* @param {SchemaNode[]} schemaNodes the source node for each view
* @param {string[]} sourceNodePaths the path for each source node
* @param {Connection[]} connections the array of active connections
* @returns {Observable<boolean>}
*/
public setVdbModelViews(vdbName: string, modelName: string, viewNames: string[],
schemaNodes: SchemaNode[], connections: Connection[]): Observable<boolean> {
sourceNodePaths: string[], connections: Connection[]): Observable<boolean> {

// construct source table paths and modelSource paths needed for all views
const modelSourcePaths = [];
const tablePaths = [];
for ( const schemaNode of schemaNodes ) {
for ( const sourceNodePath of sourceNodePaths ) {
// Get the connection for the source node
const connName = schemaNode.getConnectionName();
const connName = PathUtils.getConnectionName(sourceNodePath);
let nodeConn: Connection = null;
for ( const conn of connections ) {
if ( conn.getId().toLowerCase() === connName.toLowerCase() ) {
Expand All @@ -280,7 +280,7 @@ export class VdbService extends ApiService {

// Construct source table and modelSource paths for current node
const vdbPath = this.getKomodoUserWorkspacePath() + "/" + nodeConn.getId() + "/" + schemaVdbName;
const tablePath = vdbPath + "/" + schemaVdbModelName + "/" + schemaNode.getName();
const tablePath = vdbPath + "/" + schemaVdbModelName + "/" + PathUtils.getSourceName(sourceNodePath);
const modelSourcePath = vdbPath + "/" + schemaVdbModelName + "/vdb:sources/" + schemaVdbModelSourceName;

tablePaths.push(tablePath);
Expand Down Expand Up @@ -455,14 +455,14 @@ export class VdbService extends ApiService {
* @param {string} vdbName the vdb name
* @param {string} modelName the model name
* @param {string[]} viewNames the view names (1:1 correspondence with schemaNodes)
* @param {SchemaNode[]} schemaNodes the source node for each view
* @param {string[]} sourceNodePaths the path for each source node
* @param {Connection[]} connections the array of active connections
* @returns {Observable<boolean>}
*/
public compositeSetVdbModelViews(vdbName: string, modelName: string, viewNames: string[],
schemaNodes: SchemaNode[], connections: Connection[]): Observable<boolean> {
sourceNodePaths: string[], connections: Connection[]): Observable<boolean> {
return this.undeployVdb(vdbName)
.flatMap((res) => this.setVdbModelViews(vdbName, modelName, viewNames, schemaNodes, connections));
.flatMap((res) => this.setVdbModelViews(vdbName, modelName, viewNames, sourceNodePaths, connections));
}

}
67 changes: 34 additions & 33 deletions ngapp/src/app/dataservices/shared/view.model.ts
Expand Up @@ -17,6 +17,7 @@

import { SchemaNode } from "@connections/shared/schema-node.model";
import { VdbsConstants } from "@dataservices/shared/vdbs-constants";
import { PathUtils } from "@dataservices/shared/path-utils";

/**
* View model
Expand All @@ -26,7 +27,7 @@ export class View {
private description: string;
private isSelected = false;
private isEditable = false;
private sources: SchemaNode[] = [];
private sourcePaths: string[] = [];

/**
* @param {Object} json the JSON representation of a View
Expand Down Expand Up @@ -71,17 +72,17 @@ export class View {
}

/**
* @returns {SchemaNode[]} the view sources
* @returns {string[]} the view source paths
*/
public getSources(): SchemaNode[] {
return this.sources;
public getSourcePaths(): string[] {
return this.sourcePaths;
}

/**
* @param {SchemaNode[]} sources the view sources
* @param {string[]} sourcePaths the view source paths
*/
public setSources( sources: SchemaNode[] = [] ): void {
this.sources = sources;
public setSourcePaths( sourcePaths: string[] = [] ): void {
this.sourcePaths = sourcePaths;
}

/**
Expand All @@ -92,11 +93,11 @@ export class View {
// The view currently supports single source only
let sourceNodeName = "unknownSource";
let connectionName = "unknownConnection";
const source = this.getSources()[ 0 ];
if ( source !== null ) {
sourceNodeName = source.getName();
if ( source.getConnectionName() !== null ) {
connectionName = source.getConnectionName();
const sourcePath = this.getSourcePaths()[ 0 ];
if ( sourcePath !== null ) {
sourceNodeName = PathUtils.getSourceName(sourcePath);
if ( PathUtils.getConnectionName(sourcePath) !== null ) {
connectionName = PathUtils.getConnectionName(sourcePath);
}
}

Expand All @@ -105,53 +106,53 @@ export class View {
}

/**
* Duplicate sources are not added.
* Add source path to the list of source paths
*
* @param {SchemaNode} sourceToAdd the source being added
* @param {string} sourcePathToAdd the source path to add
*/
public addSource( sourceToAdd: SchemaNode ): void {
const index = this.sources.findIndex( ( source ) =>
source.getConnectionName() === sourceToAdd.getConnectionName() && source.getPath() === sourceToAdd.getPath()
public addSourcePath( sourcePathToAdd: string ): void {
const index = this.sourcePaths.findIndex( ( sPath ) =>
sPath === sourcePathToAdd
);

if ( index === -1 ) {
this.sources.push( sourceToAdd );
this.sourcePaths.push( sourcePathToAdd );
}
}

/**
* Duplicate sources are not added.
* Add source paths to the list of source paths.
*
* @param {SchemaNode[]} sourcesToAdd the sources being added
* @param {string[]} sourcePathsToAdd the source paths being added
*/
public addSources( sourcesToAdd: SchemaNode[] = [] ): void {
public addSourcePaths( sourcePathsToAdd: string[] = [] ): void {
const self = this;

sourcesToAdd.forEach( ( source ) => {
self.addSource( source );
sourcePathsToAdd.forEach( ( sourcePath ) => {
self.addSourcePath( sourcePath );
} );
}

/**
* @param {SchemaNode} sourceToRemove the schema node of the source being removed
* @param {string} sourcePathToRemove the source path to remove
*/
public removeSource( sourceToRemove: SchemaNode ): void {
const index = this.sources.findIndex( ( source ) =>
source.getConnectionName() === sourceToRemove.getConnectionName() && source.getPath() === sourceToRemove.getPath() );
public removeSourcePath( sourcePathToRemove: string ): void {
const index = this.sourcePaths.findIndex( ( sourcePath ) =>
sourcePath === sourcePathToRemove );

if ( index !== -1 ) {
this.sources.splice( index, 1 );
this.sourcePaths.splice( index, 1 );
}
}

/**
* @param {SchemaNode} sourcesToRemove the schema nodes of the sources being removed
* @param {SchemaNode} sourcePathsToRemove the source paths to remove
*/
public removeSources( sourcesToRemove: SchemaNode[] ): void {
public removeSourcePaths( sourcePathsToRemove: string[] ): void {
const self = this;

sourcesToRemove.forEach( ( source ) => {
self.removeSource( source );
sourcePathsToRemove.forEach( ( sourcePath ) => {
self.removeSourcePath( sourcePath );
} );
}

Expand All @@ -160,7 +161,7 @@ export class View {
* @returns {boolean} true if valid
*/
public get valid(): boolean {
return this.keng__id != null && this.sources.length > 0;
return this.keng__id != null && this.sourcePaths.length > 0;
}

/**
Expand Down
Expand Up @@ -19,6 +19,7 @@ import { Component, DoCheck, EventEmitter, Input, OnInit, Output, ViewEncapsulat
import { Action, ActionConfig, CardAction, CardConfig } from "patternfly-ng";
import { LoggerService } from "@core/logger.service";
import { View } from "@dataservices/shared/view.model";
import { PathUtils } from "@dataservices/shared/path-utils";

@Component({
encapsulation: ViewEncapsulation.None,
Expand Down Expand Up @@ -130,9 +131,9 @@ export class ViewCardComponent implements DoCheck, OnInit {
*/
public get sourceTableText(): string {
let sourceText = "[No Source Selected]";
const nodes = this.view.getSources();
if (nodes && nodes.length > 0) {
sourceText = "[" + nodes[0].getConnectionName() + "] " + nodes[0].getName();
const sourcePaths = this.view.getSourcePaths();
if (sourcePaths && sourcePaths.length > 0) {
sourceText = "[" + PathUtils.getConnectionName(sourcePaths[0]) + "] " + PathUtils.getSourceName(sourcePaths[0]);
}
return sourceText;
}
Expand Down
Expand Up @@ -27,6 +27,7 @@ import { CommandFactory } from "@dataservices/virtualization/view-editor/command
import { NotificationType } from "patternfly-ng";
import { Subscription } from "rxjs/Subscription";
import { Command } from "@dataservices/virtualization/view-editor/command/command";
import { PathUtils } from "@dataservices/shared/path-utils";

@Component({
encapsulation: ViewEncapsulation.None,
Expand Down Expand Up @@ -117,19 +118,28 @@ export class ViewCanvasComponent implements OnInit, OnDestroy {
public get hasViewSources(): boolean {
const view = this.editorService.getEditorView();
if (view) {
return view.getSources().length > 0;
return view.getSourcePaths().length > 0;
}
return false;
}

/**
* Get the sources for the view
* Get the source paths for the view
* @returns {SchemaNode[]} the view sources
*/
public get viewSources(): SchemaNode[] {
const view = this.editorService.getEditorView();
if (view !== null) {
return view.getSources();
const schemaNodes: SchemaNode[] = [];
const sourcePaths = view.getSourcePaths();
for(const sourcePath of sourcePaths) {
const sNode = new SchemaNode();
sNode.setName(PathUtils.getSourceName(sourcePath));
sNode.setType(PathUtils.getSourceType(sourcePath));
sNode.setConnectionName(PathUtils.getConnectionName(sourcePath));
schemaNodes.push(sNode);
}
return schemaNodes;
}
return [];
}
Expand Down
Expand Up @@ -155,7 +155,7 @@ export class ViewEditorComponent implements DoCheck, OnDestroy, OnInit {
// Show Dialog, act upon confirmation click
const modalRef = this.modalService.show(ConnectionTableDialogComponent, {initialState});
modalRef.content.okAction.take(1).subscribe((selectedNodes) => {
this.editorService.getEditorView().setSources( selectedNodes ); // TODO remove this line when service.updateViewState works for sources
// this.editorService.getEditorView().setSources( selectedNodes ); // TODO remove this line when service.updateViewState works for sources
const tempCmd = CommandFactory.createAddSourcesCommand( selectedNodes );

if ( tempCmd instanceof Command ) {
Expand Down

0 comments on commit 4f374e3

Please sign in to comment.