Posted By

nialace on 05/05/11


Tagged

meibo


Versions (?)

liste des tâches workflow


 / Published in: JavaScript
 

  1. // Resume an activity in waiting state
  2. // return true if resuming success or throws an error if an error is found.
  3. //@param include_deadline has to be "true" for including deadlines in the response
  4. function /*boolean*/ MPP_getUserActivities( /*String*/ from, /*String*/ search_attribute_name, /*String*/ search_attribute_value, /*String*/ include_deadline, /*String*/ language) /*thows error*/ {
  5.  
  6.  
  7. var userEntry = null;
  8.  
  9. if((language!=null) && (language!="")){
  10. meibo.setUserLanguage(language);
  11. }
  12.  
  13. //var /*String*/ request = beginRequest(from, "MPP_getUserActivities");
  14.  
  15. var jsonResponse = new com.google.gson.JsonObject();
  16.  
  17. var /*String*/ error = null;
  18.  
  19. // we the Entry of the user
  20. var resultSet = executeLogicalRequest("Users", search_attribute_name+"="+search_attribute_value, 0, "useruid,userlogin", false, false);
  21. if(resultSet!=null){
  22. userEntry = resultSet.getEntry();
  23. }
  24.  
  25. //case if the webservice was called for an unknown user
  26. if(userEntry==null){
  27. jsonResponse.add("activities", new com.google.gson.JsonArray());
  28. jsonResponse.add("workitems", new com.google.gson.JsonArray());
  29. return jsonResponse.toString();
  30. }
  31.  
  32. //we retrieve roles of the user
  33. var /*vector of String*/ roles = computeRolesWithCache(userEntry);
  34.  
  35. var /*array of wapiactivityinst*/ wapiactivityinstArray = getActivityInstancesOfParticipants(roles);
  36.  
  37. var mySimpleDate = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
  38.  
  39. //json object containing activityinstances
  40. var jsonActivityInstances = new com.google.gson.JsonArray();
  41.  
  42. for each(var wapiactivityinst in wapiactivityinstArray){
  43.  
  44. var jsonActivityInstance = new com.google.gson.JsonObject();
  45.  
  46. jsonActivityInstance.addProperty("name", wapiactivityinst.getDisplayName());
  47. jsonActivityInstance.addProperty("description", wapiactivityinst.getDescription());
  48. jsonActivityInstance.addProperty("priority", ""+wapiactivityinst.getPriority());
  49.  
  50. //if we want to format the date
  51. //var dateWithFormat = mySimpleDate.format(wapiactivityinst.getEligibleDate().getJavaDate());
  52. //jsonActivityInstance.addProperty("eligibledate", dateWithFormat);
  53. jsonActivityInstance.addProperty("eligibledate", ""+wapiactivityinst.getEligibleDate().getJavaDate().getTime());
  54.  
  55. if((include_deadline!=null) && (include_deadline=="true")){
  56. var deadline = wapiactivityinst.getDeadLine();
  57. if(deadline!=null){
  58. //var deadlineWithFormat = mySimpleDate.format(deadline.getJavaDate());
  59. //jsonActivityInstance.addProperty("deadline", deadlineWithFormat);
  60. jsonActivityInstance.addProperty("deadline", ""+deadline.getJavaDate().getTime());
  61. }
  62. }
  63.  
  64. //jsonActivityInstance.addProperty("id", wapiactivityinst.getId());
  65.  
  66. var meiboURL = meibo.getMeiboBaseUrl();
  67. var url = meiboURL + "dsddores?Connection=MPP&frames=true&external=true&Project=MPP&activity="+wapiactivityinst.getId();
  68.  
  69. jsonActivityInstance.addProperty("url", url);
  70.  
  71. jsonActivityInstance.addProperty("processname", wapiactivityinst.getProcessInstance().getDescription());
  72.  
  73. jsonActivityInstances.add(jsonActivityInstance);
  74.  
  75. }
  76.  
  77. var /*array of wapiworkitem*/ wapiworkitemArray = getWorkitemsOfParticipants(userEntry.ixuid[0], roles);
  78.  
  79. //json object containing workitems
  80. var jsonWorkitems = new com.google.gson.JsonArray();
  81.  
  82.  
  83. for each(var wapiworkitem in wapiworkitemArray){
  84.  
  85. var jsonWorkitem = new com.google.gson.JsonObject();
  86.  
  87. jsonWorkitem.addProperty("name", wapiworkitem.getActivityInstance().getDisplayName());
  88. jsonWorkitem.addProperty("description", wapiworkitem.getActivityInstance().getDescription());
  89.  
  90. //if we want to format the date
  91. //var dateWithFormat = mySimpleDate.format(wapiworkitem.getEligibleDate().getJavaDate());
  92. //jsonWorkitem.addProperty("startDate", dateWithFormat);
  93. jsonWorkitem.addProperty("startDate", ""+wapiworkitem.getEligibleDate().getJavaDate().getTime());
  94.  
  95. if((include_deadline!=null) && (include_deadline=="true")){
  96. var deadline = wapiworkitem.getActivityInstance().getDeadLine();
  97. if(deadline!=null){
  98. jsonWorkitem.addProperty("deadline", ""+deadline.getJavaDate().getTime());
  99. }
  100. }
  101.  
  102. //jsonWorkitem.addProperty("id", wapiworkitem.getId());
  103.  
  104. var meiboURL = meibo.getMeiboBaseUrl();
  105. var url = meiboURL + "dsddores?Connection=MPP&frames=true&external=true&Project=MPP&activity="+wapiworkitem.getActivityInstance().getId();
  106.  
  107. jsonWorkitem.addProperty("url", url);
  108.  
  109. jsonWorkitem.addProperty("processname", wapiworkitem.getActivityInstance().getProcessInstance().getDescription());
  110.  
  111. jsonWorkitems.add(jsonWorkitem);
  112.  
  113. }
  114.  
  115.  
  116.  
  117. //exemple gestion erreur
  118. /*
  119.   if(wapiprocinst==null){
  120.   error = "resumeProvisioning failed. Reason is wapiprocinst " + proc_inst_id + "doesn't exist";
  121.   MPP_trace(request, error);
  122.  
  123.   jsonResponse.addProperty("exitCode", "1");
  124.   jsonResponse.addProperty("errorMessage", error);
  125.  
  126.   return jsonResponse.toString();
  127.   }
  128.   */
  129.  
  130. jsonResponse.add("activities", jsonActivityInstances);
  131. jsonResponse.add("workitems", jsonWorkitems);
  132.  
  133. return jsonResponse.toString();
  134.  
  135. }
  136.  
  137. /*
  138. return all roles of a specific user
  139. */
  140. function /*Vector*/ computeRoles(userEntry){
  141.  
  142. var arrayRoles = new java.util.Vector();
  143.  
  144. if(userEntry!=null){
  145.  
  146. var clientRoles = computeClientRolesHelper(userEntry.getDn());
  147.  
  148. for each(var role in clientRoles){
  149. arrayRoles.add(role);
  150. }
  151.  
  152. arrayRoles.add(userEntry.ixuid[0]);
  153.  
  154. }
  155.  
  156. return arrayRoles;
  157. }
  158.  
  159.  
  160. function /*array of wapiactivityinst*/ getActivityInstancesOfParticipants(roles){
  161.  
  162. var arrayRole = new Array();
  163. arrayRole[0] = "Studio";
  164.  
  165. meibo.setWorkflowRoles(arrayRole);
  166.  
  167. var /*WAPISession*/ wapiSession = meibo.getWorkflowSession();
  168.  
  169. if (wapiSession == null) {
  170. return null;
  171. }
  172.  
  173. var filter = "state=1";
  174.  
  175. var result = new Array();
  176.  
  177. if(roles.size()>0){
  178. result = wapiSession.getActivityInstances(roles, filter);
  179. }
  180.  
  181. return result;
  182.  
  183. }
  184.  
  185. function /*array of string*/ getWorkitemsOfParticipants(/*String*/ user_login, roles){
  186.  
  187. var arrayRole = new Array();
  188. arrayRole[0] = "Studio";
  189.  
  190. meibo.setWorkflowRoles(arrayRole);
  191.  
  192. var /*WAPISession*/ wapiSession = meibo.getWorkflowSession();
  193.  
  194. if (wapiSession == null) {
  195. return null;
  196. }
  197.  
  198. //executing tasks
  199. var filter = "state=2";
  200.  
  201. return wapiSession.getWorkItems(user_login, filter);
  202.  
  203. }

Report this snippet  

You need to login to post a comment.