Search in sources :

Example 46 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest 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 47 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest 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 48 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest 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 49 with UpdateRequest

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

the class IdentificationPlugin method process.

/**
     * For registry metacards verifies the update should take place by checking that the update
     * metacard is at least as up to date as the existing one. Also updates the tags, identifiers,
     * and transient attributes of the updated metacard.
     *
     * @param input the {@link UpdateRequest} to process
     * @return
     * @throws PluginExecutionException
     * @throws StopProcessingException
     */
@Override
public UpdateRequest process(UpdateRequest input) throws PluginExecutionException, StopProcessingException {
    if (!Requests.isLocal(input)) {
        return input;
    }
    OperationTransaction operationTransaction = (OperationTransaction) input.getProperties().get(Constants.OPERATION_TRANSACTION_KEY);
    List<Metacard> previousMetacards = operationTransaction.getPreviousStateMetacards();
    Map<String, Metacard> previousMetacardsMap = previousMetacards.stream().filter(e -> RegistryUtility.isRegistryMetacard(e) || RegistryUtility.isInternalRegistryMetacard(e)).collect(Collectors.toMap(RegistryUtility::getRegistryId, Function.identity()));
    List<Map.Entry<Serializable, Metacard>> entriesToRemove = new ArrayList<>();
    List<Map.Entry<Serializable, Metacard>> registryUpdates = input.getUpdates().stream().filter(e -> RegistryUtility.isRegistryMetacard(e.getValue())).collect(Collectors.toList());
    for (Map.Entry<Serializable, Metacard> entry : registryUpdates) {
        Metacard updateMetacard = entry.getValue();
        Metacard existingMetacard = previousMetacardsMap.get(RegistryUtility.getRegistryId(updateMetacard));
        if (existingMetacard == null) {
            continue;
        }
        if (updateMetacard.getMetadata() != null && !updateMetacard.getModifiedDate().before(existingMetacard.getModifiedDate())) {
            updateMetacard.setAttribute(new AttributeImpl(Metacard.ID, existingMetacard.getId()));
            copyTransientAttributes(updateMetacard, existingMetacard);
            updateTags(updateMetacard);
            if (isInternal(updateMetacard)) {
                updateMetacard.setAttribute(existingMetacard.getAttribute(RegistryObjectMetacardType.REMOTE_METACARD_ID));
                updateMetacard.setAttribute(existingMetacard.getAttribute(RegistryObjectMetacardType.REMOTE_REGISTRY_ID));
            }
            updateIdentifiers(updateMetacard, false);
        } else {
            entriesToRemove.add(entry);
        }
    }
    input.getUpdates().removeAll(entriesToRemove);
    return input;
}
Also used : PreIngestPlugin(ddf.catalog.plugin.PreIngestPlugin) CreateRequest(ddf.catalog.operation.CreateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) OperationTransaction(ddf.catalog.operation.OperationTransaction) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) MetacardMarshaller(org.codice.ddf.registry.schemabindings.helper.MetacardMarshaller) Requests(ddf.catalog.util.impl.Requests) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) UpdateRequest(ddf.catalog.operation.UpdateRequest) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) RegistryPackageType(oasis.names.tc.ebxml_regrep.xsd.rim._3.RegistryPackageType) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) StopProcessingException(ddf.catalog.plugin.StopProcessingException) ParserException(org.codice.ddf.parser.ParserException) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) DeleteRequest(ddf.catalog.operation.DeleteRequest) List(java.util.List) Attribute(ddf.catalog.data.Attribute) ExternalIdentifierType(oasis.names.tc.ebxml_regrep.xsd.rim._3.ExternalIdentifierType) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) Serializable(java.io.Serializable) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) OperationTransaction(ddf.catalog.operation.OperationTransaction) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map)

Example 50 with UpdateRequest

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

the class WorkspaceAccessPluginTest method mockUpdateRequest.

private UpdateRequest mockUpdateRequest(Map<String, Metacard> updates) {
    UpdateRequest update = mock(UpdateRequest.class);
    doReturn(new ArrayList(updates.entrySet())).when(update).getUpdates();
    return update;
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) ArrayList(java.util.ArrayList)

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