/**
*
* Copyright (C) 2021 Akorbi Digital RMP
*
* This file is part of RunMyProcess SDK-JS.
*
* RunMyProcess SDK-JS is free software: you can redistribute it and/or modify
* it under the terms of 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.
*/
/**
* Create a new instance of representations
@constructor
@property {Array} active - Array of active representations.
@property {Array} inactive - Array of inactive representations.
@property {Array} pending - Array of pending representations.
@property {Object} author - The author of the resource
@property {Array} representations - Array of representations.
@see User
@see Resource
*/
function UserRepresentationList(){
this.active = [];
this.inactive = [];
this.pending = [];
this.author = new User();
this.representations = [];
};
/**
@borrows
Inherits Resource
*/
UserRepresentationList.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
UserRepresentationList.prototype.loadPreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
this.generateUrl = function () {
return this.selfUrl;
};
};
/**
Overrides Resource's loadSet method to set local variables after request.
@method
@param {json} rObject - JSON representation of the loaded data.
@see Resource#loadSet
*/
UserRepresentationList.prototype.loadSet = function (rObject) {
try {
var father = this;
father.active = [];
father.inactive = [];
father.pending = [];
father.representations = [];
var ent = father.entries;
for (var i=0;i<ent.length;i++){
var del = new UserDelegation();
del.selfUrl = father.linkSearch('self', ent[i].link);
del.id = ent[i].id;
var v_activationDate = del.termSearch('activation_date',del.getArray(ent[i], "category"));
if(v_activationDate)del.activationDate = new Date(Resource.removeDecimalsFromDateString(v_activationDate.label));
var v_endate = del.termSearch('end_date',del.getArray(ent[i], "category"));
if(v_endate)del.endDate = new Date(Resource.removeDecimalsFromDateString(v_endate.label));
var v_status = del.termSearch('status',del.getArray(ent[i], "category"));
if(v_status)del.status = v_status.label;
del.startDate = new Date(Resource.removeDecimalsFromDateString(del.termSearch('start_date',del.getArray(ent[i], "category")).label));
del.author = new User();
if(ent[i].author){
del.author.email = ent[i].author.email;
del.author.selfUrl = ent[i].author.uri;
del.author.name = ent[i].author.name;
}
del.contributor = new User();
if(ent[i].contributor){
del.contributor.email = ent[i].contributor.email;
del.contributor.selfUrl = ent[i].contributor.uri;
del.contributor.name = ent[i].contributor.name;
}
var v_project = father.termSearch ("project", ent[i].category);
if(v_project){
del.project = new Project();
del.project.id = v_project.label;
del.project.selfUrl = Resource.findLink('project',ent[i].link);
}
if (father.termSearch ("status", ent[i].category).label===father.harcodedValues('DELESTATUS','A')){
father.active.push(del);
};
if (father.termSearch ("status", ent[i].category).label===father.harcodedValues('DELESTATUS','I')){
father.inactive.push(del);
};
if (father.termSearch ("status", ent[i].category).label===father.harcodedValues('DELESTATUS','P')){
father.pending.push(del);
};
var modifiedBylnk = Resource.findLinkObject('modifiedBy',ent[i].link);
if(modifiedBylnk){
del.modifiedBy = new User();
del.modifiedBy.selfUrl=modifiedBylnk.href;
del.modifiedBy.title = modifiedBylnk.title;
}
father.representations.push(del);
};
}catch (e) {
var eOptions = {};
eOptions.object=e;
this.errorManager(eOptions);
};
};
/**
Retrieve harcoded values for the user class.
@param {String} paramGroup - group of parameters
@param {String} localID - the local identifier
@return {String} value - the return harcoded value
*/
UserRepresentationList.prototype.harcodedValues = function (p_paramGroup, p_localID) {
switch (p_paramGroup) {
case 'STATUS':
switch (p_localID) {
case 'A':
return 'ACTIVE';
break;
case 'P':
return 'PENDING';
break;
case 'I':
return 'INACTIVE';
break;
default:
return undefined;
}
break;
case 'DELESTATUS':
switch (p_localID) {
case 'A':
return 'ACTIVE';
break;
case 'P':
return 'PENDING';
break;
case 'I':
return 'INACTIVE';
break;
default:
return undefined;
}
break;
case 'PROFILE':
switch (p_localID) {
case 'U':
return 'USER';
break;
case 'A':
return 'ADMINISTRATOR';
break;
default:
return undefined;
}
break;
default:
return undefined;
}
};