Search in sources :

Example 1 with AccessPlugin

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);
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AccessPlugin(ddf.catalog.plugin.AccessPlugin) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Result(ddf.catalog.data.Result)

Example 2 with AccessPlugin

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);
}
Also used : TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) AccessPlugin(ddf.catalog.plugin.AccessPlugin) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) BinaryContent(ddf.catalog.data.BinaryContent) Security(org.codice.ddf.security.common.Security) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Subject(ddf.security.Subject) QueryResponse(ddf.catalog.operation.QueryResponse) SourceResponse(ddf.catalog.operation.SourceResponse) Response(javax.ws.rs.core.Response) Metacard(ddf.catalog.data.Metacard) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) QueryResponse(ddf.catalog.operation.QueryResponse) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Before(org.junit.Before)

Aggregations

QueryResponse (ddf.catalog.operation.QueryResponse)2 AccessPlugin (ddf.catalog.plugin.AccessPlugin)2 BinaryContent (ddf.catalog.data.BinaryContent)1 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)1 StopProcessingException (ddf.catalog.plugin.StopProcessingException)1 QueryResponseTransformer (ddf.catalog.transform.QueryResponseTransformer)1 Subject (ddf.security.Subject)1 URL (java.net.URL)1 Response (javax.ws.rs.core.Response)1 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)1 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)1 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)1 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)1 Security (org.codice.ddf.security.common.Security)1