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

Commit

Permalink
Improvements to creation of dataservices
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrillin committed Dec 8, 2017
1 parent e2cef57 commit 6551bee
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 48 deletions.
2 changes: 1 addition & 1 deletion ngapp/src/app/app.component.spec.ts
@@ -1,8 +1,8 @@
import { async, TestBed } from "@angular/core/testing";
import { RouterTestingModule } from "@angular/router/testing";
import { CoreModule } from "@core/core.module";
import { AppComponent } from "./app.component";
import { ModalModule } from "ngx-bootstrap";
import { AppComponent } from "./app.component";

describe("AppComponent", () => {
beforeEach(async(() => {
Expand Down
10 changes: 5 additions & 5 deletions ngapp/src/app/core/about-dialog/about-dialog.component.html
Expand Up @@ -12,15 +12,15 @@ <h2><span i18n="@@about.loading"
</h2>
</div>
<div *ngIf="info" class="modal-body">
<h1>{{info.appTitle}}</h1>
<div class="product-versions-pf">{{info.appDescription}}</div>
<h1>{{ info.appTitle }}</h1>
<div class="product-versions-pf">{{ info.appDescription }}</div>
<div class="product-versions-pf">
<ul class="list-unstyled">
<li><strong>App Name:</strong> {{info.appName}}</li>
<li><strong>App Version:</strong> {{info.appVersion}}</li>
<li><strong>App Name:</strong> {{ info.appName }}</li>
<li><strong>App Version:</strong> {{ info.appVersion }}</li>
</ul>
</div>
<div class="trademark-pf">{{info.copyright}}</div>
<div class="trademark-pf">{{ info.copyright }}</div>
</div>
<div class="modal-footer">
<img [src]="logoImageSrc" alt="{{logoImageAlt}}" />
Expand Down
10 changes: 5 additions & 5 deletions ngapp/src/app/core/about-dialog/about-dialog.component.spec.ts
@@ -1,10 +1,10 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, TestBed } from "@angular/core/testing";

import { AboutDialogComponent } from './about-dialog.component';
import { MockAboutService } from "@core/about-dialog/mock-about.service";
import { About } from "@core/about-dialog/about.model";
import { MockAboutService } from "@core/about-dialog/mock-about.service";
import { AboutDialogComponent } from "./about-dialog.component";

describe('AboutDialogComponent', () => {
describe("AboutDialogComponent", () => {
let component: AboutDialogComponent;
let fixture: ComponentFixture<AboutDialogComponent>;

Expand All @@ -22,7 +22,7 @@ describe('AboutDialogComponent', () => {
fixture.detectChanges();
});

it('should be created', () => {
it("should be created", () => {
expect(component).toBeTruthy();
});
});
12 changes: 6 additions & 6 deletions ngapp/src/app/core/about-dialog/about-dialog.component.ts
Expand Up @@ -15,22 +15,22 @@
* limitations under the License.
*/

import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
import { About } from "@core/about-dialog/about.model";
import { Component, EventEmitter, Input, Output, ViewEncapsulation } from "@angular/core";
import { AboutEvent } from "@core/about-dialog/about-event";
import { About } from "@core/about-dialog/about.model";

@Component({
encapsulation: ViewEncapsulation.None,
selector: 'app-about-dialog',
templateUrl: './about-dialog.component.html',
styleUrls: ['./about-dialog.component.css']
selector: "app-about-dialog",
templateUrl: "./about-dialog.component.html",
styleUrls: ["./about-dialog.component.css"]
})
export class AboutDialogComponent {

/**
* The Event is emitted when modal is closed
*/
@Output( 'onCancel' ) public onCancel = new EventEmitter();
@Output( "onCancel" ) public onCancel = new EventEmitter();

/**
* The about information.
Expand Down
2 changes: 1 addition & 1 deletion ngapp/src/app/core/about-dialog/about-event.ts
Expand Up @@ -20,6 +20,6 @@ export class AboutEvent {
/**
* Flag indicating Modal is open
*/
close?: boolean;
public close?: boolean;

}
12 changes: 6 additions & 6 deletions ngapp/src/app/core/about-dialog/about.model.ts
Expand Up @@ -26,7 +26,7 @@ export class About {
// "App Description": "A tool that allows creating, editing and managing dynamic VDBs and their contents",
// "App Version": "0.0.4-SNAPSHOT",
// "Repository Workspace": "komodoLocalWorkspace",
// "Repository Configuration": "vfs:/content/ds-builder-archive.ear/vdb-builder.war/WEB-INF/lib/komodo-core-0.0.4-SNAPSHOT.jar/org/komodo/repository/local-repository-config.json",
// "Repository Configuration": "vfs:/dirLocation/komodo-core-0.0.4-SNAPSHOT.jar/org/komodo/repository/local-repository-config.json",
// "Repository Vdb Total": "1"
// }
// }
Expand All @@ -41,39 +41,39 @@ export class About {

public get appDescription(): string {
if ( this.Information && this.Information[ "App Description" ] != null ) {
return this.Information[ "App Description" ]
return this.Information[ "App Description" ];
}

return "App description not found";
}

public get appName(): string {
if ( this.Information && this.Information[ "App Name" ] ) {
return this.Information[ "App Name" ]
return this.Information[ "App Name" ];
}

return "App name not found";
}

public get appTitle(): string {
if ( this.Information && this.Information[ "App Title" ] ) {
return this.Information[ "App Title" ]
return this.Information[ "App Title" ];
}

return "App title not found";
}

public get appVersion(): string {
if ( this.Information && this.Information[ "App Version" ] ) {
return this.Information[ "App Version" ]
return this.Information[ "App Version" ];
}

return "App version not found";
}

public get copyright(): string {
if ( this.Information && this.Information[ "App Copyright" ] ) {
return this.Information[ "App Copyright" ]
return this.Information[ "App Copyright" ];
}

return "2017-2018 Red Hat, Inc.";
Expand Down
8 changes: 4 additions & 4 deletions ngapp/src/app/core/about-dialog/about.service.spec.ts
@@ -1,18 +1,18 @@
import { TestBed, inject } from '@angular/core/testing';
import { inject, TestBed } from "@angular/core/testing";
import { HttpModule } from "@angular/http";
import { AboutService } from '@core/about-dialog/about.service';
import { AboutService } from "@core/about-dialog/about.service";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";

describe('AboutService', () => {
describe("AboutService", () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ HttpModule ],
providers: [ AboutService, AppSettingsService, LoggerService ]
});
});

it('should be created',
it("should be created",
inject([ AboutService, AppSettingsService, LoggerService ],
( service: AboutService ) => {
expect( service ).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion ngapp/src/app/core/about-dialog/about.service.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { Injectable } from '@angular/core';
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { About } from "@core/about-dialog/about.model";
import { ApiService } from "@core/api.service";
Expand Down
6 changes: 3 additions & 3 deletions ngapp/src/app/core/about-dialog/mock-about.service.ts
@@ -1,10 +1,10 @@
import { Injectable } from "@angular/core";
import { Http } from "@angular/http";
import { Injectable } from '@angular/core';
import { AboutService } from "@core/about-dialog/about.service";
import { Observable } from "rxjs/Observable";
import { About } from "@core/about-dialog/about.model";
import { AboutService } from "@core/about-dialog/about.service";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { Observable } from "rxjs/Observable";

@Injectable()
export class MockAboutService extends AboutService {
Expand Down
4 changes: 2 additions & 2 deletions ngapp/src/app/core/core.module.ts
Expand Up @@ -19,14 +19,14 @@ import { CommonModule } from "@angular/common";
import { NgModule, Optional, SkipSelf } from "@angular/core";
import { HttpModule } from "@angular/http";
import { RouterModule } from "@angular/router";
import { AboutDialogComponent } from '@core/about-dialog/about-dialog.component';
import { AboutDialogComponent } from "@core/about-dialog/about-dialog.component";
import { AboutService } from "@core/about-dialog/about.service";
import { AppSettingsService } from "@core/app-settings.service";
import { BreadcrumbComponent } from "@core/breadcrumbs/breadcrumb/breadcrumb.component";
import { BreadcrumbsComponent } from "@core/breadcrumbs/breadcrumbs.component";
import { LoggerService } from "@core/logger.service";
import { NavHeaderComponent } from "@core/nav-header/nav-header.component";
import { VerticalNavComponent } from "@core/vertical-nav/vertical-nav.component";
import { AboutService } from "@core/about-dialog/about.service";
import { ModalModule } from "ngx-bootstrap/modal";
import { BsModalService } from "ngx-bootstrap/modal";

Expand Down
12 changes: 6 additions & 6 deletions ngapp/src/app/core/nav-header/nav-header.component.spec.ts
@@ -1,13 +1,13 @@
import { async, ComponentFixture, inject, TestBed } from "@angular/core/testing";
import { LoggerService } from "@core/logger.service";
import { NavHeaderComponent } from "@core/nav-header/nav-header.component";
import { AboutService } from "@core/about-dialog/about.service";
import { HttpModule } from "@angular/http";
import { AboutDialogComponent } from "@core/about-dialog/about-dialog.component";
import { AboutService } from "@core/about-dialog/about.service";
import { MockAboutService } from "@core/about-dialog/mock-about.service";
import { BsModalService } from "ngx-bootstrap/modal";
import { ModalModule } from "ngx-bootstrap";
import { HttpModule } from "@angular/http";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
import { NavHeaderComponent } from "@core/nav-header/nav-header.component";
import { ModalModule } from "ngx-bootstrap";
import { BsModalService } from "ngx-bootstrap/modal";

describe("NavHeaderComponent", () => {
let component: NavHeaderComponent;
Expand Down
8 changes: 4 additions & 4 deletions ngapp/src/app/core/nav-header/nav-header.component.ts
Expand Up @@ -16,12 +16,12 @@
*/

import { Component, TemplateRef } from "@angular/core";
import { LoggerService } from "@core/logger.service";
import { BsModalRef } from "ngx-bootstrap/modal/modal-options.class";
import { BsModalService } from "ngx-bootstrap/modal";
import { AboutEvent } from "@core/about-dialog/about-event";
import { AboutService } from "@core/about-dialog/about.service";
import { About } from "@core/about-dialog/about.model";
import { AboutService } from "@core/about-dialog/about.service";
import { LoggerService } from "@core/logger.service";
import { BsModalService } from "ngx-bootstrap/modal";
import { BsModalRef } from "ngx-bootstrap/modal/modal-options.class";

@Component({
moduleId: module.id,
Expand Down
Expand Up @@ -74,7 +74,11 @@ <h3 class="blank-slate-pf-main-action">Creation was successful</h3>
<div class="wizard-pf-complete blank-slate-pf" *ngIf="createComplete && !createSuccessful">
<div class="wizard-pf-failed-icon"><span class="glyphicon glyphicon-remove-circle"></span></div>
<h3 class="blank-slate-pf-main-action">Creation failed</h3>
<p class="blank-slate-pf-secondary-action">The dataservice creation failed. Correct any properties and retry.</p>
<div class="blank-slate-pf-secondary-action">
The dataservice creation failed!
<br>
<div style="font-style: italic;">{{ errorDetails }}</div>
</div>
</div>
</div>
</pfng-wizard-substep>
Expand Down
Expand Up @@ -23,8 +23,8 @@ import {
} from "@angular/core";

import { FormControl, FormGroup } from "@angular/forms";
import { Validators } from "@angular/forms";
import { AbstractControl } from "@angular/forms";
import { Validators } from "@angular/forms";
import { Router } from "@angular/router";
import { LoggerService } from "@core/logger.service";
import { ConnectionTableSelectorComponent } from "@dataservices/connection-table-selector/connection-table-selector.component";
Expand Down Expand Up @@ -81,6 +81,7 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
private router: Router;
private deploymentChangeSubscription: Subscription;
private sourceVdbUnderDeployment: string;
private errorDetailMessage: string;

constructor(router: Router, dataserviceService: DataserviceService,
notifierService: NotifierService, logger: LoggerService, vdbService: VdbService ) {
Expand Down Expand Up @@ -277,6 +278,7 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
},
(error) => {
self.logger.error("[AddDataserviceWizardComponent] Error: %o", error);
self.setErrorDetails(error);
self.createComplete = true;
self.createSuccessful = false;
self.step3bConfig.nextEnabled = false;
Expand Down Expand Up @@ -388,6 +390,13 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
this.setNavAway(this.step2Config.nextEnabled);
}

/**
* @returns {string} the error details message
*/
public get errorDetails(): string {
return this.errorDetailMessage;
}

// ----------------
// Private Methods
// ----------------
Expand Down Expand Up @@ -446,12 +455,29 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
},
(error) => {
self.logger.error("[AddDataserviceWizardComponent] Error: %o", error);
self.setErrorDetails(error);
self.createComplete = true;
self.createSuccessful = false;
self.step3bConfig.nextEnabled = false;
this.step3bConfig.previousEnabled = true;
}
);
}

/**
* Sets the error details for the response
* @param resp the rest call response
*/
private setErrorDetails( resp: any ): void {
// Get the error from the response json
this.errorDetailMessage = "";
if (resp) {
this.errorDetailMessage = resp.json().error;
}
// Error visible if message has content
if (this.errorDetailMessage.length === 0) {
this.errorDetailMessage = "Please check dataservice entries and retry";
}
}

}
47 changes: 46 additions & 1 deletion ngapp/src/app/dataservices/shared/vdb.service.ts
Expand Up @@ -64,6 +64,33 @@ export class VdbService extends ApiService {
.catch( ( error ) => this.handleError( error ) );
}

/**
* Determine if the workspace has a vdb with the supplied name
* @param {string} vdbName the name of the VDB
* @returns {Observable<Vdb[]>}
*/
public hasWorkspaceVdb(vdbName: string): Observable<boolean> {
return this.http
.get(environment.komodoWorkspaceUrl + VdbsConstants.vdbsRootPath, this.getAuthRequestOptions())
.map((response) => {
const vdbs = response.json();
// Determine if the vdbName exists in the list
let vdbFound = false;
for (const vdb of vdbs) {
const name = vdb.keng__id;
if (name === vdbName) {
vdbFound = true;
break;
}
}
if (vdbFound) {
return response.ok;
}
return !response.ok;
})
.catch( ( error ) => this.handleError( error ) );
}

/**
* Get the vdbs from the komodo rest interface
* @returns {Observable<Vdb[]>}
Expand Down Expand Up @@ -312,10 +339,28 @@ export class VdbService extends ApiService {
vdbModelSource.setTranslatorName(connection.getDriverName());

// Chain the individual calls together in series to build the Vdb and deploy it
return this.createVdb(vdb)
return this.deleteVdbIfFound(vdb.getId())
.flatMap((res) => this.createVdb(vdb))
.flatMap((res) => this.createVdbModel(vdb.getId(), vdbModel))
.flatMap((res) => this.createVdbModelSource(vdb.getId(), vdbModel.getId(), vdbModelSource))
.flatMap((res) => this.deployVdb(vdb.getId()));
}

/**
* Deletes the workspace VDB if found. Checks the workspace first, before attempting the delete.
* If the VDB is not found the delete attempt is skipped.
* @param {string} vdbName the name of the vdb
* @returns {Observable<boolean>}
*/
public deleteVdbIfFound(vdbName: string): Observable<boolean> {
return this.hasWorkspaceVdb(vdbName)
.switchMap( (resp) => {
if (resp === true) {
return this.deleteVdb(vdbName);
} else {
return Observable.of(true);
}
});
}

}

0 comments on commit 6551bee

Please sign in to comment.