Search in sources :

Example 1 with TaskModelFactory

use of org.kie.internal.task.api.TaskModelFactory in project jbpm by kiegroup.

the class StartCaseWorkItemHandler method parseParameters.

protected void parseParameters(WorkItem workItem, Map<String, Object> caseFileData, Map<String, OrganizationalEntity> roleAssignments, Map<String, List<String>> accessRestrictions) {
    TaskModelFactory taskModelFactory = TaskModelProvider.getFactory();
    CaseFileInstance caseFile = getCaseFile(ksession);
    for (Entry<String, Object> entry : workItem.getParameters().entrySet()) {
        if (entry.getKey().startsWith(DATA_PREFIX)) {
            String name = entry.getKey().replaceFirst(DATA_PREFIX, "");
            caseFileData.put(name, entry.getValue());
            logger.debug("Added {} item to case file with value {}", name, entry.getValue());
        } else if (entry.getKey().startsWith(USER_ROLE_PREFIX)) {
            String name = entry.getKey().replaceFirst(USER_ROLE_PREFIX, "");
            User user = taskModelFactory.newUser((String) entry.getValue());
            if (caseFile != null) {
                try {
                    Collection<OrganizationalEntity> caseAssignments = ((CaseAssignment) caseFile).getAssignments(name);
                    user = (User) caseAssignments.stream().filter(oe -> oe instanceof User).findFirst().orElseThrow(() -> new IllegalArgumentException());
                } catch (IllegalArgumentException e) {
                    logger.debug("no such role {} or there is no user found for given role name", name);
                }
            }
            roleAssignments.put(name, user);
            logger.debug("Added user {} as assignment to the role {}", entry.getValue(), entry.getKey());
        } else if (entry.getKey().startsWith(GROUP_ROLE_PREFIX)) {
            String name = entry.getKey().replaceFirst(GROUP_ROLE_PREFIX, "");
            Group group = taskModelFactory.newGroup((String) entry.getValue());
            if (caseFile != null) {
                try {
                    Collection<OrganizationalEntity> caseAssignments = ((CaseAssignment) caseFile).getAssignments(name);
                    group = (Group) caseAssignments.stream().filter(oe -> oe instanceof Group).findFirst().orElseThrow(() -> new IllegalArgumentException());
                } catch (IllegalArgumentException e) {
                    logger.debug("no such role {} or there is no group found for given role name", name);
                }
            }
            roleAssignments.put(name, group);
            logger.debug("Added group {} as assignment to the role {}", entry.getValue(), entry.getKey());
        } else if (entry.getKey().startsWith(DATA_ACCESS_PREFIX)) {
            String name = entry.getKey().replaceFirst(DATA_ACCESS_PREFIX, "");
            String[] roles = ((String) entry.getValue()).split(",");
            List<String> restrictedTo = new ArrayList<>(Arrays.asList(roles));
            accessRestrictions.put(name, restrictedTo);
            logger.debug("Added access restriction for {} with following roles {}", name, restrictedTo);
        }
    }
}
Also used : Arrays(java.util.Arrays) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) RuntimeManagerRegistry(org.kie.internal.runtime.manager.RuntimeManagerRegistry) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ArrayList(java.util.ArrayList) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Map(java.util.Map) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) KieSession(org.kie.api.runtime.KieSession) User(org.kie.api.task.model.User) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) Logger(org.slf4j.Logger) WorkItem(org.kie.api.runtime.process.WorkItem) Collection(java.util.Collection) CaseService(org.jbpm.casemgmt.api.CaseService) TaskModelProvider(org.kie.internal.task.api.TaskModelProvider) ClassObjectFilter(org.drools.core.ClassObjectFilter) List(java.util.List) Group(org.kie.api.task.model.Group) Entry(java.util.Map.Entry) CaseFileInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ClassObjectFilter (org.drools.core.ClassObjectFilter)1 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 CaseService (org.jbpm.casemgmt.api.CaseService)1 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)1 CaseFileInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseFileInstanceImpl)1 PerCaseRuntimeManager (org.jbpm.runtime.manager.impl.PerCaseRuntimeManager)1 ServiceRegistry (org.jbpm.services.api.service.ServiceRegistry)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 CaseAssignment (org.kie.api.runtime.process.CaseAssignment)1 WorkItem (org.kie.api.runtime.process.WorkItem)1 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)1