Search in sources :

Example 6 with PathIds

use of io.crnk.core.engine.internal.dispatcher.path.PathIds in project crnk-framework by crnk-project.

the class ResourceGet method handle.

/**
 * {@inheritDoc}
 * <p>
 * Passes the request to controller method.
 */
@Override
public Response handle(JsonPath jsonPath, QueryAdapter queryAdapter, RepositoryMethodParameterProvider parameterProvider, Document requestBody) {
    String resourceType = jsonPath.getElementName();
    PathIds resourceIds = jsonPath.getIds();
    RegistryEntry registryEntry = getRegistryEntry(resourceType);
    String id = resourceIds.getIds().get(0);
    @SuppressWarnings("unchecked") Class<? extends Serializable> idClass = (Class<? extends Serializable>) registryEntry.getResourceInformation().getIdField().getType();
    Serializable castedId = typeParser.parse(id, idClass);
    ResourceRepositoryAdapter resourceRepository = registryEntry.getResourceRepository(parameterProvider);
    JsonApiResponse entities = resourceRepository.findOne(castedId, queryAdapter);
    Document responseDocument = documentMapper.toDocument(entities, queryAdapter);
    // return explicit { data : null } if values found
    if (!responseDocument.getData().isPresent()) {
        responseDocument.setData(Nullable.nullValue());
    }
    return new Response(responseDocument, 200);
}
Also used : JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Response(io.crnk.core.engine.dispatcher.Response) Serializable(java.io.Serializable) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) PathIds(io.crnk.core.engine.internal.dispatcher.path.PathIds) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Document(io.crnk.core.engine.document.Document) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

Response (io.crnk.core.engine.dispatcher.Response)6 PathIds (io.crnk.core.engine.internal.dispatcher.path.PathIds)6 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)6 Serializable (java.io.Serializable)6 Document (io.crnk.core.engine.document.Document)5 ResourceField (io.crnk.core.engine.information.resource.ResourceField)4 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)4 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)4 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)3 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)2 Resource (io.crnk.core.engine.document.Resource)1 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 RequestBodyException (io.crnk.core.exception.RequestBodyException)1 ResourceNotFoundException (io.crnk.core.exception.ResourceNotFoundException)1 ArrayList (java.util.ArrayList)1