Search in sources :

Example 16 with HumanTaskRuntimeException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException in project carbon-business-process by wso2.

the class TaskOperationServiceImpl 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)

Example 17 with HumanTaskRuntimeException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException in project carbon-business-process by wso2.

the class TransformerUtils method transformOrganizationalEntityList.

/**
 * Transforms the TOrganizationalEntity type to OrganizationalEntity.
 *
 * @param tOEntity : The object to be transformed.
 * @return : The transformed object list.
 */
public static List<OrganizationalEntityDAO> transformOrganizationalEntityList(TOrganizationalEntity tOEntity) {
    HumanTaskEngine taskEngine = HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine();
    HumanTaskDAOConnection daoConn = taskEngine.getDaoConnectionFactory().getConnection();
    List<OrganizationalEntityDAO> organizationalEntities = new ArrayList<OrganizationalEntityDAO>();
    TOrganizationalEntityChoice[] usersAndGroups = tOEntity.getTOrganizationalEntityChoice();
    for (TOrganizationalEntityChoice userOrGroup : usersAndGroups) {
        String userName = null;
        OrganizationalEntityDAO.OrganizationalEntityType type = null;
        if (userOrGroup.getUser() != null) {
            TUser user = userOrGroup.getUser();
            userName = user.getTUser().trim();
            type = OrganizationalEntityDAO.OrganizationalEntityType.USER;
        } else if (userOrGroup.getGroup() != null) {
            TGroup group = userOrGroup.getGroup();
            userName = group.getTGroup().trim();
            type = OrganizationalEntityDAO.OrganizationalEntityType.GROUP;
        }
        if (org.h2.util.StringUtils.isNullOrEmpty(userName) || type == null) {
            throw new HumanTaskRuntimeException("Cannot extract OrganizationalEntity from :" + tOEntity);
        }
        OrganizationalEntityDAO orgEntity = daoConn.createNewOrgEntityObject(userName, type);
        organizationalEntities.add(orgEntity);
    }
    return organizationalEntities;
}
Also used : HumanTaskEngine(org.wso2.carbon.humantask.core.engine.HumanTaskEngine) ArrayList(java.util.ArrayList) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 18 with HumanTaskRuntimeException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException 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 19 with HumanTaskRuntimeException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException in project carbon-business-process by wso2.

the class RemovableTaskCleanupJob method execute.

/**
 * The task clean up execution logic.
 */
public void execute() {
    HumanTaskServerConfiguration serverConfiguration = HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getServerConfig();
    final SimpleQueryCriteria queryCriteria = createQueryCriteria(serverConfiguration);
    log.info("Running the task cleanup service.....");
    try {
        HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                HumanTaskDAOConnection daoConnection = HumanTaskCleanupSchedulerServiceComponent.getHumanTaskServer().getDaoConnectionFactory().getConnection();
                daoConnection.removeTasks(queryCriteria);
                return null;
            }
        });
    } catch (Exception ex) {
        String errMsg = "Task Cleanup operation failed! :";
        log.error(errMsg, ex);
        throw new HumanTaskRuntimeException(errMsg, ex);
    }
}
Also used : HumanTaskServerConfiguration(org.wso2.carbon.humantask.core.configuration.HumanTaskServerConfiguration) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) HumanTaskDAOConnection(org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) SimpleQueryCriteria(org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)

Example 20 with HumanTaskRuntimeException

use of org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException 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

HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)20 ArrayList (java.util.ArrayList)7 PeopleQueryEvaluator (org.wso2.carbon.humantask.core.engine.PeopleQueryEvaluator)4 OrganizationalEntityDAO (org.wso2.carbon.humantask.core.dao.OrganizationalEntityDAO)3 UserStoreException (org.wso2.carbon.user.core.UserStoreException)3 Calendar (java.util.Calendar)2 List (java.util.List)2 URI (org.apache.axis2.databinding.types.URI)2 GenericHumanRoleDAO (org.wso2.carbon.humantask.core.dao.GenericHumanRoleDAO)2 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)2 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)2 TaskConfiguration (org.wso2.carbon.humantask.core.store.TaskConfiguration)2 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 Date (java.util.Date)1 AxisFault (org.apache.axis2.AxisFault)1 AxisService (org.apache.axis2.description.AxisService)1 TArgument (org.wso2.carbon.humantask.TArgument)1 HumanTaskServerConfiguration (org.wso2.carbon.humantask.core.configuration.HumanTaskServerConfiguration)1 HumanTaskDAOConnection (org.wso2.carbon.humantask.core.dao.HumanTaskDAOConnection)1 SimpleQueryCriteria (org.wso2.carbon.humantask.core.dao.SimpleQueryCriteria)1