Search in sources :

Example 26 with ClassObjectFilter

use of org.drools.core.ClassObjectFilter 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 27 with ClassObjectFilter

use of org.drools.core.ClassObjectFilter in project jbpm by kiegroup.

the class StartCaseWorkItemHandler method getCaseFile.

protected CaseFileInstance getCaseFile(KieSession ksession) {
    if (ksession == null) {
        logger.debug("No ksession available returning null as case file");
        return null;
    }
    Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
    if (caseFiles.size() == 0) {
        logger.debug("No case file available in working memory returning null as case file");
        return null;
    }
    CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
    return caseFile;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) ClassObjectFilter(org.drools.core.ClassObjectFilter)

Example 28 with ClassObjectFilter

use of org.drools.core.ClassObjectFilter in project jbpm by kiegroup.

the class StartProcessSLAViolationListener method getCaseFile.

protected CaseFileInstance getCaseFile(KieSession ksession) {
    Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
    if (caseFiles.size() == 0) {
        return null;
    }
    CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
    return caseFile;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) ClassObjectFilter(org.drools.core.ClassObjectFilter)

Example 29 with ClassObjectFilter

use of org.drools.core.ClassObjectFilter in project jbpm by kiegroup.

the class CaseCommand method getCaseFile.

protected CaseFileInstance getCaseFile(KieSession ksession, String caseId) {
    Collection<? extends Object> caseFiles = ksession.getObjects(new ClassObjectFilter(CaseFileInstance.class));
    if (caseFiles.size() == 0) {
        return null;
    }
    CaseFileInstance caseFile = (CaseFileInstance) caseFiles.iterator().next();
    return caseFile;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) ClassObjectFilter(org.drools.core.ClassObjectFilter)

Example 30 with ClassObjectFilter

use of org.drools.core.ClassObjectFilter 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

ClassObjectFilter (org.drools.core.ClassObjectFilter)55 KieSession (org.kie.api.runtime.KieSession)44 Test (org.junit.Test)40 FactHandle (org.kie.api.runtime.rule.FactHandle)29 InternalFactHandle (org.drools.core.common.InternalFactHandle)24 KieBase (org.kie.api.KieBase)19 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)17 ArrayList (java.util.ArrayList)15 List (java.util.List)14 Collection (java.util.Collection)12 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)11 Person (org.drools.compiler.Person)8 KiePackage (org.kie.api.definition.KiePackage)8 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)8 HashMap (java.util.HashMap)7 KieHelper (org.kie.internal.utils.KieHelper)6 Cheese (org.drools.compiler.Cheese)5 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 RegistryContext (org.drools.core.command.impl.RegistryContext)4 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)4