Search in sources :

Example 1 with CswSubscribe

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.

the class AbstractCswSource method configureEventService.

private void configureEventService() {
    if (!cswSourceConfiguration.isRegisterForEvents()) {
        LOGGER.debug("registerForEvents = false - do not configure site {} for events", this.getId());
        removeEventServiceSubscription();
        return;
    }
    if (StringUtils.isEmpty(cswSourceConfiguration.getEventServiceAddress())) {
        LOGGER.debug("eventServiceAddress is NULL or empty - do not configure site {} for events", this.getId());
        return;
    }
    // a single event should be sent)
    if (filterlessSubscriptionId != null) {
        LOGGER.debug("filterless subscription already configured for site " + filterlessSubscriptionId);
        return;
    }
    initSubscribeClientFactory();
    CswSubscribe cswSubscribe = subscribeClientFactory.getClientForSubject(getSystemSubject());
    GetRecordsType request = createSubscriptionGetRecordsRequest();
    try {
        Response response = cswSubscribe.createRecordsSubscription(request);
        if (Response.Status.OK.getStatusCode() == response.getStatus()) {
            AcknowledgementType acknowledgementType = response.readEntity(AcknowledgementType.class);
            filterlessSubscriptionId = acknowledgementType.getRequestId();
        }
    } catch (CswException e) {
        LOGGER.info("Failed to register a subscription for events from csw source with id of " + this.getId());
    }
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 2 with CswSubscribe

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.

the class AbstractCswSource method removeEventServiceSubscription.

private void removeEventServiceSubscription() {
    if (filterlessSubscriptionId != null && subscribeClientFactory != null) {
        CswSubscribe cswSubscribe = subscribeClientFactory.getClientForSubject(getSystemSubject());
        try {
            cswSubscribe.deleteRecordsSubscription(filterlessSubscriptionId);
        } catch (CswException e) {
            LOGGER.info("Failed to remove filterless subscription registered for id {} for csw source with id of {}", filterlessSubscriptionId, this.getId());
        }
        filterlessSubscriptionId = null;
    }
}
Also used : CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)

Example 3 with CswSubscribe

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe in project ddf by codice.

the class TestCswSource method testRefreshWithRegisterForEvents.

@Test
public void testRefreshWithRegisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    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);
    // 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(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 4 with CswSubscribe

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe 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 5 with CswSubscribe

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe 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)

Aggregations

CswSubscribe (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe)5 ResourceResponse (ddf.catalog.operation.ResourceResponse)4 SourceResponse (ddf.catalog.operation.SourceResponse)4 Response (javax.ws.rs.core.Response)4 AcknowledgementType (net.opengis.cat.csw.v_2_0_2.AcknowledgementType)4 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)4 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)2