use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method decorateRepository.
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object decorateRepository(Object repository) {
Object decoratedRepository = repository;
List<RepositoryDecoratorFactory> repositoryDecorators = moduleRegistry.getRepositoryDecoratorFactories();
for (RepositoryDecoratorFactory repositoryDecorator : repositoryDecorators) {
Decorator decorator = null;
if (decoratedRepository instanceof RelationshipRepositoryV2) {
decorator = repositoryDecorator.decorateRepository((RelationshipRepositoryV2) decoratedRepository);
} else if (decoratedRepository instanceof ResourceRepositoryV2) {
decorator = repositoryDecorator.decorateRepository((ResourceRepositoryV2) decoratedRepository);
}
if (decorator != null) {
decorator.setDecoratedObject(decoratedRepository);
decoratedRepository = decorator;
}
}
return decoratedRepository;
}
use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class ResourceRepositoryAdapter method delete.
public JsonApiResponse delete(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();
if (isAnnotated) {
((AnnotatedResourceRepositoryAdapter) resourceRepository).delete(id, queryAdapter);
} else if (resourceRepository instanceof ResourceRepositoryV2) {
((ResourceRepositoryV2) resourceRepository).delete(id);
} else {
((ResourceRepository) resourceRepository).delete(id);
}
return new JsonApiResponse();
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forDelete(moduleRegistry, resourceInformation, queryAdapter, id);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.core.repository.ResourceRepositoryV2 in project crnk-framework by crnk-project.
the class ResourceRepositoryAdapter method findAll.
public JsonApiResponse findAll(Iterable ids, QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@SuppressWarnings("rawtypes")
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
QueryAdapter queryAdapter = request.getQueryAdapter();
Iterable<?> ids = request.getIds();
Object resources;
if (isAnnotated) {
resources = ((AnnotatedResourceRepositoryAdapter) resourceRepository).findAll(ids, queryAdapter);
} else if (resourceRepository instanceof ResourceRepositoryV2) {
resources = ((ResourceRepositoryV2) resourceRepository).findAll(ids, request.getQuerySpec(resourceInformation));
} else {
resources = ((ResourceRepository) resourceRepository).findAll(ids, request.getQueryParams());
}
return getResponse(resourceRepository, resources, request);
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindIds(moduleRegistry, resourceInformation, queryAdapter, ids);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.core.repository.ResourceRepositoryV2 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.repository.ResourceRepositoryV2 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));
}
Aggregations