Search in sources :

Example 16 with ResourceNotFoundException

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

the class MetaResourceRepositoryImpl method findOne.

@SuppressWarnings("unchecked")
@Override
public T findOne(String id, QuerySpec querySpec) {
    MetaLookup lookup = lookupSupplier.get();
    MetaElement metaElement = lookup.getMetaById().get(id);
    Class<T> resourceClass = this.getResourceClass();
    if (metaElement != null && resourceClass.isInstance(metaElement)) {
        MetaElement wrappedElement = MetaUtils.adjustForRequest(lookup, metaElement);
        if (wrappedElement != null) {
            return (T) metaElement;
        }
    }
    throw new ResourceNotFoundException(id);
}
Also used : MetaLookup(io.crnk.meta.MetaLookup) MetaElement(io.crnk.meta.model.MetaElement) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException)

Example 17 with ResourceNotFoundException

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

the class ExceptionTest method testUnknownRepository.

@Test
public void testUnknownRepository() {
    UnknownResource task = new UnknownResource();
    task.setId("test");
    ResourceRepositoryV2<UnknownResource, String> taskRepo = client.getRepositoryForType(UnknownResource.class);
    try {
        taskRepo.create(task);
        Assert.fail();
    } catch (ResourceNotFoundException e) {
    // ok
    }
}
Also used : UnknownResource(io.crnk.test.mock.models.UnknownResource) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 18 with ResourceNotFoundException

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

the class ComplexPojoRepository method findOne.

@Override
public ComplexPojo findOne(Long aLong, QueryParams queryParams) {
    if (THREAD_LOCAL_REPOSITORY.size() < 1) {
        ComplexPojo complexPojo = new ComplexPojo();
        complexPojo.setContainedPojo(new ContainedPojo());
        complexPojo.getContainedPojo().setUpdateableProperty1("value from repository mock");
        complexPojo.getContainedPojo().setUpdateableProperty2("value from repository mock");
        complexPojo.setId(1l);
        THREAD_LOCAL_REPOSITORY.put(complexPojo.getId(), complexPojo);
    }
    ComplexPojo complexPojo = THREAD_LOCAL_REPOSITORY.get(aLong);
    if (complexPojo == null) {
        throw new ResourceNotFoundException("");
    }
    return complexPojo;
}
Also used : ComplexPojo(io.crnk.core.mock.models.ComplexPojo) ContainedPojo(io.crnk.core.mock.models.ContainedPojo) ResourceNotFoundException(io.crnk.core.exception.ResourceNotFoundException)

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