Search in sources :

Example 31 with ClassObjectFilter

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

the class EscalateToAdminSLAViolationListener 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 32 with ClassObjectFilter

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

the class NotifyOwnerSLAViolationListener 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 33 with ClassObjectFilter

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

the class NotifyParentCaseEventListener 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 34 with ClassObjectFilter

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

the class VariableScopeInstance method getVariable.

public Object getVariable(String name) {
    Object value = variables.get(name);
    if (value != null) {
        return value;
    }
    // support for processInstanceId and parentProcessInstanceId
    if ("processInstanceId".equals(name) && getProcessInstance() != null) {
        return getProcessInstance().getId();
    } else if ("parentProcessInstanceId".equals(name) && getProcessInstance() != null) {
        return getProcessInstance().getParentProcessInstanceId();
    }
    if (getProcessInstance() != null && getProcessInstance().getKnowledgeRuntime() != null) {
        // support for globals
        value = getProcessInstance().getKnowledgeRuntime().getGlobal(name);
        if (value != null) {
            return value;
        }
        // support for case file data
        @SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) getProcessInstance().getKnowledgeRuntime().getObjects(new ClassObjectFilter(CaseData.class));
        if (caseFiles.size() == 1) {
            CaseData caseFile = caseFiles.iterator().next();
            // check if there is case file prefix and if so remove it before checking case file data
            final String lookUpName = name.startsWith(VariableScope.CASE_FILE_PREFIX) ? name.replaceFirst(VariableScope.CASE_FILE_PREFIX, "") : name;
            if (caseFile != null) {
                return caseFile.getData(lookUpName);
            }
        }
    }
    return null;
}
Also used : CaseData(org.kie.api.runtime.process.CaseData) ClassObjectFilter(org.drools.core.ClassObjectFilter) Collection(java.util.Collection)

Example 35 with ClassObjectFilter

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

the class AbstractHTWorkItemHandler method createTaskBasedOnWorkItemParams.

protected Task createTaskBasedOnWorkItemParams(KieSession session, WorkItem workItem) {
    InternalTask task = (InternalTask) TaskModelProvider.getFactory().newTask();
    String taskName = (String) workItem.getParameter("NodeName");
    CaseData caseFile = null;
    String locale = (String) workItem.getParameter("Locale");
    if (locale == null) {
        locale = "en-UK";
    }
    if (taskName != null) {
        List<I18NText> names = new ArrayList<I18NText>();
        I18NText text = TaskModelProvider.getFactory().newI18NText();
        ((InternalI18NText) text).setLanguage(locale);
        ((InternalI18NText) text).setText(taskName);
        names.add(text);
        task.setNames(names);
    }
    task.setName(taskName);
    // this should be replaced by FormName filled by designer
    // TaskName shouldn't be trimmed if we are planning to use that for the task lists
    String formName = (String) workItem.getParameter("TaskName");
    if (formName != null) {
        task.setFormName(formName);
    }
    String comment = (String) workItem.getParameter("Comment");
    if (comment == null) {
        comment = "";
    }
    String description = (String) workItem.getParameter("Description");
    if (description == null) {
        description = comment;
    }
    List<I18NText> descriptions = new ArrayList<I18NText>();
    I18NText descText = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) descText).setLanguage(locale);
    ((InternalI18NText) descText).setText(description);
    descriptions.add(descText);
    task.setDescriptions(descriptions);
    task.setDescription(description);
    List<I18NText> subjects = new ArrayList<I18NText>();
    I18NText subjectText = TaskModelProvider.getFactory().newI18NText();
    ((InternalI18NText) subjectText).setLanguage(locale);
    ((InternalI18NText) subjectText).setText(comment);
    subjects.add(subjectText);
    task.setSubjects(subjects);
    task.setSubject(comment);
    String priorityString = (String) workItem.getParameter("Priority");
    int priority = 0;
    if (priorityString != null) {
        try {
            priority = new Integer(priorityString);
        } catch (NumberFormatException e) {
        // do nothing
        }
    }
    task.setPriority(priority);
    InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
    taskData.setWorkItemId(workItem.getId());
    taskData.setProcessInstanceId(workItem.getProcessInstanceId());
    if (session != null) {
        if (session.getProcessInstance(workItem.getProcessInstanceId()) != null) {
            taskData.setProcessId(session.getProcessInstance(workItem.getProcessInstanceId()).getProcess().getId());
            String deploymentId = ((WorkItemImpl) workItem).getDeploymentId();
            taskData.setDeploymentId(deploymentId);
        }
        if (session instanceof KieSession) {
            taskData.setProcessSessionId(((KieSession) session).getIdentifier());
        }
        @SuppressWarnings("unchecked") Collection<CaseData> caseFiles = (Collection<CaseData>) session.getObjects(new ClassObjectFilter(CaseData.class));
        if (caseFiles != null && caseFiles.size() == 1) {
            caseFile = caseFiles.iterator().next();
        }
    }
    taskData.setSkipable(!"false".equals(workItem.getParameter("Skippable")));
    // Sub Task Data
    Long parentId = (Long) workItem.getParameter("ParentId");
    if (parentId != null) {
        taskData.setParentId(parentId);
    }
    String createdBy = (String) workItem.getParameter("CreatedBy");
    if (createdBy != null && createdBy.trim().length() > 0) {
        User user = TaskModelProvider.getFactory().newUser();
        ((InternalOrganizationalEntity) user).setId(createdBy);
        taskData.setCreatedBy(user);
    }
    String dueDateString = (String) workItem.getParameter("DueDate");
    Date date = null;
    if (dueDateString != null && !dueDateString.isEmpty()) {
        if (DateTimeUtils.isPeriod(dueDateString)) {
            Long longDateValue = DateTimeUtils.parseDateAsDuration(dueDateString.substring(1));
            date = new Date(System.currentTimeMillis() + longDateValue);
        } else {
            date = new Date(DateTimeUtils.parseDateTime(dueDateString));
        }
    }
    if (date != null) {
        taskData.setExpirationTime(date);
    }
    PeopleAssignmentHelper peopleAssignmentHelper = new PeopleAssignmentHelper(caseFile);
    peopleAssignmentHelper.handlePeopleAssignments(workItem, task, taskData);
    PeopleAssignments peopleAssignments = task.getPeopleAssignments();
    List<OrganizationalEntity> businessAdministrators = peopleAssignments.getBusinessAdministrators();
    taskData.initialize();
    task.setTaskData(taskData);
    task.setDeadlines(HumanTaskHandlerHelper.setDeadlines(workItem, businessAdministrators, session.getEnvironment()));
    return task;
}
Also used : CaseData(org.kie.api.runtime.process.CaseData) User(org.kie.api.task.model.User) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) PeopleAssignments(org.kie.api.task.model.PeopleAssignments) KieSession(org.kie.api.runtime.KieSession) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) Date(java.util.Date) PeopleAssignmentHelper(org.jbpm.services.task.wih.util.PeopleAssignmentHelper) ClassObjectFilter(org.drools.core.ClassObjectFilter) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) Collection(java.util.Collection)

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