Logo

Docs

  • HOME

Source: User/UserDelegationList.js

/**
 *
 * 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 Delegations
  	@constructor
	@property {Array} active - Array of active delegations.
	@property {Array} inactive - Array of inactive delegations.
	@property {Array} pending - Array of pending delegations.
	@property {Object} author - The author of the resource
	@property {Array} delegations - Array of delegations.
	@see User
	@see Resource
*/
function UserDelegationList(){
	this.active = [];
	this.inactive = [];
	this.pending = [];
	this.author = new User();
	this.delegations = [];
};
/**
	 @borrows
	 Inherits Resource
*/
UserDelegationList.prototype = new  Resource();
/**
	Overrides Resource's loadPreset method.
	@method
	@see Resource#loadPreset
*/
UserDelegationList.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
*/
UserDelegationList.prototype.loadSet = function (rObject) {
	try {
		var father = this;
		father.active = [];
		father.inactive = [];
		father.pending = [];
		father.delegations = [];
		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();
			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();
			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.delegations.push(del);
		};
	}catch (e) {
		var eOptions = {};
		eOptions.object=e;
		this.errorManager(eOptions);
	};
};
/**
	Creates a new Delegation.
	@method
	@param {object} options - options to be used during the call<br/>
	@param {Resource~onSuccess} options.onSuccess - a callback function called in case of a success
	@param {Resource~onFailure} [options.onFailure] - a callback function called in case of a failure
	@param {String} [options.baseUrl] - base URL. If not set the current base URL will be used
	@param {string} [options.status] - status of delegation (will be set to PENDING if null)
	@param {User} options.author - user delegating
	@param {User} options.contributor - user delegated
	@param {project} [options.project] - project associated
	@param {Date} options.startDate - expiration date
*/
UserDelegationList.prototype.save = function (options) {
	this.xml = this.generate_xml(options).trim();
	this.resourceSave(options);
};
/**
	Generates a save/update xml to be posted to the server.
	@method
	@param {object} options - options to be used during the call<br/>
	@param {Resource~onSuccess} options.onSuccess - a callback function called in case of a success
	@param {Resource~onFailure} [options.onFailure] - a callback function called in case of a failure
	@param {String} [options.baseUrl] - base URL. If not set the current base URL will be used
	@param {string} [options.status] - status of delegation (will be set to PENDING if null)
	@param {User} options.author - user delegating
	@param {User} options.contributor - user delegated
	@param {project} [options.project] - project associated
	@param {Date} options.startDate - expiration date
*/
UserDelegationList.prototype.generate_xml = function (options) {
	var v_baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	var v_start_date=this.toISOString(options.startDate);
	var v_status = options.status || 'PENDING';
	var v_auth_email = options.author.email;
	var v_auth_uri = options.author.selfUrl;
	var v_cont_email = options.contributor.email;
	var v_cont_uri = options.contributor.selfUrl;
	var v_projectCategory = ''
	if(options.project)v_projectCategory='<category term="project" label="'+options.project.id+'" />';
	var v_activationCategory = ''
	if(options.activationDate)v_activationCategory='<category term="activation_date" label="'+this.toISOString(options.activationDate)+'" />';
	var v_endCategory = ''
	if(options.endDate)v_endCategory='<category term="end_date" label="'+this.toISOString(options.endDate)+'" />'
	var xml = '<?xml version="1.0" encoding="UTF-8"?>'
				+'<feed xml:base="'+v_baseUrl+'" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2005/Atom">'
				+'	<id />'
				+'	  <entry>'
				+'		<title>Title</title>'
				+'		<category term="start_date" label="'+v_start_date+'" />'
				+'			<category term="status" label="'+v_status+'" />'
				+			v_projectCategory
				+			v_activationCategory
				+			v_endCategory
				+'		<author>'
				+'		  <email>'+v_auth_email+'</email>'
				+'					<uri>'+v_auth_uri+'</uri>'
				+'		</author>'
				+'		<contributor>'
				+'		  <email>'+v_cont_email+'</email>'
				+'					<uri>'+v_cont_uri+'</uri>'
				+'		</contributor>'
				+'		<id>1</id>'
				+'	  </entry>'
				+'</feed>'
				;

	return xml;
};

/**
	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
*/
UserDelegationList.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;
		}
};

Index

Classes

  • AccessLog
  • AllLaneUserList
  • AppInstanceReport
  • Context
  • Customer
  • CustomerDomainList
  • CustomerList
  • CustomerSubscriptionList
  • CustomerTrafficList
  • CustomList
  • CustomListList
  • Domain
  • Host
  • HostList
  • HostMode
  • I18n
  • I18nDico
  • Lane
  • LaneList
  • LanePoolList
  • LogLog
  • Metadata
  • Oauth
  • OauthList
  • Pool
  • PoolList
  • Preferences
  • Process
  • ProcessList
  • Project
  • ProjectAppliQuery
  • ProjectChildList
  • ProjectLaneList
  • ProjectList
  • ProjectProcess
  • ProjectProcessList
  • ProjectProcessQuery
  • ProjectVersion
  • ProjectVersionList
  • Report
  • RequestLog
  • Resource
  • SavedQuery
  • Subscription
  • Token
  • Traffic
  • Usage
  • User
  • UserAccessList
  • UserDelegation
  • UserDelegationList
  • UserLaneList
  • UserList
  • UserRepresentationList
  • UserSupportAuth
  • UserSupportAuthList
  • WebInterface
  • WebInterfaceList

Global

  • context

© Akorbi Digital RMP. All Rights Reserved - Legal terms - Contact