use of ddf.catalog.plugin.AccessPlugin in project ddf by codice.
the class SendEvent method sendEvent.
private void sendEvent(String operation, Metacard... metacards) {
if (subject == null) {
return;
}
try {
List<Result> results = Arrays.asList(metacards).stream().map(ResultImpl::new).collect(Collectors.toList());
QueryResponse queryResponse = new QueryResponseImpl(query, results, true, metacards.length);
CswRecordCollection recordCollection = new CswRecordCollection();
recordCollection.setElementName(elementName);
recordCollection.setElementSetType(elementSetType);
recordCollection.setById(false);
recordCollection.setRequest(request);
recordCollection.setResultType(resultType);
recordCollection.setDoWriteNamespaces(false);
recordCollection.setMimeType(mimeType);
recordCollection.setOutputSchema(outputSchema);
queryResponse.getRequest().getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
for (AccessPlugin plugin : getAccessPlugins()) {
queryResponse = plugin.processPostQuery(queryResponse);
}
if (queryResponse.getResults().isEmpty()) {
return;
}
recordCollection.setSourceResponse(queryResponse);
send(operation, recordCollection);
} catch (StopProcessingException | InvalidSyntaxException e) {
LOGGER.debug("Unable to send event error running AccessPlugin processPostQuery. ", e);
}
}
use of ddf.catalog.plugin.AccessPlugin in project ddf by codice.
the class SendEventTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("ddf.home", ".");
callbackURI = new URL("https://localhost:12345/services/csw/subscription/event");
ObjectFactory objectFactory = new ObjectFactory();
request = new GetRecordsType();
request.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
request.setResultType(ResultType.RESULTS);
request.getResponseHandler().add(callbackURI.toString());
queryType = new QueryType();
elementSetNameType = new ElementSetNameType();
elementSetNameType.setValue(ElementSetType.BRIEF);
queryType.setElementSetName(elementSetNameType);
request.setAbstractQuery(objectFactory.createAbstractQuery(queryType));
transformerManager = mock(TransformerManager.class);
transformer = mock(QueryResponseTransformer.class);
binaryContent = mock(BinaryContent.class);
when(transformerManager.getTransformerBySchema(Matchers.contains(CswConstants.CSW_OUTPUT_SCHEMA))).thenReturn(transformer);
when(transformer.transform(any(SourceResponse.class), anyMap())).thenReturn(binaryContent);
when(binaryContent.getByteArray()).thenReturn("byte array with message contents".getBytes());
query = mock(QueryRequest.class);
metacard = mock(Metacard.class);
webclient = mock(WebClient.class);
mockCxfClientFactory = mock(SecureCxfClientFactory.class);
response = mock(Response.class);
subject = mock(Subject.class);
mockSecurity = mock(Security.class);
headers.put(Subject.class.toString(), Arrays.asList(new Subject[] { subject }));
AccessPlugin accessPlugin = mock(AccessPlugin.class);
accessPlugins.add(accessPlugin);
when(mockCxfClientFactory.getWebClient()).thenReturn(webclient);
when(webclient.invoke(anyString(), any(QueryResponse.class))).thenReturn(response);
when(response.getHeaders()).thenReturn(headers);
when(accessPlugin.processPostQuery(any(QueryResponse.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
sendEvent = new SendEventExtension(transformerManager, request, query, mockCxfClientFactory);
sendEvent.setSubject(subject);
}
Aggregations