Search in sources :

Example 1 with UpdateStringCommand

use of org.jbpm.shared.services.impl.commands.UpdateStringCommand in project jbpm by kiegroup.

the class CaseInstanceAuditEventListener method afterCaseRoleAssignmentRemoved.

@Override
public void afterCaseRoleAssignmentRemoved(CaseRoleAssignmentEvent event) {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("caseId", event.getCaseId());
    parameters.put("role", event.getRole());
    parameters.put("entity", event.getEntity().getId());
    UpdateStringCommand updateCommand = new UpdateStringCommand(DELETE_CASE_ROLE_ASSIGNMENT_QUERY, parameters);
    commandService.execute(updateCommand);
    logger.debug("Removed {} role assignment for entity {} for case id {}", event.getRole(), event.getEntity(), event.getCaseId());
}
Also used : UpdateStringCommand(org.jbpm.shared.services.impl.commands.UpdateStringCommand) HashMap(java.util.HashMap)

Example 2 with UpdateStringCommand

use of org.jbpm.shared.services.impl.commands.UpdateStringCommand in project jbpm by kiegroup.

the class CaseInstanceAuditEventListener method afterCaseReopen.

@Override
public void afterCaseReopen(CaseReopenEvent event) {
    logger.debug("Updating process instance id ({})in case assignment log for case id {}", event.getProcessInstanceId(), event.getCaseId());
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("piID", event.getProcessInstanceId());
    parameters.put("caseId", event.getCaseId());
    UpdateStringCommand updateCommand = new UpdateStringCommand(UPDATE_CASE_PROCESS_INST_ID_QUERY, parameters);
    int updated = commandService.execute(updateCommand);
    logger.debug("Updated {} role assignment entries for case id {}", updated, event.getCaseId());
}
Also used : UpdateStringCommand(org.jbpm.shared.services.impl.commands.UpdateStringCommand) HashMap(java.util.HashMap)

Example 3 with UpdateStringCommand

use of org.jbpm.shared.services.impl.commands.UpdateStringCommand in project jbpm by kiegroup.

the class CaseInstanceAuditEventListener method afterCaseDataRemoved.

@Override
public void afterCaseDataRemoved(CaseDataEvent event) {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("caseId", event.getCaseId());
    parameters.put("itemNames", new ArrayList<>(event.getData().keySet()));
    UpdateStringCommand updateCommand = new UpdateStringCommand(DELETE_CASE_DATA_BY_NAME_QUERY, parameters);
    commandService.execute(updateCommand);
}
Also used : UpdateStringCommand(org.jbpm.shared.services.impl.commands.UpdateStringCommand) HashMap(java.util.HashMap)

Example 4 with UpdateStringCommand

use of org.jbpm.shared.services.impl.commands.UpdateStringCommand in project jbpm by kiegroup.

the class ExecutionErrorCleanupCommand method execute.

@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    SimpleDateFormat formatToUse = DATE_FORMAT;
    String dataFormat = (String) ctx.getData("DateFormat");
    if (dataFormat != null) {
        formatToUse = new SimpleDateFormat(dataFormat);
    }
    ExecutionResults executionResults = new ExecutionResults();
    String emfName = (String) ctx.getData("EmfName");
    if (emfName == null) {
        emfName = "org.jbpm.domain";
    }
    String singleRun = (String) ctx.getData("SingleRun");
    if ("true".equalsIgnoreCase(singleRun)) {
        // disable rescheduling
        this.nextScheduleTimeAdd = -1;
    }
    String nextRun = (String) ctx.getData("NextRun");
    if (nextRun != null) {
        nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun);
    }
    // get hold of persistence and create instance of audit service
    EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(emfName);
    // collect parameters
    String olderThan = (String) ctx.getData("OlderThan");
    String olderThanPeriod = (String) ctx.getData("OlderThanPeriod");
    String forProcess = (String) ctx.getData("ForProcess");
    String forProcessInstance = (String) ctx.getData("ForProcessInstance");
    String forDeployment = (String) ctx.getData("ForDeployment");
    if (olderThanPeriod != null) {
        long olderThanDuration = DateTimeUtils.parseDateAsDuration(olderThanPeriod);
        Date olderThanDate = new Date(System.currentTimeMillis() - olderThanDuration);
        olderThan = formatToUse.format(olderThanDate);
    }
    Map<String, Object> parameters = new HashMap<>();
    StringBuilder cleanUpErrorsQuery = new StringBuilder();
    cleanUpErrorsQuery.append("delete from ExecutionErrorInfo where processInstanceId in " + "(select processInstanceId from ProcessInstanceLog where status in (2,3))");
    if (olderThan != null && !olderThan.isEmpty()) {
        cleanUpErrorsQuery.append(" and errorDate < :olderThan");
        parameters.put("olderThan", formatToUse.parse(olderThan));
    }
    if (forProcess != null && !forProcess.isEmpty()) {
        cleanUpErrorsQuery.append(" and processId = :forProcess");
        parameters.put("forProcess", forProcess);
    }
    if (forProcessInstance != null && !forProcessInstance.isEmpty()) {
        cleanUpErrorsQuery.append(" and processInstanceId = :forProcessInstance");
        parameters.put("forProcessInstance", Long.parseLong(forProcessInstance));
    }
    if (forDeployment != null && !forDeployment.isEmpty()) {
        cleanUpErrorsQuery.append(" and deploymentId = :forDeployment");
        parameters.put("forDeployment", forDeployment);
    }
    TransactionalCommandService commandService = new TransactionalCommandService(emf);
    int deletedErrors = commandService.execute(new UpdateStringCommand(cleanUpErrorsQuery.toString(), parameters));
    logger.debug("Number of Execution errors deleted {}", deletedErrors);
    executionResults.setData("ErrorsDeleted", deletedErrors);
    return executionResults;
}
Also used : HashMap(java.util.HashMap) ExecutionResults(org.kie.api.executor.ExecutionResults) Date(java.util.Date) UpdateStringCommand(org.jbpm.shared.services.impl.commands.UpdateStringCommand) EntityManagerFactory(javax.persistence.EntityManagerFactory) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with UpdateStringCommand

use of org.jbpm.shared.services.impl.commands.UpdateStringCommand in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method cleanup.

@After
public void cleanup() {
    if (query != null) {
        try {
            queryService.unregisterQuery(query.getName());
        } catch (QueryNotFoundException e) {
        }
    }
    if (processInstanceId != null) {
        // let's abort process instance to leave the system in clear state
        processService.abortProcessInstance(processInstanceId);
        ProcessInstance pi = processService.getProcessInstance(processInstanceId);
        assertNull(pi);
    }
    int deleted = 0;
    deleted += commandService.execute(new UpdateStringCommand("delete from  NodeInstanceLog nid"));
    deleted += commandService.execute(new UpdateStringCommand("delete from  ProcessInstanceLog pid"));
    deleted += commandService.execute(new UpdateStringCommand("delete from  VariableInstanceLog vsd"));
    deleted += commandService.execute(new UpdateStringCommand("delete from  AuditTaskImpl vsd"));
    deleted += commandService.execute(new UpdateStringCommand("delete from  TaskVariableImpl vsd"));
    System.out.println("Deleted " + deleted);
    cleanupSingletonSessionId();
    if (units != null && !units.isEmpty()) {
        for (DeploymentUnit unit : units) {
            deploymentService.undeploy(unit);
        }
        units.clear();
    }
}
Also used : UpdateStringCommand(org.jbpm.shared.services.impl.commands.UpdateStringCommand) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) After(org.junit.After)

Aggregations

UpdateStringCommand (org.jbpm.shared.services.impl.commands.UpdateStringCommand)10 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)6 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)6 After (org.junit.After)6 HashMap (java.util.HashMap)4 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)4 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 QueryNotFoundException (org.jbpm.services.api.query.QueryNotFoundException)1 TransactionalCommandService (org.jbpm.shared.services.impl.TransactionalCommandService)1 ExecutionResults (org.kie.api.executor.ExecutionResults)1