use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class FilterPluginTest method setup.
@Before
public void setup() {
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>();
realms.add(realm);
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(realms);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {
@Override
public String getName() {
return "testuser";
}
}, realm.getName());
Subject systemSubject = new MockSubject(manager, principalCollection);
plugin = new FilterPlugin() {
@Override
protected Subject getSystemSubject() {
return systemSubject;
}
};
QueryRequestImpl request = getSampleRequest();
Map<String, Serializable> properties = new HashMap<>();
Subject subject = new MockSubject(manager, principalCollection);
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
request.setProperties(properties);
incomingResponse = new QueryResponseImpl(request);
ResourceRequest resourceRequest = mock(ResourceRequest.class);
when(resourceRequest.getProperties()).thenReturn(properties);
resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class));
resourceResponse.setProperties(properties);
DeleteRequest deleteRequest = mock(DeleteRequest.class);
when(deleteRequest.getProperties()).thenReturn(properties);
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(getExactRolesMetacard());
deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards);
List<Metacard> badDeletedMetacards = new ArrayList<>();
badDeletedMetacards.add(getMoreRolesMetacard());
badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards);
createRequest = new CreateRequestImpl(getExactRolesMetacard());
createRequest.setProperties(properties);
badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard());
badCreateRequest.setProperties(properties);
updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard());
updateRequest.setProperties(properties);
ResultImpl result1 = new ResultImpl(getMoreRolesMetacard());
ResultImpl result2 = new ResultImpl(getMissingRolesMetacard());
ResultImpl result3 = new ResultImpl(getExactRolesMetacard());
ResultImpl result4 = new ResultImpl(getNoRolesMetacard());
ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard());
incomingResponse.addResult(result1, false);
incomingResponse.addResult(result2, false);
incomingResponse.addResult(result3, false);
incomingResponse.addResult(result4, false);
incomingResponse.addResult(result5, true);
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class FilterPluginTest method testNoSubject.
@Test(expected = StopProcessingException.class)
public void testNoSubject() throws Exception {
QueryResponseImpl response = new QueryResponseImpl(getSampleRequest());
plugin.processPostQuery(response);
fail("Plugin should have thrown exception when no subject was sent in.");
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class TestCswEndpoint method testPostGetRecordById.
@Test
public void testPostGetRecordById() throws CswException, FederationException, SourceUnavailableException, UnsupportedQueryException {
final GetRecordByIdType getRecordByIdType = new GetRecordByIdType();
getRecordByIdType.setId(Collections.singletonList("123,456"));
getRecordByIdType.setOutputFormat(MediaType.APPLICATION_XML);
getRecordByIdType.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
final Metacard metacard1 = new MetacardImpl();
final Metacard metacard2 = new MetacardImpl();
final List<Result> mockResults = Arrays.asList(new ResultImpl(metacard1), new ResultImpl(metacard2));
final QueryResponse queryResponse = new QueryResponseImpl(null, mockResults, mockResults.size());
doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
final CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdType, null);
verifyCswRecordCollection(cswRecordCollection, metacard1, metacard2);
// "summary" is the default if none is specified in the request.
assertThat(cswRecordCollection.getElementSetType(), is(ElementSetType.SUMMARY));
}
use of ddf.catalog.operation.impl.QueryResponseImpl in project ddf by codice.
the class CachingFederationStrategy method sourceFederate.
private QueryResponse sourceFederate(List<Source> sources, final QueryRequest queryRequest) {
if (LOGGER.isDebugEnabled()) {
for (Source source : sources) {
if (source != null) {
LOGGER.debug("source to query: {}", source.getId());
}
}
}
Query originalQuery = queryRequest.getQuery();
int offset = originalQuery.getStartIndex();
final int pageSize = originalQuery.getPageSize();
// limit offset to max value
if (offset > this.maxStartIndex) {
offset = this.maxStartIndex;
}
final QueryResponseImpl queryResponseQueue = new QueryResponseImpl(queryRequest, null);
Map<Future<SourceResponse>, QueryRequest> futures = new HashMap<>();
Query modifiedQuery = getModifiedQuery(originalQuery, sources.size(), offset, pageSize);
QueryRequest modifiedQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
CompletionService<SourceResponse> queryCompletion = new ExecutorCompletionService<>(queryExecutorService);
// Do NOT call source.isAvailable() when checking sources
for (final Source source : sources) {
if (source != null) {
if (!futuresContainsSource(source, futures)) {
LOGGER.debug("running query on source: {}", source.getId());
QueryRequest sourceQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), Collections.singleton(source.getId()), new HashMap<>(queryRequest.getProperties()));
try {
for (PreFederatedQueryPlugin service : preQuery) {
try {
sourceQueryRequest = service.process(source, sourceQueryRequest);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PreFederatedQueryPlugin", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing", e);
}
if (source instanceof CatalogProvider && SystemInfo.getSiteName().equals(source.getId())) {
// TODO RAP 12 Jul 16: DDF-2294 - Extract into a new PreFederatedQueryPlugin
sourceQueryRequest = validationQueryFactory.getQueryRequestWithValidationFilter(sourceQueryRequest, showErrors, showWarnings);
}
futures.put(queryCompletion.submit(new CallableSourceResponse(source, sourceQueryRequest)), sourceQueryRequest);
} else {
LOGGER.info("Duplicate source found with name {}. Ignoring second one.", source.getId());
}
}
}
QueryResponseImpl offsetResults = null;
// OffsetResultHandler does.
if (offset > 1 && sources.size() > 1) {
offsetResults = new QueryResponseImpl(queryRequest, null);
queryExecutorService.submit(new OffsetResultHandler(queryResponseQueue, offsetResults, pageSize, offset));
}
queryExecutorService.submit(sortedQueryMonitorFactory.createMonitor(queryCompletion, futures, queryResponseQueue, modifiedQueryRequest, postQuery));
QueryResponse queryResponse;
if (offset > 1 && sources.size() > 1) {
queryResponse = offsetResults;
LOGGER.debug("returning offsetResults");
} else {
queryResponse = queryResponseQueue;
LOGGER.debug("returning returnResults: {}", queryResponse);
}
LOGGER.debug("returning Query Results: {}", queryResponse);
return queryResponse;
}
Aggregations