Search in sources :

Example 6 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class CswQueryResponseTransformer method writeAcknowledgement.

private ByteArrayOutputStream writeAcknowledgement(GetRecordsType request) throws CatalogTransformerException {
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        JAXBContext jaxBContext = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:" + "net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0");
        Marshaller marshaller = jaxBContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        AcknowledgementType ack = new AcknowledgementType();
        EchoedRequestType echoedRequest = new EchoedRequestType();
        JAXBElement<GetRecordsType> jaxBRequest = new ObjectFactory().createGetRecords(request);
        echoedRequest.setAny(jaxBRequest);
        ack.setEchoedRequest(echoedRequest);
        try {
            ack.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
        } catch (DatatypeConfigurationException e) {
            LOGGER.debug("Failed to set timestamp on Acknowledgement, Exception {}", e);
        }
        JAXBElement<AcknowledgementType> jaxBAck = new ObjectFactory().createAcknowledgement(ack);
        marshaller.marshal(jaxBAck, byteArrayOutputStream);
        return byteArrayOutputStream;
    } catch (JAXBException e) {
        throw new CatalogTransformerException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) EchoedRequestType(net.opengis.cat.csw.v_2_0_2.EchoedRequestType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBContext(javax.xml.bind.JAXBContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 7 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class CswSubscriptionEndpoint method createAcknowledgment.

private Response createAcknowledgment(GetRecordsType request) {
    AcknowledgementType acknowledgementType = new AcknowledgementType();
    if (request != null) {
        EchoedRequestType echoedRequest = new EchoedRequestType();
        echoedRequest.setAny(objectFactory.createGetRecords(request));
        acknowledgementType.setEchoedRequest(echoedRequest);
        acknowledgementType.setRequestId(request.getRequestId());
    }
    if (datatypeFactory != null) {
        acknowledgementType.setTimeStamp(datatypeFactory.newXMLGregorianCalendar());
    }
    return Response.ok().entity(acknowledgementType).build();
}
Also used : EchoedRequestType(net.opengis.cat.csw.v_2_0_2.EchoedRequestType) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 8 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class TestCswSource method testRefreshWithUpdateRegisterForEvents.

@Test
public void testRefreshWithUpdateRegisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    cswSource.filterlessSubscriptionId = subscriptionId;
    CswSubscribe client = mock(CswSubscribe.class);
    Response response = mock(Response.class);
    AcknowledgementType ack = mock(AcknowledgementType.class);
    when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
    when(response.getStatus()).thenReturn(200);
    when(response.readEntity(any(Class.class))).thenReturn(ack);
    when(ack.getRequestId()).thenReturn(subscriptionId);
    when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
    cswSource.cswSourceConfiguration.setRegisterForEvents(true);
    cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint + "/original");
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
    configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
    Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
    verify(client).deleteRecordsSubscription(subscriptionId);
    verify(ack).getRequestId();
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 9 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class TestCswSource method testRefreshWithUnregisterForEvents.

@Test
public void testRefreshWithUnregisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    cswSource.filterlessSubscriptionId = subscriptionId;
    CswSubscribe client = mock(CswSubscribe.class);
    Response response = mock(Response.class);
    AcknowledgementType ack = mock(AcknowledgementType.class);
    when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
    when(response.getStatus()).thenReturn(200);
    when(response.readEntity(any(Class.class))).thenReturn(ack);
    when(ack.getRequestId()).thenReturn(subscriptionId);
    when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
    cswSource.cswSourceConfiguration.setRegisterForEvents(true);
    cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint);
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    configuration.put(cswSource.REGISTER_FOR_EVENTS, false);
    configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    Assert.assertFalse(cswSourceConfiguration.isRegisterForEvents());
    Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
    verify(client).deleteRecordsSubscription(subscriptionId);
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 10 with AcknowledgementType

use of net.opengis.cat.csw.v_2_0_2.AcknowledgementType in project ddf by codice.

the class CswSubscriptionEndpointTest method testCreateRecordsSubscriptionPOST.

@Test
public void testCreateRecordsSubscriptionPOST() throws Exception {
    CSW_LOGGER.setLevel(Level.DEBUG);
    GetRecordsRequest getRecordsRequest = createDefaultGetRecordsRequest();
    getRecordsRequest.setResponseHandler(RESPONSE_HANDLER_URL);
    Response response = cswSubscriptionEndpoint.createRecordsSubscription(getRecordsRequest.get202RecordsType());
    AcknowledgementType createAck = (AcknowledgementType) response.getEntity();
    assertThat(createAck, notNullValue());
    assertThat(createAck.getRequestId(), notNullValue());
    CSW_LOGGER.setLevel(Level.INFO);
    verify(mockContext).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
}
Also used : Response(javax.ws.rs.core.Response) Dictionary(java.util.Dictionary) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) GetRecordsRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest) Test(org.junit.Test)

Aggregations

AcknowledgementType (net.opengis.cat.csw.v_2_0_2.AcknowledgementType)11 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)6 SourceResponse (ddf.catalog.operation.SourceResponse)5 ResourceResponse (ddf.catalog.operation.ResourceResponse)4 CswSubscribe (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Subscription (ddf.catalog.event.Subscription)3 Dictionary (java.util.Dictionary)3 JAXBElement (javax.xml.bind.JAXBElement)3 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)3 GetRecordsRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordsRequest)3 CswSubscription (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription)3 EchoedRequestType (net.opengis.cat.csw.v_2_0_2.EchoedRequestType)2 BinaryContent (ddf.catalog.data.BinaryContent)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Serializable (java.io.Serializable)1