Search in sources :

Example 26 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class TestCswEndpoint method testUpdateTransactionWithNewRecord.

@Test
public void testUpdateTransactionWithNewRecord() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    MetacardImpl updatedMetacard = new MetacardImpl();
    updatedMetacard.setId("123");
    UpdateAction updateAction = new UpdateAction(updatedMetacard, CswConstants.CSW_RECORD, "");
    CswTransactionRequest transactionRequest = new CswTransactionRequest();
    transactionRequest.getUpdateActions().add(updateAction);
    transactionRequest.setVersion(CswConstants.VERSION_2_0_2);
    transactionRequest.setService(CswConstants.CSW);
    transactionRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(transactionRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(1));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    assertThat(actualUpdateRequest.getUpdates().size(), is(1));
    assertThat(actualUpdateRequest.getUpdates().get(0).getValue().getId(), is("123"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) Test(org.junit.Test)

Example 27 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class CachingFederationStrategyTest method testProcessUpdateResponse.

@Test
public void testProcessUpdateResponse() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
    UpdateResponse response = mock(UpdateResponseImpl.class);
    UpdateRequest request = mock(UpdateRequestImpl.class);
    when(request.hasProperties()).thenReturn(true);
    when(request.getProperties()).thenReturn(testMap);
    when(response.getRequest()).thenReturn(request);
    MetacardImpl newMetacard = mock(MetacardImpl.class);
    when(newMetacard.getId()).thenReturn("new metacard");
    when(newMetacard.getSourceId()).thenReturn("new source ID");
    UpdateImpl updateImpl = mock(UpdateImpl.class);
    when(updateImpl.getNewMetacard()).thenReturn(newMetacard);
    List<Update> cards = Arrays.asList(updateImpl);
    ArgumentCaptor<List<Metacard>> metacardsCaptor = ArgumentCaptor.forClass((Class) List.class);
    when(response.getUpdatedMetacards()).thenReturn(cards);
    doNothing().when(cache).create(metacardsCaptor.capture());
    assertThat(response, is(strategy.process(response)));
    assertThat(metacardsCaptor.getValue().contains(newMetacard), is(true));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) List(java.util.List) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 28 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 29 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 30 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)

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