use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class SolrProviderTest method testUpdateUnknownAttribute.
/**
* Testing update operation of unknown attribute. Should return no results.
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
public void testUpdateUnknownAttribute() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
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() {
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));
return updateList;
}
@Override
public String getAttributeName() {
return "dataAccess";
}
});
assertEquals(0, response.getUpdatedMetacards().size());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class SolrProviderTest method testUpdateNullList.
/**
* Tests null list in UpdateRequest
*
* @throws IngestException
* @throws UnsupportedQueryException
*/
@Test
public void testUpdateNullList() throws IngestException, UnsupportedQueryException {
deleteAllIn(provider);
UpdateResponse response = provider.update(new UpdateRequestImpl(null, Metacard.ID, null));
assertEquals(0, response.getUpdatedMetacards().size());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class SolrProviderTest method testSpatialCreateAndUpdateWithClockwiseRectangle.
@Test
public void testSpatialCreateAndUpdateWithClockwiseRectangle() throws Exception {
deleteAllIn(provider);
/** CREATE **/
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
CreateResponse createResponse = create(Arrays.asList((Metacard) metacard));
assertEquals(1, createResponse.getCreatedMetacards().size());
Filter filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
/** UPDATE **/
MockMetacard updatedMetacard = new MockMetacard(Library.getTampaRecord());
updatedMetacard.setLocation(CLOCKWISE_ARIZONA_RECTANGLE_WKT);
String[] ids = { metacard.getId() };
UpdateResponse updateResponse = update(ids, Arrays.asList((Metacard) updatedMetacard));
assertEquals(1, updateResponse.getUpdatedMetacards().size());
filter = filterBuilder.attribute(Metacard.GEOGRAPHY).intersecting().wkt(FLAGSTAFF_AIRPORT_POINT_WKT);
sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class RestReplicatorPlugin method process.
@Override
public UpdateResponse process(UpdateResponse input) throws PluginExecutionException {
if (Requests.isLocal(input.getRequest()) && client != null && transformer != null) {
WebClient updateClient = WebClient.fromClient(client);
updateClient.type(MediaType.APPLICATION_JSON);
List<Update> updates = input.getUpdatedMetacards();
if (updates == null) {
return input;
}
UpdateRequest request = input.getRequest();
if (request != null && !Metacard.ID.equals(request.getAttributeName())) {
throw new PluginExecutionException(new UnsupportedOperationException("Cannot replicate records that are not updated by " + Metacard.ID));
}
for (int i = 0; i < updates.size(); i++) {
Update update = updates.get(i);
if (request != null && request.getUpdates() != null && request.getUpdates().get(i) != null && request.getUpdates().get(i).getKey() != null) {
updateClient.path(request.getUpdates().get(i).getKey());
Metacard newMetacard = update.getNewMetacard();
String newData = transform(newMetacard, updateClient);
Response r = updateClient.put(newData);
LOGGER.debug("RESPONSE: [{}]", ToStringBuilder.reflectionToString(r));
}
}
}
return input;
}
use of ddf.catalog.operation.UpdateResponse in project ddf by codice.
the class TestPlugin method testUpdate.
@Test
@Ignore
public void testUpdate() throws PluginExecutionException, IngestException, SourceUnavailableException {
// given
UpdateResponse updateResponse = new UpdateResponseImpl(new UpdateRequestImpl("23", metacard), null, Arrays.asList(metacard), Arrays.asList(metacard));
// when
UpdateResponse response = plugin.process(updateResponse);
// then
verify(endpoint).updateDocument(argThat(is("23")), isA(HttpHeaders.class), isA(InputStream.class));
assertThat(response, sameInstance(updateResponse));
}
Aggregations