Search in sources :

Example 6 with OperationTransactionImpl

use of ddf.catalog.operation.impl.OperationTransactionImpl 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 7 with OperationTransactionImpl

use of ddf.catalog.operation.impl.OperationTransactionImpl 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 8 with OperationTransactionImpl

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

the class DeleteOperations method populateMetacards.

private DeleteRequest populateMetacards(DeleteRequest deleteRequest, List<String> fanoutTagBlacklist) throws IngestException, StopProcessingException {
    QueryRequestImpl queryRequest = createQueryRequest(deleteRequest);
    QueryResponse query;
    try {
        query = queryOperations.doQuery(queryRequest, frameworkProperties.getFederationStrategy());
    } catch (FederationException e) {
        LOGGER.debug("Unable to complete query for updated metacards.", e);
        throw new IngestException("Exception during runtime while performing delete");
    }
    List<Metacard> metacards = query.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
    if (blockDeleteMetacards(metacards, fanoutTagBlacklist)) {
        String message = "Fanout proxy does not support delete operations with blacklisted metacard tag";
        LOGGER.debug("{}. Tags blacklist: {}", message, fanoutTagBlacklist);
        throw new IngestException(message);
    }
    if (!foundAllDeleteRequestMetacards(deleteRequest, query)) {
        logFailedQueryInfo(deleteRequest, query);
        throw new StopProcessingException("Could not find all metacards specified in request");
    }
    deleteRequest = rewriteRequestToAvoidHistoryConflicts(deleteRequest, query);
    deleteRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.DELETE, metacards));
    return deleteRequest;
}
Also used : Metacard(ddf.catalog.data.Metacard) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException)

Aggregations

OperationTransactionImpl (ddf.catalog.operation.impl.OperationTransactionImpl)8 Metacard (ddf.catalog.data.Metacard)4 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)4 Test (org.junit.Test)4 OperationTransaction (ddf.catalog.operation.OperationTransaction)3 IngestException (ddf.catalog.source.IngestException)3 InternalIngestException (ddf.catalog.source.InternalIngestException)3 HashMap (java.util.HashMap)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 FederationException (ddf.catalog.federation.FederationException)2 QueryResponse (ddf.catalog.operation.QueryResponse)2 UpdateRequest (ddf.catalog.operation.UpdateRequest)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 StopProcessingException (ddf.catalog.plugin.StopProcessingException)2 Serializable (java.io.Serializable)2 BigInteger (java.math.BigInteger)2 AbstractMap (java.util.AbstractMap)2 ArrayList (java.util.ArrayList)2 TransactionResponseType (net.opengis.cat.csw.v_2_0_2.TransactionResponseType)2 TransactionSummaryType (net.opengis.cat.csw.v_2_0_2.TransactionSummaryType)2