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

Commit

Permalink
Merge pull request #83 from phantomjinx/master
Browse files Browse the repository at this point in the history
TeiidTools-307
  • Loading branch information
mdrillin committed Jan 24, 2018
2 parents da47f69 + 1bb9749 commit e69d0ac
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 34 deletions.
6 changes: 5 additions & 1 deletion ngapp/README.md
Expand Up @@ -2,9 +2,13 @@

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.3.2.

## Running with [Nodejs](https://nodejs.org)

Execute `npm start` to serve the Angular app using nodejs. Navigate to `http://localhost:8080`. This command is meant for production and the files in the `dist` directory will have to be recompiled for code changes to be displayed.

## Development server

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
Execute `npm start -- -d` for a development server. Navigate to `http://localhost:8080/`. The app will automatically reload if you change any of the source files.

## Code scaffolding

Expand Down
3 changes: 2 additions & 1 deletion ngapp/package.json
Expand Up @@ -4,8 +4,8 @@
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 8080 --disable-host-check",
"build": "ng build",
"start": "./start.sh",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
Expand All @@ -23,6 +23,7 @@
"@angular/router": "^4.4.6",
"@swimlane/ngx-datatable": "^11.1.5",
"core-js": "^2.4.1",
"express": "^4.16.2",
"ng2-codemirror": "^1.1.3",
"ngx-bootstrap": "^1.9.3",
"patternfly": "^3.37.1",
Expand Down
15 changes: 15 additions & 0 deletions ngapp/server.js
@@ -0,0 +1,15 @@
var express = require("express");
var bodyParser = require("body-parser");

var app = express();
app.use(bodyParser.json());

// Create link to Angular build directory
var distDir = __dirname + "/dist/";
app.use(express.static(distDir));

// Initialize the app.
var server = app.listen(process.env.PORT || 8080, function () {
var port = server.address().port;
console.log("App now running on port", port);
});
18 changes: 12 additions & 6 deletions ngapp/src/app/core/api.service.ts
Expand Up @@ -29,20 +29,26 @@ export abstract class ApiService {
protected appSettings: AppSettingsService;
protected logger: LoggerService;

constructor( appSettings: AppSettingsService, logger: LoggerService ) {
constructor( appSettings: AppSettingsService, logger: LoggerService) {
this.appSettings = appSettings;
this.logger = logger;
}

/**
* Get the Auth RequestOptions
* TODO: User and password are currently hardcoded to the DSB kit server credentials (dsbUser | 1demo-user1)
* @returns the base url of the application
*/
protected getBaseUrl(): string {
return window.location.protocol + '://' + window.location.hostname;
}

/**
* Get the Auth RequestOptions if any
* Note: Since usage of the oauth-proxy no additional auth request options are necessary
*
* @returns {RequestOptions}
*/
protected getAuthRequestOptions(): RequestOptions {
const userPasswordStr = this.appSettings.getKomodoUser() + ":" + this.appSettings.getKomodoUserPassword();
const headers = new Headers({ "Authorization": "Basic " + btoa(userPasswordStr) });
return new RequestOptions({ headers });
return this.appSettings.getAuthRequestOptions();
}

/**
Expand Down
90 changes: 72 additions & 18 deletions ngapp/src/app/core/app-settings.service.ts
Expand Up @@ -16,7 +16,12 @@
*/

import { Injectable } from "@angular/core";
import { Http, Headers, RequestOptions, Response } from "@angular/http";
import { LoggerService } from "@core/logger.service";
import { LayoutType } from "@shared/layout-type.enum";
import { Observable } from "rxjs/Observable";
import { ErrorObservable } from "rxjs/observable/ErrorObservable";
import { environment } from "@environments/environment";

@Injectable()
export class AppSettingsService {
Expand All @@ -30,20 +35,24 @@ export class AppSettingsService {
public readonly GIT_REPO_PATH_KEY = "repo-path-property";
public readonly GIT_REPO_FILE_PATH_KEY = "file-path-property";

private readonly komodoRoot = "tko:komodo/tko:workspace";

// TODO: temporary location for user and password
private readonly komodoUser = "dsbUser";
private readonly komodoUserPassword = "1demo-user1";

// Map to maintain the target git repository properties
private readonly gitRepoProperties: Map<string, string>;

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

// page layouts
private svcPageLayout: LayoutType = LayoutType.CARD;
private connPageLayout: LayoutType = LayoutType.CARD;

constructor() {
private http: Http;
private logger: LoggerService;

private userProfile: Object;

constructor(http: Http, logger: LoggerService) {
this.http = http;
this.logger = logger;

// TODO: The git repository properties will be picked up based on the Openshift install location
this.gitRepoProperties = new Map<string, string>();
this.gitRepoProperties.set(this.GIT_REPO_PATH_KEY, "https://github.com/GIT_USER/GIT_REPO");
Expand All @@ -52,30 +61,75 @@ export class AppSettingsService {
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");

//
// Do a call to fetch the user profile on init of service.
// The fetchProfile method returns an observable
// which we subscribe to and on completion assigns the variable
// values accordingly
//
this.fetchUserProfile().subscribe(
(profile) => {
this.userProfile = profile;
},
(error) => {
this.logger.error( "[fetchUserProfile] Error: %o", error );
});
}

/*
* Get the komodo workspace path for the current user
* @returns {string} the komodo workspace path
private handleError(error: Response): ErrorObservable {
this.logger.error( this.constructor.name + "::handleError" );
return Observable.throw(error);
}

private fetchUserProfile(): Observable<Object> {
return this.http.get(AppSettingsService.userProfileUrl, this.getAuthRequestOptions())
.map((response) => {
const userInfo = response.json();
return userInfo.Information;
})
.catch((error) => this.handleError(error));
}

/**
* Get the Auth RequestOptions if any
* Note: Since usage of the oauth-proxy no additional auth request options are necessary
*
* @returns {RequestOptions}
*/
public getKomodoUserWorkspacePath( ): string {
return this.komodoRoot + "/" + this.komodoUser;
public getAuthRequestOptions(): RequestOptions {
const headers = new Headers({});
return new RequestOptions({ headers });
}

/*
* Get the logged in komodo user
* @returns {string} the komodo user
*/
public getKomodoUser( ): string {
return this.komodoUser;
public getKomodoUser(): string {
if (! this.userProfile)
throw new Error('Failed to retrieve the user profile so cannot provide a user name');

let komodoUser = this.userProfile['User Name'];
if (! komodoUser)
throw new Error('Failed to retrieve the user name from the user profile');

return komodoUser;
}

/*
* Get the logged in komodo user password
* @returns {string} the komodo user password
* Get the komodo workspace path for the current user
* @returns {string} the komodo workspace path
*/
public getKomodoUserPassword( ): string {
return this.komodoUserPassword;
public getKomodoUserWorkspacePath(): string {
if (! this.userProfile)
throw new Error('Failed to retrieve the user profile so cannot provide a workspace path');

let workspace = this.userProfile['Workspace'];
if (! workspace)
throw new Error('Failed to retrieve the workspace path from the user profile');

return workspace;
}

/*
Expand Down
16 changes: 12 additions & 4 deletions ngapp/src/environments/environment.prod.ts
Expand Up @@ -17,23 +17,31 @@

import { DataservicesConstants } from "@dataservices/shared/dataservices-constants";

export const komodoEngine = "vdb-builder";

export const komodoRestVersion = "v1";

export const environment = {

production: true,

komodoEngine: komodoEngine,

komodoRestVersion: komodoRestVersion,

// the home page path
homePagePath: DataservicesConstants.dataservicesRootPath,

// REST URL - Komodo import export url
komodoImportExportUrl: "https://localhost:8443/vdb-builder/v1/importexport",
komodoImportExportUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/importexport",

// REST URL - Komodo workspace
komodoWorkspaceUrl: "https://localhost:8443/vdb-builder/v1/workspace",
komodoWorkspaceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/workspace",

// REST URL - Komodo teiid server
komodoTeiidUrl: "https://localhost:8443/vdb-builder/v1/teiid",
komodoTeiidUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/teiid",

// REST URL - Komodo service
komodoServiceUrl: "https://localhost:8443/vdb-builder/v1/service",
komodoServiceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/service"

};
16 changes: 12 additions & 4 deletions ngapp/src/environments/environment.ts
Expand Up @@ -21,22 +21,30 @@ import { DataservicesConstants } from "@dataservices/shared/dataservices-constan
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const komodoEngine = "vdb-builder";

export const komodoRestVersion = "v1";

export const environment = {
production: false,

komodoEngine: komodoEngine,

komodoRestVersion: komodoRestVersion,

// the home page path
homePagePath: DataservicesConstants.dataservicesRootPath,

// REST URL - Komodo import export url
komodoImportExportUrl: "https://localhost:8443/vdb-builder/v1/importexport",
komodoImportExportUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/importexport",

// REST URL - Komodo workspace
komodoWorkspaceUrl: "https://localhost:8443/vdb-builder/v1/workspace",
komodoWorkspaceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/workspace",

// REST URL - Komodo teiid server
komodoTeiidUrl: "https://localhost:8443/vdb-builder/v1/teiid",
komodoTeiidUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/teiid",

// REST URL - Komodo service
komodoServiceUrl: "https://localhost:8443/vdb-builder/v1/service",
komodoServiceUrl: "/" + komodoEngine + "/" + komodoRestVersion + "/service"

};
32 changes: 32 additions & 0 deletions ngapp/start.sh
@@ -0,0 +1,32 @@
#!/bin/bash

#################
#
# Show help and exit
#
#################
function show_help {
echo "Usage: $0 [-d] [-h]"
echo "-d: run in development mode"
echo ""
echo "To passthrough additional arguments, enter '--' followed by the extra arguments"
exit 1
}

#
# Determine the command line options
#
while getopts ":d" opt;
do
case $opt in
d) DEV=1 ;;
h) show_help ;;
esac
done
shift "$(expr $OPTIND - 1)"

if [ "${DEV}" == "1" ]; then
ng serve --host 0.0.0.0 --port 8080 --disable-host-check
else
ng build && node ./server.js
fi

0 comments on commit e69d0ac

Please sign in to comment.