Hi every body,
I need write custom rest API for filtering archiving human task with Process Name.
Once I do, but result not exactly true same as Bonita API “/bonita/API/bpm/archivedHumanTask?p=0&c=10&o=reached_state_date DESC&f=assigned_id=4&f=state=completed&d=rootContainerId”.
This is my code :
RestApiResponse doHandle(HttpServletRequest request, RestApiResponseBuilder responseBuilder, RestAPIContext context) {
// To retrieve query parameters use the request.getParameter(..) method.
// Be careful, parameter values are always returned as String values
def ProcessName = request.getParameter "ProcessName"
if (ProcessName == null) {
return buildResponse(responseBuilder, HttpServletResponse.SC_BAD_REQUEST,"""{"error" : "the parameter ProcessName is missing"}""")
}
def UserId = request.getParameter "UserId"
if (UserId == null) {
return buildResponse(responseBuilder, HttpServletResponse.SC_BAD_REQUEST,"""{"error" : "the parameter UserId is missing"}""")
}
def Count = request.getParameter "Count"
if (Count == null) {
Count = -1;
}
long maxResults = context.apiClient.getProcessAPI().getNumberOfProcessDeploymentInfos();
final SearchOptionsBuilder processDepBuilder = new SearchOptionsBuilder(0, (int)maxResults);
processDepBuilder.filter(ProcessDeploymentInfoSearchDescriptor.NAME, ProcessName);
final SearchResult<ProcessDeploymentInfo> processDepSearchResult = context.apiClient.getProcessAPI().searchProcessDeploymentInfos(processDepBuilder.done());
List<ProcessDeploymentInfo> processDepFinalResult = new ArrayList<ProcessDeploymentInfo>();
for(object in processDepSearchResult.result)
{
processDepFinalResult.add(object);
}
maxResults = Count;
final SearchOptionsBuilder archiveHumanTaskBuilder = new SearchOptionsBuilder(0, (int)maxResults);
int lengthOfList = processDepFinalResult.size();
int counter = 0;
for(object in processDepFinalResult)
{
counter = counter + 1;
archiveHumanTaskBuilder.filter(ArchivedHumanTaskInstanceSearchDescriptor.PROCESS_DEFINITION_ID, object.getProcessId());
if(counter != lengthOfList)
archiveHumanTaskBuilder.or();
}
archiveHumanTaskBuilder.and();
archiveHumanTaskBuilder.filter(ArchivedHumanTaskInstanceSearchDescriptor.ASSIGNEE_ID, UserId);
final SearchResult<ArchivedHumanTaskInstance> archivedHumanTaskSearchResult = context.apiClient.getProcessAPI().searchArchivedHumanTasks(archiveHumanTaskBuilder.done());
List<ArchivedHumanTaskInstance> archivedHumanTaskFinalResult = new ArrayList<ArchivedHumanTaskInstance>();
for(object in archivedHumanTaskSearchResult.result)
{
archivedHumanTaskFinalResult.add(object);
}
for (int i=0; i<archivedHumanTaskFinalResult.size()-1;++i)
{
for (int j=i+1;j<archivedHumanTaskFinalResult.size();++j)
{
if (archivedHumanTaskFinalResult.get(i).flownodeDefinitionId.equals(archivedHumanTaskFinalResult.get(j).flownodeDefinitionId))
{
archivedHumanTaskFinalResult.removeAt(j);
j=i+1;
}
}
}
def result = archivedHumanTaskFinalResult;
// Send the result as a JSON representation
// You may use buildPagedResponse if your result is multiple
return buildResponse(responseBuilder, HttpServletResponse.SC_OK, new JsonBuilder(result).toPrettyString())
}
Please Guide Me,
Ali