Logo

Docs

  • HOME

Source: User/UserDelegation.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 Delegation
	@constructor
	@property {String} startDate - string representation of the start of the delegation
	@property {String} status - Status of the delegation
	@property {User} author - the user that generated the delegation
	@property {User} contributor -  the contributor
	@see UserDelegationList
	@see Resource
*/
function UserDelegation(){
	this.startDate;
	this.activationDate;
	this.endDate;
	this.status;
	this.author;
	this.contributor;
	this.project;
	this.modifiedBy;
};
/**
	 @borrows
	 Inherits Resource
*/
UserDelegation.prototype = new  Resource();
/**
	Overrides Resource's loadPreset method.
	@method
	@see Resource#loadPreset
*/
UserDelegation.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
*/
UserDelegation.prototype.loadSet = function (rObject) {
	var father = this;
	var cats = father.entries[0].category;
	father.startDate = new Date(Resource.removeDecimalsFromDateString(father.termSearch('start_date',cats).label));

	var v_activationDate = father.termSearch('activation_date',cats);
	if(v_activationDate)father.activationDate = new Date(Resource.removeDecimalsFromDateString(v_activationDate.label));
	
	var v_endate = father.termSearch('end_date',cats);
	if(v_endate)father.endDate = new Date(Resource.removeDecimalsFromDateString(v_endate.label));
	
	var v_status = father.termSearch('status',cats);
	if(v_status)father.status = v_status.label;
	father.author = new User();
	father.author.email = rObject.entry.author.email;
	father.author.selfUrl = rObject.entry.author.uri;
	father.author.name = rObject.entry.author.name;
	father.contributor = new User();
	father.contributor.email = rObject.entry.contributor.email;
	father.contributor.selfUrl = rObject.entry.contributor.uri;
	father.contributor.name = rObject.entry.contributor.name;
	var v_project = father.termSearch('project',cats);
	if(v_project){
		father.project = new Project();
		father.project.id = v_project.label;
		father.project.selfUrl = Resource.findLink('project',father.entries[0].link);
	}
	var modifiedBylnk = Resource.findLinkObject('modifiedBy',father.entries[0].link);
	if(modifiedBylnk){
		del.modifiedBy = new User();
		del.modifiedBy.selfUrl=modifiedBylnk.href;
		del.modifiedBy.title = modifiedBylnk.title;
	}	
};
/**
 update a delegation with previously set values.
	@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
*/
UserDelegation.prototype.update = function (options) {
	var father = this;
	father.updatePreset = function () {
		father.generateUrl = function () {
			return father.selfUrl;
		};
		father.xml = father.generate_xml(options).trim();
	};
	father.resourceUpdate(options);
};
/**
	Activate a loaded delegation. The Activate function sets the Status to ACTIVE and updates the 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
*/
UserDelegation.prototype.Activate = function (options) {
			this.status = 'ACTIVE';
			this.update(options);
};
/**
	Deactivate a loaded delegation. The Deactivate function sets the Status to INACTIVE and updates the 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
*/
UserDelegation.prototype.Deactivate = function (options) {
			this.status = 'INACTIVE';
			this.update(options);
};
/**
	Pending a loaded delegation. The Pending function sets the Status to PENDING and updates the 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
*/
UserDelegation.prototype.setPending = function (options) {
			this.status = 'PENDING';
			this.update(options);
};
/**
	Delete delegation. The Delete function removes a loaded 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
*/
UserDelegation.prototype.deleteDelegation = function (options) {
	var father = this;
	father.deletePreset = function () {
		father.generateUrl = function () {
			return father.selfUrl;
		};
	};
	father.remove(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
*/
UserDelegation.prototype.generate_xml = function (options) {
	father = this;
	
	var v_baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	var v_start_date=this.toISOString(father.startDate);
	var v_status = father.status || 'PENDING';
	var v_auth_email = father.author.email;
	var v_auth_uri = father.author.selfUrl;
	var v_cont_email = father.contributor.email;
	var v_cont_uri = father.contributor.selfUrl;
	var v_projectCategory = ''
	if(father.project)v_projectCategory='<category term="project" label="'+father.project.id+'" />';
	var v_activationCategory = ''
	if(father.activationDate)v_activationCategory='<category term="activation_date" label="'+this.toISOString(father.activationDate)+'" />';
	var v_endCategory = ''
	if(father.endDate)v_endCategory='<category term="end_date" label="'+this.toISOString(father.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;
};

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