Search in sources :

Example 26 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition in project jbpm by kiegroup.

the class CaseServiceImpl method newCaseFileInstance.

@Override
public CaseFileInstance newCaseFileInstance(String deploymentId, String caseDefinition, Map<String, Object> data, Map<String, OrganizationalEntity> rolesAssignment) {
    CaseDefinition def = caseRuntimeDataService.getCase(deploymentId, caseDefinition);
    if (def == null) {
        throw new CaseDefinitionNotFoundException("Case definition " + caseDefinition + " does not exist in deployment " + deploymentId);
    }
    CaseFileInstanceImpl caseFile = new CaseFileInstanceImpl(caseDefinition, data);
    caseFile.setupRoles(def.getCaseRoles());
    caseFile.setAccessRestrictions(def.getDataAccessRestrictions());
    rolesAssignment.entrySet().stream().forEach(entry -> caseFile.assign(entry.getKey(), entry.getValue()));
    return caseFile;
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) CaseDefinitionNotFoundException(org.jbpm.casemgmt.api.CaseDefinitionNotFoundException)

Example 27 with CaseDefinition

use of org.jbpm.casemgmt.api.model.CaseDefinition 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

CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)27 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)17 Test (org.junit.Test)17 QueryContext (org.kie.api.runtime.query.QueryContext)13 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)10 CaseStage (org.jbpm.casemgmt.api.model.CaseStage)10 ArrayList (java.util.ArrayList)9 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)9 HashMap (java.util.HashMap)7 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)7 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)6 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)5 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)5 CaseRole (org.jbpm.casemgmt.api.model.CaseRole)5 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)5 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)5 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)5 UserImpl (org.jbpm.services.task.impl.model.UserImpl)5