Search in sources :

Example 11 with UpdateResponse

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());
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.containsString(org.hamcrest.Matchers.containsString) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map)

Example 12 with UpdateResponse

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());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 13 with UpdateResponse

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());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 14 with UpdateResponse

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;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) Update(ddf.catalog.operation.Update) WebClient(org.apache.cxf.jaxrs.client.WebClient) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 15 with UpdateResponse

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));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) HttpHeaders(javax.ws.rs.core.HttpHeaders) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) InputStream(java.io.InputStream) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

UpdateResponse (ddf.catalog.operation.UpdateResponse)57 Test (org.junit.Test)38 Metacard (ddf.catalog.data.Metacard)36 HashMap (java.util.HashMap)24 UpdateRequest (ddf.catalog.operation.UpdateRequest)22 Serializable (java.io.Serializable)22 ArrayList (java.util.ArrayList)22 Update (ddf.catalog.operation.Update)21 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)15 List (java.util.List)15 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)14 CreateResponse (ddf.catalog.operation.CreateResponse)13 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)11 Map (java.util.Map)11 ContentItem (ddf.catalog.content.data.ContentItem)10 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)10 Result (ddf.catalog.data.Result)10 IngestException (ddf.catalog.source.IngestException)10 DeleteResponse (ddf.catalog.operation.DeleteResponse)9 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)9