use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class RepositoryFilterTest method findBulkOneTargetsBulkImpl.
@SuppressWarnings({ "unchecked" })
@Test
public void findBulkOneTargetsBulkImpl() throws Exception {
taskRelationAdapter.findBulkManyTargets(Arrays.asList(1L), assignedTasksField, queryAdapter);
ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);
Mockito.verify(filter, Mockito.times(0)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterBulkRequest(contexts.capture(), Mockito.any(RepositoryBulkRequestFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterLinks(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryLinksFilterChain.class));
Mockito.verify(filter, Mockito.times(1)).filterMeta(Mockito.any(RepositoryFilterContext.class), Mockito.any(Iterable.class), Mockito.any(RepositoryMetaFilterChain.class));
Assert.assertEquals(1, contexts.getAllValues().size());
RepositoryFilterContext context1 = contexts.getAllValues().get(0);
RepositoryRequestSpec requestSpec1 = context1.getRequest();
Assert.assertEquals(queryAdapter, requestSpec1.getQueryAdapter());
Assert.assertNull(requestSpec1.getEntity());
Assert.assertEquals("assignedTasks", requestSpec1.getRelationshipField().getUnderlyingName());
Assert.assertEquals(HttpMethod.GET, requestSpec1.getMethod());
Assert.assertEquals(Arrays.asList(1L), requestSpec1.getIds());
Assert.assertSame(querySpec, requestSpec1.getQuerySpec(userInfo));
}
use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class SleuthRepositoryFilter method filterRequest.
@Override
public JsonApiResponse filterRequest(RepositoryFilterContext context, RepositoryRequestFilterChain chain) {
RepositoryRequestSpec request = context.getRequest();
String query = SleuthUtil.getQuery(request, moduleContext.getResourceRegistry());
Span span = tracer.createSpan(SleuthUtil.getSpanName(request));
JsonApiResponse result = null;
Exception exception = null;
try {
span.tag("lc", COMPONENT_NAME);
result = chain.doFilter(context);
return result;
} catch (RuntimeException e) {
exception = e;
throw e;
} finally {
boolean resultError = result != null && result.getErrors() != null && result.getErrors().iterator().hasNext();
boolean failed = exception != null || resultError;
String status = failed ? STRING_EXCEPTION : STRING_OK;
span.tag(STATUS_CODE_ANNOTATION, status);
writeQuery(span, query);
writeResults(span, result);
tracer.close(span);
}
}
use of io.crnk.core.engine.dispatcher.RepositoryRequestSpec in project crnk-framework by crnk-project.
the class BraveRepositoryFilter method filterRequest.
@Override
public JsonApiResponse filterRequest(RepositoryFilterContext context, RepositoryRequestFilterChain chain) {
Tracer tracer = tracing.tracer();
RepositoryRequestSpec request = context.getRequest();
String query = BraveUtil.getQuery(request, moduleContext.getResourceRegistry());
Span span = tracer.nextSpan();
span.name(BraveUtil.getSpanName(request));
span.tag(Constants.LOCAL_COMPONENT, COMPONENT_NAME);
span.start();
JsonApiResponse result = null;
Exception exception = null;
try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) {
result = chain.doFilter(context);
return result;
} catch (RuntimeException e) {
exception = e;
throw e;
} finally {
boolean resultError = result != null && result.getErrors() != null && result.getErrors().iterator().hasNext();
boolean failed = exception != null || resultError;
String status = failed ? STRING_EXCEPTION : STRING_OK;
span.tag(STATUS_CODE_ANNOTATION, status);
writeQuery(span, query);
writeResults(span, result);
span.finish();
}
}
Aggregations