use of io.crnk.core.engine.filter.RepositoryFilterContext in project crnk-framework by crnk-project.
the class RelationshipRepositoryAdapter method setRelation.
@SuppressWarnings("rawtypes")
public JsonApiResponse setRelation(T source, J targetId, ResourceField field, QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
Object source = request.getEntity();
Serializable targetId = request.getId();
ResourceField field = request.getRelationshipField();
QueryAdapter queryAdapter = request.getQueryAdapter();
if (isAnnotated) {
((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).setRelation(source, targetId, field.getUnderlyingName(), queryAdapter);
} else if (relationshipRepository instanceof RelationshipRepositoryV2) {
((RelationshipRepositoryV2) relationshipRepository).setRelation(source, targetId, field.getUnderlyingName());
} else {
((RelationshipRepository) relationshipRepository).setRelation(source, targetId, field.getUnderlyingName());
}
return new JsonApiResponse();
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.PATCH, source, queryAdapter, Arrays.asList(targetId), field);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.core.engine.filter.RepositoryFilterContext in project crnk-framework by crnk-project.
the class RelationshipRepositoryAdapter method addRelations.
@SuppressWarnings("rawtypes")
public JsonApiResponse addRelations(T source, Iterable<J> targetIds, ResourceField field, QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
Object source = request.getEntity();
Iterable<?> targetIds = request.getIds();
ResourceField field = request.getRelationshipField();
QueryAdapter queryAdapter = request.getQueryAdapter();
if (isAnnotated) {
((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).addRelations(source, targetIds, field.getUnderlyingName(), queryAdapter);
} else if (relationshipRepository instanceof RelationshipRepositoryV2) {
((RelationshipRepositoryV2) relationshipRepository).addRelations(source, targetIds, field.getUnderlyingName());
} else {
((RelationshipRepository) relationshipRepository).addRelations(source, targetIds, field.getUnderlyingName());
}
return new JsonApiResponse();
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.POST, source, queryAdapter, targetIds, field);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.core.engine.filter.RepositoryFilterContext 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.engine.filter.RepositoryFilterContext 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.engine.filter.RepositoryFilterContext in project crnk-framework by crnk-project.
the class RelationshipRepositoryAdapter method removeRelations.
@SuppressWarnings("rawtypes")
public JsonApiResponse removeRelations(T source, Iterable<J> targetIds, ResourceField field, QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
Object source = request.getEntity();
Iterable<?> targetIds = request.getIds();
ResourceField field = request.getRelationshipField();
QueryAdapter queryAdapter = request.getQueryAdapter();
if (isAnnotated) {
((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName(), queryAdapter);
} else if (relationshipRepository instanceof RelationshipRepositoryV2) {
((RelationshipRepositoryV2) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName());
} else {
((RelationshipRepository) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName());
}
return new JsonApiResponse();
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.DELETE, source, queryAdapter, targetIds, field);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Aggregations