use of org.wso2.carbon.humantask.core.engine.commands.Delegate in project carbon-business-process by wso2.
the class TaskOperationsImpl method delegate.
/**
* Assign the task to one user and set the task to state Reserved.
* @param taskId : task identifier
* @param delegatee : organizational entity (htt:tOrganizationalEntity)
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws IllegalArgumentFault
* @throws RecipientNotAllowedException
* @throws IllegalAccessFault
*/
public void delegate(final URI taskId, final TOrganizationalEntity delegatee) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, RecipientNotAllowedException, IllegalAccessFault {
try {
validateTaskId(taskId);
if (delegatee == null) {
throw new IllegalArgumentFault("The delegatee cannot be null!");
}
HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {
public Object call() throws Exception {
List<OrganizationalEntityDAO> orgEntities = TransformerUtils.transformOrganizationalEntityList(delegatee);
if (orgEntities.size() > 1) {
throw new IllegalArgumentFault("There can be only 1 delegatee of type user!");
}
Delegate delegateCommand = new Delegate(getCaller(), new Long(taskId.toString()), orgEntities.get(0));
delegateCommand.execute();
return null;
}
});
} catch (Exception ex) {
handleException(ex);
}
}
use of org.wso2.carbon.humantask.core.engine.commands.Delegate in project carbon-business-process by wso2.
the class Delegate method checkPreConditions.
/**
* Checks the Pre-conditions before executing the task operation.
*/
@Override
protected void checkPreConditions() {
checkForValidTask();
OrganizationalEntityDAO caller = getOperationInvoker();
TaskDAO task = getTask();
// if the delegatee is not an existing user
if (!getEngine().getPeopleQueryEvaluator().isExistingUser(delegatee.getName())) {
String errMsg = String.format("The user[%s] cannot delegate task[id:%d] to the given" + " delegatee[name:%s] as he/she does not exist in the user store", caller.getName(), task.getId(), delegatee.getName());
log.error(errMsg);
throw new HumanTaskIllegalArgumentException(errMsg);
}
if (isExcludedOwner(delegatee.getName())) {
String errMsg = String.format("The user[%s] cannot delegate task[id:%d] to the given" + " delegatee[name:%s] as he/she is an exclude owner for this task.", caller.getName(), task.getId(), delegatee.getName());
log.error(errMsg);
throw new HumanTaskIllegalArgumentException(errMsg);
}
// if the task is in reserved or in-progress we have to release it first.
if (TaskStatus.RESERVED.equals(task.getStatus()) || TaskStatus.IN_PROGRESS.equals(task.getStatus())) {
// task releasing can be done only by bus admins and the actual owner.
List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoles = new ArrayList<GenericHumanRoleDAO.GenericHumanRoleType>();
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
try {
authoriseRoles(allowedRoles);
} catch (Exception ex) {
String err = String.format("The task[id:%d] can be only delegated after it's released. " + "But for the task to be released you need to be a business " + "administrator or the actual owner of the task. " + "Given user[%s] is not in those roles!", task.getId(), caller.getName());
log.error(err);
throw new HumanTaskIllegalAccessException(err, ex);
}
task.release();
}
// Add delegatee as a potential owner.
GenericHumanRoleDAO potentialOwnersRole = task.getGenericHumanRole(GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS);
if (getEngine().getPeopleQueryEvaluator().isOrgEntityInRole(delegatee, potentialOwnersRole)) {
task.persistToPotentialOwners(delegatee);
}
}
Aggregations