use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class DummyPreIngestPlugin method process.
public UpdateRequest process(UpdateRequest input) throws PluginExecutionException {
String methodName = "process(UpdateRequest)";
LOGGER.debug(ENTERING, methodName);
UpdateRequest newRequest = input;
if (newRequest != null) {
List<Entry<Serializable, Metacard>> updates = newRequest.getUpdates();
List<Metacard> updatedMetacards = new ArrayList<Metacard>();
for (Entry<Serializable, Metacard> updateEntry : updates) {
Metacard metacard = updateEntry.getValue();
updatedMetacards.add(metacard);
}
// Loop to get all ids
List<String> ids = new ArrayList<String>();
int i = 0;
for (Entry<Serializable, Metacard> updateEntry : updates) {
if (i % 2 == 0) {
ids.add((String) updateEntry.getKey());
}
i++;
}
updatedMetacards = this.filterOutMetacards(updatedMetacards);
LOGGER.debug("Returning new update request with id list size: {} and metacard list size: {}", ids.size(), updatedMetacards.size());
newRequest = new UpdateRequestImpl(ids.toArray(new String[ids.size()]), updatedMetacards);
}
LOGGER.debug(EXITING, methodName);
return newRequest;
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class SolrProviderTest method testUpdateAlternativeAttribute.
/**
* Testing update operation of alternative attribute. Should return positive results.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testUpdateAlternativeAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
final MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
create(metacard);
UpdateResponse response = 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() {
MetacardImpl newMetacard = new MetacardImpl(metacard);
newMetacard.setContentTypeName("newContentName");
List<Entry<Serializable, Metacard>> updateList = new ArrayList<Entry<Serializable, Metacard>>();
updateList.add(new SimpleEntry<Serializable, Metacard>(MockMetacard.DEFAULT_TITLE, newMetacard));
return updateList;
}
@Override
public String getAttributeName() {
return Metacard.TITLE;
}
});
Update update = response.getUpdatedMetacards().get(0);
assertThat(update.getNewMetacard().getId(), is(equalTo(update.getOldMetacard().getId())));
assertEquals(1, response.getUpdatedMetacards().size());
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class SecurityPluginTest method testNominalCaseUpdate.
@Test
public void testNominalCaseUpdate() throws Exception {
Subject mockSubject = mock(Subject.class);
ThreadContext.bind(mockSubject);
UpdateRequest request = new MockUpdateRequest();
SecurityPlugin plugin = new SecurityPlugin();
request = plugin.processPreUpdate(request, new HashMap<>());
assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class FrameworkProducer method update.
/**
* Updates metacard(s) in the catalog using the Catalog Framework.
*
* @param exchange
* The {@link org.apache.camel.Exchange} can contain a
* {@link org.apache.camel.Message} with a body of type {@link java.util.List} of
* Metacard or a single Metacard.
* @throws ddf.catalog.source.SourceUnavailableException
* @throws ddf.catalog.source.IngestException
* @throws ddf.camel.component.catalog.framework.FrameworkProducerException
*/
private void update(final Exchange exchange) throws SourceUnavailableException, IngestException, FrameworkProducerException {
UpdateResponse updateResponse = null;
// read in data from exchange
final List<Metacard> metacardsToBeUpdated = readBodyDataAsMetacards(exchange);
// process data if valid
if (!validateList(metacardsToBeUpdated, Metacard.class)) {
processCatalogResponse(updateResponse, exchange);
throw new FrameworkProducerException("Validation of Metacard list failed");
}
LOGGER.debug("Validation of Metacard list passed...");
final String[] metacardIds = new String[metacardsToBeUpdated.size()];
for (int i = 0; i < metacardsToBeUpdated.size(); i++) {
metacardIds[i] = metacardsToBeUpdated.get(i).getId();
}
final UpdateRequest updateRequest = new UpdateRequestImpl(metacardIds, metacardsToBeUpdated);
final int expectedNumberOfUpdatedMetacards = metacardsToBeUpdated.size();
if (expectedNumberOfUpdatedMetacards < 1) {
LOGGER.debug("Empty list of Metacards...nothing to process");
processCatalogResponse(updateResponse, exchange);
return;
}
LOGGER.debug("Making UPDATE call to Catalog Framework...");
updateResponse = catalogFramework.update(updateRequest);
if (updateResponse == null) {
LOGGER.debug("UpdateResponse is null from catalog framework");
processCatalogResponse(updateResponse, exchange);
return;
}
final List<Update> updatedMetacards = updateResponse.getUpdatedMetacards();
if (updatedMetacards == null) {
LOGGER.debug("UpdateResponse returned null metacards list");
processCatalogResponse(updateResponse, exchange);
return;
}
final int numberOfUpdatedMetacards = updatedMetacards.size();
if (numberOfUpdatedMetacards != expectedNumberOfUpdatedMetacards) {
LOGGER.debug("Expected {} metacards updated but only {} were successfully updated", expectedNumberOfUpdatedMetacards, numberOfUpdatedMetacards);
processCatalogResponse(updateResponse, exchange);
return;
}
LOGGER.debug("Updated {} metacards", numberOfUpdatedMetacards);
processCatalogResponse(updateResponse, exchange);
}
use of ddf.catalog.operation.UpdateRequest in project ddf by codice.
the class CatalogBackupPluginTest method getUpdateResponse.
private UpdateResponse getUpdateResponse(List<String> oldMetacardIds) {
List<Update> updatedMetacards = new ArrayList<>(oldMetacardIds.size());
int i = 0;
for (String oldMetacardId : oldMetacardIds) {
Metacard oldMetacard = getMetacard(oldMetacardId, BASE_OLD_TITLE + i);
Metacard newMetacard = getMetacard(oldMetacardId, BASE_NEW_TITLE + i);
// Create UpdateResponse
Update mockUpdate = mock(Update.class);
when(mockUpdate.getOldMetacard()).thenReturn(oldMetacard);
when(mockUpdate.getNewMetacard()).thenReturn(newMetacard);
updatedMetacards.add(mockUpdate);
i++;
}
UpdateRequest request = mock(UpdateRequest.class);
UpdateResponse mockUpdateResponse = mock(UpdateResponse.class);
when(mockUpdateResponse.getUpdatedMetacards()).thenReturn(updatedMetacards);
when(mockUpdateResponse.getRequest()).thenReturn(request);
return mockUpdateResponse;
}
Aggregations