use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class FederationAdminServiceImpl method updateRegistryEntry.
@Override
public void updateRegistryEntry(Metacard updateMetacard, Set<String> destinations) throws FederationAdminException {
validateRegistryMetacards(Collections.singletonList(updateMetacard));
Map<String, Serializable> properties = new HashMap<>();
String mcardId = updateMetacard.getId();
if (isRemoteMetacard(updateMetacard) || CollectionUtils.isNotEmpty(destinations)) {
Filter idFilter = filterBuilder.attribute(RegistryObjectMetacardType.REMOTE_METACARD_ID).is().equalTo().text(updateMetacard.getId());
Filter tagFilter = filterBuilder.attribute(Metacard.TAGS).is().like().text(RegistryConstants.REGISTRY_TAG_INTERNAL);
List<Metacard> results = this.getRegistryMetacardsByFilter(filterBuilder.allOf(tagFilter, idFilter), destinations);
if (results.size() != 1) {
throw new FederationAdminException("Could not find metacard to update.");
}
mcardId = results.get(0).getId();
LOGGER.debug("Looked up remote-mcard-id {} and got id {}", updateMetacard.getId(), mcardId);
}
List<Map.Entry<Serializable, Metacard>> updateList = new ArrayList<>();
updateList.add(new AbstractMap.SimpleEntry<>(mcardId, updateMetacard));
UpdateRequest updateRequest = new UpdateRequestImpl(updateList, Metacard.ID, properties, destinations);
try {
UpdateResponse updateResponse = security.runWithSubjectOrElevate(() -> catalogFramework.update(updateRequest));
if (!updateResponse.getProcessingErrors().isEmpty()) {
throw new FederationAdminException("Processing error occurred while updating registry entry. Details:" + System.lineSeparator() + stringifyProcessingErrors(updateResponse.getProcessingErrors()));
}
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error updating registry entry.";
LOGGER.debug("{} Metacard ID: {}", message, updateMetacard.getId());
throw new FederationAdminException(message, e);
}
}
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 FanoutCatalogFrameworkTest method testBlacklistedTagUpdateRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagUpdateRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
UpdateRequest request = new UpdateRequestImpl(metacard.getId(), metacard);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
framework.update(request);
}
Aggregations