Logo

Docs

  • HOME

Source: User/User.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 User
  	@constructor
	@property {String} title - user's title
	@property {String} name - user's name
	@property {String} email - user's email
	@property {String} status - user's status
	@property {String} language - user's language
	@property {String} profile - user's profile
	@property {String} receive_alert - is the user marked to receive alert
	@property {String} password - user's password
	@property {Array} lanes - Array containing a list of lanes
	@property {Array} lanePools - Array containing a list of pools loaded from lanes;
	@property {Array} authorizations - Array containing a list of authorizations
	@property {Date} updated - The updated date and time
	@property {Object} author - Contains the data of the user's author
	@property {Object} extension - Contains the user's extension
	@property {Object} preference - Contains the user's preference
	@property {Array} poolLinks - List of pool links
	@property {Array} projects - List of projects
	@property {Array} delegations - Contains a list of delegations
	@property {Object} metadata - Contains the user's metadata
	@property {Object} preferences - Contains the user's preferences
	@property {Array} oauths - Contains the user's external applications authorizations
	@property {Array} accessRestrictions - List of access restrictions
	@property {String} billingStatus - is the user's bill status
	@property {String} clientLanguage - is the user's Client Language
	@property (Date) published - The published date 
	@see UserList
	@see Resource
	@example Load user from list
		var userList = new UserList();
		var optUL = {};
		optUL.onSuccess =  function(){
			var user = userList.users[0];
			var optU = {};
			optU.onSuccess =  function(){
				alert('User '+user.id+' loaded');
			};
			user.load(optU);
		};
		userList.load(optUL);
	@example Load logged in user data
		var user = new User();
		var optU = {};
		optU.onSuccess =  function(){
			alert('User '+user.id+' loaded');
		};
		user.load(optU);
 */
function User(){
	this.title;
	this.name;
	this.email;
	this.status;
	this.language;
	this.profile;
	this.receive_alert;
	this.password;
	this.lanes = [];
	this.acceptanceLanes = [];
	this.lanePools = [];
	this.laneUserType;
	this.authorizations = [];
	this.updated = new Date();
	this.author = {};
	this.extension = {};
	this.preference = {};
	this.poolLinks=[];
	this.projects=[];
	this.delegations = [];
	this.representations = [];
	this.metadata={};
	this.preferences={};
	this.oauths = [];
	this.oauths2 = [];
	this.accessRestrictions = [];
	this.billingStatus;
	this.clientLanguage;
	this.saveQuery = {};//DEPRECATED
	this.published = new Date();
};
/**
	 @borrows
	 Inherits Resource
*/
User.prototype = new  Resource();
/**
	Overrides Resource's loadPreset method.
	@method
	@see Resource#loadPreset
*/
User.prototype.loadPreset = function () {
	/**
		Overrides Resource's generateUrl method to return the request url
		@method
		@see Resource#generateUrl
	*/
	this.generateUrl = function () {
		return this.selfUrl||context.link.self;
	};
};
/**
	Overrides Resource's loadSet method to set local variables after request.
	@method
	@param {json} rObject - JSON representation of the loaded data.
	@see Resource#loadSet
*/
User.prototype.loadSet = function (rObject) {
	try {
		//-----------USER DATA
		this.title = rObject.title;
		this.name = rObject.author.name;
		this.email = rObject.author.email;
		this.author = rObject.author;
		var cat = this.categories;
		this.accessRestrictions = [];
			
		for (var i = 0; i < cat.length; i++) {
			switch (cat[i].term) {
				case 'profile':
					this.profile = cat[i].label;
					break;
				case 'language':
					this.language = cat[i].label;
					break;
				case 'client_language':
					this.clientLanguage = cat[i].label;
					break;
				case 'status':
					this.status = cat[i].label;
					break;
				case 'receive_alert':
					this.receive_alert = cat[i].label;
					break;
				case 'billing_status':
					this.billingStatus = cat[i].label;
					break;
				case 'access_restriction':
					this.accessRestrictions.push(cat[i].label);
			}
		}
		var ent=this.entries;
		for (var i = 0; i < ent.length; i++) {
			switch (ent[i].title) {
				case 'extension':
					var jsonrep=Resource.decodeBase64(ent[i].content.P_value);
					jsonrep = jsonrep.replace(/<([:A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][-.0-9\xB7\u0300-\u036F\u0203F-\u2040]*)([^>]*?)\s*?\/>/g, '');
					this.extension[Resource.findTerm('mode',ent[i].category).label]= jsonrep;
					break;
				case 'preferences':
					var jsonrep=Resource.decodeBase64(ent[i].content.P_value);
					jsonrep = jsonrep.replace(/<([:A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][-.0-9\xB7\u0300-\u036F\u0203F-\u2040]*)([^>]*?)\s*?\/>/g, '');
					//this.preference = jsonrep;
					this.preference[Resource.findTerm('mode',ent[i].category).label]= jsonrep;
					break;
			}
		}

		var meta = new Metadata();
		meta.selfUrl = this.linkSearch('metadata', this.getArray(this.object, 'link'));
		this.metadata = meta;
		var pref = new Preferences();
		pref.selfUrl = this.linkSearch('preferences', this.getArray(this.object, 'link'));
		this.preferences = pref;
	}catch (e) {
		alert(e);
	};
};
/**
 Overrides Resource's saveSet.
 @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
 @see Resource#createSet
*/
User.prototype.saveSet = function (options) {
 father = this;
 var opt = {};
 opt.onSuccess = function(){
  options.onSuccess();
 };
 opt.onFailure = function(e){
   options.eObject=e;
   father.errorManager(options);
 };
 opt.baseUrl = ' ';//the base url is set on save return
    father.load(opt);
};

//----------LANELIST
/**
Load a list of lanes.
@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
@param {Array} [options.filters] - an array of filters
@see Resource#load
@example Load Lanes
    function loadLanes(p_user){//user object
		p_user.loadLanes({
			onSuccess : function(){
				alert("there are " +p_user.lanes+" lanes");
			}
		});
	};
*/
User.prototype.loadLanes = function (options) {
	var father = this;
	var laneList = new UserLaneList();
	laneList.selfUrl = laneList.reconstructedLinkSearch('user_lane', father.links);
	var opt = {};
	opt.onSuccess = function(){
		father.lanes = laneList.lanes;
		father.lanePools = laneList.pools;
		options.onSuccess();
	};
	opt.onFailure = function(e){
		options.eObject=e;
		father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	opt.mode = options.mode;
	laneList.load(opt);
};
//----------LANELIST IN ACCEPTANCE
/**
Load a list of lanes.
@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
@param {Array} [options.filters] - an array of filters
@see Resource#load
@example Load Lanes
    function loadLanes(p_user){//user object
		p_user.loadLanes({
			onSuccess : function(){
				alert("there are " +p_user.lanes+" lanes");
			}
		});
	};
*/
User.prototype.loadAcceptanceLanes = function (options) {
	var father = this;
	var laneList = new UserLaneList();
	laneList.selfUrl = laneList.reconstructedLinkSearch('user_lane', father.links);
	var opt = {};
	opt.onSuccess = function(){
		father.lanes = laneList.lanes;
		father.lanePools = laneList.pools;
		options.onSuccess();
	};
	opt.onFailure = function(e){
		options.eObject=e;
		father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	opt.mode = 'ACCEPTANCE';
	laneList.load(opt);
};
/**
Load pools in a serialized manner
	@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 {Array} [options.filters] - an array of filters
	@param {Object} [options.pagination] -an Object with pagination variables (nb and first)
	@example Load Pools in a serialized manner
	function LoadPoolsSerialized(p_user){
		p_user.loadPoolsSerialized({
			onSuccess:function(){
				alert(JSON.stringify(p_user.pools));
				alert(JSON.stringify(p_user.lanes));
			}
		});
	}
*/
User.prototype.loadPoolsSerialized = function (options) {
	var father = this;
	if (father.lanes.lenght){//Check if lanes where loaded

		var opt = {};
		opt.onSuccess = function(){
			var laneList = new UserLaneList();
			laneList.lanes = father.lanes;
			laneList.pools = father.lanePools;
			laneList.loadPoolsSerialized(options);
		};
		opt.onFailure = function(e){
			options.eObject=e;
			father.errorManager(options);
		};
		opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
		opt.pagination = options.pagination;
		opt.filters = options.filters;
		father.loadLanes(opt);

	}else{
		var laneList = new UserLaneList();
		laneList.lanes = father.lanes;
		laneList.pools = father.lanePools;
		laneList.loadPoolsSerialized(options);
	}
};
//---------END LANELIST
//---------AUTHORIZATIONS
/**
	Load a list of Authorizations.
	@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
	@param {Array} [options.filters] - an array of filters
	@param {Object} [options.pagination] -an Object with pagination variables (nb and first)
	@param {Array} [options.filters] - an array of filters
	@see Resource#load
	@example Load Authorizations
		function loadAuth(p_user){//user object
			p_user.loadAuthorizations({
				onSuccess : function(){
					alert("there are " +p_user.authorizations.length+" authorizations");
				}
			});
		};
*/
User.prototype.loadAuthorizations = function (options) {
	var father = this;
	var authList = new UserSupportAuthList();
	authList.selfUrl = authList.reconstructedLinkSearch('support_auth', father.links);
	var opt = {};
	opt.onSuccess = function(){
		father.authorizations = authList.authorizations;
		options.onSuccess();
	};
	opt.onFailure = function(e){
			options.eObject=e;
			father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	authList.load(opt);
};
/**
Create new support authorizations for a specific user.
	@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.email - email of the user to authorize
	@param {Date} options.expires - expiration date
*/
User.prototype.createAuthorization = function (options) {
	var authList = new UserSupportAuthList();
	var father = this;
	authList.selfUrl = father.linkSearch('support_auth', father.links);
	authList.xml = authList.generate_xml(options.email,options.expires, options.baseUrl).trim();
	authList.resourceSave(options);
};
//---------END AUTHORIZATIONS
//---------DELEGATIONS
/**
Load a list of Delegations.
@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
@param {Array} [options.filters] - an array of filters
@see Resource#load
@example Load Delegations
    function loadDel(p_user){//user object
		p_user.loadDelegations({
			onSuccess : function(){
				alert("there are " +p_user.delegations.length+" delegations");
			}
		});
	};
*/
User.prototype.loadDelegations = function (options) {
	var father = this;
	var delList = new UserDelegationList();
	delList.selfUrl = delList.reconstructedLinkSearch('delegation', father.getArray(father.object, 'link'));
	var opt = {};
	opt.onSuccess = function(){
		father.delegations = delList.delegations;
		options.onSuccess();
	};
	opt.onFailure = function(e){
			options.eObject=e;
			father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	delList.load(opt);
};

//Duplicate Deprecated
User.prototype.createDelegation = function (options) {
	var delList = new UserDelegationList();
	var father = this;
	delList.selfUrl = father.linkSearch('delegation', father.links);
	delList.xml = delList.generate_xml(options).trim();
	delList.resourceSave(options);
};
/**
Load a list of Representations.
@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
@param {Array} [options.filters] - an array of filters
@see Resource#load

*/
User.prototype.loadRepresentations = function (options) {
	var father = this;
	var delList = new UserRepresentationList();
	delList.selfUrl = delList.reconstructedLinkSearch('representation', father.getArray(father.object, 'link'));
	var opt = {};
	opt.onSuccess = function(){
		father.representations = delList.representations;
		options.onSuccess();
	};
	opt.onFailure = function(e){
			options.eObject=e;
			father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	delList.load(opt);
};
//---------END DELEGATIONS
//---------OAUTH (external apps)
/**
Load a list of Oauths.
@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
@param {Array} [options.filters] - an array of filters
@see Resource#load
@example Load Oauths
    function loadOauths(p_user){//user object
		p_user.loadOauths({
			onSuccess : function(){
				alert("there are " +p_user.oauths.length+" oauths");
			}
		});
	};
*/
User.prototype.loadOauths = function (options) {
	var father = this;
	var oauthList = new OauthList();
	oauthList.selfUrl = oauthList.reconstructedLinkSearch('oauth_access', father.getArray(father.object, 'link'));
	var opt = {};
	opt.onSuccess = function(){
		father.oauths = oauthList.oauths;
		options.onSuccess();
	};
	opt.onFailure = function(e){
			options.eObject=e;
			father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	oauthList.load(opt);
};
/**
Load a list of Oauths.
@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
@param {Array} [options.filters] - an array of filters
@see Resource#load
@example Load Oauths
    function loadOauths(p_user){//user object
		p_user.loadOauths({
			onSuccess : function(){
				alert("there are " +p_user.oauths.length+" oauths");
			}
		});
	};
*/
User.prototype.loadOauths2 = function (options) {
	var father = this;
	var oauthList = new OauthList();
	oauthList.selfUrl = oauthList.reconstructedLinkSearch('oauth2_services_access', father.getArray(father.object, 'link'));
	var opt = {};
	opt.onSuccess = function(){
		father.oauths2 = oauthList.oauths;
		options.onSuccess();
	};
	opt.onFailure = function(e){
			options.eObject=e;
			father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	oauthList.load(opt);
};
//---------END OAUTH

/**
	Overrides Resource's savePreset method.DEPRECATED
	@method
	@see Resource#savePreset
*/
User.prototype.savePreset = function () {
	/**
		Overrides Resource's generateUrl method to return the Post url
		@method
		@see Resource#generateUrl
	*/
};
/**
  Create a new User.
	@method
	@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
	@see Resource#resourceSave
	@example Create a User
        var user = new User();
		user.name = 'UserName';
		user.email = 'uName@domain.com';
		user.create({
			onSuccess : function(){
			alert('User '+user.id+' created!');
			}
		});
 */
User.prototype.create = function (options) {
	var father = this;
	var userList =  new UserList();

	/**
		Overrides Resource's savePreset method.
		@method
		@see Resource#savePreset
	*/
	userList.savePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		userList.generateUrl = function () {
			userList.selfUrl = context.link.user;
			return userList.selfUrl;
		};
	};
	var opt = {};
	opt.onSuccess = function(rData){
		father.object = rData;
		father.id = father.object.id;
		father.entries = father.getArray(father.object, "entry");
		father.categories = father.getArray(father.object, "category");
		father.links = father.getArray(father.object, "link");
		father.selfUrl = father.linkSearch('self', father.links);
		father.rights = father.object.rights;
	    father.loadSet(father.object);
	    options.onSuccess(father.object);
	};
	opt.onFailure = function(e){
		options.eObject=e;
		father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.update = false;
	userList.xml = father.generate_xml(false).trim();
	userList.save(opt);

};

/**
	Overrides Resource's updatePreset method.
	@method
	@see Resource#updatePreset
*/
User.prototype.updatePreset = function () {
	/**
		Overrides Resource's generateUrl method to return the Post url
		@method
		@see Resource#generateUrl
	*/
	this.generateUrl = function () {
		return this.selfUrl;
	};
	this.xml = this.generate_xml(false).trim();
};
/**
	Override Resource update method.
	@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
	@see Resource#update
	@example Update a User
        function updateAUser(p_user){//user object
			p_user.name = p_user.name+'new';
			p_user.update({
			onSuccess : function(){
							alert('user '+p_user.id+' updated!');
						}
			});

		};
 */
User.prototype.update = function (options) {
	var father = this;
	/**
		Overrides Resource's updatePreset method.
		@method
		@see Resource#updatePreset
	*/
	father.updatePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		father.generateUrl = function () {
			return father.selfUrl;
		};
		father.xml=father.generate_xml(false).trim();
	};
	father.resourceUpdate(options);
};
/** DEPRECATED
	Sets the user status to inactive and posts it to the server
	@deprecated
	@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
 */
User.prototype.userDeactivate = function (options) {
	var father = this;
	/**
		Overrides Resource's updatePreset method.
		@method
		@see Resource#updatePreset
	*/
	father.updatePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		father.generateUrl = function () {
			return father.selfUrl;
		};
		father.status = father.harcodedValues('STATUS','I');
		father.xml = father.generate_xml(false).trim();
	};
	father.resourceUpdate(options.onSuccess, options.onFailure, options.baseUrl);
};

/**
	Generates a save/update xml to be posted to the server
	@method
	@param {Boolean} p_ischangepass - flag to add the password category to the xml
	@param {Array} [p_addCategories] - additional categories to be added to the xml
	@param {String} [baseUrl] - base URL. If not set the current base URL will be used
 */
User.prototype.generate_xml = function (p_ischangepass,p_addCategories, baseUrl) {
	var v_baseUrl = baseUrl || RMPApplication.getBaseUrl();
	var v_title = this.title || this.name;
	var v_status = this.status || this.harcodedValues('STATUS','P');
	var v_language = this.language || 'en';
	var v_clientLanguage ='';
	if(this.clientLanguage)v_clientLanguage='<category term="client_language" label="'+this.clientLanguage+'"/>';
	var v_profile = this.profile ||  this.harcodedValues('PROFILE','U');
	var v_receive_alert = this.receive_alert || 'false';
	var v_addCat = '';
	
	
	var v_extension = '';//Resource.encodeBase64(this.extension)||"e30=";
	for (var key in this.extension) {
		if (this.extension.hasOwnProperty(key)) {
			var extVal = "e30";
			if(this.extension[key]) extVal=Resource.encodeBase64(this.extension[key]);
			v_extension=v_extension+
				'<entry>'+
					'<title>extension</title>'+
					'<category term="mode" label="'+key+'"/>'+
					'<content type="text/base64">'+extVal+'</content>'+
				'</entry>';
		}
	}
	var v_preferences = '';//Resource.encodeBase64(this.preference)||"e30=";	
	for (var key in this.preference) {
		if (this.preference.hasOwnProperty(key)) {
			var preVal = "e30";
			if(this.preference[key]) preVal=Resource.encodeBase64(this.preference[key]);
			v_preferences=v_preferences+
				'<entry>'+
					'<title>preferences</title>'+
					'<category term="mode" label="'+key+'"/>'+
					'<content type="text/base64">'+ preVal+'</content>'+
				'</entry>';
		}
	}
	if (p_addCategories !== undefined) {
		for (var i = 0; i < p_addCategories.length; i++) {		
			v_addCat = v_addCat + ' <category term="' + p_addCategories[i][1] + '" label="' + p_addCategories[i][2] + '"/>';
		}
	}
	if (p_ischangepass) {
		v_addCat = v_addCat + ' <category term="password" label="' + this.password + '"/>';
	}
	for (var i = 0; i < this.accessRestrictions.length; i++) {		
		v_addCat = v_addCat + ' <category term="access_restriction" label="' + this.accessRestrictions[i] + '"/>';
	}
	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"> '
	+ '<title>' + v_title + '</title> '
	+ '<rights>(c) RunMyProcess</rights> '
	+ '<category term="status" label="' + v_status + '"/> '
	+ '<category term="language" label="' + v_language + '"/> '
	+ v_clientLanguage
	+ '<category term="profile" label="' + v_profile + '"/> '
	+ '<author> ' + '<name>' + this.name + '</name> '
	+ '<email>' + this.email + '</email> ' + '</author> '
	+ '<category term="receive_alert" label="' + v_receive_alert + '"/>' + v_addCat
	+ v_extension
	+ v_preferences
	/*+ ' <entry> ' 
	+ '<title>extension</title> '
	+ '<content type="text/base64">'+v_extension+'</content> '
	+ '</entry> '
	+ '	<entry> '
	+ '<title>preferences</title> '
	+ '<content type="text/base64">'+v_preferences+'</content> '
	+ '</entry> '*/
	+ '</feed>';

	return xml;
};
/**
  Reset a user's password.
	@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
 */
User.prototype.resetPassword = function (options) {
	var father = this;
	/**
		Overrides Resource's generateUrl method to return the request url
		@method
		@see Resource#generateUrl
	*/
	this.generateUrl = function () {
		return this.linkSearch('reset_password', father.links);
	};
	this.remove(options);
};
/**
  Create new support authorizations for a specific user.
	@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.email - email of the user to be authorized
	@param {String} options.expires - representation on when the authorization expires
 */
User.prototype.saveAuth = function (options) {
	var auth1 = new Support_auth();
	/**
		Overrides Resource's savePreset method.
		@method
		@see Resource#savePreset
	*/
	auth1.savePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		auth1.generateUrl = function () {
			return auth1.selfUrl;
		};
	};
	auth1.xml = auth1.generate_xml(options.email,options.expires, options.baseUrl).trim();
	auth1.selfUrl = this.linkSearch('suport_auth', this.links);
	auth1.save(options);
};
/**
* Delete specific support authorizations of a user.
	@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.authId - id of the authorization to be deleted
 */
User.prototype.deleteAuth = function (options) {
	var father = this;
	var auth1 = new Support_auths();
	/**
		Overrides Resource's deletePreset method.
		@method
		@see Resource#deletePreset
	*/
	auth1.deletePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		auth1.generateUrl = function () {
			return auth1.selfUrl;
		};
	};
	auth1.selfUrl = father.linkSearch('suport_auth', father.getLinks())+options.authId;
	auth1.loadSet = function (rObject) {
	   // this.setAuth(auth1);
	};
	auth1.remove(options);
};
/**
	Change a user's password.
	@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.password] - the new password to be set
*/
User.prototype.changePassword = function(options){
	var father = this;
	/**
		Overrides Resource's updatePreset method.
		@method
		@see Resource#updatePreset
	*/
	father.updatePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		father.generateUrl = function () {
			return father.selfUrl;
		};
		father.password = options.password;
		father.xml = father.generate_xml(true).trim();
	};
	father.resourceUpdate(options);
};
/**
	Load user peojects.
	@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 {Object} [options.pagination] -an Object with pagination variables (nb and first)
	@param {Array} [options.filters] - an array of filters
*/
User.prototype.loadProjects = function (options) {
	var father = this;
	var pl = new ProjectList();
	/**
		Overrides Resource's loadPreset method.
		@method
		@see Resource#loadPreset
	*/
	pl.loadPreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		pl.generateUrl = function () {
			return pl.selfUrl;
		};
	};
	var entries = father.getArray(context.object, 'entry');
	pl.selfUrl = pl.reconstructedLinkSearch('project', father.entryLinks(entries));
	var opt = [];
	opt.onSuccess = function (rObject) {
		father.projects = pl.projects;
	    options.onSuccess(father.object);
	};
	opt.onFailure = function(e){
		options.eObject=e;
		father.errorManager(options);
	};
	opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	opt.update = false;
	opt.pagination = options.pagination;
	opt.filters = options.filters;
	pl.load(opt);
};
/**
	Create new delegation for a specific user.
	@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 {User} options.delegatedUser - the user to be delegated
	@param {Date} options.startDate - the date in which the delegation becomes active
*/
User.prototype.saveDelegation = function (options) {
	var del1 = new UserDelegation();
	/**
		Overrides Resource's savePreset method.
		@method
		@see Resource#savePreset
	*/
	del1.savePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		del1.generateUrl = function () {
			return del1.selfUrl;
		};
	};
	del1.startDate = this.toISOString(options.startDate);
	del1.status = this.harcodedValues('STATUS','P');
	del1.authorEmail = this.object.author.email;
	del1.contributorEmail = options.delegatedUser.email;
	del1.authorUrl = this.selfUrl;
	del1.contributorUrl = options.delegatedUser.selfUrl;
	del1.xml = del1.generate_xml(options.baseUrl).trim();
	del1.selfUrl = this.linkSearch('delegation', this.getArray(this.object, 'link'));
	del1.save(options.onSuccess, options.onFailure, options.baseUrl);
};
/**
	Loads the user currently logged id
	@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
*/
User.prototype.loadLogginUser = function (options) {
	this.selfUrl = undefined;
	this.load(options);
};
/**
	Retrieve harcoded values for the user class.
 	@param {String} paramGroup - group of parameters
	@param {String} localID - the local identifier
	@return {String} value - the return hardcoded value
*/
User.prototype.harcodedValues = function (paramGroup, localID) {
	 switch (paramGroup) {
			case 'STATUS':
				switch (localID) {
							case 'A':
								return 'ACTIVE';
								break;
							case 'P':
								return 'PENDING';
								break;
							case 'I':
								return 'INACTIVE';
								break;
							default:
								return undefined;
						}
				break;
			case 'DELESTATUS':
				switch (localID) {
							case 'A':
								return 'ACTIVE';
								break;
							case 'P':
								return 'PENDING';
								break;
							case 'I':
								return 'INACTIVE';
								break;
							default:
								return undefined;
						}
				break;
			case 'PROFILE':
				switch (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