Logo

Docs

  • HOME

Source: Process/Process.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 Process
	@constructor
	@property {User} author - Contains the author's information.
	@property {String} title - the title of the process
	@property {Date} published = new Date(); - the published date
	@property {User} cotributor = new User(); - the contributor
	@property {Date} updated - the updated date
	@property {String}  generator - the generator
	@property {Object} process - the process
	@property {Object} summary - the summary of the process (value and type)


	@see ProcessList
	@see Resource
*/
function Process(){
	this.title;
	this.published = new Date();
	this.author=new User();
	this.contributor = new User();
	this.updated = new Date();
	this.generator;
	this.base;
	this.process = {};
	//this.diagram = {};
	this.summary={};
	this.project = new Project();
};
/**
	 @borrows
	 Inherits Resource
*/
Process.prototype = new  Resource();
/**
	Overrides Resource's loadPreset method.
	@method
	@see Resource#loadPreset
*/
Process.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
*/
Process.prototype.loadSet = function (rObject) {
	var father = this;
	father.generator = rObject.generator;
	father.author = new User();
	father.author.name = rObject.author.name;
	father.author.selfUrl = rObject.author.uri;
	father.contributor.name = rObject.contributor.name;
	father.contributor.selfUrl = rObject.contributor.uri;
	father.title = rObject.title;
	father.updated = new Date(rObject.updated);
	father.published = new Date(father.entries[0].published);
	father.links = father.links.concat(father.getArray(father.entries[0], "link"));
	father.process = father.entries[0].process;
	//father.diagram = father.entries[0].diagram;
	father.project = new Project();
	var projectLink = father.linkObjectSearch('project', father.getArray(rObject.entry, 'link'));
	father.project.selfUrl = projectLink.href;
	father.project.title = projectLink.title;
	father.project.id = projectLink.type;
	father.base = rObject.base;
	if (father.entries[0].summary){
		father.summary.value = father.entries[0].summary.P_value;
		father.summary.type =  father.entries[0].summary.type;
	}
};
/**
  Create a new Process.
	@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
	@param {String} [options.process] - the process xml
	@see Resource#resourceSave
 */
Process.prototype.create = function (options) {
	var father = this;
	var processList = new ProcessList();

	/**
		Overrides Resource's savePreset method.
		@method
		@see Resource#savePreset
	*/
	processList.savePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		processList.generateUrl = function () {
			processList.selfUrl = context.link.customerConfig + "process/";//HARDCODED
			return processList.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;

	var defCat = father.getDefaultCategories();
	var defExists = false;
	for (var i = 0 ; i<defCat.length;i++) {
	    defExists = false;
        for (var j = 0 ; j<father.categories.length;j++) {
            if (defCat[i].term===father.categories[j].term){
              defExists = true;
              break;
            }
        }
        if (!defExists){
           father.categories.push(defCat[i]);
        }
	}

	var defLks = father.getDefaultLinks();
	defExists = false;
	for (var i = 0 ; i<defLks.length;i++) {
	    defExists = false;
        for (var j = 0 ; j<father.links.length;j++) {
            if (defLks[i].term===father.links[j].term){
              defExists = true;
              break;
            }
        }
        if (!defExists){
           father.links.push(defLks[i]);
        }
	}

	opt.process = options.process;
	//opt.diagram = options.diagram;
	opt.processListUrl=processList.selfUrl;
	processList.xml = father.generate_xml(opt).trim();
	processList.save(opt);

};
/**
  Save an existing Process.
	@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
 */
 Process.prototype.update = function (options){
	var father = this;
	/**
		Overrides Resource's savePreset method.
		@method
		@see Resource#savePreset
	*/
	father.updatePreset = function () {
		/**
			Overrides Resource's generateUrl method to return the request url
			@method
			@see Resource#generateUrl
		*/
		father.generateUrl = function () {
			return father.selfUrl;
		}
	};
	var procOpt = {};
	procOpt.onSuccess = function(rData){
		if(rData.feed){
			father.object = rData.feed;
			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);
		}else{
			father.object = rData;
		}
	    options.onSuccess(father.object);
	}
	procOpt.onFailure = function(e){
		options.eObject=e;
		father.errorManager(options);
	};
	procOpt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	procOpt.update = true;
	procOpt.process = options.process || father.process;
	//procOpt.diagram = options.diagram || father.diagram;
	father.xml = father.generate_xml(procOpt).trim();
	father.resourceUpdate(procOpt);
 };

/**
  generate xml to create/update
	@method
	@param {object} options - options to be used during the call<br/>
	@param {Boolean} options.update - Is this an xml for update
	@param {String} [options.baseUrl] - base URL. If not set the current base URL will be used
	@see Resource#resourceSave
 */
Process.prototype.generate_xml = function (options) {
	var father=this;
	var v_baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
	var v_title = father.encodeHTML(father.title);
	var v_process = '';
	var v_process = options.process;
	/*var v_diagram = '';
	if(options.diagram) v_diagram = JSON.stringify(options.diagram);*/
	var v_selfUrl = options.processListUrl;
	var v_authorURL = father.author.selfUrl || context.link.self;
	var v_rights = father.rights || '(c) RunMyProcess';
	var v_addCat = '';
	if (father.categories !== undefined) {
		for (var i = 0 ; i<father.categories.length;i++) {
		   var obj = father.categories[i];
		   v_addCat = v_addCat + '<category ';
		   for (var prop in obj) {
				v_addCat = v_addCat + prop +'="'+father.encodeHTML(obj[prop])+'" ';
		   }
		   v_addCat = v_addCat + '/>';
		}
	}
	var v_links = '';
	if (father.links !== undefined) {
		for (var i = 0 ; i<father.links.length;i++) {
		   var obj = father.links[i];
		   v_links = v_links + '<link ';
		   for (var prop in obj) {
				v_links = v_links + prop +'="'+father.encodeHTML(obj[prop])+'" ';
		   }
		   v_links = v_links + '/>';
		}
	}
	var v_summaryType = father.summaryType || 'text/base64';
	var v_summary = father.encodeHTML(father.summary.P_value) || '';
	var v_projectUrl = father.project.selfUrl;


	var xml = '<feed xml:base="'+RMPApplication.getBaseUrl()+'" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2005/Atom" xmlns:p="http://www.runmyprocess.com/library/">'
		+ '<title>'+v_title+'</title>'
		+ '<link rel="self" href="'+v_selfUrl+'"/>'
		+ '<rights>'+v_rights+'</rights>'
		+ '<author>'
		+ '	<uri>'+v_authorURL+'</uri>'
		+ '</author>'
		+ '<entry>'
		+ '	<title>'+v_title+'</title>'
		+ '	<link rel="project" href="'+v_projectUrl+'"/>'
		+	v_process
		//+ 	v_diagram
		+ '	<summary>'
		+ 	v_summary
		+ '	</summary>'
		+	v_addCat
		+	v_links
		+ '</entry>'
	+ '</feed>';


	return xml;

};

Process.prototype.getDefaultCategories = function () {
	return [
		{term:'type', label:'PROCESS'},
		{term:'public_access', label:'false'}
	];
};
Process.prototype.getDefaultLinks = function () {
	return [];
};








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