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);
}
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"));
}
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"));
}
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));
}
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;
}
Aggregations