use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class RegistryStoreImpl method update.
@Override
public UpdateResponse update(UpdateRequest request) throws IngestException {
if (request.getUpdates().stream().map(e -> RegistryUtility.getRegistryId(e.getValue())).anyMatch(Objects::isNull)) {
throw new IngestException("One or more of the metacards is not a registry metacard");
}
Map<String, Metacard> updatedMetacards = request.getUpdates().stream().collect(Collectors.toMap(e -> RegistryUtility.getRegistryId(e.getValue()), Map.Entry::getValue));
Map<String, Metacard> origMetacards = ((OperationTransaction) request.getPropertyValue(Constants.OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards().stream().collect(Collectors.toMap(RegistryUtility::getRegistryId, e -> e));
//update the new metacards with the id from the orig so that they can be found on the remote system
try {
for (Map.Entry<String, Metacard> entry : updatedMetacards.entrySet()) {
setMetacardExtID(entry.getValue(), origMetacards.get(entry.getKey()).getId());
}
} catch (ParserException e) {
throw new IngestException("Could not update metacards id", e);
}
return super.update(request);
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateByIdentifier.
/**
* Tests that the framework properly passes an update by identifier request to the local
* provider.
*/
@Test
public void testUpdateByIdentifier() throws Exception {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
newCard.setResourceURI(new URI("DDF:///12345"));
metacards.add(newCard);
// create the entry manually in the provider
List<Metacard> insertedCards = provider.create(new CreateRequestImpl(metacards)).getCreatedMetacards();
ArrayList<URI> list = new ArrayList<URI>();
list.add(new URI("DDF:///12345"));
UpdateRequest request = new UpdateRequestImpl((URI[]) list.toArray(new URI[list.size()]), insertedCards);
List<Result> mockFederationResults = metacards.stream().map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
// send update to framework
UpdateResponse updateResponse = framework.update(request);
List<Update> returnedCards = updateResponse.getUpdatedMetacards();
assertNotNull(returnedCards);
assertEquals(list.size(), returnedCards.size());
assertTrue(provider.hasReceivedUpdateByIdentifier());
// make sure that the event was posted correctly
assertTrue(eventAdmin.wasEventPosted());
assertEquals(eventAdmin.getLastEvent().getId(), returnedCards.get(returnedCards.size() - 1).getOldMetacard().getId());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class UpdateOperations method doRemoteUpdate.
private UpdateResponse doRemoteUpdate(UpdateRequest updateRequest) {
HashSet<ProcessingDetails> exceptions = new HashSet<>();
Map<String, Serializable> properties = new HashMap<>();
List<CatalogStore> stores = opsCatStoreSupport.getCatalogStoresForRequest(updateRequest, exceptions);
List<Update> updates = new ArrayList<>();
for (CatalogStore store : stores) {
try {
if (!store.isAvailable()) {
exceptions.add(new ProcessingDetailsImpl(store.getId(), null, "CatalogStore is not available"));
} else {
UpdateResponse response = store.update(updateRequest);
properties.put(store.getId(), new ArrayList<>(response.getUpdatedMetacards()));
updates = response.getUpdatedMetacards();
}
} catch (IngestException e) {
INGEST_LOGGER.error("Error updating metacards for CatalogStore {}", store.getId(), e);
exceptions.add(new ProcessingDetailsImpl(store.getId(), e));
}
}
return new UpdateResponseImpl(updateRequest, properties, updates, exceptions);
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class UpdateOperations method doUpdate.
//
// Private helper methods
//
private UpdateResponse doUpdate(UpdateRequest updateRequest) throws IngestException, SourceUnavailableException {
updateRequest = queryOperations.setFlagsOnRequest(updateRequest);
updateRequest = validateUpdateRequest(updateRequest);
updateRequest = validateLocalSource(updateRequest);
try {
updateRequest = injectAttributes(updateRequest);
updateRequest = setDefaultValues(updateRequest);
updateRequest = populateMetacards(updateRequest);
updateRequest = processPreAuthorizationPlugins(updateRequest);
updateRequest = populateUpdateRequestPolicyMap(updateRequest);
updateRequest = processPreUpdateAccessPlugins(updateRequest);
updateRequest = processPreIngestPlugins(updateRequest);
updateRequest = validateUpdateRequest(updateRequest);
// Call the update on the catalog
LOGGER.debug("Calling catalog.update() with {} updates.", updateRequest.getUpdates().size());
UpdateResponse updateResponse = performLocalUpdate(updateRequest);
updateResponse = performRemoteUpdate(updateRequest, updateResponse);
// Handle the posting of messages to pubsub
updateResponse = validateFixUpdateResponse(updateResponse, updateRequest);
return updateResponse;
} catch (StopProcessingException see) {
throw new IngestException(PRE_INGEST_ERROR, see);
} catch (RuntimeException re) {
throw new InternalIngestException("Exception during runtime while performing update", re);
}
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateWithDefaults.
@Test
public void testUpdateWithDefaults() throws Exception {
final String title = "some title";
final Date expiration = new Date();
List<Metacard> metacards = getMetacards(title, expiration);
CreateRequest createRequest = new CreateRequestImpl(metacards);
CreateResponse createResponse = framework.create(createRequest);
verifyDefaults(createResponse.getCreatedMetacards(), title, expiration, null, null, null, null);
registerDefaults();
List<Result> mockFederationResults = metacards.stream().map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
UpdateRequest updateRequest = new UpdateRequestImpl(new String[] { "1", "2", "3", "4", "5" }, createResponse.getCreatedMetacards());
UpdateResponse updateResponse = framework.update(updateRequest);
List<Metacard> updatedMetacards = updateResponse.getUpdatedMetacards().stream().map(Update::getNewMetacard).collect(Collectors.toList());
verifyDefaults(updatedMetacards, title, expiration, DEFAULT_TITLE, DEFAULT_EXPIRATION, DEFAULT_TITLE_CUSTOM, DEFAULT_EXPIRATION_CUSTOM);
}
Aggregations