Search in sources :

Example 1 with ResourceNotFoundException

use of io.crnk.core.exception.ResourceNotFoundException in project crnk-framework by crnk-project.

the class ProcessInstanceRepositoryTest method checkDelete.

@Test
public void checkDelete() {
    ScheduleApprovalProcessInstance processInstance = postProcess(null, null, null);
    processRepository.delete(processInstance.getId());
    try {
        processRepository.findOne(processInstance.getId(), new QuerySpec(ScheduleApprovalProcessInstance.class));
        Assert.fail();
    } catch (ResourceNotFoundException e) {
    // ok
    }
}
Also used : ScheduleApprovalProcessInstance(io.crnk.activiti.example.model.ScheduleApprovalProcessInstance) QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 2 with ResourceNotFoundException

use of io.crnk.core.exception.ResourceNotFoundException in project crnk-framework by crnk-project.

the class TaskResourceRepositoryTest method deleteTask.

@Test
public void deleteTask() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    ApproveTask resource = taskRepository.findOne(task.getId(), querySpec);
    taskRepository.delete(resource.getId());
    try {
        taskRepository.findOne(task.getId(), querySpec);
        Assert.fail();
    } catch (ResourceNotFoundException e) {
    // ok
    }
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) ApproveTask(io.crnk.activiti.example.model.ApproveTask) Test(org.junit.Test)

Example 3 with ResourceNotFoundException

use of io.crnk.core.exception.ResourceNotFoundException 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 4 with ResourceNotFoundException

use of io.crnk.core.exception.ResourceNotFoundException in project crnk-framework by crnk-project.

the class SecurityModule method toType.

private <T> String toType(Class<T> resourceClass) {
    ResourceRegistry resourceRegistry = context.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntryForClass(resourceClass);
    if (entry == null) {
        throw new ResourceNotFoundException("resource type not found: " + resourceClass.getName());
    }
    ResourceInformation resourceInformation = entry.getResourceInformation();
    return resourceInformation.getResourceType();
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 5 with ResourceNotFoundException

use of io.crnk.core.exception.ResourceNotFoundException in project crnk-framework by crnk-project.

the class ResourceRepositoryBase method findOne.

/**
 * Forwards to {@link #findAll(QuerySpec)}
 *
 * @param id        of the resource
 * @param querySpec for field and relation inclusion
 * @return resource
 */
@Override
public T findOne(I id, QuerySpec querySpec) {
    RegistryEntry entry = resourceRegistry.findEntry(resourceClass);
    String idName = entry.getResourceInformation().getIdField().getUnderlyingName();
    QuerySpec idQuerySpec = querySpec.duplicate();
    idQuerySpec.addFilter(new FilterSpec(Arrays.asList(idName), FilterOperator.EQ, id));
    Iterable<T> iterable = findAll(idQuerySpec);
    Iterator<T> iterator = iterable.iterator();
    if (iterator.hasNext()) {
        T resource = iterator.next();
        PreconditionUtil.assertFalse("expected unique result", iterator.hasNext());
        return resource;
    } else {
        throw new ResourceNotFoundException("resource not found");
    }
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)18 Test (org.junit.Test)7 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)6 QuerySpec (io.crnk.core.queryspec.QuerySpec)5 Document (io.crnk.core.engine.document.Document)4 Serializable (java.io.Serializable)4 HttpAdapterResponse (io.crnk.client.http.HttpAdapterResponse)3 Response (io.crnk.core.engine.dispatcher.Response)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)3 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)3 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)3 ApproveTask (io.crnk.activiti.example.model.ApproveTask)2 ErrorData (io.crnk.core.engine.document.ErrorData)2 ErrorDataBuilder (io.crnk.core.engine.document.ErrorDataBuilder)2 Resource (io.crnk.core.engine.document.Resource)2 MetaLookup (io.crnk.meta.MetaLookup)2 MetaElement (io.crnk.meta.model.MetaElement)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ScheduleApprovalProcessInstance (io.crnk.activiti.example.model.ScheduleApprovalProcessInstance)1 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)1