use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class ObjectSearchDelegateTest method testSearchObjectsIncludeTimeFilterInStatisticsCriteria.
@Test
public void testSearchObjectsIncludeTimeFilterInStatisticsCriteria() throws Exception {
int count = 3;
when(objectFactDao.searchObjects(any())).thenReturn(createSearchResult(count));
when(objectFactDao.calculateObjectStatistics(any())).thenReturn(ObjectStatisticsContainer.builder().build());
SearchObjectRequest request = new SearchObjectRequest().setIncludeStatistics(true).setAfter(11111L).setBefore(22222L);
ResultSet<Object> result = delegate.handle(request);
assertEquals(count, result.getCount());
assertEquals(count, ListUtils.list(result.iterator()).size());
verify(objectFactDao).searchObjects(notNull());
verify(objectFactDao).calculateObjectStatistics(argThat(criteria -> {
assertEquals(request.getAfter(), criteria.getStartTimestamp());
assertEquals(request.getBefore(), criteria.getEndTimestamp());
return true;
}));
}
use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class ObjectResponseConverterTest method testConvertWithStatistics.
@Test
public void testConvertWithStatistics() {
ObjectResponseConverter converter = new ObjectResponseConverter(objectTypeConverter, factTypeConverter, id -> Collections.singleton(new ObjectStatisticsContainer.FactStatistic(UUID.randomUUID(), 42, 123456789, 987654321)));
ObjectRecord record = createRecord();
Object model = converter.apply(record);
assertModel(record, model);
assertEquals(1, model.getStatistics().size());
assertNotNull(model.getStatistics().get(0).getType());
assertEquals(42, model.getStatistics().get(0).getCount());
assertEquals(123456789, (long) model.getStatistics().get(0).getLastAddedTimestamp());
assertEquals(987654321, (long) model.getStatistics().get(0).getLastSeenTimestamp());
}
use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class TraverseGraphDelegateTest method testTraverseGraphByObjectSearchWithoutSearchResult.
@Test
public void testTraverseGraphByObjectSearchWithoutSearchResult() throws Exception {
TraverseByObjectSearchRequest request = new TraverseByObjectSearchRequest();
when(objectSearch.handle(request)).thenReturn(StreamingResultSet.<Object>builder().build());
ResultSet<?> result = delegate.handle(request);
assertFalse(result.iterator().hasNext());
}
use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class TraverseGraphDelegate method executeTraversal.
private void executeTraversal(Collection<UUID> startingObjects, String query) throws InvalidArgumentException, OperationTimeoutException {
try (Graph graph = createGraph();
GremlinExecutor executor = createExecutor()) {
// Create the first step of the graph traversal, i.e. starting the traversal at the Object(s) specified in the request.
// This is injected into the script execution as variable 'g'. Every query has to start from 'g'.
GraphTraversal<Vertex, Vertex> startingPoint = graph.traversal().V(startingObjects.toArray());
Map<String, java.lang.Object> bindings = MapUtils.map(T("g", startingPoint));
// Start script execution and wait until result arrived or execution is aborted.
// Use 'withResult' callback here because the graph will then be iterated inside the 'eval' thread, thus, every
// exception caused by the traversal will be handled inside that thread as well which will result in an ExecutionException.
executor.eval(query, SCRIPT_ENGINE, bindings, this::produceTraversalResult).get();
} catch (ExecutionException ex) {
// Exceptions causing the script execution to fail are wrapped inside an ExecutionException. Need to unwrap them.
Throwable cause = ObjectUtils.ifNull(ex.getCause(), ex);
// In both cases throw an own OperationTimeoutException in order to signal the timeout to the user.
if (cause instanceof TimeoutException) {
throw new OperationTimeoutException("The performed graph traversal query timed out.", "graph.traversal.timeout");
}
// e.g. invalid syntax, an unsupported operation such as 'addE()', or an operation not allowed by the sandbox.
throw new InvalidArgumentException().addValidationError(cause.getMessage(), "graph.traversal.failure", "query", query);
} catch (Exception ex) {
// Something bad happened, abort method.
throw new IllegalStateException("Could not perform graph traversal.", ex);
}
}
use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class ObjectSearchDelegate method handle.
public ResultSet<Object> handle(SearchObjectRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException {
securityContext.checkPermission(TiFunctionConstants.viewThreatIntelFact);
FactSearchCriteria criteria = requestConverter.apply(request);
if (criteria.isUnbounded()) {
throw new AccessDeniedException("Unbounded searches are not allowed. Specify at least one search parameter (in addition to 'limit').");
}
ResultContainer<ObjectRecord> searchResult = objectFactDao.searchObjects(criteria);
// Return search result and add statistics while iterating over the result.
return StreamingResultSet.<Object>builder().setCount(searchResult.getCount()).setLimit(criteria.getLimit()).setValues(new AddStatisticsIterator(searchResult, request)).build();
}
Aggregations