Search in sources :

Example 1 with CaseFileInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.

the class CaseServiceImpl method getCaseRoleAssignments.

@Override
public Collection<CaseRoleInstance> getCaseRoleAssignments(String caseId) throws CaseNotFoundException {
    authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.MODIFY_ROLE_ASSIGNMENT);
    ProcessInstanceDesc pi = verifyCaseIdExists(caseId);
    CaseFileInstance caseFile = internalGetCaseFileInstance(caseId, pi.getDeploymentId());
    return ((CaseFileInstanceImpl) caseFile).getAssignments();
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc)

Example 2 with CaseFileInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.

the class CaseServiceImpl method newCaseFileInstance.

/*
     * new instances methods
     */
@Override
public CaseFileInstance newCaseFileInstance(String deploymentId, String caseDefinition, Map<String, Object> data) {
    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());
    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 3 with CaseFileInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl 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 4 with CaseFileInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.

the class AddDataCaseFileInstanceCommand method execute.

@Override
public Void execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
    if (caseFiles.size() != 1) {
        throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size());
    }
    CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
    // apply authorization
    authorizationManager.checkDataAuthorization(caseFile.getCaseId(), caseFile, parameters.keySet());
    FactHandle factHandle = ksession.getFactHandle(caseFile);
    CaseEventSupport caseEventSupport = getCaseEventSupport(context);
    caseEventSupport.fireBeforeCaseDataAdded(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), parameters);
    caseFile.addAll(parameters);
    // setup data restriction if any are given
    for (String name : parameters.keySet()) {
        if (accessRestriction != null) {
            ((CaseFileInstanceImpl) caseFile).addDataAccessRestriction(name, accessRestriction);
        } else {
            ((CaseFileInstanceImpl) caseFile).removeDataAccessRestriction(name);
        }
    }
    ksession.update(factHandle, caseFile);
    triggerRules(ksession);
    caseEventSupport.fireAfterCaseDataAdded(caseFile.getCaseId(), caseFile, caseFile.getDefinitionId(), parameters);
    return null;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) ClassObjectFilter(org.drools.core.ClassObjectFilter) FactHandle(org.kie.api.runtime.rule.FactHandle) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext)

Example 5 with CaseFileInstanceImpl

use of org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl in project jbpm by kiegroup.

the class CaseCommentCommand method execute.

@Override
public String execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
    if (caseFiles.size() != 1) {
        throw new IllegalStateException("Not able to find distinct case file - found case files " + caseFiles.size());
    }
    CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
    FactHandle factHandle = ksession.getFactHandle(caseFile);
    CaseEventSupport caseEventSupport = getCaseEventSupport(context);
    String commentIdentifier = null;
    if (add) {
        CommentInstance commentInstance = new CommentInstanceImpl(author, comment, restrictedTo);
        caseEventSupport.fireBeforeCaseCommentAdded(caseFile.getCaseId(), caseFile, commentInstance);
        ((CaseFileInstanceImpl) caseFile).addComment(commentInstance);
        commentIdentifier = commentInstance.getId();
        caseEventSupport.fireAfterCaseCommentAdded(caseFile.getCaseId(), caseFile, commentInstance);
    } else if (update) {
        CommentInstance toUpdate = ((CaseFileInstanceImpl) caseFile).getComments().stream().filter(c -> c.getId().equals(commentId)).findFirst().orElseThrow(() -> new CaseCommentNotFoundException("Cannot find comment with id " + commentId));
        if (!this.author.equals(toUpdate.getAuthor())) {
            throw new IllegalStateException("Only original author can update comment");
        }
        // apply authorization
        authorizationManager.checkCommentAuthorization(caseFile.getCaseId(), caseFile, toUpdate);
        caseEventSupport.fireBeforeCaseCommentUpdated(caseFile.getCaseId(), caseFile, toUpdate);
        ((CommentInstanceImpl) toUpdate).setComment(updatedText);
        if (restrictedTo != null) {
            ((CommentInstanceImpl) toUpdate).setRestrictedTo(restrictedTo);
        }
        commentIdentifier = toUpdate.getId();
        caseEventSupport.fireAfterCaseCommentUpdated(caseFile.getCaseId(), caseFile, toUpdate);
    } else if (remove) {
        CommentInstance toRemove = ((CaseFileInstanceImpl) caseFile).getComments().stream().filter(c -> c.getId().equals(commentId)).findFirst().orElseThrow(() -> new CaseCommentNotFoundException("Cannot find comment with id " + commentId));
        // apply authorization
        authorizationManager.checkCommentAuthorization(caseFile.getCaseId(), caseFile, toRemove);
        caseEventSupport.fireBeforeCaseCommentRemoved(caseFile.getCaseId(), caseFile, toRemove);
        ((CaseFileInstanceImpl) caseFile).removeComment(toRemove);
        commentIdentifier = toRemove.getId();
        caseEventSupport.fireAfterCaseCommentRemoved(caseFile.getCaseId(), caseFile, toRemove);
    }
    ksession.update(factHandle, caseFile);
    triggerRules(ksession);
    return commentIdentifier;
}
Also used : IdentityProvider(org.kie.internal.identity.IdentityProvider) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) RegistryContext(org.drools.core.command.impl.RegistryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) Collection(java.util.Collection) ClassObjectFilter(org.drools.core.ClassObjectFilter) FactHandle(org.kie.api.runtime.rule.FactHandle) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) List(java.util.List) Context(org.kie.api.runtime.Context) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) KieSession(org.kie.api.runtime.KieSession) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) FactHandle(org.kie.api.runtime.rule.FactHandle) CommentInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) RegistryContext(org.drools.core.command.impl.RegistryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) ClassObjectFilter(org.drools.core.ClassObjectFilter) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) KieSession(org.kie.api.runtime.KieSession)

Aggregations

CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)16 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 List (java.util.List)6 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)5 CaseDefinitionNotFoundException (org.jbpm.casemgmt.api.CaseDefinitionNotFoundException)4 Map (java.util.Map)3 ClassObjectFilter (org.drools.core.ClassObjectFilter)3 RegistryContext (org.drools.core.command.impl.RegistryContext)3 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)3 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)3 KieSession (org.kie.api.runtime.KieSession)3 FactHandle (org.kie.api.runtime.rule.FactHandle)3 Collection (java.util.Collection)2 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 CaseRoleInstance (org.jbpm.casemgmt.api.model.instance.CaseRoleInstance)2 CommentInstance (org.jbpm.casemgmt.api.model.instance.CommentInstance)2 CommentInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CommentInstanceImpl)2