Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

angular.module('zeppelinWebApp')
.controller('ParagraphCtrl', function($scope,$rootScope, $route, $window, $element, $routeParams, $location,
$timeout, $compile, websocketMsgSrv) {
$timeout, $compile, websocketMsgSrv, dataValidatorSrv) {

$scope.paragraph = null;
$scope.editor = null;
Expand Down Expand Up @@ -1338,6 +1338,12 @@ angular.module('zeppelinWebApp')
});
}

var msg = dataValidatorSrv.validateChartData(data);
//Only console print error found
if(msg.error){
console.log(msg.msg);
}

// clear aggregation name, if possible
var namesWithoutAggr = {};
var colName;
Expand Down Expand Up @@ -1473,6 +1479,12 @@ angular.module('zeppelinWebApp')
};
}

var msg = dataValidatorSrv.validateScatterData(data);
//TODO- warning need to error model or services will needed
if(msg.error){
console.log(msg.msg);
}

for (var i = 0; i < data.rows.length; i++) {
row = data.rows[i];
if (xAxis) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.
*/
'use strict';

angular.module('zeppelinWebApp').factory('chartdataValidator', function(
$rootScope, DataValidator, dataModelSchemas) {

var simpleChartSchema = dataModelSchemas.D3ChartDataSchema;
var chartdataValidator = new DataValidator(simpleChartSchema);

//overriding the check data
chartdataValidator.checkData = function() {
basicCheck();
};

function rowCheck(dataRows) {
if(dataRows instanceof Object) {
for(var key in dataRows) {
schemaChecker(key, 0);
if(dataRows.hasOwnProperty(key)) {
var obj = dataRows[key];
rowValueCheck(obj);
}
}
} else {
markValidationError('dataRows is not a Object | ');
}
}

function rowValueCheck(record) {
if(record instanceof Object) {
for(var key in record) {
var recordValues = record[key];
var countKey = 1;
for(var recordKey in recordValues) {

if(recordValues.hasOwnProperty(recordKey)) {
var values = recordValues[recordKey];
schemaChecker(values, countKey);
countKey++;
}
}
}
} else {
markValidationError('record is not a Object | ');
}
}

function basicCheck() {
var data = chartdataValidator.data;
if(data.schema && data.rows) {
rowCheck(data.rows);
return true;
} else {
markValidationError('data rows does not exisiting | ');
}
}

function schemaChecker(record, index) {
if(isNaN(record) !== (simpleChartSchema.type[index] === 'string')) {
markValidationError('data record ' + record +
' is not matching for schema | ');
}
//record is passed
}

function markValidationError(msg) {
chartdataValidator.setMsg(msg);
chartdataValidator.setError();
}

return chartdataValidator;
});
104 changes: 104 additions & 0 deletions zeppelin-web/src/components/data-validator/data-validator-factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.
*/
'use strict';

angular.module('zeppelinWebApp').factory('DataValidator', function($rootScope) {

var msg = '';
var errorStatus = false;
var DataValidator = function(schema) {
this.schema = schema;
this.error = getErrorStatus;
this.setError = setError;
this.checkData = checkData;
this.getMsg = getMsg;
this.setMsg = setMsg;
this.clearMsg = clearMsg;
this.data = null;
};

function checkData() {
if(basicCheck(this.data, this.schema)) { // jshint ignore:line
msg += 'data is exisiting | ';
} else {
msg += 'data does not exisiting | ';
}
}

function getMsg() {
return msg;
}

function setMsg(newMsg) {
msg += newMsg;
}

function clearMsg() {
msg = '';
}

function getErrorStatus() {
return errorStatus;
}

function setError() {
errorStatus = true;
}

function basicCheck(data, schema) {
if(data.code && data.rows) {
rowCheck(data.rows, 3, schema);
return true;
} else {
msg += 'data rows does not exisiting | ';
setError();
return false;
}
}

function rowCheck(rowData, num, schema) {
if(rowData) {
for(var i = 0; i < rowData.length; i++) {
var row = rowData[i];
if(dataCheckValidator(row, schema)) {
msg += 'data record does not mapping to data schema| ';
}
}
} else {
setError();
msg += 'data row does not exisiting | ';
}
}

function dataCheckValidator(record, schema) {
if(record) {
for(var i = 0; i < schema.type.length; i++) {
if(isNaN(record[i]) !== (schema.type[i] === 'string')) {
errorStatus = true;
msg += 'data record ' + (record[i]) +
' is not matching for schema | ';
return true;
}
} //end validation on data record
errorStatus = false;
return false;
} else {
msg += 'data record does not exisiting | ';
setError();
return true;
}
}

return DataValidator;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*/
'use strict';

angular.module('zeppelinWebApp')
.constant('dataModelSchemas', {
'D3ChartDataSchema': {
type: ['number', 'number', 'number'],
},
'PieChartSchema': {
type: ['number', 'number'],
},
'ScatterDataSchema': {
type: ['number', 'number'],
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.
*/
'use strict';

angular.module('zeppelinWebApp').service('dataValidatorSrv', function(
$rootScope, scatterdataValidator, chartdataValidator,
dataModelSchemas) {

this.validateChartData = function(data) {
var chartValidator = chartdataValidator;
doBasicCheck(chartValidator, data);
return buildMsg(chartValidator);
};

this.validateScatterData = function(data) {
var scatterChartValidator = scatterdataValidator;
doBasicCheck(scatterChartValidator, data);
return buildMsg(scatterChartValidator);
};

function buildMsg(validator) {
var msg = {
'error': validator.error(),
'msg': validator.getMsg()
};
return msg;
}

function doBasicCheck(validator, data) {
validator.clearMsg();
validator.data = data;
validator.checkData();
}

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/
'use strict';

angular.module('zeppelinWebApp').factory('scatterdataValidator', function(
$rootScope, DataValidator, dataModelSchemas) {

var simpleChartSchema = dataModelSchemas.ScatterDataSchema;
var scatterdataValidator = new DataValidator(simpleChartSchema);
return scatterdataValidator;
});
5 changes: 5 additions & 0 deletions zeppelin-web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@
<script src="components/websocketEvents/websocketEvents.factory.js"></script>
<script src="components/notebookListDataFactory/notebookList.datafactory.js"></script>
<script src="components/baseUrl/baseUrl.service.js"></script>
<script src="components/data-validator/data-validator-schema.js"></script>
<script src="components/data-validator/data-validator-factory.js"></script>
<script src="components/data-validator/chart-data-validator-factory.js"></script>
<script src="components/data-validator/scatter-data-validator-factory.js"></script>
<script src="components/data-validator/data-validator-service.js"></script>
<!-- endbuild -->
</body>
</html>
1 change: 1 addition & 0 deletions zeppelin-web/test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = function(config) {
// endbower
'src/app/app.js',
'src/app/app.controller.js',
'src/components/data-validator/*.js',
'src/app/**/*.js',
'test/spec/**/*.js'
],
Expand Down
Loading