Name
sn_appclient.AppManagerApiUtil
Description
No description available
Script
var AppManagerApiUtil = Class.create();
AppManagerApiUtil.prototype = {
initialize: function(request, response) {
this.httpRequest = request;
this.httpResponse = response;
this.SUCESS_RESPONSE_CODE = 200;
this.JSON_CONTENT_TYPE = "application/json";
},
getRequestParams: function() {
if (this.params)
return this.params;
this.params = {};
this.params.queryParams = {};
Object.keys(this.httpRequest.queryParams).forEach(function(key) {
this.params.queryParams[key] = this.httpRequest.queryParams[key].toString();
}, this);
this.params.pathParams = this.httpRequest.pathParams || {};
return this.params;
},
getRequestBody: function() {
var body = this.httpRequest.body || {};
return body.data || {};
},
logErrorMessage: function(message) {
gs.error("AppManagerApiUtil: Error with resource: {0} with request-params: {1} is {2}", this.httpRequest.uri, JSON.stringify(this.params), message);
},
setResponseBody: function(responseData) {
this.httpResponse.setContentType(this.JSON_CONTENT_TYPE);
this.httpResponse.setStatus(this.SUCESS_RESPONSE_CODE);
this.httpResponse.setBody(responseData);
},
setHeader: function(header, value) {
response.setHeader(header, value);
},
addTotalCountHeader: function(value) {
this.setHeader(Constants.HEADER_TOTAL_COUNT, value);
},
setError: function(err) {
this.logErrorMessage(JSON.stringify(err));
var myError = new sn_ws_err.ServiceError();
if (err.hasOwnProperty('errorCode')) {
myError.setStatus(err.errorCode);
} else {
myError.setStatus(400);
}
if (err.hasOwnProperty('errorDescription')) {
myError.setMessage(err.errorDescription);
myError.setDetail(err.errorAction || err.errorDescription);
} else {
myError.setMessage(err);
myError.setDetail(err);
}
if (err.hasOwnProperty("stack"))
myError = err;
this.httpResponse.setError(myError);
},
getPaginationParams: function() {
if (!this.params)
this.getRequestParams();
var paginationParams = {};
paginationParams[Constants.SYSPARM_OFFSET] = CommonUtils.getOffset(this.params.queryParams);
paginationParams[Constants.SYSPARM_LIMIT] = CommonUtils.getLimit(this.params.queryParams);
return paginationParams;
},
getSearchTerm: function() {
var searchTerm = this.params.queryParams[Constants.SEARCH_EXPRESSION];
if (searchTerm)
searchTerm = CommonUtils.getEscapedRegExp(searchTerm);
return searchTerm;
},
getFilterParams: function() {
var filterParamsJSON = this.params.queryParams[Constants.FILTERS_PARAMS];
var filterParams = [];
if (filterParamsJSON)
filterParams = JSON.parse(filterParamsJSON);
return filterParams;
},
getRequestBody: function() {
var requestBody = '';
if (this.httpRequest.body)
requestBody = this.httpRequest.body.data;
return requestBody;
},
type: 'AppManagerApiUtil'
};
Sys ID
b08ad363537411106883ddeeff7b12db