Name
sn_chg_score.ChangeSuccessScorePropertiesSNC
Description
Provides functions to validate system properties related to the calculation of Change Success Score
Script
var ChangeSuccessScorePropertiesSNC = Class.create();
ChangeSuccessScorePropertiesSNC.prototype = {
initialize: function() {
this._changeSuccessScoreUtils = new ChangeSuccessScoreUtils();
this._propertyNames = [this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_MINIMUM_PROP,
this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_MAXIMUM_PROP,
this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_ENTRY_LEVEL_PROP];
this._lowestScorePermitted = 0;
this._highestScorePermitted = 9999;
},
isSuccessScoreProperty: function(propertyGr) {
if (!this._isPropertyGr(propertyGr))
return false;
var propertyName = propertyGr.getValue("name");
if (!propertyName || !Array.isArray(this._propertyNames))
return false;
return this._propertyNames.indexOf(propertyName) >= 0;
},
validateProperty: function(propertyGr) {
if (!this._isPropertyGr(propertyGr))
return null;
var propertyName = propertyGr.getValue("name");
var errors = null;
switch(propertyName) {
case this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_MINIMUM_PROP:
errors = this._validateMinScoreProperty(propertyGr);
break;
case this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_MAXIMUM_PROP:
errors = this._validateMaxScoreProperty(propertyGr);
break;
case this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_ENTRY_LEVEL_PROP:
errors = this._validateEntryLevelScoreProperty(propertyGr);
break;
}
return errors;
},
_validateMinScoreProperty: function(propertyGr) {
var errors = [];
if (!this._isPropertyGr(propertyGr))
return errors;
var propertyName = propertyGr.getValue("name");
if (propertyName !== this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_MINIMUM_PROP)
return;
var propertyValue = parseInt(propertyGr.getValue("value"));
if (isNaN(propertyValue)) {
errors.push(this._integerError(propertyName, propertyGr.getValue("value")));
return errors;
}
if (propertyValue < this._lowestScorePermitted)
errors.push(gs.getMessage("Value for \"{0}\" cannot be less than {1}", [propertyName, "" + this._lowestScorePermitted]));
var maxAllowedScore = this._changeSuccessScoreUtils.getMaxAllowedScore();
if (propertyValue >= maxAllowedScore)
errors.push(gs.getMessage("Value for \"{0}\" must be less than maximum allowed score which is currently {1}",
[propertyName, "" + maxAllowedScore]));
return errors;
},
_validateMaxScoreProperty: function(propertyGr) {
var errors = [];
if (!this._isPropertyGr(propertyGr))
return errors;
var propertyName = propertyGr.getValue("name");
if (propertyName !== this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_MAXIMUM_PROP)
return;
var propertyValue = parseInt(propertyGr.getValue("value"));
if (isNaN(propertyValue)) {
errors.push(this._integerError(propertyName, propertyGr.getValue("value")));
return errors;
}
if (propertyValue > this._highestScorePermitted)
errors.push(gs.getMessage("Value for \"{0}\" cannot be greater than {1}", [propertyName, "" + this._highestScorePermitted]));
var minAllowedScore = this._changeSuccessScoreUtils.getMinAllowedScore();
if (propertyValue <= minAllowedScore)
errors.push(gs.getMessage("Value for \"{0}\" must be greater than minimum allowed score which is currently {1}",
[propertyName, "" + minAllowedScore]));
return errors;
},
_validateEntryLevelScoreProperty: function(propertyGr) {
var errors = [];
if (!this._isPropertyGr(propertyGr))
return errors;
var propertyName = propertyGr.getValue("name");
if (propertyName !== this._changeSuccessScoreUtils.CHG_SUCCESS_SCORE_ENTRY_LEVEL_PROP)
return;
var propertyValue = parseInt(propertyGr.getValue("value"));
if (isNaN(propertyValue)) {
errors.push(this._integerError(propertyName, propertyGr.getValue("value")));
return errors;
}
var minAllowedScore = this._changeSuccessScoreUtils.getMinAllowedScore();
var maxAllowedScore = this._changeSuccessScoreUtils.getMaxAllowedScore();
if (propertyValue < minAllowedScore || propertyValue > maxAllowedScore)
errors.push(gs.getMessage("Value for {0} must be between the minimum and maximum allowed scores which are currently {1} and {2}",
[propertyName, "" + minAllowedScore, "" + maxAllowedScore]));
return errors;
},
_integerError: function(propertyName, propertyValue) {
if (gs.nil(propertyName))
return "";
return gs.getMessage("\"{0}\" is not a valid integer value for property \"{1}\"", [propertyValue, propertyName]);
},
_isPropertyGr: function(propertyGr) {
return propertyGr && typeof propertyGr.getTableName === "function" && propertyGr.getTableName() === "sys_properties";
},
type: 'ChangeSuccessScorePropertiesSNC'
};
Sys ID
1d6ab0d1735f0110e289235f04f6a774