Search in sources :

Example 11 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class TransformerUtils method transformTaskAuthorization.

/**
 * Creates the TTaskAuthorisationParams object based on the authorisations the caller has on the
 * given task
 *
 * @param task       : The TaskDAO object for the authorisations to be checked.
 * @param callerName : The caller user name.
 * @return : The TTaskAuthorisationParams object containing the authorisation parameters as
 *         boolean flags.
 */
public static TTaskAuthorisationParams transformTaskAuthorization(TaskDAO task, String callerName) {
    PeopleQueryEvaluator pqe = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
    OrganizationalEntityDAO caller = pqe.createUserOrgEntityForName(callerName);
    TTaskAuthorisationParams authParams = new TTaskAuthorisationParams();
    if (TaskType.TASK.equals(task.getType())) {
        authParams.setAuthorisedToActivate(OperationAuthorizationUtil.authorisedToActivate(task, caller, pqe));
        authParams.setAuthorisedToClaim(OperationAuthorizationUtil.authorisedToClaim(task, caller, pqe));
        authParams.setAuthorisedToComment(OperationAuthorizationUtil.authorisedToComment(task, caller, pqe));
        authParams.setAuthorisedToComplete(OperationAuthorizationUtil.authorisedToComplete(task, caller, pqe));
        authParams.setAuthorisedToDelegate(OperationAuthorizationUtil.authorisedToDelegate(task, caller, pqe));
        authParams.setAuthorisedToDeleteFault(OperationAuthorizationUtil.authorisedToDeleteFault(task, caller, pqe));
        authParams.setAuthorisedToDeleteComment(OperationAuthorizationUtil.authorisedToDeleteComment(task, caller, pqe));
        authParams.setAuthorisedToDeleteOutput(OperationAuthorizationUtil.authorisedToDeleteOutput(task, caller, pqe));
        authParams.setAuthorisedToExit(OperationAuthorizationUtil.authorisedToExit(task, caller, pqe));
        authParams.setAuthorisedToFail(OperationAuthorizationUtil.authorisedToFail(task, caller, pqe));
        authParams.setAuthorisedToForward(OperationAuthorizationUtil.authorisedToForward(task, caller, pqe));
        authParams.setAuthorisedToGetComments(OperationAuthorizationUtil.authorisedToGetComments(task, caller, pqe));
        authParams.setAuthorisedToGetDescription(OperationAuthorizationUtil.authorisedToGetDescription(task, caller, pqe));
        authParams.setAuthorisedToGetInput(OperationAuthorizationUtil.authorisedToGetInput(task, caller, pqe));
        authParams.setAuthorisedToNominate(OperationAuthorizationUtil.authorisedToNominate(task, caller, pqe));
        authParams.setAuthorisedToRelease(OperationAuthorizationUtil.authorisedToRelease(task, caller, pqe));
        authParams.setAuthorisedToResume(OperationAuthorizationUtil.authorisedToResume(task, caller, pqe));
        authParams.setAuthorisedToRemove(OperationAuthorizationUtil.authorisedToRemove(task, caller, pqe));
        authParams.setAuthorisedToSetFault(OperationAuthorizationUtil.authorisedToSetFault(task, caller, pqe));
        authParams.setAuthorisedToSetOutput(OperationAuthorizationUtil.authorisedToSetOutput(task, caller, pqe));
        authParams.setAuthorisedToSetPriority(OperationAuthorizationUtil.authorisedToSetPriority(task, caller, pqe));
        authParams.setAuthorisedToSkip(OperationAuthorizationUtil.authorisedToSkip(task, caller, pqe));
        authParams.setAuthorisedToStart(OperationAuthorizationUtil.authorisedToStart(task, caller, pqe));
        authParams.setAuthorisedToStop(OperationAuthorizationUtil.authorisedToStop(task, caller, pqe));
        authParams.setAuthorisedToSuspend(OperationAuthorizationUtil.authorisedToSuspend(task, caller, pqe));
        authParams.setAuthorisedToUpdateComment(OperationAuthorizationUtil.authorisedToUpdateComment(task, caller, pqe));
    } else if (TaskType.NOTIFICATION.equals(task.getType())) {
        authParams.setAuthorisedToGetDescription(OperationAuthorizationUtil.authorisedToGetDescription(task, caller, pqe));
        authParams.setAuthorisedToRemove(OperationAuthorizationUtil.authorisedToRemove(task, caller, pqe));
    }
    return authParams;
}
Also used : PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)

Example 12 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class TransformerUtils method transformToSimpleQueryRow.

// /**
// * @param matchingTasks :
// * @return :
// */
// public static TTaskSimpleQueryResultSet createSimpleQueryResultSet(
// List<TaskDAO> matchingTasks) {
// 
// TTaskSimpleQueryResultSet resultSet = new TTaskSimpleQueryResultSet();
// 
// for (TaskDAO matchingTask : matchingTasks) {
// resultSet.addRow(transformToSimpleQueryRow(matchingTask));
// }
// 
// return resultSet;
// }
/**
 * @param matchingTask :
 * @return :
 */
public static TTaskSimpleQueryResultRow transformToSimpleQueryRow(TaskDAO matchingTask) {
    TTaskSimpleQueryResultRow row = new TTaskSimpleQueryResultRow();
    row.setName(QName.valueOf(matchingTask.getDefinitionName()));
    row.setTaskType(matchingTask.getType().toString());
    try {
        row.setId(new URI(matchingTask.getId().toString()));
    } catch (URI.MalformedURIException e) {
        throw new HumanTaskRuntimeException("The task id :[" + matchingTask.getId() + "] is invalid", e);
    }
    Calendar createdTime = Calendar.getInstance();
    createdTime.setTime(matchingTask.getCreatedOn());
    row.setCreatedTime(createdTime);
    // set the task priority.
    TPriority priority = new TPriority();
    priority.setTPriority(BigInteger.valueOf(matchingTask.getPriority()));
    row.setPriority(priority);
    // set the task status
    TStatus taskStatus = new TStatus();
    taskStatus.setTStatus(matchingTask.getStatus().toString());
    row.setStatus(taskStatus);
    row.setPresentationSubject((transformPresentationSubject(CommonTaskUtil.getDefaultPresentationSubject(matchingTask))));
    row.setPresentationName(transformPresentationName(CommonTaskUtil.getDefaultPresentationName(matchingTask)));
    return row;
}
Also used : Calendar(java.util.Calendar) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) URI(org.apache.axis2.databinding.types.URI)

Example 13 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class HTQueryBuildHelperImpl method getTaskDataById.

/**
 * @param taskId
 * @return all the task details for the given taskID
 * @throws IllegalAccessFault
 * @throws IllegalArgumentFault
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws URI.MalformedURIException
 */
public String[] getTaskDataById(String taskId) throws IllegalAccessFault, IllegalArgumentFault, IllegalStateFault, IllegalOperationFault, URI.MalformedURIException {
    String[] output = { "" };
    List<String> outputList = new ArrayList<>();
    TaskDAO task;
    URI uri = new URI(taskId);
    try {
        final Long validatedTaskId = validateTaskId(uri);
        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(validatedTaskId);
                return task;
            }
        });
    } catch (Exception ex) {
        throw new IllegalAccessFault(ex);
    }
    GenericHumanRoleDAO.GenericHumanRoleType[] genericHumanRoleTypes = GenericHumanRoleDAO.GenericHumanRoleType.values();
    MessageDAO inputMessageDAO = task.getInputMessage();
    MessageDAO outputMessageDAO = task.getOutputMessage();
    String description = task.getTaskDescription("text/plain");
    String titleString = String.format("%1$-" + 25 + "s", "Task Name") + ":" + task.getName();
    outputList.add(titleString);
    for (int i = 0; i < genericHumanRoleTypes.length; i++) {
        List<OrganizationalEntityDAO> organizationalEntityDAOs = CommonTaskUtil.getOrgEntitiesForRole(task, genericHumanRoleTypes[i]);
        if (organizationalEntityDAOs.size() > 0) {
            String taskDataString = String.format("%1$-" + 25 + "s", genericHumanRoleTypes[i]) + ":";
            for (int j = 0; j < organizationalEntityDAOs.size(); j++) {
                taskDataString = taskDataString + organizationalEntityDAOs.get(j).getName() + " [" + organizationalEntityDAOs.get(j).getOrgEntityType() + "]  ";
            }
            outputList.add(taskDataString);
        }
    }
    if (description != null) {
        String taskDescriptionString = String.format("%1$-" + 25 + "s", "Task Description") + ":" + task.getTaskDescription("text/plain");
        outputList.add(taskDescriptionString);
    }
    Element inputBodyData = inputMessageDAO.getBodyData();
    if (inputBodyData != null) {
        String inputMsgStr = String.format("%1$-" + 25 + "s", "Task Input") + ":" + "\n" + DOMUtils.domToString(inputBodyData);
        outputList.add(inputMsgStr);
    }
    if (outputMessageDAO != null) {
        Element outputBodyData = outputMessageDAO.getBodyData();
        if (outputBodyData != null) {
            String outputMessageStr = String.format("%1$-" + 25 + "s", "Task Output") + ":" + "\n" + DOMUtils.domToString(outputBodyData);
            outputList.add(outputMessageStr);
        }
    }
    output = new String[outputList.size()];
    int i = 0;
    for (Object o : outputList) {
        output[i++] = o.toString();
    }
    return output;
}
Also used : IllegalAccessFault(org.wso2.carbon.humantask.client.api.IllegalAccessFault) HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) Element(org.w3c.dom.Element) URI(org.apache.axis2.databinding.types.URI) Callable(java.util.concurrent.Callable)

Example 14 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class TaskOperationsImpl method complete.

/**
 * Execution of the task finished successfully.
 * @param taskIdURI : task identifier
 * @param outputStr : task outcome (String)
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void complete(final URI taskIdURI, final String outputStr) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                Element output = DOMUtils.stringToDOM(outputStr);
                Complete completeCommand = new Complete(getCaller(), taskId, output);
                completeCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : Complete(org.wso2.carbon.humantask.core.engine.commands.Complete) Element(org.w3c.dom.Element) 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 15 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class TaskOperationsImpl method getCaller.

private String getCaller() {
    // TODO - remove hard coded user name value once moved to task view page.
    String userName = "admin";
    PeopleQueryEvaluator pqe = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getPeopleQueryEvaluator();
    if (StringUtils.isNotEmpty(pqe.getLoggedInUser())) {
        userName = pqe.getLoggedInUser();
    }
    // logged in user.
    if (StringUtils.isEmpty(userName)) {
        throw new HumanTaskRuntimeException("Cannot determine the user name of the user " + "performing the task operation!");
    }
    return userName;
}
Also used : PeopleQueryEvaluator(org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Aggregations

HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)41 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)35 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)28 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)28 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)27 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)25 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)25 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)25 ArrayList (java.util.ArrayList)14 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)13 Element (org.w3c.dom.Element)12 QName (javax.xml.namespace.QName)11 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)11 IOException (java.io.IOException)9 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)9 AxisFault (org.apache.axis2.AxisFault)8 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)8