use of io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithEmptyAddRelationsShouldThrowException.
@Test(expected = RepositoryMethodException.class)
public void onClassWithEmptyAddRelationsShouldThrowException() throws Exception {
// GIVEN
RelationshipRepositoryWithEmptyAddRelations repo = new RelationshipRepositoryWithEmptyAddRelations();
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
// WHEN
sut.addRelations(new Task(), Collections.singleton(1L), "project", queryAdapter);
}
use of io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter 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));
}
use of io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter in project crnk-framework by crnk-project.
the class RelationshipRepositoryAdapter method setRelations.
@SuppressWarnings("rawtypes")
public JsonApiResponse setRelations(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).setRelations(source, targetIds, field.getUnderlyingName(), queryAdapter);
} else if (relationshipRepository instanceof RelationshipRepositoryV2) {
((RelationshipRepositoryV2) relationshipRepository).setRelations(source, targetIds, field.getUnderlyingName());
} else {
((RelationshipRepository) relationshipRepository).setRelations(source, targetIds, field.getUnderlyingName());
}
return new JsonApiResponse();
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.PATCH, source, queryAdapter, targetIds, field);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
use of io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithRemoveRelationsShouldAddValue.
@Test
public void onClassWithRemoveRelationsShouldAddValue() throws Exception {
// GIVEN
RelationshipRepositoryWithRemoveRelations repo = spy(RelationshipRepositoryWithRemoveRelations.class);
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
Task task = new Task();
// WHEN
sut.removeRelations(task, Collections.singleton(1L), "project", queryAdapter);
// THEN
verify(repo).removeRelations(eq(task), eq(Collections.singleton(1L)), eq("project"));
}
use of io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithoutAddRelationsShouldThrowException.
@Test(expected = RepositoryAnnotationNotFoundException.class)
public void onClassWithoutAddRelationsShouldThrowException() throws Exception {
// GIVEN
RelationshipRepositoryWithoutAnyMethods repo = new RelationshipRepositoryWithoutAnyMethods();
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
// WHEN
sut.addRelations(new Task(), Collections.singleton(1L), "project", queryAdapter);
}
Aggregations