Search in sources :

Example 1 with StartCaseCommand

use of org.jbpm.casemgmt.impl.command.StartCaseCommand in project jbpm by kiegroup.

the class CaseServiceImpl method startCase.

@Override
public String startCase(String deploymentId, String caseDefinitionId, CaseFileInstance caseFile) {
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentId, caseDefinitionId);
    if (caseDef == null) {
        throw new CaseNotFoundException("Case definition " + caseDefinitionId + " not found");
    }
    String caseId = caseIdGenerator.generate(caseDef.getIdentifierPrefix(), (caseFile == null ? new HashMap<>() : caseFile.getData()));
    logger.debug("Generated case id {} for case definition id {}", caseId, caseDefinitionId);
    if (caseFile == null) {
        caseFile = new CaseFileInstanceImpl(caseId, caseDefinitionId);
        ((CaseFileInstanceImpl) caseFile).setupRoles(caseDef.getCaseRoles());
        logger.debug("CaseFile was not given, creating new empty one.");
    } else {
        ((CaseFileInstanceImpl) caseFile).setCaseId(caseId);
        logger.debug("CaseFile {} was given, associating it with case {}", caseFile, caseId);
    }
    // If owner is provided in the case file use that, otherwise default to current logged in user.
    boolean hasOwner = ((CaseFileInstanceImpl) caseFile).getAssignments().stream().anyMatch(role -> role.getRoleName().equals(AuthorizationManager.OWNER_ROLE));
    if (hasOwner == false) {
        ((CaseFileInstanceImpl) caseFile).assignOwner(newUser(identityProvider.getName()));
    }
    processService.execute(deploymentId, CaseContext.get(caseId), new StartCaseCommand(identityProvider, caseId, deploymentId, caseDefinitionId, caseFile, processService));
    return caseId;
}
Also used : StartCaseCommand(org.jbpm.casemgmt.impl.command.StartCaseCommand) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Aggregations

CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)1 StartCaseCommand (org.jbpm.casemgmt.impl.command.StartCaseCommand)1 CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)1