Search in sources :

Example 1 with PersistObjectCommand

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

the class CaseInstanceAuditEventListener method afterCaseRoleAssignmentAdded.

@Override
public void afterCaseRoleAssignmentAdded(CaseRoleAssignmentEvent event) {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("caseId", event.getCaseId());
    QueryStringCommand<List<Long>> queryCommand = new QueryStringCommand<List<Long>>(FIND_CASE_PROCESS_INST_ID_QUERY, parameters);
    List<Long> processInstanceId = commandService.execute(queryCommand);
    if (processInstanceId.isEmpty()) {
        return;
    }
    CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(processInstanceId.get(0), event.getCaseId(), event.getRole(), event.getEntity());
    commandService.execute(new PersistObjectCommand(assignmentLog));
}
Also used : QueryStringCommand(org.jbpm.shared.services.impl.commands.QueryStringCommand) HashMap(java.util.HashMap) PersistObjectCommand(org.jbpm.shared.services.impl.commands.PersistObjectCommand) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with PersistObjectCommand

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

the class CaseInstanceAuditEventListener method afterCaseStarted.

@Override
public void afterCaseStarted(CaseStartEvent event) {
    CaseFileInstance caseFile = event.getCaseFile();
    if (caseFile == null) {
        return;
    }
    Collection<CaseRoleInstance> caseRoleAssignments = ((CaseFileInstanceImpl) caseFile).getAssignments();
    if (caseRoleAssignments != null && !caseRoleAssignments.isEmpty()) {
        for (CaseRoleInstance roleAssignment : caseRoleAssignments) {
            logger.debug("Role {} has following assignments {}", roleAssignment.getRoleName(), roleAssignment.getRoleAssignments());
            if (roleAssignment.getRoleAssignments() != null && !roleAssignment.getRoleAssignments().isEmpty()) {
                List<CaseRoleAssignmentLog> objects = new ArrayList<>();
                roleAssignment.getRoleAssignments().forEach(entity -> {
                    CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(event.getProcessInstanceId(), event.getCaseId(), roleAssignment.getRoleName(), entity);
                    objects.add(assignmentLog);
                });
                commandService.execute(new PersistObjectCommand(objects.toArray()));
            }
        }
    } else {
        // add public role so it can be found by queries that take assignments into consideration
        CaseRoleAssignmentLog assignmentLog = new CaseRoleAssignmentLog(event.getProcessInstanceId(), event.getCaseId(), "*", TaskModelProvider.getFactory().newGroup(AuthorizationManager.PUBLIC_GROUP));
        commandService.execute(new PersistObjectCommand(assignmentLog));
    }
    Map<String, Object> initialData = caseFile.getData();
    if (initialData.isEmpty()) {
        return;
    }
    List<CaseFileDataLog> insert = new ArrayList<>();
    initialData.forEach((name, value) -> {
        if (value != null) {
            CaseFileDataLog caseFileDataLog = new CaseFileDataLog(event.getCaseId(), caseFile.getDefinitionId(), name);
            insert.add(caseFileDataLog);
            caseFileDataLog.setItemType(value.getClass().getName());
            caseFileDataLog.setItemValue(value.toString());
            caseFileDataLog.setLastModified(new Date());
            caseFileDataLog.setLastModifiedBy(event.getUser());
        }
    });
    commandService.execute(new PersistObjectCommand(insert.toArray()));
}
Also used : CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) PersistObjectCommand(org.jbpm.shared.services.impl.commands.PersistObjectCommand) CaseRoleInstance(org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)

Example 3 with PersistObjectCommand

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

the class TableCaseIdGenerator method register.

@Override
public void register(String prefix) {
    CaseIdInfo caseIdInfo = findCaseIdInfoByPrefix(prefix);
    if (caseIdInfo == null) {
        logger.debug("Case id prefix {} not yet registered", prefix);
        caseIdInfo = new CaseIdInfo();
        caseIdInfo.setCaseIdPrefix(prefix);
        caseIdInfo.setCurrentValue(new Long(0));
        commandService.execute(new PersistObjectCommand(caseIdInfo));
    } else {
        logger.debug("Case id prefix {} already registered and it's current value is {}", prefix, caseIdInfo.getCurrentValue());
    }
}
Also used : PersistObjectCommand(org.jbpm.shared.services.impl.commands.PersistObjectCommand)

Example 4 with PersistObjectCommand

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

the class DeploymentStore method enableDeploymentUnit.

public void enableDeploymentUnit(DeploymentUnit unit) {
    String unitContent = xstream.toXML(unit);
    DeploymentStoreEntry entry = findDeploymentStoreByDeploymentId(unit.getIdentifier());
    if (entry != null) {
        // update only
        // 0 - disabled, 1 - enabled, 2 - activated, 3 - deactivated
        entry.setState(STATE_ENABLED);
        entry.setUpdateDate(new Date());
        entry.setDeploymentUnit(unitContent);
        commandService.execute(new MergeObjectCommand(entry));
        return;
    }
    entry = new DeploymentStoreEntry();
    entry.setDeploymentId(unit.getIdentifier());
    // 0 - disabled, 1 - enabled, 2 - activated, 3 - deactivated
    entry.setState(STATE_ENABLED);
    entry.setUpdateDate(new Date());
    entry.setDeploymentUnit(unitContent);
    if (unit instanceof AttributesAware) {
        String attribtues = buildEntryAttributes(((AttributesAware) unit).getAttributes());
        entry.setAttributes(attribtues);
    }
    commandService.execute(new PersistObjectCommand(entry));
}
Also used : AttributesAware(org.jbpm.kie.services.api.AttributesAware) PersistObjectCommand(org.jbpm.shared.services.impl.commands.PersistObjectCommand) MergeObjectCommand(org.jbpm.shared.services.impl.commands.MergeObjectCommand) Date(java.util.Date)

Example 5 with PersistObjectCommand

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

the class CaseInstanceAuditEventListener method afterCaseDataAdded.

@Override
public void afterCaseDataAdded(CaseDataEvent event) {
    Map<String, Object> addedData = event.getData();
    if (addedData.isEmpty()) {
        return;
    }
    List<CaseFileDataLog> insert = new ArrayList<>();
    List<CaseFileDataLog> update = new ArrayList<>();
    List<String> currentCaseData = currentCaseData(event.getCaseId());
    addedData.forEach((name, value) -> {
        if (value != null) {
            CaseFileDataLog caseFileDataLog = null;
            if (currentCaseData.contains(name)) {
                logger.debug("Case instance {} has already stored log value for {} thus it's going to be updated", event.getCaseId(), name);
                caseFileDataLog = caseFileDataByName(event.getCaseId(), name);
                update.add(caseFileDataLog);
            } else {
                logger.debug("Case instance {} has no log value for {} thus it's going to be inserted", event.getCaseId(), name);
                caseFileDataLog = new CaseFileDataLog(event.getCaseId(), event.getDefinitionId(), name);
                insert.add(caseFileDataLog);
            }
            caseFileDataLog.setItemType(value.getClass().getName());
            caseFileDataLog.setItemValue(value.toString());
            caseFileDataLog.setLastModified(new Date());
            caseFileDataLog.setLastModifiedBy(event.getUser());
        }
    });
    commandService.execute(new PersistObjectCommand(insert.toArray()));
    commandService.execute(new MergeObjectCommand(update.toArray()));
}
Also used : PersistObjectCommand(org.jbpm.shared.services.impl.commands.PersistObjectCommand) ArrayList(java.util.ArrayList) MergeObjectCommand(org.jbpm.shared.services.impl.commands.MergeObjectCommand) Date(java.util.Date)

Aggregations

PersistObjectCommand (org.jbpm.shared.services.impl.commands.PersistObjectCommand)5 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 MergeObjectCommand (org.jbpm.shared.services.impl.commands.MergeObjectCommand)2 HashMap (java.util.HashMap)1 List (java.util.List)1 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)1 CaseRoleInstance (org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)1 CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)1 AttributesAware (org.jbpm.kie.services.api.AttributesAware)1 QueryStringCommand (org.jbpm.shared.services.impl.commands.QueryStringCommand)1