public static void authorizeWorkflowItem(Context context, String workflowItemId) throws AuthorizeException, SQLException {
WorkflowItem workflowItem = WorkflowItem.find(context, Integer.parseInt(workflowItemId.substring(1)));
if((workflowItem.getState() == WorkflowManager.WFSTATE_STEP1 ||
workflowItem.getState() == WorkflowManager.WFSTATE_STEP2 ||
workflowItem.getState() == WorkflowManager.WFSTATE_STEP3) && workflowItem.getOwner().getID() != context.getCurrentUser().getID()){
throw new AuthorizeException("You are not allowed to perform this task.");
}else
if((workflowItem.getState() == WorkflowManager.WFSTATE_STEP1POOL ||
workflowItem.getState() == WorkflowManager.WFSTATE_STEP2POOL ||
workflowItem.getState() == WorkflowManager.WFSTATE_STEP3POOL)){
// Verify if the current user has the current workflowItem among his pooled tasks
boolean hasPooledTask = false;
List<WorkflowItem> pooledTasks = WorkflowManager.getPooledTasks(context, context.getCurrentUser());
for (WorkflowItem pooledItem : pooledTasks) {
if(pooledItem.getID() == workflowItem.getID()){
hasPooledTask = true;
}
}
if(!hasPooledTask){
throw new AuthorizeException("You are not allowed to perform this task.");
}
}
}