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);
}
Aggregations