/ Published in: JavaScript
Expand |
Embed | Plain Text
// Resume an activity in waiting state // return true if resuming success or throws an error if an error is found. //@param include_deadline has to be "true" for including deadlines in the response function /*boolean*/ MPP_getUserActivities( /*String*/ from, /*String*/ search_attribute_name, /*String*/ search_attribute_value, /*String*/ include_deadline, /*String*/ language) /*thows error*/ { var userEntry = null; if((language!=null) && (language!="")){ meibo.setUserLanguage(language); } //var /*String*/ request = beginRequest(from, "MPP_getUserActivities"); var jsonResponse = new com.google.gson.JsonObject(); var /*String*/ error = null; // we the Entry of the user var resultSet = executeLogicalRequest("Users", search_attribute_name+"="+search_attribute_value, 0, "useruid,userlogin", false, false); if(resultSet!=null){ userEntry = resultSet.getEntry(); } //case if the webservice was called for an unknown user if(userEntry==null){ jsonResponse.add("activities", new com.google.gson.JsonArray()); jsonResponse.add("workitems", new com.google.gson.JsonArray()); return jsonResponse.toString(); } //we retrieve roles of the user var /*vector of String*/ roles = computeRolesWithCache(userEntry); var /*array of wapiactivityinst*/ wapiactivityinstArray = getActivityInstancesOfParticipants(roles); var mySimpleDate = new java.text.SimpleDateFormat("yyyyMMddHHmmss"); //json object containing activityinstances var jsonActivityInstances = new com.google.gson.JsonArray(); for each(var wapiactivityinst in wapiactivityinstArray){ var jsonActivityInstance = new com.google.gson.JsonObject(); jsonActivityInstance.addProperty("name", wapiactivityinst.getDisplayName()); jsonActivityInstance.addProperty("description", wapiactivityinst.getDescription()); jsonActivityInstance.addProperty("priority", ""+wapiactivityinst.getPriority()); //if we want to format the date //var dateWithFormat = mySimpleDate.format(wapiactivityinst.getEligibleDate().getJavaDate()); //jsonActivityInstance.addProperty("eligibledate", dateWithFormat); jsonActivityInstance.addProperty("eligibledate", ""+wapiactivityinst.getEligibleDate().getJavaDate().getTime()); if((include_deadline!=null) && (include_deadline=="true")){ var deadline = wapiactivityinst.getDeadLine(); if(deadline!=null){ //var deadlineWithFormat = mySimpleDate.format(deadline.getJavaDate()); //jsonActivityInstance.addProperty("deadline", deadlineWithFormat); jsonActivityInstance.addProperty("deadline", ""+deadline.getJavaDate().getTime()); } } //jsonActivityInstance.addProperty("id", wapiactivityinst.getId()); var meiboURL = meibo.getMeiboBaseUrl(); var url = meiboURL + "dsddores?Connection=MPP&frames=true&external=true&Project=MPP&activity="+wapiactivityinst.getId(); jsonActivityInstance.addProperty("url", url); jsonActivityInstance.addProperty("processname", wapiactivityinst.getProcessInstance().getDescription()); jsonActivityInstances.add(jsonActivityInstance); } var /*array of wapiworkitem*/ wapiworkitemArray = getWorkitemsOfParticipants(userEntry.ixuid[0], roles); //json object containing workitems var jsonWorkitems = new com.google.gson.JsonArray(); for each(var wapiworkitem in wapiworkitemArray){ var jsonWorkitem = new com.google.gson.JsonObject(); jsonWorkitem.addProperty("name", wapiworkitem.getActivityInstance().getDisplayName()); jsonWorkitem.addProperty("description", wapiworkitem.getActivityInstance().getDescription()); //if we want to format the date //var dateWithFormat = mySimpleDate.format(wapiworkitem.getEligibleDate().getJavaDate()); //jsonWorkitem.addProperty("startDate", dateWithFormat); jsonWorkitem.addProperty("startDate", ""+wapiworkitem.getEligibleDate().getJavaDate().getTime()); if((include_deadline!=null) && (include_deadline=="true")){ var deadline = wapiworkitem.getActivityInstance().getDeadLine(); if(deadline!=null){ jsonWorkitem.addProperty("deadline", ""+deadline.getJavaDate().getTime()); } } //jsonWorkitem.addProperty("id", wapiworkitem.getId()); var meiboURL = meibo.getMeiboBaseUrl(); var url = meiboURL + "dsddores?Connection=MPP&frames=true&external=true&Project=MPP&activity="+wapiworkitem.getActivityInstance().getId(); jsonWorkitem.addProperty("url", url); jsonWorkitem.addProperty("processname", wapiworkitem.getActivityInstance().getProcessInstance().getDescription()); jsonWorkitems.add(jsonWorkitem); } //exemple gestion erreur /* if(wapiprocinst==null){ error = "resumeProvisioning failed. Reason is wapiprocinst " + proc_inst_id + "doesn't exist"; MPP_trace(request, error); jsonResponse.addProperty("exitCode", "1"); jsonResponse.addProperty("errorMessage", error); return jsonResponse.toString(); } */ jsonResponse.add("activities", jsonActivityInstances); jsonResponse.add("workitems", jsonWorkitems); return jsonResponse.toString(); } /* return all roles of a specific user */ function /*Vector*/ computeRoles(userEntry){ var arrayRoles = new java.util.Vector(); if(userEntry!=null){ var clientRoles = computeClientRolesHelper(userEntry.getDn()); for each(var role in clientRoles){ arrayRoles.add(role); } arrayRoles.add(userEntry.ixuid[0]); } return arrayRoles; } function /*array of wapiactivityinst*/ getActivityInstancesOfParticipants(roles){ var arrayRole = new Array(); arrayRole[0] = "Studio"; meibo.setWorkflowRoles(arrayRole); var /*WAPISession*/ wapiSession = meibo.getWorkflowSession(); if (wapiSession == null) { return null; } var filter = "state=1"; var result = new Array(); if(roles.size()>0){ result = wapiSession.getActivityInstances(roles, filter); } return result; } function /*array of string*/ getWorkitemsOfParticipants(/*String*/ user_login, roles){ var arrayRole = new Array(); arrayRole[0] = "Studio"; meibo.setWorkflowRoles(arrayRole); var /*WAPISession*/ wapiSession = meibo.getWorkflowSession(); if (wapiSession == null) { return null; } //executing tasks var filter = "state=2"; return wapiSession.getWorkItems(user_login, filter); }
You need to login to post a comment.
