diff options
Diffstat (limited to 'dcaedftool/src/app')
21 files changed, 1902 insertions, 0 deletions
diff --git a/dcaedftool/src/app/app.component.spec.ts b/dcaedftool/src/app/app.component.spec.ts new file mode 100644 index 0000000..8c62c7e --- /dev/null +++ b/dcaedftool/src/app/app.component.spec.ts @@ -0,0 +1,91 @@ +// org.onap.dcae +// ============LICENSE_START==================================================== +// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +// ============================================================================= +// 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. +// ============LICENSE_END====================================================== +// +// ECOMP is a trademark and service mark of AT&T Intellectual Property. +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import {HttpModule} from '@angular/http'; // for future +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // for future +import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; // for future +import { MaterialModule } from '@angular/material'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { RouterModule, Routes } from '@angular/router'; +import { APP_BASE_HREF } from '@angular/common'; + + + +import { AppComponent } from './app.component'; +import { DFSchemaComponent } from './df-schema.component'; +import { DFJSONInputComponent } from './df-jsoninput.component'; +import { DFControlComponent } from './df-control.component'; +import {ValidateMetaSchemaService} from './validate-metaschema.service'; +import {ValidateJSONService} from './validate-json.service'; +import {MetaSchemaService} from './metaschema.service'; + +const dfroutes: Routes = [ + { path: '', redirectTo: 'schemaval', pathMatch: 'full' }, + { path: 'schemaval', component: DFSchemaComponent }, + { path: 'jsoninput', component: DFJSONInputComponent }, + +]; + +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +describe('AppComponent', function () { + let de: DebugElement; + let comp: AppComponent; + let fixture: ComponentFixture<AppComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ BrowserModule, + BrowserAnimationsModule, + FormsModule, + HttpModule, + ReactiveFormsModule, + FlexLayoutModule, + MaterialModule, + RouterModule.forRoot(dfroutes), + ], + providers: [{provide: APP_BASE_HREF, useValue: '/'}], + declarations: [ AppComponent, + DFSchemaComponent, + DFJSONInputComponent, + DFControlComponent, + + ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AppComponent); + comp = fixture.componentInstance; + //de = fixture.debugElement.query(By.css('h1')); + }); + + it('should create component', () => expect(comp).toBeDefined() ); + +/* it('should have expected <h1> text', () => { + fixture.detectChanges(); + const h1 = de.nativeElement; + expect(h1.innerText).toMatch(/angular/i, + '<h1> should say something about "Angular"'); + }); */ +}); diff --git a/dcaedftool/src/app/app.component.ts b/dcaedftool/src/app/app.component.ts new file mode 100644 index 0000000..76f21ff --- /dev/null +++ b/dcaedftool/src/app/app.component.ts @@ -0,0 +1,25 @@ +// org.onap.dcae +// ============LICENSE_START==================================================== +// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +// ============================================================================= +// 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. +// ============LICENSE_END====================================================== +// +// ECOMP is a trademark and service mark of AT&T Intellectual Property. +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-df', + template: '<app-df-control></app-df-control>' +}) +export class AppComponent { name = 'Data Format Processing'; } diff --git a/dcaedftool/src/app/app.module.ts b/dcaedftool/src/app/app.module.ts new file mode 100644 index 0000000..7f91574 --- /dev/null +++ b/dcaedftool/src/app/app.module.ts @@ -0,0 +1,67 @@ +// org.onap.dcae +// ============LICENSE_START==================================================== +// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +// ============================================================================= +// 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. +// ============LICENSE_END====================================================== +// +// ECOMP is a trademark and service mark of AT&T Intellectual Property. +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import {HttpModule} from '@angular/http'; // for future +import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // for future +import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; // for future +import { MaterialModule } from '@angular/material'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { RouterModule, Routes } from '@angular/router'; + +import 'ajv'; +import 'hammerjs'; + +import { AppComponent } from './app.component'; +import { DFSchemaComponent } from './df-schema.component'; +import { DFJSONInputComponent } from './df-jsoninput.component'; +import { DFControlComponent } from './df-control.component'; +import {ValidateMetaSchemaService} from './validate-metaschema.service'; +import {ValidateJSONService} from './validate-json.service'; +import {MetaSchemaService} from './metaschema.service'; + +const dfroutes: Routes = [ + { path: '', redirectTo: 'schemaval', pathMatch: 'full' }, + { path: 'schemaval', component: DFSchemaComponent }, + { path: 'jsoninput', component: DFJSONInputComponent }, + +]; +@NgModule({ + imports: [ BrowserModule, + BrowserAnimationsModule, + FormsModule, + HttpModule, + ReactiveFormsModule, + FlexLayoutModule, + RouterModule.forRoot(dfroutes), + MaterialModule, + ], + declarations: [ AppComponent, + DFSchemaComponent, + DFJSONInputComponent, + DFControlComponent + ], + providers: [ + ValidateMetaSchemaService, + ValidateJSONService, + MetaSchemaService +], + bootstrap: [ AppComponent ] +}) +export class AppModule { } diff --git a/dcaedftool/src/app/df-control.component.css b/dcaedftool/src/app/df-control.component.css new file mode 100644 index 0000000..4cc85d1 --- /dev/null +++ b/dcaedftool/src/app/df-control.component.css @@ -0,0 +1,85 @@ +/*
+ org.onap.dcae
+ ============LICENSE_START====================================================
+ Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ =============================================================================
+ 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.
+ ============LICENSE_END======================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+*/
+md-sidenav-container {
+
+}
+
+md-card {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 150%;
+ text-align:center;
+ margin-left: 100px;
+ padding-left: 10px;
+ background-color: #f2f2f2;
+}
+.app-title {
+ color: white;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 150%;
+ background-color: #3f51b5;
+}
+.app-menu-button {
+ color: white;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 150%;
+ background-color: #3f51b5;
+}
+.schema-version {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 50%;
+ background-color: #f2f2f2;
+}
+.nav-title {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 150%;
+ padding-left: 16px;
+ margin-left: 100px;
+ background-color: #f2f2f2;
+}
+.active-nav {
+ color: #3f51b5;
+ min-width: 520px;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ padding-left: 16px;
+ min-width: 520px;
+ background-color: #f2f2f2;
+}
+.nav-button {
+ min-width: 520px;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ padding-left: 16px;
+ background-color: #f2f2f2;
+}
+
+md-sidenav {
+ background-color: #f2f2f2;
+ padding: 10px;
+ min-width: 100px;
+}
+md-toolbar {
+ padding: 6px;
+
+}
diff --git a/dcaedftool/src/app/df-control.component.html b/dcaedftool/src/app/df-control.component.html new file mode 100644 index 0000000..37e97d8 --- /dev/null +++ b/dcaedftool/src/app/df-control.component.html @@ -0,0 +1,66 @@ +<!--
+ org.onap.dcae
+ ============LICENSE_START====================================================
+ Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ =============================================================================
+ 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.
+ ============LICENSE_END======================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+-->
+
+ <md-sidenav-container>
+
+ <!-- over doesn't seem to work correctly? -->
+ <md-sidenav #sidenav mode="side" color="primary">
+ <md-list class="select-button">
+ <md-list-item>
+ <button md-raised-button class="nav-button" [routerLink] = " ['schemaval']" [routerLinkActive] = "'active-nav'" >
+ VERIFY DATA FORMAT SCHEMA
+ </button>
+ </md-list-item>
+ <md-list-item>
+ <button md-raised-button class="nav-button" [routerLink] = " ['jsoninput']" [routerLinkActive] = "'active-nav'">
+ VERIFY JSON DATA FORMAT SCHEMA AND TEST JSON INPUT
+ </button>
+ </md-list-item>
+ <md-list-item>
+ <button md-raised-button class="nav-button">
+ GENERATE JSON DATA FORMAT SCHEMA FROM JSON INPUT
+ </button>
+ </md-list-item>
+ <md-list-item>
+ <button md-raised-button class="nav-button">
+ VERIFY DELIMITED DATA FORMAT SCHEMA AND TEST INPUT
+ </button>
+ </md-list-item>
+ <md-list-item>
+ <button md-raised-button class="nav-button">
+ VERIFY XML DATA FORMAT SCHEMA AND TEST INPUT
+ </button>
+ </md-list-item>
+ </md-list>
+
+
+
+ </md-sidenav>
+
+ <md-toolbar color="primary">
+
+ <button md-button class="app-menu-button" (click)="sidenav.toggle() ">
+ <i class="material-icons">menu</i>
+ </button>
+ <span class="app-title">DCAE Data Format Schema Tool</span>
+ </md-toolbar>
+ <router-outlet></router-outlet>
+</md-sidenav-container>
diff --git a/dcaedftool/src/app/df-control.component.spec.ts b/dcaedftool/src/app/df-control.component.spec.ts new file mode 100644 index 0000000..3cdf314 --- /dev/null +++ b/dcaedftool/src/app/df-control.component.spec.ts @@ -0,0 +1,86 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+import {HttpModule} from '@angular/http'; // for future
+import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // for future
+import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; // for future
+import { MaterialModule } from '@angular/material';
+import { FlexLayoutModule } from '@angular/flex-layout';
+import { APP_BASE_HREF } from '@angular/common';
+
+import {ValidateMetaSchemaService} from './validate-metaschema.service';
+import {ValidateJSONService} from './validate-json.service';
+import {MetaSchemaService} from './metaschema.service';
+import {DFJSONInputComponent} from './df-jsoninput.component';
+import {DFSchemaComponent} from './df-schema.component';
+import {DFControlComponent} from './df-control.component';
+import { RouterModule, Routes } from '@angular/router';
+
+
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { DebugElement } from '@angular/core';
+
+describe('DFControlComponent Tests', function () {
+ let de: DebugElement;
+ let comp: DFControlComponent;
+ let fixture: ComponentFixture<DFControlComponent>;
+ const dfroutes: Routes = [
+ { path: '', redirectTo: 'schemaval', pathMatch: 'full' },
+ { path: 'schemaval', component: DFSchemaComponent },
+ { path: 'jsoninput', component: DFJSONInputComponent },
+
+ ];
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ imports: [ BrowserModule,
+ BrowserAnimationsModule,
+ FormsModule,
+ HttpModule,
+ ReactiveFormsModule,
+ FlexLayoutModule,
+ RouterModule.forRoot(dfroutes),
+ MaterialModule,
+
+ ],
+ providers: [{provide: APP_BASE_HREF, useValue: '/'},
+ ValidateMetaSchemaService,
+ ValidateJSONService,
+ MetaSchemaService
+ ],
+ declarations: [
+ DFJSONInputComponent,
+ DFControlComponent,
+ DFSchemaComponent,
+
+ ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(DFControlComponent);
+ comp = fixture.componentInstance;
+ //de = fixture.debugElement.query(By.css('h1'));
+ });
+
+ it('should create component', () => expect(comp).toBeDefined() );
+
+});
diff --git a/dcaedftool/src/app/df-control.component.ts b/dcaedftool/src/app/df-control.component.ts new file mode 100644 index 0000000..d8d2686 --- /dev/null +++ b/dcaedftool/src/app/df-control.component.ts @@ -0,0 +1,29 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Component } from '@angular/core';
+import { MdToolbarModule, MdToolbarRow, MdSidenav, MdButton, MdList, MdListItem} from '@angular/material';
+
+@Component({
+ selector: 'app-df-control',
+ templateUrl: './df-control.component.html',
+ styleUrls: [ './df-control.component.css']
+})
+export class DFControlComponent {
+
+}
diff --git a/dcaedftool/src/app/df-jsoninput.component.css b/dcaedftool/src/app/df-jsoninput.component.css new file mode 100644 index 0000000..94050bd --- /dev/null +++ b/dcaedftool/src/app/df-jsoninput.component.css @@ -0,0 +1,179 @@ +/*
+ org.onap.dcae
+ ============LICENSE_START====================================================
+ Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ =============================================================================
+ 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.
+ ============LICENSE_END======================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+*/
+.scenario-toolbar {
+ color: #f2f2f2;
+ min-width: 520px;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ /*padding-left: 16px;
+ min-width: 520px; */
+ text-align: center;
+ background-color: #f2f2f2
+}
+.scenario-title {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 120%;
+ text-align: center;
+ background-color: #f2f2f2
+}
+.metaschema-title {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 50%;
+ font-weight: bold;
+ text-align: left;
+ background-color: #f2f2f2
+}
+.metaschema-card {
+ margin: 0px;
+}
+
+.metaschema-text {
+ padding: 0px;
+ margin: 0px;
+ width: 100%;
+ font-size: 50%;
+ background-color: #f2f2f2;
+ white-space: pre-wrap;
+}
+.schema-input-container {
+ margin: 5px;
+}
+.schemainput-title {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 50%;
+ font-weight: bold;
+ text-align: left;
+ margin: 5px;
+ background-color: #f2f2f2
+}
+.schema-input-textarea {
+ padding: 10px;
+ width: 100%;
+ height: 600px;
+ font-size: 100%;
+ background-color: #f2f2f2
+}
+
+.schema-input {
+ padding: 30px;
+ width: 95%;
+/* height: 400px; */
+ padding-left: 20px;
+ padding-right: 20px;
+ padding-top: 20px;
+ background-color: #f2f2f2
+}
+.schema-msgs {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ background-color: #ffffff
+}
+.schema-error {
+ color: black;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ background-color: #ffffff
+}
+
+.json-input-container {
+ margin: 5px;
+}
+.json-container {
+ margin: 5px;
+}
+.jsoninput-title {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 50%;
+ font-weight: bold;
+ text-align: left;
+ margin: 5px;
+ background-color: #f2f2f2
+}
+.json-input-textarea {
+ padding: 10px;
+ width: 100%;
+ height: 600px;
+ font-size: 100%;
+ background-color: #f2f2f2
+}
+.json-input {
+ padding: 30px;
+ width: 95%;
+/* height: 400px; */
+ padding-left: 20px;
+ padding-right: 20px;
+ padding-top: 20px;
+ background-color: #f2f2f2
+}
+.json-msgs {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ background-color: #ffffff
+}
+.json-error {
+ color: black;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ background-color: #ffffff
+}
+.schema-version {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 75%;
+ text-align: center;
+ padding: 10px;
+ background-color: #f2f2f2
+}
+.schema-version md-content {
+ background: #f2f2f2;
+ color: #3f51bf;
+}
+
+.schema-version md-option:hover {
+ background: #f2f2f2;
+ color: #3f51bf;
+}
+.meta-version-button {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 120%;
+ text-align: center;
+ text-indent: 200px;
+ padding: 30px;
+ background-color: #f2f2f2
+}
+.meta-display-button {
+ color: #3f51bf;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size:80%;
+ font-weight: bold;
+ padding-bottom: 2px;
+ text-align: center ;
+ white-space: wrap;
+ overflow:hidden;
+ background-color: #f2f2f2
+}
diff --git a/dcaedftool/src/app/df-jsoninput.component.html b/dcaedftool/src/app/df-jsoninput.component.html new file mode 100644 index 0000000..df8e04c --- /dev/null +++ b/dcaedftool/src/app/df-jsoninput.component.html @@ -0,0 +1,94 @@ +<!--
+ org.onap.dcae
+ ============LICENSE_START====================================================
+ Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ =============================================================================
+ 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.
+ ============LICENSE_END======================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+-->
+<md-toolbar class="scenario-toolbar">
+ <div fxLayout="row" fxFill>
+ <div fxLayout="row" fxFlex fxFill >
+ <div class="one" fxFlex="15" fxHide="true" fxLayoutAlign="center center">
+ <md-select class="schema-version" placeholder="MetaSchema Version" >
+ <md-option class="schema-version" >
+ 1.0.0
+ </md-option>
+ <br>
+ </md-select>
+ </div>
+ <div fxFlex="15" fxLayoutAlign="center center">
+ <button md-raised-button class="meta-display-button" (click)=toggleMetaSchema() >
+ {{metaButton}}
+ </button>
+ </div>
+ <div fxFlex="75" fxLayoutAlign="center center">
+ <h1 class="scenario-title" text-align:center > Verify JSON Schema and Test Input</h1>
+ </div>
+ </div>
+ </div>
+
+</md-toolbar>
+
+<div fxLayout="row" fxFill flexLayoutGap=10px>
+ <div fxLayout="row" fxFlex fxFill flexLayoutGap=10px>
+ <div class="metaschema" fxFlex="100" fxFill fxShow={{metaDisplay}} flex="grow" fxLayoutAlign="center center">
+ <md-card class="metaschema-card">
+ <md-card-title class="metaschema-title">
+ Data Format MetaSchema
+ </md-card-title>
+ <md-card-content class="metaschema-text">
+ {{dfmetaschema}}
+ </md-card-content>
+ </md-card>
+ </div>
+ <div class="schema-container" fxLayout="column" fxFlex="100" fxFill flex="grow" fxLayoutAlign="center center">
+ <md-card class="schema-input-title" fxFlex="100" fxFill flex="grow" fxLayoutAlign="center center">
+ <md-card-title class="schemainput-title" fxFlex="100" fxFill flex="grow" fxLayoutAlign="left left">
+ Application Schema
+ </md-card-title>
+ </md-card>
+ <textarea mdInput class="schema-input-textarea" placeholder="Enter your Application Schema Definition Here" [ngModel]="dfschema" (keyup)="doDFSchemaChange($event)" fxLayoutAlign="center center" autofocus="">
+ </textarea>
+ <md-card class="schema-msgs" fxLayout="column" fxFlex="100" fxFill flex="grow" fxLayoutAlign="left left" >
+ <h4>Schema Verification Messages</h4>
+ <span style="color:black">{{schemaMsg}}</span>
+ <ul class="schema-error" *ngFor="let msg of schemaErrMsgs">
+ <li class="schema-error" >
+ {{msg}}
+ </li>
+ </ul>
+ </md-card>
+ </div>
+ <div class="json-container" fxLayout="column" fxFlex="100" fxFill flex="grow" fxLayoutAlign="center center">
+ <md-card class="json-input-title" fxFlex="100" fxFill flex="grow" fxLayoutAlign="center center">
+ <md-card-title class="jsoninput-title" fxFlex="100" fxFill flex="grow" fxLayoutAlign="left left">
+ JSON Input
+ </md-card-title>
+ </md-card>
+ <textarea mdInput class="json-input-textarea" placeholder="Enter JSON Input Here" [ngModel]="dfjson" (keyup)="doDFJSONChange($event)" fxLayoutAlign="center center" autofocus="">
+ </textarea>
+ <md-card class="json-msgs" fxLayout="column" fxFlex="100" fxFill flex="grow" fxLayoutAlign="left left">
+ <h4>JSON Input Messages</h4>
+ <span style="color:black">{{jsonMsg}}</span>
+ <ul class="json-error" *ngFor="let msg of jsonErrMsgs">
+ <li class="json-error" >
+ {{msg}}
+ </li>
+ </ul>
+ </md-card>
+ </div>
+ </div>
+</div>
diff --git a/dcaedftool/src/app/df-jsoninput.component.spec.ts b/dcaedftool/src/app/df-jsoninput.component.spec.ts new file mode 100644 index 0000000..a5f8406 --- /dev/null +++ b/dcaedftool/src/app/df-jsoninput.component.spec.ts @@ -0,0 +1,153 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+import {HttpModule} from '@angular/http'; // for future
+import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // for future
+import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; // for future
+import { MaterialModule } from '@angular/material';
+import { FlexLayoutModule } from '@angular/flex-layout';
+import { RouterModule, Routes } from '@angular/router';
+import { APP_BASE_HREF } from '@angular/common';
+
+import {ValidateMetaSchemaService} from './validate-metaschema.service';
+import {ValidateJSONService} from './validate-json.service';
+import {MetaSchemaService} from './metaschema.service';
+import {DFJSONInputComponent} from './df-jsoninput.component';
+
+
+
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { DebugElement } from '@angular/core';
+
+describe('DFSJSONInputComponent Tests', function () {
+ let de: DebugElement;
+ let comp: DFJSONInputComponent;
+ let fixture: ComponentFixture<DFJSONInputComponent>;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ imports: [ BrowserModule,
+ BrowserAnimationsModule,
+ FormsModule,
+ HttpModule,
+ ReactiveFormsModule,
+ FlexLayoutModule,
+ MaterialModule,
+
+ ],
+ providers: [{provide: APP_BASE_HREF, useValue: '/'},
+ ValidateMetaSchemaService,
+ ValidateJSONService,
+ MetaSchemaService
+ ],
+ declarations: [
+ DFJSONInputComponent,
+
+ ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(DFJSONInputComponent);
+ comp = fixture.componentInstance;
+ //de = fixture.debugElement.query(By.css('h1'));
+ });
+
+ it('should create component', () => expect(comp).toBeDefined() );
+
+ it('should have no metaschema display as default', () => {
+ expect(comp.metaButton).toMatch('Display MetaSchema');
+ });
+ it('should metaschema display after toggle', () => {
+ comp.toggleMetaSchema();
+ expect(comp.metaButton).toMatch('Hide MetaSchema');
+ });
+ it('should validate valid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch("Valid Data Format Schema") ;
+ });
+ it('should not validate an invalid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch("Invalid Data Format Schema") ;
+ });
+ it('schema must have JSON schema ', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "json1schema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch("Invalid Schema - must specify jsonschema") ;
+ });
+ it('JSON schema must be 04', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-05/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch(/Invalid JSON Schema Data Format - jsonschema\$schema version must be 04/) ;
+ });
+ it('should fail if JSON input and no schema', () => {
+ let ev = {target: {name: "test", value: '{}'}};
+ comp.doDFJSONChange(ev);
+ expect(comp.jsonMsg).toMatch("Enter a Valid Schema") ;
+ });
+ it('should validate if JSON input and match valid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ let jev = {target: {name: "test", value: '{"raw-text": "test"}'}};
+ comp.doDFJSONChange(jev);
+ expect(comp.jsonMsg).toMatch("JSON Input Validated") ;
+ });
+ it('should not validate if JSON input does not match valid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ let jev = {target: {name: "test", value: '{"badraw-text": "test"}'}};
+ comp.doDFJSONChange(jev);
+ expect(comp.jsonMsg).toMatch("JSON Input does not match Schema") ;
+ });
+ it('should recover if schema becomes valid', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch("Invalid Data Format Schema") ;
+ let jev = {target: {name: "test", value: '{"raw-text": "test"}'}};
+ comp.doDFJSONChange(jev);
+ let ev2 = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev2);
+ expect(comp.jsonMsg).toMatch("JSON Input Validated") ;
+ expect(comp.schemaMsg).toMatch("Valid Data Format Schema") ;
+ });
+ it('should fail if schema becomes invalid', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ let jev = {target: {name: "test", value: '{"raw-text": "test"}'}};
+ comp.doDFJSONChange(jev);
+ ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "json1schema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.jsonMsg).toMatch("Enter a valid Schema") ;
+ });
+ it('should validate if JSON input is fixed to match valid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ let jev = {target: {name: "test", value: '{"badraw-text": "test"}'}};
+ comp.doDFJSONChange(jev);
+ expect(comp.jsonMsg).toMatch("JSON Input does not match Schema") ;
+ jev = {target: {name: "test", value: '{"raw-text": "test"}'}};
+ comp.doDFJSONChange(jev);
+ expect(comp.jsonMsg).toMatch("JSON Input Validated") ;
+ });
+});
diff --git a/dcaedftool/src/app/df-jsoninput.component.ts b/dcaedftool/src/app/df-jsoninput.component.ts new file mode 100644 index 0000000..0006d5f --- /dev/null +++ b/dcaedftool/src/app/df-jsoninput.component.ts @@ -0,0 +1,246 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Component, Input, OnInit, OnChanges} from '@angular/core';
+import { MdToolbarModule, MdButton, MdInputModule, MdSelectModule} from '@angular/material';
+import {ValidateMetaSchemaService} from './validate-metaschema.service';
+import {ValidateJSONService} from './validate-json.service';
+import {MetaSchemaService} from './metaschema.service';
+import * as Ajv from 'ajv';
+
+@Component({
+ selector: 'app-df-jsoninput',
+ templateUrl: './df-jsoninput.component.html',
+ styleUrls: [ './df-jsoninput.component.css']
+})
+export class DFJSONInputComponent implements OnInit /*, OnChanges */ {
+
+ public dfschema = '';
+ private jsonTestObject: any;
+ private validJSON = false;
+ public metaDisplay = false;
+ public metaButton = 'Display MetaSchema';
+ public schemaMsg: string;
+ public schemaErrMsgs: string[] = [];
+ private ajvService: any;
+ private hideMeta = 'Hide MetaSchema';
+ private displayMeta = 'Display Metaschema';
+ private schemaValidate: Object;
+ private validateMetaSchema: ValidateMetaSchemaService;
+ private jsonValidate: ValidateJSONService;
+ private metaSchema: MetaSchemaService;
+ private validSchema = false;
+ public dfmetaschema: string;
+ public dfjson: string;
+ public jsonMsg: string;
+ public jsonErrMsgs: string[] = [];
+
+ constructor (validateMetaSchemaService: ValidateMetaSchemaService, validateJSONService: ValidateJSONService, metaSchemaService: MetaSchemaService) {
+ this.validateMetaSchema = validateMetaSchemaService;
+ this.metaSchema = metaSchemaService;
+ this.dfmetaschema = this.metaSchema.currentMetaSchemaFormatted();
+ this.jsonValidate = validateJSONService;
+ }
+
+
+ ngOnInit(): void {
+ }
+
+ toggleMetaSchema(): void {
+ this.metaDisplay = !this.metaDisplay;
+ if (this.metaDisplay === true) {
+ this.metaButton = this.hideMeta;
+ } else {
+ this.metaButton = this.displayMeta;
+ }
+ }
+ doDFSchemaChange(ev: any) {
+ this.schemaMsg = '';
+ this.schemaErrMsgs = [];
+ this.validSchema = false;
+ this.dfschema = ev.target.value;
+ if (this.dfschema.length == 0) {
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a Valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ return;
+ }
+ if (this.jsonValidate.validate(this.dfschema) === false) {
+ // assumes simple message - TBD???
+ this.schemaMsg = this.jsonValidate.validateMsgs();
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ return;
+ }
+ const pschema = JSON.parse(this.dfschema);
+ if (!pschema.hasOwnProperty('jsonschema')) {
+ this.schemaMsg = 'Invalid Schema - must specify jsonschema';
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ return;
+ }
+ const jsonSchema = pschema.jsonschema;
+ if (jsonSchema.hasOwnProperty('$schema')) {
+ try {
+ if (!(jsonSchema.$schema === 'http://json-schema.org/draft-04/schema#') ) {
+ this.schemaMsg = 'Invalid JSON Schema Data Format - jsonschema$schema version must be 04';
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a Valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ return;
+ }
+ } catch(schemaVersionErr) {
+ this.schemaMsg = 'Invalid JSON Schema Data Format - jsonschema$schema version must be 04';
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a Valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ return;
+ }
+ } else {
+ this.schemaMsg = 'Invalid JSON Schema Data Format - jsonschema$schema must specified';
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a Valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ return;
+ }
+ if (this.validateMetaSchema.validate(this.dfschema) === false) {
+ this.schemaMsg = 'Invalid Data Format Schema';
+ this.schemaErrMsgs = this.validateMetaSchema.validateMsgs();
+ if (this.validJSON) {
+ this.jsonMsg = 'Enter a valid Schema';
+ this.jsonErrMsgs = [];
+ }
+ } else {
+ this.schemaMsg = 'Valid Data Format Schema';
+ this.validSchema = true;
+ if (this.validJSON ) {
+ this.validateJSON();
+ }
+ }
+ }
+
+ // no reuse - so no service
+ validateJSON() {
+ this.jsonErrMsgs = [];
+ this.jsonMsg = '';
+ this.validJSON = false;
+ if (this.dfjson.length == 0) {
+ return;
+ }
+ if (this.jsonValidate.validate(this.dfjson) === false) {
+ this.jsonMsg = this.jsonValidate.validateMsgs();
+ this.jsonErrMsgs = [];
+ return;
+ }
+ this.validJSON = true;
+ if (!this.validSchema) {
+ this.jsonMsg = 'Enter a Valid Schema';
+ this.jsonErrMsgs = [];
+ return;
+ }
+ // check for jsonschema in Schema file and validate based on version
+ const valpschema = JSON.parse(this.dfschema);
+ const valjsonSchema = valpschema.jsonschema;
+ const schemaVersion = valjsonSchema.$schema;
+
+ try {
+ if (schemaVersion === 'http://json-schema.org/draft-04/schema#') {
+ this.ajvService = new Ajv({
+ meta: false, // optional, to prevent adding draft-06 meta-schema
+ extendRefs: true, // optional, current default is to 'fail', spec behaviour is to 'ignore'
+ allErrors: true,
+ unknownFormats: 'ignore' // optional, current default is true (fail)
+ });
+ // change this to http get at some point TBD
+ const schemav4: any = { 'id': 'http://json-schema.org/draft-04/schema#', '$schema': 'http://json-schema.org/draft-04/schema#', 'description': 'Core schema meta-schema', 'definitions': { 'schemaArray': { 'type': 'array', 'minItems': 1, 'items': { '$ref': '#' } }, 'positiveInteger': { 'type': 'integer', 'minimum': 0 }, 'positiveIntegerDefault0': { 'allOf': [ { '$ref': '#/definitions/positiveInteger' }, { 'default': 0 } ] }, 'simpleTypes': { 'enum': [ 'array', 'boolean', 'integer', 'null', 'number', 'object', 'string' ] }, 'stringArray': { 'type': 'array', 'items': { 'type': 'string' }, 'minItems': 1, 'uniqueItems': true } }, 'type': 'object', 'properties': { 'id': { 'type': 'string', 'format': 'uri' }, '$schema': { 'type': 'string', 'format': 'uri' }, 'title': { 'type': 'string' }, 'description': { 'type': 'string' }, 'default': {}, 'multipleOf': { 'type': 'number', 'minimum': 0, 'exclusiveMinimum': true }, 'maximum': { 'type': 'number' }, 'exclusiveMaximum': { 'type': 'boolean', 'default': false }, 'minimum': { 'type': 'number' }, 'exclusiveMinimum': { 'type': 'boolean', 'default': false }, 'maxLength': { '$ref': '#/definitions/positiveInteger' }, 'minLength': { '$ref': '#/definitions/positiveIntegerDefault0' }, 'pattern': { 'type': 'string', 'format': 'regex' }, 'additionalItems': { 'anyOf': [ { 'type': 'boolean' }, { '$ref': '#' } ], 'default': {} }, 'items': { 'anyOf': [ { '$ref': '#' }, { '$ref': '#/definitions/schemaArray' } ], 'default': {} }, 'maxItems': { '$ref': '#/definitions/positiveInteger' }, 'minItems': { '$ref': '#/definitions/positiveIntegerDefault0' }, 'uniqueItems': { 'type': 'boolean', 'default': false }, 'maxProperties': { '$ref': '#/definitions/positiveInteger' }, 'minProperties': { '$ref': '#/definitions/positiveIntegerDefault0' }, 'required': { '$ref': '#/definitions/stringArray' }, 'additionalProperties': { 'anyOf': [ { 'type': 'boolean' }, { '$ref': '#' } ], 'default': {} }, 'definitions': { 'type': 'object', 'additionalProperties': { '$ref': '#' }, 'default': {} }, 'properties': { 'type': 'object', 'additionalProperties': { '$ref': '#' }, 'default': {} }, 'patternProperties': { 'type': 'object', 'additionalProperties': { '$ref': '#' }, 'default': {} }, 'dependencies': { 'type': 'object', 'additionalProperties': { 'anyOf': [ { '$ref': '#' }, { '$ref': '#/definitions/stringArray' } ] } }, 'enum': { 'type': 'array', 'minItems': 1, 'uniqueItems': true }, 'type': { 'anyOf': [ { '$ref': '#/definitions/simpleTypes' }, { 'type': 'array', 'items': { '$ref': '#/definitions/simpleTypes' }, 'minItems': 1, 'uniqueItems': true } ] }, 'allOf': { '$ref': '#/definitions/schemaArray' }, 'anyOf': { '$ref': '#/definitions/schemaArray' }, 'oneOf': { '$ref': '#/definitions/schemaArray' }, 'not': { '$ref': '#' } }, 'dependencies': { 'exclusiveMaximum': [ 'maximum' ], 'exclusiveMinimum': [ 'minimum' ] }, 'default': {}}
+
+ const metaSchema = schemav4;
+
+ this.ajvService.addMetaSchema(metaSchema);
+ this.ajvService._opts.defaultMeta = metaSchema.id;
+
+ // Optionally you can also disable keywords defined in draft-06
+ this.ajvService.removeKeyword('propertyNames');
+ this.ajvService.removeKeyword('contains');
+ this.ajvService.removeKeyword('const');
+
+ } else {
+ this.jsonMsg = 'Invalid JSON Schema Data Format - jsonschema$schema version must be 04';
+ this.jsonErrMsgs = [];
+ return;
+ }
+ } catch (ajvErrMsg) {
+
+ this.jsonMsg = 'Failed - Schema checking initialization: ' + ajvErrMsg;
+ this.jsonErrMsgs = [];
+ return;
+ }
+
+
+ try {
+ const pschema = JSON.parse(this.dfschema);
+ const jsonSchema = pschema.jsonschema;
+
+ const sValidate = this.ajvService.compile(jsonSchema);
+ const result = sValidate(JSON.parse(this.dfjson));
+
+ let j = 0;
+ if (result === false) {
+ for ( const errMsg of Object.keys(sValidate.errors)) {
+ let msg = sValidate.errors[errMsg].message;
+ if (sValidate.errors[errMsg].hasOwnProperty('params')) {
+ if (sValidate.errors[errMsg].params.hasOwnProperty('additionalProperty')) {
+ msg = msg + ' - ';
+ msg = msg + sValidate.errors[errMsg].params.additionalProperty;
+ }
+ }
+ let dupMsg = false;
+ for (const k in this.jsonErrMsgs) {
+ if ( this.jsonErrMsgs[k] === msg) {
+ dupMsg = true;
+ }
+ }
+ if (dupMsg === false) {
+ this.jsonErrMsgs[j] = msg;
+ j = j + 1;
+ }
+ }
+ this.jsonMsg = 'JSON Input does not match Schema:';
+ return;
+ }
+ } catch (schemaError) {
+ this.jsonMsg = 'Unexpected Schema Validation Error' + schemaError;
+ return;
+ }
+ this.jsonMsg = 'JSON Input Validated';
+ this.jsonErrMsgs = [];
+ }
+
+ doDFJSONChange(ev: any) {
+ this.dfjson = ev.target.value;
+ this.validateJSON();
+ }
+}
diff --git a/dcaedftool/src/app/df-schema.component.css b/dcaedftool/src/app/df-schema.component.css new file mode 100644 index 0000000..304fc89 --- /dev/null +++ b/dcaedftool/src/app/df-schema.component.css @@ -0,0 +1,149 @@ +/*
+ org.onap.dcae
+ ============LICENSE_START====================================================
+ Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ =============================================================================
+ 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.
+ ============LICENSE_END======================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+*/
+.scenario-toolbar {
+ color: #f2f2f2;
+ min-width: 520px;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ /*padding-left: 16px;
+ min-width: 520px; */
+ text-align: center;
+ background-color: #f2f2f2
+}
+.scenario-title {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 120%;
+ text-align: center;
+ background-color: #f2f2f2
+}
+.metaschema-title {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 50%;
+ font-weight: bold;
+ text-align: left;
+ background-color: #f2f2f2
+}
+
+.metaschema-text {
+ padding: 0px;
+ margin: 0px;
+ width: 100%;
+ font-size: 50%;
+ background-color: #f2f2f2;
+ white-space: pre-wrap;
+}
+.metaschema {
+ margin: 0px;
+}
+.metaschema-card {
+ margin: 0px;
+}
+.schema-container {
+ margin: 5px;
+}
+.schema-input-card {
+ margin: 5px;
+}
+
+.schema-container {
+ margin: 5px;
+}
+.schemainput-title {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 50%;
+ font-weight: bold;
+ text-align: left;
+ margin: 5px;
+ background-color: #f2f2f2
+}
+
+.schema-input-textarea {
+ padding: 10px;
+ width: 100%;
+ height: 600px;
+ font-size: 100%;
+ background-color: #f2f2f2
+}
+.schema-input {
+ padding: 30px;
+ width: 95%;
+/* height: 400px; */
+ padding-left: 20px;
+ padding-right: 20px;
+ padding-top: 20px;
+ background-color: #f2f2f2
+}
+.schema-msgs {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 100%;
+ background-color: #ffffff
+}
+.schema-version {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 75%;
+ text-align: center;
+ padding: 10px;
+ background-color: #f2f2f2
+}
+.schema-version md-content {
+ background: #f2f2f2;
+ color: #3f51b5;
+}
+.schema-error {
+ color: black;
+
+}
+
+.schema-version md-option:hover {
+ background: #f2f2f2;
+ color: #3f51b5;
+}
+.meta-version-button {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 120%;
+ text-align: center;
+ text-indent: 200px;
+ padding: 30px;
+ background-color: #f2f2f2
+}
+.meta-display-button {
+ color: #3f51b5;
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 80%;
+ font-weight: bold;
+/* height: 25px; */
+ padding-bottom: 2px;
+ text-align: center ;
+ white-space: wrap;
+ overflow:hidden;
+
+
+ background-color: #f2f2f2
+}
+.schema-container {
+ margin: 5px;
+}
diff --git a/dcaedftool/src/app/df-schema.component.html b/dcaedftool/src/app/df-schema.component.html new file mode 100644 index 0000000..2a90e97 --- /dev/null +++ b/dcaedftool/src/app/df-schema.component.html @@ -0,0 +1,75 @@ +<!--
+ org.onap.dcae
+ ============LICENSE_START====================================================
+ Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ =============================================================================
+ 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.
+ ============LICENSE_END======================================================
+
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+-->
+<md-toolbar class="scenario-toolbar">
+ <div fxLayout="row" fxFill>
+ <div fxLayout="row" fxFlex fxFill >
+ <div class="one" fxFlex="15" fxHide="true" fxLayoutAlign="center center">
+ <md-select class="schema-version" placeholder="MetaSchema Version" >
+ <md-option class="schema-version" >
+ 1.0.0
+ </md-option>
+ <br>
+ </md-select>
+ </div>
+ <div fxFlex="15" fxLayoutAlign="center center">
+ <button md-raised-button class="meta-display-button" (click)=toggleMetaSchema() >
+ {{metaButton}}
+ </button>
+ </div>
+ <div fxFlex="75" fxLayoutAlign="center center">
+ <h1 class="scenario-title" text-align:center >Data Format Schema Verification</h1>
+ </div>
+ </div>
+ </div>
+</md-toolbar>
+
+<div fxLayout="row" fxFill flexLayoutGap=10px>
+ <div fxLayout="row" fxFlex fxFill flexLayoutGap=10px>
+ <div class="metaschema" fxFlex="100" fxFill fxShow={{metaDisplay}} flex="grow" fxLayoutAlign="center center">
+ <md-card class="metaschema-card">
+ <md-card-title class="metaschema-title">
+ Data Format MetaSchema
+ </md-card-title>
+ <md-card-content class="metaschema-text">
+ {{dfmetaschema}}
+ </md-card-content>
+ </md-card>
+ </div>
+ <div class="schema-container" fxLayout="column" fxFlex="100" fxFill flex="grow" fxLayoutAlign="center center">
+ <md-card class="schema-input-title" fxFlex="100" fxFill flex="grow" fxLayoutAlign="center center">
+ <md-card-title class="schemainput-title" fxFlex="100" fxFill flex="grow" fxLayoutAlign="left left">
+ Application Schema
+ </md-card-title>
+ </md-card>
+ <textarea mdInput class="schema-input-textarea" placeholder="Enter your Application Schema Definition Here" [ngModel]="dfschema" (keyup)="doDFSchemaChange($event)" flex="grow" fxLayoutAlign="center center" autofocus="">
+ </textarea>
+ <md-card class="schema-msgs" fxLayout="column" fxFlex="100" fxFill flex="grow" fxLayoutAlign="left left">
+ <h4>Schema Verification Messages</h4>
+ <span style="color:black">{{schemaMsg}}</span>
+ <ul class="schema-error" *ngFor="let msg of schemaErrMsgs">
+ <li class="schema-error" >
+ {{msg}}
+ </li>
+ </ul>
+ </md-card>
+ </div>
+ </div>
+</div>
diff --git a/dcaedftool/src/app/df-schema.component.spec.ts b/dcaedftool/src/app/df-schema.component.spec.ts new file mode 100644 index 0000000..dac20f2 --- /dev/null +++ b/dcaedftool/src/app/df-schema.component.spec.ts @@ -0,0 +1,99 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';
+import {HttpModule} from '@angular/http'; // for future
+import {FormsModule, ReactiveFormsModule} from '@angular/forms'; // for future
+import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; // for future
+import { MaterialModule } from '@angular/material';
+import { FlexLayoutModule } from '@angular/flex-layout';
+import { RouterModule, Routes } from '@angular/router';
+import { APP_BASE_HREF } from '@angular/common';
+
+import {ValidateMetaSchemaService} from './validate-metaschema.service';
+import {ValidateJSONService} from './validate-json.service';
+import {MetaSchemaService} from './metaschema.service';
+import {DFSchemaComponent} from './df-schema.component';
+
+
+
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
+import { DebugElement } from '@angular/core';
+
+describe('DFSchemaComponent Tests', function () {
+ let de: DebugElement;
+ let comp: DFSchemaComponent;
+ let fixture: ComponentFixture<DFSchemaComponent>;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ imports: [ BrowserModule,
+ BrowserAnimationsModule,
+ FormsModule,
+ HttpModule,
+ ReactiveFormsModule,
+ FlexLayoutModule,
+ MaterialModule,
+
+ ],
+ providers: [{provide: APP_BASE_HREF, useValue: '/'},
+ ValidateMetaSchemaService,
+ ValidateJSONService,
+ MetaSchemaService
+ ],
+ declarations: [
+ DFSchemaComponent,
+
+ ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(DFSchemaComponent);
+ comp = fixture.componentInstance;
+ //de = fixture.debugElement.query(By.css('h1'));
+ });
+
+ it('should create component', () => expect(comp).toBeDefined() );
+
+ it('should have no metaschema display as default', () => {
+ expect(comp.metaButton).toMatch('Display MetaSchema');
+ });
+ it('should metaschema display after toggle', () => {
+ comp.toggleMetaSchema();
+ expect(comp.metaButton).toMatch('Hide MetaSchema');
+ });
+ it('should validate valid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch("Valid Data Format Schema") ;
+ });
+ it('should not validate an invalid schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch("Invalid Data Format Schema:") ;
+ });
+ it('jsonschema must be 04 or 06 schema', () => {
+ let ev = {target: {name: "test", value: '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"}, "jsonschema": { "$schema": "http://json-schema.org/draft-05/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'}};
+ comp.doDFSchemaChange(ev);
+ expect(comp.schemaMsg).toMatch(/Invalid JSON Schema Data Format - jsonschema\$schema version must be 04 or 06/) ;
+ });
+});
diff --git a/dcaedftool/src/app/df-schema.component.ts b/dcaedftool/src/app/df-schema.component.ts new file mode 100644 index 0000000..8075c79 --- /dev/null +++ b/dcaedftool/src/app/df-schema.component.ts @@ -0,0 +1,109 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Component, Input, OnInit, OnChanges} from '@angular/core';
+import { MdToolbarModule, MdButton, MdInputModule, MdSelectModule} from '@angular/material';
+import {ValidateMetaSchemaService} from './validate-metaschema.service';
+import {MetaSchemaService} from './metaschema.service';
+
+@Component({
+ selector: 'app-df-schema',
+ templateUrl: './df-schema.component.html',
+ styleUrls: [ './df-schema.component.css']
+})
+export class DFSchemaComponent implements OnInit /*, OnChanges */ {
+ public dfschema = '';
+ private jsonTestObject: any;
+ private validJSON: boolean;
+ public metaDisplay = false;
+ public schemaMsg: string;
+ public schemaErrMsgs: string[] = [];
+ private schemaMsgColor: string;
+ private schemaPassColor = '#00ff00';
+ private schemaFailColor = '#ff0000';
+ public metaButton = 'Display MetaSchema';
+ private hideMeta = 'Hide MetaSchema';
+ private displayMeta = 'Display Metaschema';
+ private schemaValidate: Object;
+ private validateMetaSchema: ValidateMetaSchemaService;
+ private metaSchema: MetaSchemaService;
+
+
+ // inline for now - TBD
+ public dfmetaschema: string;
+ private dfjson: string;
+
+ constructor (validateMetaSchemaService: ValidateMetaSchemaService, metaSchemaService: MetaSchemaService) {
+ this.validateMetaSchema = validateMetaSchemaService;
+ this.metaSchema = metaSchemaService;
+ this.dfmetaschema = this.metaSchema.currentMetaSchemaFormatted();
+ }
+
+ ngOnInit(): void {
+ this.schemaMsgColor=this.schemaPassColor;
+ }
+
+ toggleMetaSchema(): void {
+ this.metaDisplay = !this.metaDisplay;
+ if (this.metaDisplay === true) {
+ this.metaButton = this.hideMeta;
+ } else {
+ this.metaButton = this.displayMeta;
+ }
+ }
+
+ doDFSchemaChange(ev: any) {
+ this.schemaErrMsgs = [];
+ this.schemaMsg = '';
+ this.dfschema = ev.target.value;
+ if (this.dfschema.length == 0) {
+ return;
+ }
+ try {
+ // check for JSON validity
+ this.jsonTestObject = JSON.parse(this.dfschema);
+ this.validJSON = true;
+ this.schemaMsg = 'Valid JSON';
+ } catch (jsonErrMsg) {
+ this.schemaMsg = 'Invalid JSON: ' + jsonErrMsg;
+ return;
+ }
+ if (this.jsonTestObject.hasOwnProperty('jsonschema')) {
+ if (this.jsonTestObject.jsonschema.hasOwnProperty('$schema')){
+ try {
+ if (!(this.jsonTestObject.jsonschema.$schema === 'http://json-schema.org/draft-04/schema#' || this.jsonTestObject.jsonschema.$schema === 'http://json-schema.org/draft-06/schema#')) {
+ this.schemaMsg = 'Invalid JSON Schema Data Format - jsonschema$schema version must be 04 or 06';
+ return;
+ }
+ } catch(schemaVersionErr) {
+ this.schemaMsg = 'Invalid JSON Schema Data Format - jsonschema$schema version must be 04 or 06';
+ return;
+ }
+ } else {
+ this.schemaMsg = 'Invalid JSON Schema Data Format - jsonschema$schema must be specified';
+ return;
+ }
+ }
+ if (this.validateMetaSchema.validate(this.dfschema) === false) {
+ this.schemaMsg = 'Invalid Data Format Schema:';
+ this.schemaErrMsgs = this.validateMetaSchema.validateMsgs();
+ } else {
+ this.schemaMsg = 'Valid Data Format Schema';
+ }
+ }
+ }
diff --git a/dcaedftool/src/app/metaschema.service.spec.ts b/dcaedftool/src/app/metaschema.service.spec.ts new file mode 100644 index 0000000..3edb058 --- /dev/null +++ b/dcaedftool/src/app/metaschema.service.spec.ts @@ -0,0 +1,38 @@ +// org.onap.dcae +// ============LICENSE_START==================================================== +// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +// ============================================================================= +// 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. +// ============LICENSE_END====================================================== +// +// ECOMP is a trademark and service mark of AT&T Intellectual Property. +import { Injectable } from '@angular/core'; +import {MetaSchemaService} from './metaschema.service'; + + +describe('MetaSchemaService test suite', function () { + let service: MetaSchemaService; + + beforeEach(() => { + service = new MetaSchemaService; + }); + + it('should create service', () => expect(service).toBeDefined() ); + + it('should have have a formatted schema', () => { + expect(service.currentMetaSchemaFormatted()).toMatch('/.*schema.*/') ; + }); + it('should have have a json schema', () => { + expect(service.currentMetaSchema().$schema).toMatch('/.*json-schema.org.*draft.*'); + }); +}); diff --git a/dcaedftool/src/app/metaschema.service.ts b/dcaedftool/src/app/metaschema.service.ts new file mode 100644 index 0000000..93959fe --- /dev/null +++ b/dcaedftool/src/app/metaschema.service.ts @@ -0,0 +1,55 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Injectable } from '@angular/core';
+
+@Injectable()
+export class MetaSchemaService {
+
+ private metaschemaVersions: string [] = ['1.0','1.1 test only'];
+ private metaschemaVersion: string;
+
+ // Get it from a external URL? Note version 6 now.
+ private metaschema1_obj: any ={'$schema': 'http://json-schema.org/draft-04/schema#','title':'Data format specification schema Version 1.0','type':'object','oneOf':[{'properties':{'self':{'$ref':'#/definitions/self'},'dataformatversion':{'$ref':'#/definitions/dataformatversion'},'reference':{'type':'object','description':'A reference to an external schema','properties':{'name':{'$ref':'#/definitions/name'},'version':{'$ref':'#/definitions/version'},'format':{'$ref':'#/definitions/format'}},'required':['name','version','format'],'additionalProperties':false}},'required':['self','dataformatversion','reference'],'additionalProperties':false},{'properties':{'self':{'$ref':'#/definitions/self'},'dataformatversion':{'$ref':'#/definitions/dataformatversion'},'jsonschema':{'$schema':'http://json-schema.org/draft-04/schema#','description':'The JSON schema for this data format'}},'required':['self','dataformatversion','jsonschema'],'additionalProperties':false},{'properties':{'self':{'$ref':'#/definitions/self'},'dataformatversion':{'$ref':'#/definitions/dataformatversion'},'delimitedschema':{'type':'object','description':'A JSON schema for delimited files','properties':{'delimiter':{'enum':[',','|','\t']},'fields':{'type':'array','description':'Array of field descriptions','items':{'$ref':'#/definitions/field'}}},'additionalProperties':false}},'required':['self','dataformatversion','delimitedschema'],'additionalProperties':false},{'properties':{'self':{'$ref':'#/definitions/self'},'dataformatversion':{'$ref':'#/definitions/dataformatversion'},'unstructured':{'type':'object','description':'A JSON schema for unstructured text','properties':{'encoding':{'type':'string','enum':['ASCII','UTF-8','UTF-16','UTF-32']}},'additionalProperties':false}},'required':['self','dataformatversion','unstructured'],'additionalProperties':false}],'definitions':{'name':{'type':'string'},'version':{'type':'string','pattern':'^(\\d+\\.)(\\d+\\.)(\\*|\\d+)$'},'self':{'description':'Identifying Information','type':'object','properties':{'name':{'$ref':'#/definitions/name'},'version':{'$ref':'#/definitions/version'},'description':{'type':'string'}},'required':['name','version'],'additionalProperties':false},'format':{'description':'Referenceschematype','type':'string','enum':['JSON','DelimitedFormat','XML','Unstructured']},'field':{'description':'Afielddefinitionforthedelimitedschema','type':'object','properties':{'name':{'type':'string'},'description':{'type':'string'},'fieldtype':{'description':'the field type; XML schema types','type':'string','enum':['string','boolean','decimal','float','double','duration','dateTime','time','date','gYearMonth','gYear','gMonthDay','gDay','gMonth','hexBinary','base64Binary','anyURI','QName','NOTATION','normalizedString','token','language','IDREFS','ENTITIES','NMTOKEN','NMTOKENS','Name','NCName','ID','IDREF','ENTITY','integer','nonPositiveInteger','negativeInteger','long','int','short','byte','nonNegativeInteger','unsignedLong','unsignedInt','unsignedShort','unsignedByte','positiveInteger']},'fieldPattern':{'description':'Regular expression','type':'integer'},'fieldMaxLength':{'description':'The maximum length','type':'integer'},'fieldMinLength':{'description':'The minimum length','type':'integer'},'fieldMinimum':{'description':'The minimum numeric value','type':'integer'},'fieldMaximum':{'description':'The maximum numeric value','type':'integer'}},'additionalProperties':false},'dataformatversion':{'type':'string','enum':['1.0.0']}}};
+
+ private currentMetaSchemaVersion = '1.0';
+
+ constructor() {
+ }
+
+ currentMetaSchema(): any {
+ return this.metaschema1_obj;
+ }
+ currentMetaSchemaFormatted(): string {
+ return JSON.stringify(this.metaschema1_obj, undefined, '\t');
+ }
+
+ metaSchemaVersion(): string {
+ return this.currentMetaSchemaVersion;
+ }
+
+ setMetaSchemaVersion(newVersion: string): boolean {
+ this.currentMetaSchemaVersion = newVersion;
+ return true;
+ }
+
+ metaSchemaVersions(): any {
+ return this.metaschemaVersions;
+ }
+
+}
diff --git a/dcaedftool/src/app/validate-json.service.spec.ts b/dcaedftool/src/app/validate-json.service.spec.ts new file mode 100644 index 0000000..b9f0dc0 --- /dev/null +++ b/dcaedftool/src/app/validate-json.service.spec.ts @@ -0,0 +1,42 @@ +// org.onap.dcae +// ============LICENSE_START==================================================== +// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +// ============================================================================= +// 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. +// ============LICENSE_END====================================================== +// +// ECOMP is a trademark and service mark of AT&T Intellectual Property. +import { Injectable } from '@angular/core'; +import {ValidateJSONService} from './validate-json.service'; + + +describe('ValidateJSONService test suite', function () { + let service: ValidateJSONService; + + beforeEach(() => { + service = new ValidateJSONService; + }); + + it('should create service', () => expect(service).toBeDefined() ); + + it('should validate valid json', () => { + var jsonString = '{"testjson": "teststring"}' + expect(service.validate(jsonString)).toBe(true) ; + expect(service.validateMsgs()).toMatch('Valid JSON') ; + }); + it('should fail to validate invalid json', () => { + var jsonString = '"testjson": "teststring"}' + expect(service.validate(jsonString)).toBe(false) ; + expect(service.validateMsgs()).toMatch('Invalid JSON/*') ; + }); +}); diff --git a/dcaedftool/src/app/validate-json.service.ts b/dcaedftool/src/app/validate-json.service.ts new file mode 100644 index 0000000..e85d664 --- /dev/null +++ b/dcaedftool/src/app/validate-json.service.ts @@ -0,0 +1,49 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Injectable } from '@angular/core';
+
+
+@Injectable()
+export class ValidateJSONService {
+
+ private lastErrors: string;
+
+
+ constructor() {
+
+ }
+
+ validate( jsonString: string): boolean {
+ try {
+ // check for JSON validity
+ const jsonTestObject = JSON.parse(jsonString);
+ this.lastErrors = 'Valid JSON';
+ return true;
+ } catch (jsonErrMsg) {
+ this.lastErrors = 'Invalid JSON: ' + jsonErrMsg;
+ return false;
+ }
+
+ }
+ validateMsgs(): string {
+ return this.lastErrors;
+ }
+
+
+}
diff --git a/dcaedftool/src/app/validate-metaschema.service.spec.ts b/dcaedftool/src/app/validate-metaschema.service.spec.ts new file mode 100644 index 0000000..bdc28a3 --- /dev/null +++ b/dcaedftool/src/app/validate-metaschema.service.spec.ts @@ -0,0 +1,66 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Injectable } from '@angular/core';
+import {ValidateMetaSchemaService} from './validate-metaschema.service';
+import {MetaSchemaService} from './metaschema.service';
+import {ValidateJSONService} from './validate-json.service';
+
+describe('ValidateMetaSchemaService test suite', function () {
+ let service: ValidateMetaSchemaService;
+
+ beforeEach(() => {
+ let jsonservice = new ValidateJSONService;
+ let metaservice = new MetaSchemaService;
+ service = new ValidateMetaSchemaService(metaservice, jsonservice);
+ });
+
+ it('should create service', () => expect(service).toBeDefined() );
+
+
+ it('should fail to validate invalid json', () => {
+ var jsonString = '"testjson": "teststring"}'
+ expect(service.validate(jsonString)).toBe(false) ;
+ expect(service.validateMsgs()).toMatch("Invalid JSON.*");
+ });
+ it('should validate valid JSON schema', () => {
+ var jsonString = '{"self": { "name": "CUDA Simple JSON Example","version": "1.0.0","description": "An example of unnested JSON schema for CUDA Input and output"},"dataformatversion": "1.0.0", "jsonschema": { "$schema": "http://json-schema.org/draft-04/schema#","type": "object", "properties": {"raw-text": {"type": "string" } }, "required": ["raw-text"], "additionalProperties": false }}'
+ expect(service.validate(jsonString)).toBe(true) ;
+ });
+
+ it('should validate valid reference schema', () => {
+ var jsonString ='{ "self": { "name": "Common Event Format Definition", "version": "25.0.0", "description": "Common Event Format Definition"}, "dataformatversion": "1.0.0", "reference": { "name": "Common Event Format", "format": "JSON", "version": "25.0.0" }}';
+ expect(service.validate(jsonString)).toBe(true) ;
+ });
+
+ it('should validate valid delimited schema', () => {
+ var jsonString ='{"self": {"name": "Delimited Format Example", "version": "1.0.0", "description": "Delimited format example just for testing" }, "dataformatversion": "1.0.0", "delimitedschema": { "delimiter": "|", "fields": [{ "name": "field1", "description": "test field1", "fieldtype": "string" }, { "name": "field2", "description": "test field2", "fieldtype": "boolean" }] } }'
+ expect(service.validate(jsonString)).toBe(true) ;
+ });
+
+ it('should validate valid unstructured schema', () => {
+ var jsonString ='{ "self": { "name": "CUDA Unstructured Text Example","version": "25.0.0", "description": "An example of a unstructured text used for both input and output for CUDA"}, "dataformatversion": "1.0.0","unstructured": { "encoding": "UTF-8"}}';
+ expect(service.validate(jsonString)).toBe(true) ;
+ });
+
+ it('should fail to validate invalid schema', () => {
+ var jsonString = '{"testjson": "teststring"}'
+ expect(service.validate(jsonString)).toBe(false) ;
+ });
+
+});
diff --git a/dcaedftool/src/app/validate-metaschema.service.ts b/dcaedftool/src/app/validate-metaschema.service.ts new file mode 100644 index 0000000..6a61f0b --- /dev/null +++ b/dcaedftool/src/app/validate-metaschema.service.ts @@ -0,0 +1,99 @@ +// org.onap.dcae
+// ============LICENSE_START====================================================
+// Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+// =============================================================================
+// 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.
+// ============LICENSE_END======================================================
+//
+// ECOMP is a trademark and service mark of AT&T Intellectual Property.
+import { Injectable } from '@angular/core';
+import {MetaSchemaService} from './metaschema.service';
+import {ValidateJSONService} from './validate-json.service';
+import * as Ajv from 'ajv';
+
+@Injectable()
+export class ValidateMetaSchemaService {
+
+ private ajv: any;
+ private schemaValidate: any;
+ private metaSchema: MetaSchemaService;
+ private jsonValidate: ValidateJSONService;
+ private lastErrors:string[] = [];
+
+ constructor(metaSchemaService: MetaSchemaService, jsonValidateService: ValidateJSONService) {
+ this.metaSchema = metaSchemaService;
+ this.jsonValidate = jsonValidateService;
+ }
+
+ validate(schema: string): boolean {
+ // check JSON
+ if (this.jsonValidate.validate(schema) === false) {
+ // assumes simple message - TBD???
+ this.lastErrors[0] = this.jsonValidate.validateMsgs();
+ return false;
+ }
+ // Schema is assumed to be V4 for now (jsonschema does not support V6 yet so we must wait since this is used by the CLI)
+ try {
+ this.ajv = new Ajv({
+ meta: false, // optional, to prevent adding draft-06 meta-schema
+ extendRefs: true, // optional, current default is to 'fail', spec behaviour is to 'ignore'
+ allErrors: true,
+ unknownFormats: 'ignore' // optional, current default is true (fail)
+ });
+ // change this to http get at some point TBD
+ const schemav4: any = { 'id': 'http://json-schema.org/draft-04/schema#', '$schema': 'http://json-schema.org/draft-04/schema#', 'description': 'Core schema meta-schema', 'definitions': { 'schemaArray': { 'type': 'array', 'minItems': 1, 'items': { '$ref': '#' } }, 'positiveInteger': { 'type': 'integer', 'minimum': 0 }, 'positiveIntegerDefault0': { 'allOf': [ { '$ref': '#/definitions/positiveInteger' }, { 'default': 0 } ] }, 'simpleTypes': { 'enum': [ 'array', 'boolean', 'integer', 'null', 'number', 'object', 'string' ] }, 'stringArray': { 'type': 'array', 'items': { 'type': 'string' }, 'minItems': 1, 'uniqueItems': true } }, 'type': 'object', 'properties': { 'id': { 'type': 'string', 'format': 'uri' }, '$schema': { 'type': 'string', 'format': 'uri' }, 'title': { 'type': 'string' }, 'description': { 'type': 'string' }, 'default': {}, 'multipleOf': { 'type': 'number', 'minimum': 0, 'exclusiveMinimum': true }, 'maximum': { 'type': 'number' }, 'exclusiveMaximum': { 'type': 'boolean', 'default': false }, 'minimum': { 'type': 'number' }, 'exclusiveMinimum': { 'type': 'boolean', 'default': false }, 'maxLength': { '$ref': '#/definitions/positiveInteger' }, 'minLength': { '$ref': '#/definitions/positiveIntegerDefault0' }, 'pattern': { 'type': 'string', 'format': 'regex' }, 'additionalItems': { 'anyOf': [ { 'type': 'boolean' }, { '$ref': '#' } ], 'default': {} }, 'items': { 'anyOf': [ { '$ref': '#' }, { '$ref': '#/definitions/schemaArray' } ], 'default': {} }, 'maxItems': { '$ref': '#/definitions/positiveInteger' }, 'minItems': { '$ref': '#/definitions/positiveIntegerDefault0' }, 'uniqueItems': { 'type': 'boolean', 'default': false }, 'maxProperties': { '$ref': '#/definitions/positiveInteger' }, 'minProperties': { '$ref': '#/definitions/positiveIntegerDefault0' }, 'required': { '$ref': '#/definitions/stringArray' }, 'additionalProperties': { 'anyOf': [ { 'type': 'boolean' }, { '$ref': '#' } ], 'default': {} }, 'definitions': { 'type': 'object', 'additionalProperties': { '$ref': '#' }, 'default': {} }, 'properties': { 'type': 'object', 'additionalProperties': { '$ref': '#' }, 'default': {} }, 'patternProperties': { 'type': 'object', 'additionalProperties': { '$ref': '#' }, 'default': {} }, 'dependencies': { 'type': 'object', 'additionalProperties': { 'anyOf': [ { '$ref': '#' }, { '$ref': '#/definitions/stringArray' } ] } }, 'enum': { 'type': 'array', 'minItems': 1, 'uniqueItems': true }, 'type': { 'anyOf': [ { '$ref': '#/definitions/simpleTypes' }, { 'type': 'array', 'items': { '$ref': '#/definitions/simpleTypes' }, 'minItems': 1, 'uniqueItems': true } ] }, 'allOf': { '$ref': '#/definitions/schemaArray' }, 'anyOf': { '$ref': '#/definitions/schemaArray' }, 'oneOf': { '$ref': '#/definitions/schemaArray' }, 'not': { '$ref': '#' } }, 'dependencies': { 'exclusiveMaximum': [ 'maximum' ], 'exclusiveMinimum': [ 'minimum' ] }, 'default': {}}
+
+ const metaSchema = schemav4;
+
+ this.ajv.addMetaSchema(metaSchema);
+ this.ajv._opts.defaultMeta = metaSchema.id;
+
+ // Optionally you can also disable keywords defined in draft-06
+ this.ajv.removeKeyword('propertyNames');
+ this.ajv.removeKeyword('contains');
+ this.ajv.removeKeyword('const');
+
+ const sValidate = this.ajv.compile(this.metaSchema.currentMetaSchema());
+ const result = sValidate(JSON.parse(schema));
+ let j = 0;
+ if (result === false) {
+ for ( const errMsg of Object.keys(sValidate.errors)) {
+ let msg = sValidate.errors[errMsg].message;
+ if (sValidate.errors[errMsg].hasOwnProperty('params')) {
+ if (sValidate.errors[errMsg].params.hasOwnProperty('additionalProperty')) {
+ msg = msg + ' - ';
+ msg = msg + sValidate.errors[errMsg].params.additionalProperty;
+ }
+ }
+ let dupMsg = false;
+ for (const k in this.lastErrors) {
+ if ( this.lastErrors[k] === msg) {
+ dupMsg = true;
+ }
+ }
+ if (dupMsg === false) {
+ this.lastErrors[j] = msg;
+ j = j + 1;
+ }
+ }
+ }
+ return result;
+ } catch(ajvError){
+ this.lastErrors[0] = ajvError;
+ }
+ }
+
+ validateMsgs(): string[] {
+ return this.lastErrors;
+ }
+}
|