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

Commit

Permalink
Issue 27 Implement Validators for name and jndi checks
Browse files Browse the repository at this point in the history
- New dataservice wizard now is validation the dataservice name using the Komodo REST service
- Made the help icon in the nav-header a bit larger
- Changed home page to Dataservice Summary
  • Loading branch information
elvisisking committed Dec 8, 2017
1 parent 50a0903 commit 312c0b5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ngapp/src/app/core/nav-header/nav-header.component.html
Expand Up @@ -6,7 +6,7 @@
<ul class="nav navbar-nav navbar-right navbar-iconic">
<li class="dropdown">
<a class="dropdown-toggle nav-item-iconic" (click)="openAbout(aboutTemplate)">
<span title="About" class="fa pficon-help"></span>
<span title="About" class="fa pficon-help navbar-help-icon"></span>
<ng-template #aboutTemplate>
<app-about-dialog [(info)]="aboutInfo" (onCancel)="closeAbout($event)">
</app-about-dialog>
Expand Down
4 changes: 4 additions & 0 deletions ngapp/src/app/core/nav-header/nav-header.component.less
Expand Up @@ -7,6 +7,10 @@
height: @navbar-height - 3;
}

.navbar-help-icon {
font-size: 1.5em;
}

.navbar .navbar-brand {
padding: 0;
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ <h3><i>{{ step2InstructionMessage }}</i></h3>
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-5">
<input class="form-control" formControlName="name" title="">
<div class="help-block" *ngIf="!nameValid">{{ getBasicPropertyErrorMessage("name") }}</div>
<div class="help-block" *ngIf="!nameValid">{{ nameValidationError }}</div>
</div>
</div>
<div [ngClass]="'form-group'">
Expand Down
Expand Up @@ -79,6 +79,7 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
private deploymentChangeSubscription: Subscription;
private sourceVdbUnderDeployment: string;
private errorDetailMessage: string;
public nameValidationError: string = "";

constructor(router: Router, dataserviceService: DataserviceService,
notifierService: NotifierService, logger: LoggerService, vdbService: VdbService ) {
Expand Down Expand Up @@ -171,11 +172,30 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
return this.tableSelectorLoadingState === LoadingState.LOADED_INVALID;
}

public handleNameChanged( input: AbstractControl ): void {
const self = this;

this.dataserviceService.isValidName( input.value ).subscribe(
( errorMsg ) => {
if ( errorMsg ) {
// only update if error has changed
if ( errorMsg != self.nameValidationError ) {
self.nameValidationError = errorMsg;
}
} else { // name is valid
self.nameValidationError = "";
}
},
( error ) => {
self.logger.error( "[handleNameChanged] Error: %o", error );
} );
}

/*
* Return the name valid state
*/
public get nameValid(): boolean {
return this.basicPropertyForm.controls["name"].valid;
return this.nameValidationError == null || this.nameValidationError.length == 0;
}

/*
Expand Down Expand Up @@ -382,7 +402,7 @@ export class AddDataserviceWizardComponent implements OnInit, OnDestroy {
*/
private createBasicPropertyForm(): void {
this.basicPropertyForm = new FormGroup({
name: new FormControl("", Validators.required),
name: new FormControl( "", this.handleNameChanged.bind( this ) ),
description: new FormControl("")
});
// Responds to basic property changes - updates the page status
Expand Down
32 changes: 31 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} from "@angular/http";
import { ApiService } from "@core/api.service";
import { AppSettingsService } from "@core/app-settings.service";
import { LoggerService } from "@core/logger.service";
Expand All @@ -39,6 +39,10 @@ import { Subscription } from "rxjs/Subscription";
@Injectable()
export class DataserviceService extends ApiService {

private static readonly nameValidationUrl = environment.komodoWorkspaceUrl
+ DataservicesConstants.dataservicesRootPath
+ "/nameValidation/";

// Observable dataservice state changes
// Using replay status with cache of 1, so subscribers dont get an initial value on subscription
public dataserviceStateChange: Subject< Map<string, DeploymentState> > = new ReplaySubject< Map<string, DeploymentState> >(1);
Expand Down Expand Up @@ -78,6 +82,32 @@ export class DataserviceService extends ApiService {
return this.selectedDataservice;
}

/**
* Validates the specified data service name. If the name contains valid characters and the name is unique, the
* service returns 'null'. Otherwise, a 'string' containing an error message is returned.
*
* @param {string} dataserviceName
* @returns {Observable<String>}
*/
public isValidName( name: string ): Observable< string > {
if ( !name || name.length === 0 ) {
return Observable.of( "Dataservice name cannot be empty" );
}

const url = DataserviceService.nameValidationUrl + encodeURIComponent( name );

return this.http.get( url, this.getAuthRequestOptions() )
.map( ( response ) => {
if ( response.ok ) {
if ( response.text() ) {
return response.text();
}

return "";
} } )
.catch( ( error ) => this.handleError( error ) );
}

/**
* Get the dataservices from the komodo rest interface
* @returns {Observable<Dataservice[]>}
Expand Down
Expand Up @@ -25,4 +25,5 @@ export class DataservicesConstants {

public static readonly testDataserviceRoute = DataservicesConstants.dataservicesRootRoute + "/test-dataservice";
public static readonly testDataservicePath = DataservicesConstants.dataservicesRootPath + "/test-dataservice";

}
4 changes: 2 additions & 2 deletions ngapp/src/environments/environment.prod.ts
Expand Up @@ -15,14 +15,14 @@
* limitations under the License.
*/

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

export const environment = {

production: true,

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

// REST URL - Komodo import export url
komodoImportExportUrl: "https://localhost:8443/vdb-builder/v1/importexport",
Expand Down
4 changes: 2 additions & 2 deletions ngapp/src/environments/environment.ts
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ConnectionsConstants } from "@connections/shared/connections-constants";
import { DataservicesConstants } from "@dataservices/shared/dataservices-constants";

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
Expand All @@ -25,7 +25,7 @@ export const environment = {
production: false,

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

// REST URL - Komodo import export url
komodoImportExportUrl: "https://localhost:8443/vdb-builder/v1/importexport",
Expand Down

0 comments on commit 312c0b5

Please sign in to comment.