Search in sources :

Example 31 with UpdateRequestImpl

use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderRuntimeExceptionOnUpdateByIdentifier.

@Test(expected = IngestException.class)
public void testProviderRuntimeExceptionOnUpdateByIdentifier() throws IngestException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    // use exception provider instead of memory
    MockExceptionProvider provider = new MockExceptionProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, true);
    List<Entry<Object, Metacard>> metacards = new ArrayList<Entry<Object, Metacard>>();
    HashMap<Object, Metacard> map = new HashMap<Object, Metacard>();
    try {
        MetacardImpl newCard = new MetacardImpl();
        newCard.setId(null);
        newCard.setResourceURI(new URI("uri:///1234"));
        map.put(Metacard.ID, newCard);
        metacards.addAll(map.entrySet());
        UpdateRequest update = new UpdateRequestImpl(null, Metacard.RESOURCE_URI, null);
        framework.update(update);
    } catch (URISyntaxException e) {
        fail();
    } catch (SourceUnavailableException e) {
        fail();
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ContentType(ddf.catalog.data.ContentType) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) CatalogFramework(ddf.catalog.CatalogFramework) Matchers.anyObject(org.mockito.Matchers.anyObject) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 32 with UpdateRequestImpl

use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testProviderUnavailableUpdateByIdentifier.

/**
     * Tests that the framework properly throws a catalog exception when the local provider is not
     * available for update by identifier.
     *
     * @throws IngestException
     * @throws SourceUnavailableException
     */
@Test(expected = SourceUnavailableException.class)
public void testProviderUnavailableUpdateByIdentifier() throws SourceUnavailableException {
    MockEventProcessor eventAdmin = new MockEventProcessor();
    MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), false, null);
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, eventAdmin, false);
    List<Metacard> metacards = new ArrayList<Metacard>();
    List<URI> uris = new ArrayList<URI>();
    // expected to throw exception due to catalog provider being unavailable
    try {
        MetacardImpl newCard = new MetacardImpl();
        newCard.setId(null);
        newCard.setResourceURI(new URI("uri:///1234"));
        metacards.add(newCard);
        uris.add(new URI("uri:////1234"));
        UpdateRequest update = new UpdateRequestImpl((URI[]) uris.toArray(new URI[uris.size()]), metacards);
        framework.update(update);
    } catch (URISyntaxException e) {
        fail();
    } catch (IngestException e) {
        fail();
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) CatalogFramework(ddf.catalog.CatalogFramework) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 33 with UpdateRequestImpl

use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.

the class IdentificationPluginTest method testSetTransientAttributesOnUpdateMetacard.

@Test
public void testSetTransientAttributesOnUpdateMetacard() throws Exception {
    String xml = convert("/registry-no-extid.xml");
    MetacardImpl previousMetacard = new MetacardImpl();
    previousMetacard.setAttribute(Metacard.ID, "MetacardId");
    previousMetacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "MetacardId");
    previousMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    previousMetacard.setAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, "Published Locations");
    previousMetacard.setAttribute(RegistryObjectMetacardType.LAST_PUBLISHED, "Last Published Time");
    previousMetacard.setAttribute(Metacard.MODIFIED, new Date().from(Instant.now()));
    OperationTransaction operationTransaction = new OperationTransactionImpl(null, Collections.singletonList(previousMetacard));
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(Constants.OPERATION_TRANSACTION_KEY, operationTransaction);
    List<Map.Entry<Serializable, Metacard>> updatedEntries = new ArrayList<>();
    MetacardImpl updateMetacard = new MetacardImpl();
    updateMetacard.setAttribute(Metacard.ID, "MetacardId");
    updateMetacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, "MetacardId");
    updateMetacard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    updateMetacard.setAttribute(Metacard.MODIFIED, new Date().from(Instant.now()));
    updateMetacard.setAttribute(Metacard.METADATA, xml);
    updatedEntries.add(new AbstractMap.SimpleEntry<>(updateMetacard.getId(), updateMetacard));
    UpdateRequest updateRequest = new UpdateRequestImpl(updatedEntries, Metacard.ID, properties);
    UpdateRequest processedUpdateRequest = identificationPlugin.process(updateRequest);
    Metacard processedMetacard = processedUpdateRequest.getUpdates().get(0).getValue();
    assertThat(processedMetacard.getAttribute(RegistryObjectMetacardType.PUBLISHED_LOCATIONS).getValue(), is("Published Locations"));
    assertThat(processedMetacard.getAttribute(RegistryObjectMetacardType.LAST_PUBLISHED).getValue(), is("Last Published Time"));
}
Also used : Serializable(java.io.Serializable) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Date(java.util.Date) OperationTransaction(ddf.catalog.operation.OperationTransaction) AbstractMap(java.util.AbstractMap) Metacard(ddf.catalog.data.Metacard) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 34 with UpdateRequestImpl

use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.

the class IdentificationPluginTest method testUpdateMetacardWithModifiedTimeSameAsCurrentMetacard.

@Test
public void testUpdateMetacardWithModifiedTimeSameAsCurrentMetacard() throws Exception {
    String xml = convert("/registry-both-extid.xml");
    sampleData.setAttribute(Metacard.METADATA, xml);
    sampleData.setAttribute(RegistryObjectMetacardType.REMOTE_REGISTRY_ID, "remoteRegistryId");
    OperationTransaction operationTransaction = new OperationTransactionImpl(null, Collections.singletonList(sampleData));
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(Constants.OPERATION_TRANSACTION_KEY, operationTransaction);
    List<Map.Entry<Serializable, Metacard>> updatedEntries = new ArrayList<>();
    Metacard updateMetacard = sampleData;
    updatedEntries.add(new AbstractMap.SimpleEntry<>(updateMetacard.getId(), updateMetacard));
    UpdateRequest updateRequest = new UpdateRequestImpl(updatedEntries, Metacard.ID, properties);
    UpdateRequest processedUpdateRequest = identificationPlugin.process(updateRequest);
    assertThat(processedUpdateRequest.getUpdates().size(), is(1));
}
Also used : Serializable(java.io.Serializable) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList) OperationTransaction(ddf.catalog.operation.OperationTransaction) AbstractMap(java.util.AbstractMap) Metacard(ddf.catalog.data.Metacard) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 35 with UpdateRequestImpl

use of ddf.catalog.operation.impl.UpdateRequestImpl 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)

Aggregations

UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)39 Metacard (ddf.catalog.data.Metacard)30 ArrayList (java.util.ArrayList)24 UpdateRequest (ddf.catalog.operation.UpdateRequest)22 Test (org.junit.Test)21 HashMap (java.util.HashMap)19 Serializable (java.io.Serializable)17 UpdateResponse (ddf.catalog.operation.UpdateResponse)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 CatalogFramework (ddf.catalog.CatalogFramework)11 IngestException (ddf.catalog.source.IngestException)11 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)10 List (java.util.List)10 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)9 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)9 Entry (java.util.Map.Entry)9 QueryResponse (ddf.catalog.operation.QueryResponse)8 Update (ddf.catalog.operation.Update)8 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)8 URI (java.net.URI)8