use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class InMemoryProcessingFramework method storeMetacardUpdates.
private void storeMetacardUpdates(Map<String, Metacard> metacardsToUpdate, Map<String, Serializable> properties) {
if (MapUtils.isNotEmpty(metacardsToUpdate)) {
LOGGER.trace("Storing metacard updates");
List<Map.Entry<Serializable, Metacard>> updateList = metacardsToUpdate.values().stream().map(metacard -> new AbstractMap.SimpleEntry<Serializable, Metacard>(metacard.getId(), metacard)).collect(Collectors.toList());
UpdateRequest updateMetacardsRequest = new UpdateRequestImpl(updateList, UpdateRequest.UPDATE_BY_ID, properties);
Subject subject = (Subject) updateMetacardsRequest.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
if (subject == null) {
LOGGER.debug("No subject to send UpdateRequest. Updates will not be sent back to the catalog.");
} else {
subject.execute(() -> {
try {
catalogFramework.update(updateMetacardsRequest);
LOGGER.debug("Successfully completed update metacards request");
} catch (IngestException | SourceUnavailableException | RuntimeException e) {
LOGGER.info("Unable to complete update request", e);
}
return null;
});
}
} else {
LOGGER.debug("No metacards to update");
}
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CatalogComponentFrameworkTest method testUpdateWithIngestException.
@Test
public /**
* Operation: UPDATE
* Body contains: Metacard
*/
void testUpdateWithIngestException() throws Exception {
resetMocks();
// Setup expectations to verify
final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
mockVerifierEndpoint.expectedMessageCount(1);
final List<Metacard> metacards = new ArrayList<Metacard>();
metacards.add(metacard1);
// setup mock catalog framework
final Update update = new UpdateImpl(metacard1, metacard2);
List<Update> updates = new ArrayList<Update>();
updates.add(update);
final String[] metacardIds = new String[metacards.size()];
for (int i = 0; i < metacards.size(); i++) {
metacardIds[i] = metacards.get(i).getId();
}
UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacards);
UpdateResponse updateResponse = new UpdateResponseImpl(updateRequest, new HashMap(), updates);
when(catalogFramework.update(any(UpdateRequest.class))).thenThrow(new IngestException());
// Exercise the route with a UPDATE operation
template.sendBodyAndHeader("direct:sampleInput", metacards, "Operation", "UPDATE");
// Verify that the number of metacards in the exchange after the records
// is identical to the input
assertListSize(mockVerifierEndpoint.getExchanges(), 1);
final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
final List<Update> cardsUpdated = (List<Update>) exchange.getIn().getBody();
assertListSize(cardsUpdated, 0);
mockVerifierEndpoint.assertIsSatisfied();
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CatalogComponentFrameworkTest method testUpdateWithListOfMetacards.
@Test
public /**
* Operation: UPDATE
* Body contains: List<Metacard>
*/
void testUpdateWithListOfMetacards() throws Exception {
resetMocks();
// Setup expectations to verify
final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
mockVerifierEndpoint.expectedMessageCount(1);
final List<Metacard> metacards = new ArrayList<Metacard>();
metacards.add(metacard1);
// setup mock catalog framework
final Update update = new UpdateImpl(metacard1, metacard2);
List<Update> updates = new ArrayList<Update>();
updates.add(update);
final String[] metacardIds = new String[metacards.size()];
for (int i = 0; i < metacards.size(); i++) {
metacardIds[i] = metacards.get(i).getId();
}
UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacards);
UpdateResponse updateResponse = new UpdateResponseImpl(updateRequest, new HashMap(), updates);
when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse);
// Exercise the route with a UPDATE operation
template.sendBodyAndHeader("direct:sampleInput", metacards, "Operation", "UPDATE");
// Verify that the number of metacards in the exchange after the records
// is identical to the input
assertListSize(mockVerifierEndpoint.getExchanges(), 1);
final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
final List<Update> cardsUpdated = (List<Update>) exchange.getIn().getBody();
assertListSize(cardsUpdated, 1);
mockVerifierEndpoint.assertIsSatisfied();
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class TestMetacardGroomerPlugin method testUpdateByAlternativeIdentifier.
@Test
public void testUpdateByAlternativeIdentifier() throws PluginExecutionException, StopProcessingException, URISyntaxException {
Date snapshotOfNow = new Date();
Metacard inputMetacard = getStandardMetacard(null);
URI[] uris = new URI[1];
uris[0] = new URI(SAMPLE_ID);
UpdateRequestImpl inputRequest = new UpdateRequestImpl(uris, Arrays.asList(copy(inputMetacard)));
UpdateRequest returnedRequest = plugin.process(inputRequest);
assertNotNull(returnedRequest);
assertThat(returnedRequest.getUpdates().size(), is(1));
Metacard outputMetacard = returnedRequest.getUpdates().get(0).getValue();
assertThat(inputMetacard.getId(), is(outputMetacard.getId()));
assertEquals(DEFAULT_TITLE, outputMetacard.getTitle());
assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
assertEquals(DEFAULT_TYPE, outputMetacard.getContentTypeName());
assertEquals(DEFAULT_VERSION, outputMetacard.getContentTypeVersion());
assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
assertThat(outputMetacard.getCreatedDate().getTime(), is(inputMetacard.getCreatedDate().getTime()));
assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), equalTo(((Date) inputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime()));
assertThat(outputMetacard.getModifiedDate().getTime(), is(equalTo(inputMetacard.getModifiedDate().getTime())));
assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
assertEquals(inputMetacard.getEffectiveDate(), outputMetacard.getEffectiveDate());
assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class SolrProviderTest method testUpdateNonUniqueAttributeValue2.
/**
* Tests if we catch a rare case where some attribute value match multiple Metacards while
* others do not match any records.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test(expected = IngestException.class)
public void testUpdateNonUniqueAttributeValue2() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
MockMetacard m1 = new MockMetacard(Library.getFlagstaffRecord());
MockMetacard m2 = new MockMetacard(Library.getFlagstaffRecord());
List<Metacard> list = Arrays.asList((Metacard) m1, m2);
create(list);
provider.update(new UpdateRequest() {
@Override
public boolean hasProperties() {
return false;
}
@Override
public Serializable getPropertyValue(String name) {
return null;
}
@Override
public Set<String> getPropertyNames() {
return null;
}
@Override
public Map<String, Serializable> getProperties() {
return null;
}
@Override
public boolean containsPropertyName(String name) {
return false;
}
@Override
public List<Entry<Serializable, Metacard>> getUpdates() {
MockMetacard newMetacard = new MockMetacard(Library.getShowLowRecord());
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
updateList.add(new SimpleEntry<Serializable, Metacard>(TAMPA_QUERY_PHRASE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return Metacard.TITLE;
}
});
}
Aggregations