Search in sources :

Example 36 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class TaskOperationsImpl method loadTask.

/**
 * Return Task Abstract details for give Task ID. (Custom API) Similar to getMyTaskAbstracts method in HumanTask API
 * @param taskIdURI : task identifier
 * @return Task Abstract
 * @throws IllegalAccessFault
 */
public TTaskAbstract loadTask(URI taskIdURI) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {

            public TaskDAO call() throws Exception {
                HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
                HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
                TaskDAO task = daoConn.getTask(taskId);
                validateTaskTenant(task);
                authoriseToLoadTask(task);
                return task;
            }
        });
        return TransformerUtils.transformTask(task, getCaller());
    } catch (Exception ex) {
        log.error("Error occurred while loading task: " + taskIdURI, ex);
        handleException(ex);
    }
    return null;
}
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)

Example 37 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class TaskOperationsImpl method getRenderingTypes.

/**
 * Applies to both tasks and notifications.
 * Returns the rendering  types available for the task or notification.
 *
 * @param taskIdURI : task identifier
 * @return : Array of QNames
 * @throws IllegalArgumentFault
 */
public QName[] getRenderingTypes(URI taskIdURI) throws IllegalArgumentFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        TaskDAO task = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<TaskDAO>() {

            public TaskDAO call() throws Exception {
                HumanTaskEngine engine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
                HumanTaskDAOConnection daoConn = engine.getDaoConnectionFactory().getConnection();
                TaskDAO task = daoConn.getTask(taskId);
                validateTaskTenant(task);
                return task;
            }
        });
        HumanTaskBaseConfiguration taskConfiguration = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(task.getTenantId()).getTaskConfiguration(QName.valueOf(task.getName()));
        List<QName> renderingTypes = taskConfiguration.getRenderingTypes();
        QName[] types = new QName[renderingTypes.size()];
        types = renderingTypes.toArray(types);
        return types;
    } catch (Exception ex) {
        log.error(ex);
        throw new IllegalArgumentFault(ex);
    }
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) QName(javax.xml.namespace.QName) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) 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)

Example 38 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class TransformerUtils method generateAttachmentDAOFromID.

/**
 * Generate an {@code AttachmentDAO} for a given attachment-id
 *
 * @param task task to be associated with the particular attachment
 * @param attachmentID id of the attachment, so this will be used to extract attachment information from the
 * attachment-mgt OSGi service
 *
 * @return reference to the created {@code AttachmentDAO}
 * @throws HumanTaskException If if was failed to retrieve data from the attachment-mgt OSGi service
 */
public static AttachmentDAO generateAttachmentDAOFromID(TaskDAO task, String attachmentID) throws HumanTaskException {
    try {
        org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment attachment = HumanTaskServerHolder.getInstance().getAttachmentService().getAttachmentService().getAttachmentInfo(attachmentID);
        AttachmentDAO dao = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createAttachment();
        // Constructing the attachment DAO from the DTO
        dao.setName(attachment.getName());
        dao.setContentType(attachment.getContentType());
        dao.setTask((Task) task);
        String attachmentURL = attachment.getUrl().toString();
        // Extracting the attachment uri
        String attachmentUniqueID = attachmentURL.substring(attachmentURL.lastIndexOf("/") + 1);
        dao.setValue(attachmentUniqueID);
        dao.setAttachedAt(attachment.getCreatedTime().getTime());
        OrganizationalEntityDAO orgEntityDAO = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(attachment.getCreatedBy(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        dao.setAttachedBy((OrganizationalEntity) orgEntityDAO);
        // TODO : "AccessType is not supported by Attachment-Mgt DTOs. So using a dummy value: " + HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        dao.setAccessType(HumanTaskConstants.DEFAULT_ATTACHMENT_ACCESS_TYPE);
        return dao;
    } catch (AttachmentMgtException e) {
        String errorMsg = "Attachment Data retrieval operation failed for attachment id:" + attachmentID + ". " + "Reason:";
        log.error(e.getLocalizedMessage(), e);
        throw new HumanTaskException(errorMsg + e.getLocalizedMessage(), e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) org.wso2.carbon.humantask.client.api.types(org.wso2.carbon.humantask.client.api.types) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException)

Example 39 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class TransformerUtils method transformTask.

/**
 * Transform a TaskDAO object to a TTaskAbstract object.
 *
 * @param task           : The TaskDAO object to be transformed.
 * @param callerUserName : The user name of the caller.
 * @return : The transformed TTaskAbstract object.
 */
public static TTaskAbstract transformTask(final TaskDAO task, final String callerUserName) {
    TTaskAbstract taskAbstract = new TTaskAbstract();
    // Set the task Id
    try {
        taskAbstract.setId(new URI(task.getId().toString()));
    } catch (URI.MalformedURIException e) {
        log.warn("Invalid task Id found");
    }
    taskAbstract.setName(QName.valueOf(task.getDefinitionName()));
    taskAbstract.setRenderingMethodExists(true);
    // Set the created time
    Calendar calCreatedOn = Calendar.getInstance();
    calCreatedOn.setTime(task.getCreatedOn());
    taskAbstract.setCreatedTime(calCreatedOn);
    if (task.getUpdatedOn() != null) {
        Calendar updatedTime = Calendar.getInstance();
        updatedTime.setTime(task.getUpdatedOn());
        taskAbstract.setUpdatedTime(updatedTime);
    }
    // Set the activation time if exists.
    if (task.getActivationTime() != null) {
        Calendar calActivationTime = Calendar.getInstance();
        calActivationTime.setTime(task.getActivationTime());
        taskAbstract.setActivationTime(calActivationTime);
    }
    // Set the expiration time if exists.
    if (task.getExpirationTime() != null) {
        Calendar expirationTime = Calendar.getInstance();
        expirationTime.setTime(task.getExpirationTime());
        taskAbstract.setExpirationTime(expirationTime);
    }
    if (task.getStartByTime() != null) {
        taskAbstract.setStartByTimeExists(true);
    } else {
        taskAbstract.setStartByTimeExists(false);
    }
    if (task.getCompleteByTime() != null) {
        taskAbstract.setCompleteByTimeExists(true);
    } else {
        taskAbstract.setCompleteByTimeExists(false);
    }
    taskAbstract.setTaskType(task.getType().toString());
    taskAbstract.setHasSubTasks(CommonTaskUtil.hasSubTasks(task));
    taskAbstract.setHasComments(CommonTaskUtil.hasComments(task));
    taskAbstract.setHasAttachments(CommonTaskUtil.hasAttachments(task));
    taskAbstract.setHasFault(CommonTaskUtil.hasFault(task));
    taskAbstract.setHasOutput(CommonTaskUtil.hasOutput(task));
    taskAbstract.setEscalated(task.isEscalated());
    taskAbstract.setIsSkipable(task.isSkipable());
    taskAbstract.setStatus(transformStatus(task.getStatus()));
    taskAbstract.setPriority(transformPriority(task.getPriority()));
    taskAbstract.setPreviousStatus(transformStatus(task.getStatusBeforeSuspension()));
    taskAbstract.setHasPotentialOwners(CommonTaskUtil.hasPotentialOwners(task));
    if (CommonTaskUtil.getUserEntityForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER) != null) {
        taskAbstract.setActualOwner(createTUser(CommonTaskUtil.getUserEntityForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER)));
    }
    taskAbstract.setPotentialOwners(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS)));
    taskAbstract.setBusinessAdministrators(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS)));
    taskAbstract.setNotificationRecipients(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS)));
    taskAbstract.setTaskStakeholders(transformOrganizationalEntityList(CommonTaskUtil.getOrgEntitiesForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS)));
    taskAbstract.setTaskInitiator(createTUser(CommonTaskUtil.getUserEntityForRole(task, GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR)));
    HumanTaskBaseConfiguration baseConfiguration = CommonTaskUtil.getTaskConfiguration(task);
    if (baseConfiguration == null) {
        throw new HumanTaskRuntimeException("There's not matching task configuration for " + "task" + task.getName());
    }
    // Set the versioned package name
    taskAbstract.setPackageName(baseConfiguration.getPackageName() + "-" + baseConfiguration.getVersion());
    taskAbstract.setTenantId(task.getTenantId());
    // If this is a task set the response operation and the port type.
    if (TaskType.TASK.equals(task.getType())) {
        TaskConfiguration taskConfig = (TaskConfiguration) baseConfiguration;
        taskAbstract.setResponseOperationName(taskConfig.getResponseOperation());
        taskAbstract.setResponseServiceName(taskConfig.getResponsePortType().toString());
    }
    taskAbstract.setPresentationName(transformPresentationName(CommonTaskUtil.getDefaultPresentationName(task)));
    taskAbstract.setPresentationSubject(transformPresentationSubject(CommonTaskUtil.getDefaultPresentationSubject(task)));
    taskAbstract.setPresentationDescription(transformPresentationDescription(CommonTaskUtil.getDefaultPresentationDescription(task)));
    // Setting attachment specific information
    taskAbstract.setHasAttachments(!task.getAttachments().isEmpty());
    taskAbstract.setNumberOfAttachments(task.getAttachments().size());
    return taskAbstract;
}
Also used : Calendar(java.util.Calendar) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) URI(org.apache.axis2.databinding.types.URI)

Example 40 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO in project carbon-business-process by wso2.

the class HumanTaskDAOConnectionImpl method createTask.

public TaskDAO createTask(TaskCreationContext creationContext) throws HumanTaskException {
    HumanTaskBuilderImpl taskBuilder = new HumanTaskBuilderImpl();
    if (log.isDebugEnabled()) {
        log.debug("Creating task instance for task " + creationContext.getTaskConfiguration().getName());
    }
    MessageDAO inputMessage = createMessage(creationContext);
    inputMessage.setMessageType(MessageDAO.MessageType.INPUT);
    taskBuilder.addTaskCreationContext(creationContext).addInputMessage(inputMessage);
    TaskDAO task = taskBuilder.build();
    entityManager.persist(task);
    try {
        creationContext.injectExpressionEvaluationContext(task);
        JPATaskUtil.processGenericHumanRoles(task, creationContext.getTaskConfiguration(), creationContext.getPeopleQueryEvaluator(), creationContext.getEvalContext());
        JPATaskUtil.processPresentationElements(task, creationContext.getTaskConfiguration(), creationContext);
        if (task.getType().equals(TaskType.TASK)) {
            CommonTaskUtil.nominate(task, creationContext.getPeopleQueryEvaluator());
        } else if (task.getType().equals(TaskType.NOTIFICATION)) {
            task.setStatus(TaskStatus.READY);
            notificationScheduler = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getNotificationScheduler();
            notificationScheduler.checkForNotificationTasks(creationContext.getTaskConfiguration(), creationContext, task);
        }
        task.setPriority(CommonTaskUtil.calculateTaskPriority(creationContext.getTaskConfiguration(), creationContext.getEvalContext()));
        CommonTaskUtil.setTaskToMessage(task);
        if (TaskType.TASK.equals(task.getType())) {
            CommonTaskUtil.processDeadlines(task, (TaskConfiguration) creationContext.getTaskConfiguration(), creationContext.getEvalContext());
            CommonTaskUtil.scheduleDeadlines(task);
        }
        // Setting HumanTask context override attributes
        CommonTaskUtil.setTaskOverrideContextAttributes(task, creationContext.getMessageHeaderParts());
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getEventProcessor().processEvent(CommonTaskUtil.createNewTaskEvent(task));
    } catch (HumanTaskRuntimeException ex) {
        String errorMsg = "Error occurred after task creation for Task ID: " + task.getId() + ". Cause: " + ex.getMessage();
        log.error(errorMsg);
        task.setStatus(TaskStatus.ERROR);
        throw ex;
    }
    return task;
}
Also used : HumanTaskBuilderImpl(org.wso2.carbon.humantask.core.dao.jpa.openjpa.util.HumanTaskBuilderImpl) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Aggregations

TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)16 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)7 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)7 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)7 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)7 UserStoreException (org.wso2.carbon.user.core.UserStoreException)7 Element (org.w3c.dom.Element)6 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)6 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)6 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)6 QName (javax.xml.namespace.QName)5 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)5 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)5 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)4 URI (org.apache.axis2.databinding.types.URI)3 NodeList (org.w3c.dom.NodeList)3 PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)3 ExpressionEvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.ExpressionEvaluationContext)3 EvaluationContext (org.wso2.carbon.humantask.core.engine.runtime.api.EvaluationContext)3