/**
*
* 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 Project
@constructor
@property {Array} versions - Array of versions
@property {String} title - title of the project
@property {Array} webInterfaces - Array of web interfaces
@property {Object} summary - Contains the projects summery
@property {User} author - Contains the author's information.
@property {Object} content - Contains the content data
@property {Date} updated - The updated date and time
@property {Object} creationLane - The updated date and time
@property {Array} usersLanes - The Lanes associated to the project
@property {Array} customLists - The customLists associated to the project
@property {Array} lanes - The lanes associated to the project
@property {Array} pools - The pools associated to the project
@property {String} type - The project type
@property {Array} childs - A list of Child projects
@property {Boolean} isLoadedChild - Flag that represents if the project was loaded as a child
@see ProjectList
@see Resource
@example Load project
var proList = new ProjectList();
proList.load({
onSuccess : function(){
p.load({
onSuccess : function(){
alert("Project loaded");
}
});
}
});
*/
function Project(){
this.versions = [];
this.title;
this.webInterfaces = [];
this.summary = {};
this.author = new User();
this.content = {};
this.updated = new Date();
this.creationLane = new Lane();
this.supervisorLane = new Lane();
this.usersLanes = [];
this.customLists = [];
this.lanes = [];
this.pools = [];
this.type;
this.childs = [];
this.isLoadedChild=false;
this.wiReports = [];
this.wfReports = [];
};
/**
@borrows
Inherits Resource
*/
Project.prototype = new Resource();
/**
Overrides Resource's loadPreset method.
@method
@see Resource#loadPreset
*/
Project.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
*/
Project.prototype.loadSet = function (rObject) {
var father = this;
var pverList = new ProjectVersionList();
var projObj = father.object;
var verLink = father.linkSearch('version', father.getArray(projObj.entry, 'link'));
var modeLink = father.linkSearch('update_production_version', father.getArray(projObj.entry,'link'));
father.changeModeUrl = modeLink;
pverList.selfUrl = verLink;
father.versionList = pverList;
father.links = father.links.concat(father.getArray(projObj.entry, 'link'));
if (rObject.author){
father.author.name = rObject.author.name;
father.author.selfUrl = rObject.author.uri;
}
father.usersLanes = [];
for(var i =0; i<father.links.length;i++ ){
if (father.links[i].type=='USER'){
var lane = new Lane();
lane.selfUrl = father.links[i].href;
lane.title = father.links[i].title;
lane.isLoadedUserLane = true;
father.usersLanes.push(lane);
}
}
father.type=father.termSearch('project_type',rObject.entry.category).label;
};
/**
Load a list the list of Web Interface Reports.
@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
*/
Project.prototype.loadWIReports = function(options){
var father = this;
var paq = new ProjectAppliQuery();
paq.selfUrl = father.linkSearch('appliquery', father.links);
var opt = {};
opt.onSuccess = function(rObject){
father.wiReports=paq.reports;
options.onSuccess(rObject);
};
opt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
opt.pagination = options.pagination;
opt.filters = options.filters;
paq.load(opt);
}
/**
Load a list the list of workflow Reports.
@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
*/
Project.prototype.loadWFReports = function(options){
var father = this;
var ppq = new ProjectProcessQuery();
ppq.selfUrl = father.linkSearch('processquery', father.links);
var opt = {};
opt.onSuccess = function(rObject){
father.wiReports=ppq.reports;
options.onSuccess(rObject);
};
opt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
opt.pagination = options.pagination;
opt.filters = options.filters;
ppq.load(opt);
}
/**
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
*/
Project.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);
};
/**
Load a list the list of webInterfaces.
@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 webInterfaces
function loadwebInterface(p_project){//project object
p_project.loadWebInterfaces({
onSuccess:function(){
alert("there are " +p_project.webInterfaces.length+" web interfaces");
}
});
};
*/
Project.prototype.loadWebInterfaces = function (options) {
var father = this;
var WIList = new WebInterfaceList();
var pLink=father.linkSearch("appli",father.links);//context.link.customerConfig+"appli";//HARDCODED!!!!
father.defaultFilters.push({
"filter":"PROJECT",
"operator":"EE",
"value":father.id
}); //equivalent to ?filter=PROJECT&operator=EE&value="+this.id;//
WIList.selfUrl = pLink;
var opt = {};
opt.onSuccess = function(){
father.webInterfaces = WIList.webInterfaces;
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.orderBy = options.orderBy;
WIList.load(opt);
};
/**
Load a list the list of children projects.
@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 children projects
function LoadChildren(p_project){//project object
p_project.loadChildren({
onSuccess:function(){
alert(p_project.childs.length);
}
});
};
*/
Project.prototype.loadChildren = function (options) {
var father = this;
father.childs=[];
var childList = new ProjectChildList();
var cLink=childList.reconstructedLinkSearch('child_project', father.getArray(father.entries[0], 'link'));
if(cLink){
childList.selfUrl = cLink;
var opt = {};
opt.onSuccess = function(){
father.childs = childList.projects;
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;
childList.load(opt);
}
};
/**
Load a list the list of versions.
@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 versions
function LoadVersions(p_project){//project object
p_project.loadVersions({
onSuccess:function(){
alert(p_project.versions.length);
}
});
};
*/
Project.prototype.loadVersions = function (options) {
var father = this;
var verList = new ProjectVersionList();
var pLink=verList.reconstructedLinkSearch('version', father.getArray(father.entries[0], 'link'));//context.link.customerConfig;
verList.selfUrl = pLink;
var opt = {};
opt.onSuccess = function(){
father.versions = verList.versions;
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;
verList.load(opt);
};
/**
Load a list the list of UserLanes.
@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 ProjectLanes
function LoadLanes(p_project){//project object
p_project.loadLanes({
onSuccess : function(){
l=p_project.lanes[0];
l.load({
onSuccess : function(){
alert(l.title);
}
});
}
});
};
*/
Project.prototype.loadLanes = function (options) {
var father = this;
var laneList = new ProjectLaneList();
var pLink=laneList.reconstructedLinkSearch('lanes', father.getArray(father.entries[0], 'link'));
laneList.selfUrl = pLink;
var opt = {};
opt.onSuccess = function(){
father.lanes = laneList.lanes;
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;
laneList.load(opt);
};
/**
Load a list the list of UserLanes with pools.
@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 and pools
function LoadLanesWithPools(p_project){//project object
p_project.loadLanesAndPools({
onSuccess:function(){
alert("there are " +p_project.lanes.length+" lanes and "+p_project.pools.length+" pools");
}
});
};
*/
Project.prototype.loadLanesAndPools = function (options) {
var father = this;
var laneList = new ProjectLaneList();
var pLink=laneList.reconstructedLinkSearch('lanes', father.getArray(father.entries[0], 'link'));
laneList.selfUrl = pLink;
var opt = {};
opt.onSuccess = function(){
father.lanes = laneList.lanes;
poolOpt = {};
poolOpt.onSuccess = function(){
father.pools = laneList.pools;
options.onSuccess();
};
poolOpt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
poolOpt.baseUrl =options.baseUrl || RMPApplication.getBaseUrl();
laneList.loadPoolsSerialized(poolOpt);
};
opt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
opt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
opt.pagination = options.pagination;
opt.filters = options.filters;
laneList.load(opt);
};
/**
Load a list the CustomLists.
@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 CustomLists
function LoadCustomLists(p_project){//project object
var opt={};
opt.onSuccess=function(){
alert("there are " +p_project.customLists.length+" custom lists");
}
p_project.loadCustomLists(opt);
};
*/
Project.prototype.loadCustomLists = function (options) {
var father = this;
var customListList = new CustomListList();
customListList.selfUrl = customListList.linkSearch('customlist', father.getArray(father.entries[0], 'link'));
var opt = {};
opt.onSuccess = function(){
father.customLists = customListList.customLists;
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;
customListList.load(opt);
};
/**
Create a new Project.
@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
*/
Project.prototype.create = function (options) {
var father = this;
var projectList = new ProjectList();
projectList.selfUrl = context.link.project;
/**
Overrides Resource's savePreset method.
@method
@see Resource#savePreset
*/
projectList.savePreset = function () {
/**
Overrides Resource's generateUrl method to return the request url
@method
@see Resource#generateUrl
*/
projectList.generateUrl = function () {
return projectList.selfUrl;
};
};
var pOpt = {};
pOpt.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);
};
pOpt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
pOpt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
pOpt.update = false;
projectList.xml = father.generate_xml(pOpt).trim();
projectList.save(pOpt);
};
/**
Save a new Project.
@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
*/
Project.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 pOpt = {};
pOpt.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);
};
pOpt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
pOpt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
pOpt.update = true;
pOpt.usersLanes = options.usersLanes || '';
father.xml = father.generate_xml(pOpt).trim();
father.resourceUpdate(pOpt);
};
/**
Update Project Mode.
@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
*/
Project.prototype.updateMode = 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.changeModeUrl;
};
};
var pOpt = {};
pOpt.onSuccess = function(rData){
options.onSuccess(rData);
};
pOpt.onFailure = function(e){
options.eObject=e;
father.errorManager(options);
};
pOpt.baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
pOpt.update = true;
var v_mode = (options.mode==='TEST'?'test_version':options.mode) || 'test_version';
switch(v_mode){
case 'ACCEPTANCE': v_mode = 'acceptance_version'; break;
case 'PRODUCTION': v_mode = 'production_version'; break;
default: break;
}
pOpt.modeXml = '<link rel="'+v_mode+'" href="'+options.version.selfUrl+'"/>';
father.xml = father.generate_xml(pOpt).trim();
father.resourceUpdate(pOpt);
};
/**
generate xml to create/update
@method
@param {String} [options.baseUrl] - base URL. If not set the current base URL will be used
@see Resource#resourceSave
*/
Project.prototype.generate_xml = function (options) {
var father = this;
var v_baseUrl = options.baseUrl || RMPApplication.getBaseUrl();
var v_title = father.encodeHTML(father.title);
var v_rights = father.rights || '(c) RunMyProcess';
var v_mode = options.modeXml || '';
var v_summaryType = father.summary.type || 'html';
var v_summary = father.encodeHTML(father.summary.data) || '';
var v_laneUrl = "";
var v_usersLinks = "";
var v_type="";
var v_newChildren="";
if(father.type){
v_type='<category term="project_type" label="'+father.type+'" />';
}
if(father.creationLane.selfUrl){
v_laneUrl =v_laneUrl+'<link rel="lane-added" type="DESIGNER" href="'+father.creationLane.selfUrl+'"/>'
};
if(father.supervisorLane.selfUrl){
v_laneUrl =v_laneUrl+'<link rel="lane-added" type="SUPERVISOR" href="'+father.supervisorLane.selfUrl+'"/>'
};
if(father.usersLanes.length !== 'undefined'){
for(var i =0; i<father.usersLanes.length;i++ ){
var relType = 'lane';
if (father.usersLanes[i].isRemove)relType = 'lane-removed';
if(!father.usersLanes[i].isLoadedUserLane)v_usersLinks +='<link rel="'+relType
+'" type="USER" href="'+father.usersLanes[i].selfUrl
+'" title="'+father.usersLanes[i].title+'"/>';
}
}
if(father.childs.length !== 'undefined'){
for(var i =0; i<father.childs.length;i++ ){
if(!father.childs[i].isLoadedChild)v_usersLinks +='<link rel="child_project" type="ADDED" href="'+father.childs[i].selfUrl+'"/>';
}
}
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>'+v_rights+'</rights> '
+ '<entry> '
+ '<title>' + v_title + '</title> '
+ '<summary type="'+v_summaryType+'">'+v_summary+' </summary>'
//+ '<link rel="lane-added" type="DESIGNER" href="'+v_laneUrl+'"/>'
+ v_laneUrl
+ v_usersLinks
+ v_newChildren
+ v_mode
+ v_type
+ '<category term="version_policy" label="OLD"/>'
//+ '<link rel="lane-added" type="DESIGNER" href="config/620821136/pool/97462/lane/100431"/>'
+ '</entry> '
+ '</feed>';
return xml;
};