use of org.wso2.carbon.humantask.core.engine.HumanTaskException in project carbon-business-process by wso2.
the class TaskOperationsImpl method addAttachment.
/**
* Add attachment to a task. Returns an identifier for the attachment.
* @param taskIdentifier : task identifier
* @param name : attachment name
* @param accessType : access type
* @param contentType : content type
* @param attachment : attachment ID (String)
* @return
* @throws IllegalStateFault
* @throws IllegalOperationFault
* @throws IllegalArgumentFault
* @throws IllegalAccessFault
*/
public boolean addAttachment(URI taskIdentifier, String name, String accessType, String contentType, Object attachment) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
final Long taskId = validateTaskId(taskIdentifier);
final String attachmentID = (String) attachment;
try {
Boolean isAdded = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Boolean>() {
public Boolean call() throws Exception {
HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
TaskDAO taskDAO = daoConn.getTask(taskId);
validateTaskTenant(taskDAO);
try {
boolean isAdded = taskDAO.addAttachment(TransformerUtils.generateAttachmentDAOFromID(taskDAO, attachmentID));
if (!isAdded) {
throw new HumanTaskException("Attachment with id: " + attachmentID + "was not associated " + "task with id:" + taskId);
}
return isAdded;
} catch (HumanTaskException ex) {
String errMsg = "getAttachmentInfos operation failed. Reason: ";
log.error(errMsg + ex.getLocalizedMessage(), ex);
throw ex;
}
}
});
return isAdded;
} catch (Exception ex) {
handleException(ex);
}
return false;
}
use of org.wso2.carbon.humantask.core.engine.HumanTaskException in project carbon-business-process by wso2.
the class SimpleScheduler method execTransaction.
public <T> T execTransaction(Callable<T> transaction, int timeout) throws Exception {
TransactionManager txm = transactionManager;
if (txm == null) {
throw new HumanTaskException("Cannot locate the transaction manager; " + "the server might be shutting down.");
}
// the transaction service restores the default value.
if (timeout < 0) {
throw new IllegalArgumentException("Timeout must be positive, received: " + timeout);
}
boolean existingTransaction;
try {
existingTransaction = txm.getTransaction() != null;
} catch (Exception ex) {
String errMsg = "Internal Error, could not get current transaction.";
throw new HumanTaskException(errMsg, ex);
}
// already in transaction, execute and return directly
if (existingTransaction) {
return transaction.call();
}
// run in new transaction
Exception ex = null;
// int immediateRetryCount = _immediateTransactionRetryLimit;
transactionManager.setTransactionTimeout(timeout);
if (log.isDebugEnabled() && timeout != 0) {
log.debug("Custom transaction timeout: " + timeout);
}
try {
try {
if (log.isDebugEnabled()) {
log.debug("Beginning a new transaction");
}
txm.begin();
} catch (Exception e) {
String errMsg = "Internal Error, could not begin transaction.";
throw new HumanTaskException(errMsg, e);
}
try {
ex = null;
return transaction.call();
} catch (Exception e) {
ex = e;
} finally {
if (ex == null) {
if (log.isDebugEnabled()) {
log.debug("Committing on " + txm + "...");
}
try {
txm.commit();
} catch (Exception e2) {
ex = e2;
}
} else {
if (log.isDebugEnabled()) {
log.debug("Rollbacking on " + txm + "...");
}
txm.rollback();
}
// if (ex != null && immediateRetryCount > 0) {
// if (log.isDebugEnabled()) {
// log.debug("Will retry the transaction in " +
// _immediateTransactionRetryInterval + " msecs on " +
// transactionManager + " for error: ", ex);
// }
// Thread.sleep(_immediateTransactionRetryInterval);
// }
}
} finally {
// 0 restores the default value
transactionManager.setTransactionTimeout(0);
}
throw ex;
}
use of org.wso2.carbon.humantask.core.engine.HumanTaskException in project carbon-business-process by wso2.
the class LogicalPeopleGroupBasedOrgEntityProvider method getOrganizationalEntities.
public List<OrganizationalEntityDAO> getOrganizationalEntities(PeopleQueryEvaluator peopleQueryEvaluator, TFrom tFrom, EvaluationContext evaluationContext) throws HumanTaskException {
String roleName = null;
for (TArgument tArgument : tFrom.getArgumentArray()) {
String expressionLanguage = (tArgument.getExpressionLanguage() == null) ? tFrom.getExpressionLanguage() : tArgument.getExpressionLanguage();
if (expressionLanguage == null) {
expressionLanguage = HumanTaskConstants.WSHT_EXP_LANG_XPATH20;
}
// TODO what about expression language
if ("role".equals(tArgument.getName())) {
roleName = tArgument.newCursor().getTextValue();
if (roleName != null && roleName.contains("htd:getInput")) {
roleName = CommonTaskUtil.calculateRole(evaluationContext, roleName, expressionLanguage);
}
break;
}
}
if (roleName == null || StringUtils.isEmpty(roleName)) {
throw new HumanTaskRuntimeException("The role name cannot be empty: " + tFrom.toString());
} else {
roleName = roleName.trim();
}
List<OrganizationalEntityDAO> orgEnties = new ArrayList<OrganizationalEntityDAO>();
orgEnties.add(peopleQueryEvaluator.createGroupOrgEntityForRole(roleName));
return orgEnties;
}
use of org.wso2.carbon.humantask.core.engine.HumanTaskException in project carbon-business-process by wso2.
the class HumanTaskBuilderImpl method build.
/**
* Builds the Task from the given input.
*
* @return : The created task object.
*/
public TaskDAO build() {
validateParams();
TaskDAO task;
HumanTaskBaseConfiguration taskConfiguration = creationContext.getTaskConfiguration();
int tenantId = creationContext.getTenantId();
if (creationContext.getTaskConfiguration().isTask()) {
task = new Task(taskConfiguration.getName(), TaskType.TASK, tenantId);
} else {
task = new Task(taskConfiguration.getName(), TaskType.NOTIFICATION, tenantId);
}
task.setInputMessage(this.inputMessage);
task.setSkipable(false);
task.setEscalated(false);
task.setStatus(TaskStatus.CREATED);
task.setActivationTime(new Date());
task.setTaskVersion(taskConfiguration.getVersion());
task.setTaskPackageName(taskConfiguration.getPackageName());
task.setDefinitionName(taskConfiguration.getDefinitionName());
if (creationContext.getTaskConfiguration().isTask()) {
// Setting the attachments to the task
try {
task.setAttachments(TransformerUtils.generateAttachmentDAOListFromIDs(task, creationContext.getAttachmentIDs()));
} catch (HumanTaskException e) {
log.error(e.getLocalizedMessage(), e);
}
}
// Setting the attachments to the task
try {
task.setAttachments(TransformerUtils.generateAttachmentDAOListFromIDs(task, creationContext.getAttachmentIDs()));
} catch (HumanTaskException e) {
log.error(e.getLocalizedMessage(), e);
}
return task;
}
use of org.wso2.carbon.humantask.core.engine.HumanTaskException in project carbon-business-process by wso2.
the class JPATaskUtil method assignHumanRoles.
private static void assignHumanRoles(TaskDAO task, PeopleQueryEvaluator peopleQueryEvaluator, TGenericHumanRoleAssignment roleAssignment, GenericHumanRole.GenericHumanRoleType type, EvaluationContext evaluationContext) throws HumanTaskException {
OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(roleAssignment.getFrom());
List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, roleAssignment.getFrom(), evaluationContext);
GenericHumanRole humanRole = new GenericHumanRole();
humanRole.setType(type);
humanRole.setOrgEntities(orgEntities);
humanRole.setTask(task);
for (OrganizationalEntityDAO oe : orgEntities) {
oe.addGenericHumanRole(humanRole);
}
task.addHumanRole(humanRole);
}
Aggregations