Search in sources :

Example 6 with UpdateImpl

use of ddf.catalog.operation.impl.UpdateImpl in project ddf by codice.

the class DeliveryProcessor method process.

public void process(Event event) {
    String methodName = "process";
    LOGGER.debug("ENTERING: {}", methodName);
    Metacard entry = (Metacard) event.getProperty(PubSubConstants.HEADER_ENTRY_KEY);
    String operation = event.getProperty(PubSubConstants.HEADER_OPERATION_KEY).toString();
    LOGGER.debug("Delivering catalog entry.");
    if (subscription != null) {
        if (entry != null) {
            if (operation.equalsIgnoreCase(PubSubConstants.CREATE)) {
                try {
                    for (PreDeliveryPlugin plugin : preDelivery) {
                        LOGGER.debug("Processing 'created' entry with preDelivery plugin");
                        entry = plugin.processCreate(entry);
                    }
                    subscription.getDeliveryMethod().created(entry);
                } catch (PluginExecutionException e) {
                    LOGGER.debug("Plugin had exception during execution - still delivering the entry", e);
                    subscription.getDeliveryMethod().created(entry);
                } catch (StopProcessingException e) {
                    LOGGER.info("Pre-delivery plugin determined entry cannot be delivered", e);
                }
            } else if (operation.equalsIgnoreCase(PubSubConstants.UPDATE)) {
                // TODO: Handle hit or miss
                try {
                    for (PreDeliveryPlugin plugin : preDelivery) {
                        LOGGER.debug("Processing 'updated' entry with preDelivery plugin");
                        Update updatedEntry = plugin.processUpdateHit(new UpdateImpl(entry, null));
                        entry = updatedEntry.getNewMetacard();
                    }
                    subscription.getDeliveryMethod().updatedHit(entry, entry);
                } catch (PluginExecutionException e) {
                    LOGGER.debug("Plugin had exception during execution - still delivering the entry", e);
                    subscription.getDeliveryMethod().updatedHit(entry, entry);
                } catch (StopProcessingException e) {
                    LOGGER.info("Pre-delivery plugin determined entry cannot be delivered", e);
                }
            } else if (operation.equalsIgnoreCase(PubSubConstants.DELETE)) {
                try {
                    for (PreDeliveryPlugin plugin : preDelivery) {
                        LOGGER.debug("Processing 'deleted' entry with preDelivery plugin");
                        entry = plugin.processCreate(entry);
                    }
                    subscription.getDeliveryMethod().deleted(entry);
                } catch (PluginExecutionException e) {
                    LOGGER.debug("Plugin had exception during execution - still delivering the entry", e);
                    subscription.getDeliveryMethod().deleted(entry);
                } catch (StopProcessingException e) {
                    LOGGER.info("Pre-delivery plugin determined entry cannot be delivered", e);
                }
            } else {
                LOGGER.debug("Could not deliver hit for subscription.");
            }
        } else {
            LOGGER.debug("Could not deliver hit for subscription. Catalog entry is null.");
        }
    } else {
        LOGGER.debug("Could not deliver hit for subscription. Subscription is null.");
    }
    LOGGER.debug("EXITING: {}", methodName);
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Metacard(ddf.catalog.data.Metacard) PreDeliveryPlugin(ddf.catalog.plugin.PreDeliveryPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Update(ddf.catalog.operation.Update) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 7 with UpdateImpl

use of ddf.catalog.operation.impl.UpdateImpl in project ddf by codice.

the class TestCswEndpoint method testUpdateTransactionWithNewRecord.

@Test
public void testUpdateTransactionWithNewRecord() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    MetacardImpl updatedMetacard = new MetacardImpl();
    updatedMetacard.setId("123");
    UpdateAction updateAction = new UpdateAction(updatedMetacard, CswConstants.CSW_RECORD, "");
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    transactionRequest.getUpdateActions().add(updateAction);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(transactionRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(1));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    assertThat(actualUpdateRequest.getUpdates().size(), is(1));
    assertThat(actualUpdateRequest.getUpdates().get(0).getValue().getId(), is("123"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Test(org.junit.Test)

Example 8 with UpdateImpl

use of ddf.catalog.operation.impl.UpdateImpl in project ddf by codice.

the class TestCswEndpoint method testUpdateTransactionWithConstraint.

@Test
public void testUpdateTransactionWithConstraint() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Result> results = new ArrayList<>();
    MetacardImpl firstResult = new MetacardImpl();
    firstResult.setId("123");
    firstResult.setTitle("Title one");
    firstResult.setAttribute("subject", "Subject one");
    results.add(new ResultImpl(firstResult));
    MetacardImpl secondResult = new MetacardImpl();
    secondResult.setId("789");
    secondResult.setTitle("Title two");
    secondResult.setAttribute("subject", "Subject two");
    results.add(new ResultImpl(secondResult));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    Map<String, Serializable> recordProperties = new HashMap<>();
    recordProperties.put("title", "foo");
    recordProperties.put("subject", "bar");
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText("title = 'fake'");
    UpdateAction updateAction = new UpdateAction(recordProperties, CswConstants.CSW_RECORD, "", constraint, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest updateRequest = new CswTransactionRequest();
    updateRequest.getUpdateActions().add(updateAction);
    updateRequest.setVersion(CswConstants.VERSION_2_0_2);
    updateRequest.setService(CswConstants.CSW);
    updateRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(updateRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(2));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    List<Map.Entry<Serializable, Metacard>> updates = actualUpdateRequest.getUpdates();
    assertThat(updates.size(), is(2));
    Metacard firstUpdate = updates.get(0).getValue();
    assertThat(firstUpdate.getId(), is("123"));
    assertThat(firstUpdate.getTitle(), is("foo"));
    assertThat(firstUpdate.getAttribute("subject").getValue(), is("bar"));
    Metacard secondUpdate = updates.get(1).getValue();
    assertThat(secondUpdate.getId(), is("789"));
    assertThat(secondUpdate.getTitle(), is("foo"));
    assertThat(secondUpdate.getAttribute("subject").getValue(), is("bar"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 9 with UpdateImpl

use of ddf.catalog.operation.impl.UpdateImpl in project ddf by codice.

the class CachingFederationStrategyTest method testProcessUpdateResponse.

@Test
public void testProcessUpdateResponse() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
    UpdateResponse response = mock(UpdateResponseImpl.class);
    UpdateRequest request = mock(UpdateRequestImpl.class);
    when(request.hasProperties()).thenReturn(true);
    when(request.getProperties()).thenReturn(testMap);
    when(response.getRequest()).thenReturn(request);
    MetacardImpl newMetacard = mock(MetacardImpl.class);
    when(newMetacard.getId()).thenReturn("new metacard");
    when(newMetacard.getSourceId()).thenReturn("new source ID");
    UpdateImpl updateImpl = mock(UpdateImpl.class);
    when(updateImpl.getNewMetacard()).thenReturn(newMetacard);
    List<Update> cards = Arrays.asList(updateImpl);
    ArgumentCaptor<List<Metacard>> metacardsCaptor = ArgumentCaptor.forClass((Class) List.class);
    when(response.getUpdatedMetacards()).thenReturn(cards);
    doNothing().when(cache).create(metacardsCaptor.capture());
    assertThat(response, is(strategy.process(response)));
    assertThat(metacardsCaptor.getValue().contains(newMetacard), is(true));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) List(java.util.List) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 10 with UpdateImpl

use of ddf.catalog.operation.impl.UpdateImpl in project ddf by codice.

the class DummyPreDeliveryPlugin method processUpdateMiss.

@Override
public Update processUpdateMiss(Update update) throws PluginExecutionException, StopProcessingException {
    String methodName = "processUpdateMiss";
    LOGGER.trace(ENTERING, methodName);
    Metacard newMetacard = update.getNewMetacard();
    Metacard oldMetacard = update.getOldMetacard();
    Update newUpdate = new UpdateImpl(newMetacard, oldMetacard);
    LOGGER.trace(EXITING, methodName);
    return newUpdate;
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Metacard(ddf.catalog.data.Metacard) Update(ddf.catalog.operation.Update)

Aggregations

Update (ddf.catalog.operation.Update)11 UpdateImpl (ddf.catalog.operation.impl.UpdateImpl)11 Metacard (ddf.catalog.data.Metacard)9 ArrayList (java.util.ArrayList)8 UpdateResponse (ddf.catalog.operation.UpdateResponse)7 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)7 HashMap (java.util.HashMap)7 UpdateRequest (ddf.catalog.operation.UpdateRequest)6 Test (org.junit.Test)6 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 Serializable (java.io.Serializable)4 List (java.util.List)4 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)3 Exchange (org.apache.camel.Exchange)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 IngestException (ddf.catalog.source.IngestException)2 Entry (java.util.Map.Entry)2 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)2 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)2 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)2