Search in sources :

Example 56 with UpdateRequest

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;
}
Also used : Entry(java.util.Map.Entry) Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl)

Example 57 with UpdateRequest

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());
}
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) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) 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) Test(org.junit.Test)

Example 58 with UpdateRequest

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));
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) HashMap(java.util.HashMap) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 59 with UpdateRequest

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);
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Update(ddf.catalog.operation.Update) Endpoint(org.apache.camel.Endpoint)

Example 60 with UpdateRequest

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;
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update)

Aggregations

UpdateRequest (ddf.catalog.operation.UpdateRequest)61 Test (org.junit.Test)44 Metacard (ddf.catalog.data.Metacard)41 ArrayList (java.util.ArrayList)32 Serializable (java.io.Serializable)25 UpdateResponse (ddf.catalog.operation.UpdateResponse)23 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)23 HashMap (java.util.HashMap)21 Update (ddf.catalog.operation.Update)17 List (java.util.List)16 Entry (java.util.Map.Entry)16 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 Map (java.util.Map)12 SimpleEntry (java.util.AbstractMap.SimpleEntry)11 IngestException (ddf.catalog.source.IngestException)10 URI (java.net.URI)10 Result (ddf.catalog.data.Result)9 CreateRequest (ddf.catalog.operation.CreateRequest)9 CatalogFramework (ddf.catalog.CatalogFramework)8 CreateResponse (ddf.catalog.operation.CreateResponse)8