Search in sources :

Example 6 with TaskDAO

use of org.wso2.carbon.humantask.core.dao.TaskDAO 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 7 with TaskDAO

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

the class TaskOperationsImpl method authoriseToLoadTask.

/**
 * Throws an exception if the current user is not allowed to perform loadTask() operation
 * @param taskId
 */
private void authoriseToLoadTask(TaskDAO task) throws Exception {
    List<GenericHumanRoleDAO.GenericHumanRoleType> allowedRoles = new ArrayList<GenericHumanRoleDAO.GenericHumanRoleType>();
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.ACTUAL_OWNER);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.POTENTIAL_OWNERS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS);
    allowedRoles.add(GenericHumanRoleDAO.GenericHumanRoleType.TASK_INITIATOR);
    HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
    PeopleQueryEvaluator pqe = taskEngine.getPeopleQueryEvaluator();
    OrganizationalEntityDAO invoker = taskEngine.getScheduler().execTransaction(new Callable<OrganizationalEntityDAO>() {

        @Override
        public OrganizationalEntityDAO call() throws Exception {
            return HumanTaskServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection().createNewOrgEntityObject(getCaller(), OrganizationalEntityDAO.OrganizationalEntityType.USER);
        }
    });
    if (!OperationAuthorizationUtil.authoriseUser(task, invoker, allowedRoles, pqe)) {
        String errorMsg = String.format("The user[%s] cannot perform loadTask()" + " operation as either he is in EXCLUDED_OWNERS role or he is not in task roles [%s]", invoker.getName(), allowedRoles);
        log.error(errorMsg);
        throw new HumanTaskIllegalAccessException("Access Denied. You are not authorized to perform this task");
    }
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) OrganizationalEntityDAO(org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO) PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator) GenericHumanRoleDAO(org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO) 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 8 with TaskDAO

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

the class CommonTaskUtil method createNewTaskEvent.

/**
 * Creates a new TaskEventInfo object for the task creation event.
 *
 * @param task : The newly created task object.
 *
 * @return : The respective TaskEventInfo object for the task creation event.
 */
public static TaskEventInfo createNewTaskEvent(TaskDAO task) {
    TaskEventInfo createTaskEvent = new TaskEventInfo();
    createTaskEvent.setEventType(TaskEventType.CREATE);
    createTaskEvent.setTimestamp(task.getCreatedOn());
    // TODO - how to handle the event initiator for create task event ?
    // createTaskEvent.setEventInitiator(null);
    createTaskEvent.setTaskInfo(populateTaskInfo(task));
    return createTaskEvent;
}
Also used : TaskEventInfo(org.wso2.carbon.humantask.core.api.event.TaskEventInfo)

Example 9 with TaskDAO

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

the class CommonTaskUtil method populateTaskInfo.

/**
 * Creates the TaskInfo object from the provided TaskDAO object.
 *
 * @param taskDAO : The original task dao object
 * @return : The representational TaskInfo.
 */
public static TaskInfo populateTaskInfo(TaskDAO taskDAO) {
    TaskInfo taskInfo = new TaskInfo();
    taskInfo.setId(taskDAO.getId());
    taskInfo.setCreatedDate(taskDAO.getCreatedOn());
    taskInfo.setName(taskDAO.getName());
    if (getDefaultPresentationDescription(taskDAO) != null) {
        taskInfo.setDescription(getDefaultPresentationDescription(taskDAO).getValue());
    }
    if (getActualOwner(taskDAO) != null) {
        taskInfo.setOwner(getActualOwner(taskDAO).getName());
    }
    if (getDefaultPresentationName(taskDAO) != null) {
        taskInfo.setName(getDefaultPresentationName(taskDAO).getValue());
    }
    if (getDefaultPresentationSubject(taskDAO) != null) {
        taskInfo.setSubject(getDefaultPresentationSubject(taskDAO).getValue());
    }
    taskInfo.setStatus(taskDAO.getStatus());
    taskInfo.setType(taskDAO.getType());
    taskInfo.setModifiedDate(taskDAO.getUpdatedOn());
    taskInfo.setStatusBeforeSuspension(taskDAO.getStatusBeforeSuspension());
    return taskInfo;
}
Also used : TaskInfo(org.wso2.carbon.humantask.core.api.event.TaskInfo)

Example 10 with TaskDAO

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

the class CommonTaskUtil method populateTaskEventInfo.

/**
 * Create the TaskEventInfo object from the EventDAO and the TaskDAO.
 * @param eventDAO : The event
 * @param taskDAO : The related task dao.
 *
 * @return : The new TaskEventInfo object.
 */
public static TaskEventInfo populateTaskEventInfo(EventDAO eventDAO, TaskDAO taskDAO) {
    TaskEventInfo eventInfo = new TaskEventInfo();
    eventInfo.setTimestamp(eventDAO.getTimeStamp());
    eventInfo.setEventInitiator(eventDAO.getUser());
    eventInfo.setEventType(eventDAO.getType());
    eventInfo.setNewState(eventDAO.getNewState());
    eventInfo.setOldState(eventDAO.getOldState());
    eventInfo.setTaskInfo(populateTaskInfo(taskDAO));
    return eventInfo;
}
Also used : TaskEventInfo(org.wso2.carbon.humantask.core.api.event.TaskEventInfo)

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