Search in sources :

Example 1 with WorkflowProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class AutomaticRoleRequestByWfInvolvedIdentityEvaluator method getPermissions.

@Override
public Set<String> getPermissions(IdmAutomaticRoleRequest entity, AuthorizationPolicy policy) {
    Set<String> permissions = super.getPermissions(entity, policy);
    if (entity == null || !securityService.isAuthenticated() || entity.getWfProcessId() == null) {
        return permissions;
    }
    // 
    // search process instance by role request - its returned, if currently logged identity was involved in wf
    WorkflowProcessInstanceDto processInstance = processService.get(entity.getWfProcessId());
    if (processInstance != null) {
        permissions.addAll(policy.getPermissions());
    }
    return permissions;
}
Also used : WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)

Example 2 with WorkflowProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class RoleRequestByWfInvolvedIdentityEvaluator method getPermissions.

@Override
public Set<String> getPermissions(IdmRoleRequest entity, AuthorizationPolicy policy) {
    Set<String> permissions = super.getPermissions(entity, policy);
    if (entity == null || !securityService.isAuthenticated() || entity.getWfProcessId() == null) {
        return permissions;
    }
    // 
    // search process instance by role request - its returned, if currently logged identity was involved in wf
    WorkflowProcessInstanceDto processInstance = processService.get(entity.getWfProcessId());
    if (processInstance != null) {
        permissions.addAll(policy.getPermissions());
    }
    return permissions;
}
Also used : WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)

Example 3 with WorkflowProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowProcessInstanceService method searchInternal.

@Override
public ResourcesWrapper<WorkflowProcessInstanceDto> searchInternal(WorkflowFilterDto filter, boolean checkRight) {
    String processDefinitionId = filter.getProcessDefinitionId();
    Map<String, Object> equalsVariables = filter.getEqualsVariables();
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery();
    query.active();
    query.includeProcessVariables();
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(filter.getProcessDefinitionKey());
    }
    if (filter.getProcessInstanceId() != null) {
        query.processInstanceId(filter.getProcessInstanceId());
    }
    if (filter.getCategory() != null) {
        // Find definitions with this category (use double sided like)
        // We have to find definitions first, because process instance can't
        // be find by category.
        ProcessDefinitionQuery queryDefinition = repositoryService.createProcessDefinitionQuery();
        queryDefinition.active();
        queryDefinition.latestVersion();
        queryDefinition.processDefinitionCategoryLike(filter.getCategory() + "%");
        List<ProcessDefinition> processDefinitions = queryDefinition.list();
        Set<String> processDefinitionKeys = new HashSet<>();
        processDefinitions.forEach(p -> processDefinitionKeys.add(p.getKey()));
        if (processDefinitionKeys.isEmpty()) {
            // We don`t have any definitions ... nothing must be returned
            processDefinitionKeys.add("-1");
        }
        query.processDefinitionKeys(processDefinitionKeys);
    }
    if (equalsVariables != null) {
        for (Entry<String, Object> entry : equalsVariables.entrySet()) {
            query.variableValueEquals(entry.getKey(), entry.getValue());
        }
    }
    // (subprocess) started. This modification allow not use OR clause.
    if (checkRight && !securityService.isAdmin()) {
        query.involvedUser(securityService.getCurrentId().toString());
    }
    query.orderByProcessDefinitionId();
    query.desc();
    long count = query.count();
    List<ProcessInstance> processInstances = query.listPage((filter.getPageNumber()) * filter.getPageSize(), filter.getPageSize());
    List<WorkflowProcessInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (ProcessInstance instance : processInstances) {
            dtos.add(toResource(instance));
        }
    }
    double totalPageDouble = ((double) count / filter.getPageSize());
    double totlaPageFlorred = Math.floor(totalPageDouble);
    long totalPage = 0;
    if (totalPageDouble > totlaPageFlorred) {
        totalPage = (long) (totlaPageFlorred + 1);
    }
    return new ResourcesWrapper<>(dtos, count, totalPage, filter.getPageNumber(), filter.getPageSize());
}
Also used : ArrayList(java.util.ArrayList) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ResourcesWrapper(eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper) ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) HashSet(java.util.HashSet)

Example 4 with WorkflowProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleRequestService method cancelWF.

/**
 * Cancel unfinished workflow process for this automatic role.
 *
 * @param dto
 */
private void cancelWF(IdmAutomaticRoleRequestDto dto) {
    if (!Strings.isNullOrEmpty(dto.getWfProcessId())) {
        WorkflowFilterDto filter = new WorkflowFilterDto();
        filter.setProcessInstanceId(dto.getWfProcessId());
        Collection<WorkflowProcessInstanceDto> resources = workflowProcessInstanceService.find(filter, null).getContent();
        if (resources.isEmpty()) {
            // Process with this ID not exist ... maybe was ended
            return;
        }
        workflowProcessInstanceService.delete(dto.getWfProcessId(), "Role request use this WF, was deleted. This WF was deleted too.");
    }
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)

Example 5 with WorkflowProcessInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method cancelWF.

private void cancelWF(IdmRoleRequestDto dto) {
    if (!Strings.isNullOrEmpty(dto.getWfProcessId())) {
        WorkflowFilterDto filter = new WorkflowFilterDto();
        filter.setProcessInstanceId(dto.getWfProcessId());
        Collection<WorkflowProcessInstanceDto> resources = workflowProcessInstanceService.searchInternal(filter, false).getResources();
        if (resources.isEmpty()) {
            // Process with this ID not exist ... maybe was ended
            this.addToLog(dto, MessageFormat.format("Workflow process with ID [{0}] was not deleted, because was not found. Maybe was ended before.", dto.getWfProcessId()));
            return;
        }
        workflowProcessInstanceService.delete(dto.getWfProcessId(), "Role request use this WF, was deleted. This WF was deleted too.");
        this.addToLog(dto, MessageFormat.format("Workflow process with ID [{0}] was deleted, because this request is deleted/canceled", dto.getWfProcessId()));
    }
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)

Aggregations

WorkflowProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto)14 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)7 ArrayList (java.util.ArrayList)3 List (java.util.List)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)1 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)1 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ResourcePage (eu.bcvsolutions.idm.core.api.rest.domain.ResourcePage)1 ResourcesWrapper (eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)1 WorkflowHistoricProcessInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)1 HashSet (java.util.HashSet)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 HistoricIdentityLink (org.activiti.engine.history.HistoricIdentityLink)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)1 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)1 Task (org.activiti.engine.task.Task)1