lib/utils/utilities.js
/**
 * Given an object to be decorated, and an array of properties this function creates getters and setters for the given
 * properties. So, in the previous example, objectToBeDecorated will have this functions added after execution:
 *
 * - getAge()
 * - setAge(age)
 * - getInvoices()
 * - setInvoices(invoices)
 * - addInvoice(invoice)
 *
 * @param objectToBeDecorated object to be decorated
 * @param properties property array
 */
Given an object to be decorated, and an array of properties this function creates getters and setters for the given
properties. So, in the previous example, objectToBeDecorated will have this functions added after execution.



@param objectToBeDecorated object to be decorated
@param properties property array
Given an object to be decorated and an array of properties this function creates getters and setters for the given properties . So in the previous example objectToBeDecorated will have this functions added after execution . @param objectToBeDecorated object to be decorated @param properties property array
function decorateWithGettersAndSetters(objectToBeDecorated, properties) {
    if (!objectToBeDecorated || !properties) return null;
    var _isPluralPropertyNameWithLetterSAtTheEnd = function (propertyName) {
        return propertyName.length > 1 && propertyName.charAt(propertyName.length - 1).toUpperCase() == 'S';
    };
    properties.forEach(function (prop) {
        var capitalizedName = capitalizeFirstLetter(prop.getName());
        objectToBeDecorated["get" + capitalizedName] = function () {
            return objectToBeDecorated[prop.getName()];
        };
        objectToBeDecorated["set" + capitalizedName] = function (item) {
            objectToBeDecorated[prop.getName()] = item;
        };
        if (_isArrayProperty(prop)) {
            if (_isPluralPropertyNameWithLetterSAtTheEnd(capitalizedName)) {
                objectToBeDecorated["add" + capitalizedName.substr(0, capitalizedName.length - 1)] = function (item) {
                    objectToBeDecorated[prop.getName()].push(item);
                };
            } else {
                objectToBeDecorated["add" + capitalizedName] = function (item) {
                    objectToBeDecorated[prop.getName()].push(item);
                };
            }
        }
    });
    return objectToBeDecorated;
}
function decorateWithGettersAndSetters ( objectToBeDecorated , properties ) { if ( ! objectToBeDecorated || ! properties ) return null ; var _isPluralPropertyNameWithLetterSAtTheEnd = function ( propertyName ) { return propertyName . length > 1 && propertyName . charAt ( propertyName . length - 1 ) . toUpperCase ( ) == 'S' ; } ; properties . forEach ( function ( prop ) { var capitalizedName = capitalizeFirstLetter ( prop . getName ( ) ) ; objectToBeDecorated [ "get" + capitalizedName ] = function ( ) { return objectToBeDecorated [ prop . getName ( ) ] ; } ; objectToBeDecorated [ "set" + capitalizedName ] = function ( item ) { objectToBeDecorated [ prop . getName ( ) ] = item ; } ; if ( _isArrayProperty ( prop ) ) { if ( _isPluralPropertyNameWithLetterSAtTheEnd ( capitalizedName ) ) { objectToBeDecorated [ "add" + capitalizedName . substr ( 0 , capitalizedName . length - 1 ) ] = function ( item ) { objectToBeDecorated [ prop . getName ( ) ] . push ( item ) ; } ; } else { objectToBeDecorated [ "add" + capitalizedName ] = function ( item ) { objectToBeDecorated [ prop . getName ( ) ] . push ( item ) ; } ; } } } ) ; return objectToBeDecorated ; }
Given an object to be decorated, and an array of properties this function creates getters and setters for the given
 properties.
Given an object to be decorated and an array of properties this function creates getters and setters for the given properties .