Search in sources :

Example 1 with HumanTaskException

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;
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 2 with HumanTaskException

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;
}
Also used : TransactionManager(javax.transaction.TransactionManager) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) InvalidJobsInDbException(org.wso2.carbon.humantask.core.api.scheduler.InvalidJobsInDbException) InvalidUpdateRequestException(org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException)

Example 3 with HumanTaskException

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;
}
Also used : OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) ArrayList(java.util.ArrayList) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) TArgument(org.wso2.carbon.humantask.TArgument)

Example 4 with HumanTaskException

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;
}
Also used : Task(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) Date(java.util.Date) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 5 with HumanTaskException

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);
}
Also used : OrganizationalEntityProvider(org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)

Aggregations

HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)4 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)4 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)3 OrganizationalEntityProvider (org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.provider.OrganizationalEntityProvider)2 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)2 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TransactionManager (javax.transaction.TransactionManager)1 QName (javax.xml.namespace.QName)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)1 TArgument (org.wso2.carbon.humantask.TArgument)1 org.wso2.carbon.humantask.client.api.types (org.wso2.carbon.humantask.client.api.types)1 InvalidJobsInDbException (org.wso2.carbon.humantask.core.api.scheduler.InvalidJobsInDbException)1 InvalidUpdateRequestException (org.wso2.carbon.humantask.core.api.scheduler.InvalidUpdateRequestException)1 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)1 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)1 TaskCreationContext (org.wso2.carbon.humantask.core.dao.TaskCreationContext)1