use of io.crnk.core.engine.filter.RepositoryFilterContext in project crnk-framework by crnk-project.
the class ResourceRepositoryAdapter method findOne.
public JsonApiResponse findOne(I id, QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@SuppressWarnings("rawtypes")
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
QueryAdapter queryAdapter = request.getQueryAdapter();
Serializable id = request.getId();
Object resource;
if (isAnnotated) {
resource = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findOne(id, queryAdapter);
} else if (resourceRepository instanceof ResourceRepositoryV2) {
resource = ((ResourceRepositoryV2) resourceRepository).findOne(id, request.getQuerySpec(resourceInformation));
} else {
resource = ((ResourceRepository) resourceRepository).findOne(id, request.getQueryParams());
}
if (resource == null && return404OnNull) {
throw new ResourceNotFoundException(resourceInformation.getResourceType());
}
return getResponse(resourceRepository, resource, request);
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindId(moduleRegistry, resourceInformation, queryAdapter, id);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.core.engine.filter.RepositoryFilterContext in project crnk-framework by crnk-project.
the class ResourceRepositoryAdapter method save.
private <S extends T> JsonApiResponse save(S entity, QueryAdapter queryAdapter, final HttpMethod method) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@SuppressWarnings("rawtypes")
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
Object entity = request.getEntity();
Object resource;
if (isAnnotated) {
resource = ((AnnotatedResourceRepositoryAdapter) resourceRepository).save(entity);
} else if (resourceRepository instanceof ResourceRepositoryV2) {
if (method == HttpMethod.POST) {
resource = ((ResourceRepositoryV2) resourceRepository).create(entity);
} else {
resource = ((ResourceRepositoryV2) resourceRepository).save(entity);
}
} else {
resource = ((ResourceRepository) resourceRepository).save(entity);
}
return getResponse(resourceRepository, resource, request);
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forSave(moduleRegistry, method, resourceInformation, queryAdapter, entity);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.core.engine.filter.RepositoryFilterContext in project crnk-framework by crnk-project.
the class ResourceRepositoryAdapter method findAll.
public JsonApiResponse findAll(QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@SuppressWarnings("rawtypes")
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
QueryAdapter queryAdapter = request.getQueryAdapter();
Object resources;
if (isAnnotated) {
resources = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findAll(queryAdapter);
} else if (resourceRepository instanceof ResourceRepositoryV2) {
QuerySpec querySpec = request.getQuerySpec(resourceInformation);
resources = ((ResourceRepositoryV2) resourceRepository).findAll(querySpec);
} else {
resources = ((ResourceRepository) resourceRepository).findAll(request.getQueryParams());
}
return getResponse(resourceRepository, resources, request);
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindAll(moduleRegistry, resourceInformation, queryAdapter);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Aggregations