Search in sources :

Example 16 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class ProcessInstanceResourceRepository method create.

@Override
public <S extends T> S create(S resource) {
    checkFilter(resource, true);
    String processDefinitionKey = resource.getProcessDefinitionKey();
    String businessKey = resource.getBusinessKey();
    String tenantId = resource.getTenantId();
    Map<String, Object> variables = resourceMapper.mapToVariables(resource);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId(processDefinitionKey, businessKey, variables, tenantId);
    applyUpdates(processInstance, resource);
    return (S) findOne(processInstance.getId(), new QuerySpec(getResourceClass()));
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 17 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class ProcessInstanceResourceRepository method save.

@Override
public <S extends T> S save(S resource) {
    checkFilter(resource, true);
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(resource.getId()).includeProcessVariables().singleResult();
    if (processInstance == null) {
        throw new ResourceNotFoundException(resource.getId());
    }
    checkFilter(processInstance, false);
    checkActivate(processInstance, resource);
    Map<String, Object> variables = resourceMapper.mapToVariables(resource);
    runtimeService.setVariables(processInstance.getId(), variables);
    applyUpdates(processInstance, resource);
    return (S) findOne(processInstance.getId(), new QuerySpec(getResourceClass()));
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 18 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class ProcessInstanceResourceRepository method delete.

@Override
public void delete(String id) {
    T resource = findOne(id, new QuerySpec(getResourceClass()));
    checkFilter(resource, false);
    runtimeService.deleteProcessInstance(id, null);
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 19 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class TaskResourceRepository method delete.

@Override
public void delete(String id) {
    T resource = findOne(id, new QuerySpec(getResourceClass()));
    checkFilter(resource, false);
    taskService.deleteTask(id);
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 20 with QuerySpec

use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.

the class ApprovalIntTest method verifyApprovalStarted.

private ApproveTask verifyApprovalStarted(Schedule schedule) {
    // check approval process started
    ResourceList<ScheduleApprovalProcessInstance> scheduleApprovals = approvalRepo.findAll(new QuerySpec(ScheduleApprovalProcessInstance.class));
    Assert.assertEquals(1, scheduleApprovals.size());
    checkOpenApproval(schedule, scheduleApprovals.get(0));
    // check relationship from resource to approval process
    ScheduleApprovalProcessInstance scheduleApproval = approvalRelRepo.findOneTarget(schedule.getId().toString(), "approval", new QuerySpec(ScheduleApprovalProcessInstance.class));
    checkOpenApproval(schedule, scheduleApproval);
    // check relationship from approval process to task
    ApproveTask approveTask = processTaskRepo.findOneTarget(scheduleApprovals.get(0).getId(), "approveTask", new QuerySpec(ApproveTask.class));
    Assert.assertNotNull(approveTask);
    // check task created
    QuerySpec taskQuery = new QuerySpec(ApproveTask.class);
    taskQuery.includeRelation(Arrays.asList("form"));
    ResourceList<ApproveTask> tasks = taskRepo.findAll(taskQuery);
    Assert.assertEquals(1, tasks.size());
    ApproveTask task = tasks.get(0);
    checkApproveTaskCreated(schedule, task);
    // check search for task by process
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("processInstance", "id"), FilterOperator.EQ, scheduleApproval.getId()));
    ResourceList<ApproveTask> results = taskRepo.findAll(querySpec);
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(scheduleApproval.getId(), results.get(0).getProcessInstanceId());
    return task;
}
Also used : ScheduleApprovalProcessInstance(io.crnk.activiti.example.model.ScheduleApprovalProcessInstance) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) ApproveTask(io.crnk.activiti.example.model.ApproveTask)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)306 Test (org.junit.Test)233 FilterSpec (io.crnk.core.queryspec.FilterSpec)51 Document (io.crnk.core.engine.document.Document)45 Resource (io.crnk.core.engine.document.Resource)43 Set (java.util.Set)39 HashMap (java.util.HashMap)37 HashSet (java.util.HashSet)36 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)34 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)32 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)32 Task (io.crnk.test.mock.models.Task)32 Project (io.crnk.core.mock.models.Project)28 Relationship (io.crnk.core.engine.document.Relationship)26 Task (io.crnk.core.mock.models.Task)26 TestEntity (io.crnk.jpa.model.TestEntity)26 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)25 Serializable (java.io.Serializable)24 RelatedEntity (io.crnk.jpa.model.RelatedEntity)21 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)20