Search in sources :

Example 1 with UpdateStorageRequestImpl

use of ddf.catalog.content.operation.impl.UpdateStorageRequestImpl in project ddf by codice.

the class InMemoryProcessingFramework method storeContentItemUpdates.

private void storeContentItemUpdates(Map<String, ContentItem> contentItemsToUpdate, Map<String, Serializable> properties) {
    if (MapUtils.isNotEmpty(contentItemsToUpdate)) {
        LOGGER.trace("Storing content item updates(s)");
        UpdateStorageRequest updateStorageRequest = new UpdateStorageRequestImpl(new ArrayList<>(contentItemsToUpdate.values()), properties);
        Subject subject = (Subject) updateStorageRequest.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
        if (subject == null) {
            LOGGER.debug("No subject to send UpdateStorageRequest. Updates will not be sent back to the catalog");
        } else {
            subject.execute(() -> {
                try {
                    catalogFramework.update(updateStorageRequest);
                    LOGGER.debug("Successfully completed update storage request");
                } catch (IngestException | SourceUnavailableException | RuntimeException e) {
                    LOGGER.info("Unable to complete update storage request", e);
                }
                return null;
            });
        }
    } else {
        LOGGER.debug("No content items to update");
    }
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) IngestException(ddf.catalog.source.IngestException) Subject(ddf.security.Subject)

Example 2 with UpdateStorageRequestImpl

use of ddf.catalog.content.operation.impl.UpdateStorageRequestImpl in project ddf by codice.

the class MetacardApplication method revertContentandMetacard.

private void revertContentandMetacard(Metacard latestContent, Metacard versionMetacard, String id) throws SourceUnavailableException, IngestException, ResourceNotFoundException, IOException, ResourceNotSupportedException, FederationException, UnsupportedQueryException {
    LOGGER.trace("Reverting content and metacard for metacard [{}]. \nLatest content: [{}] \nVersion metacard: [{}]", id, latestContent.getId(), versionMetacard.getId());
    Map<String, Serializable> properties = new HashMap<>();
    properties.put("no-default-tags", true);
    ResourceResponse latestResource = catalogFramework.getLocalResource(new ResourceRequestById(latestContent.getId(), properties));
    ContentItemImpl contentItem = new ContentItemImpl(id, new ByteSourceWrapper(() -> latestResource.getResource().getInputStream()), latestResource.getResource().getMimeTypeValue(), latestResource.getResource().getName(), latestResource.getResource().getSize(), MetacardVersionImpl.toMetacard(versionMetacard, types));
    // Try to delete the "deleted metacard" marker first.
    boolean alreadyCreated = false;
    Action action = Action.fromKey((String) versionMetacard.getAttribute(MetacardVersion.ACTION).getValue());
    if (DELETE_ACTIONS.contains(action)) {
        alreadyCreated = true;
        catalogFramework.create(new CreateStorageRequestImpl(Collections.singletonList(contentItem), id, new HashMap<>()));
    } else {
        // Currently we can't guarantee the metacard will exist yet because of the 1 second
        // soft commit in solr. this busy wait loop should be fixed when alternate solution
        // is found.
        tryUpdate(4, () -> {
            catalogFramework.update(new UpdateStorageRequestImpl(Collections.singletonList(contentItem), id, new HashMap<>()));
            return true;
        });
    }
    LOGGER.trace("Successfully reverted metacard content for [{}]", id);
    revertMetacard(versionMetacard, id, alreadyCreated);
}
Also used : Serializable(java.io.Serializable) Action(ddf.catalog.core.versioning.MetacardVersion.Action) ResourceResponse(ddf.catalog.operation.ResourceResponse) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) HashMap(java.util.HashMap) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 3 with UpdateStorageRequestImpl

use of ddf.catalog.content.operation.impl.UpdateStorageRequestImpl in project ddf by codice.

the class CatalogFrameworkImplTest method testUpdateStorage.

/**
 * Tests that the framework properly passes an update request to the local provider.
 */
@Test
public void testUpdateStorage() throws Exception {
    List<ContentItem> contentItems = new ArrayList<>();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId(null);
    ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("blah".getBytes());
        }
    };
    ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
    contentItems.add(contentItem);
    CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
    Metacard insertedCard = response.getCreatedMetacards().get(0);
    List<ContentItem> updatedContentItems = new ArrayList<>();
    updatedContentItems.add(new ContentItemImpl(insertedCard.getId(), byteSource, "application/octet-stream", insertedCard));
    UpdateStorageRequest request = new UpdateStorageRequestImpl(updatedContentItems, null);
    List<Result> mockFederationResults = Stream.of(insertedCard).map(m -> {
        Result mockResult = mock(Result.class);
        when(mockResult.getMetacard()).thenReturn(m);
        return mockResult;
    }).collect(Collectors.toList());
    QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
    when(mockFederationStrategy.federate(anyList(), any())).thenReturn(queryResponse);
    // send update to framework
    List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
    assertThat(returnedCards, hasSize(1));
    final Metacard newMetacard = returnedCards.get(0).getNewMetacard();
    assertThat(newMetacard.getId(), notNullValue());
    assertThat(newMetacard.getResourceURI().toString(), is(contentItem.getUri()));
    assertThat(newMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
    assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
    // make sure that the event was posted correctly
    assertThat(eventAdmin.wasEventPosted(), is(true));
}
Also used : AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) CreateRequest(ddf.catalog.operation.CreateRequest) CoreAttributes(ddf.catalog.data.impl.types.CoreAttributes) BinaryContent(ddf.catalog.data.BinaryContent) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) AttributeType(ddf.catalog.data.AttributeType) FilterFactory(org.opengis.filter.FilterFactory) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) CreateOperations(ddf.catalog.impl.operations.CreateOperations) RemoteDeleteOperations(ddf.catalog.impl.operations.RemoteDeleteOperations) InputTransformer(ddf.catalog.transform.InputTransformer) ServiceReference(org.osgi.framework.ServiceReference) PostResourcePlugin(ddf.catalog.plugin.PostResourcePlugin) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Set(java.util.Set) SourceOperations(ddf.catalog.impl.operations.SourceOperations) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) MimeTypeResolver(ddf.mime.MimeTypeResolver) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) Stream(java.util.stream.Stream) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) Assert.assertFalse(org.junit.Assert.assertFalse) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) Matchers.is(org.hamcrest.Matchers.is) UpdateResponse(ddf.catalog.operation.UpdateResponse) BasicTypes(ddf.catalog.data.impl.BasicTypes) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Mockito.mock(org.mockito.Mockito.mock) ResourceResponse(ddf.catalog.operation.ResourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) AdditionalAnswers.returnsSecondArg(org.mockito.AdditionalAnswers.returnsSecondArg) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) CatalogFramework(ddf.catalog.CatalogFramework) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) DeleteResponse(ddf.catalog.operation.DeleteResponse) Mockito.spy(org.mockito.Mockito.spy) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) Resource(ddf.catalog.resource.Resource) ArrayList(java.util.ArrayList) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) Source(ddf.catalog.source.Source) TestWatchman(org.junit.rules.TestWatchman) ContentItem(ddf.catalog.content.data.ContentItem) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) SourceInfoRequestSources(ddf.catalog.operation.impl.SourceInfoRequestSources) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ByteSource(com.google.common.io.ByteSource) Result(ddf.catalog.data.Result) TransformOperations(ddf.catalog.impl.operations.TransformOperations) Core(ddf.catalog.data.types.Core) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) Before(org.junit.Before) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) ContentType(ddf.catalog.data.ContentType) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) SourcePoller(org.codice.ddf.catalog.sourcepoller.SourcePoller) Historian(ddf.catalog.history.Historian) SecurityLogger(ddf.security.audit.SecurityLogger) IngestException(ddf.catalog.source.IngestException) Assert.assertTrue(org.junit.Assert.assertTrue) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Subject(ddf.security.Subject) IOException(java.io.IOException) Test(org.junit.Test) AttributeInjector(ddf.catalog.data.AttributeInjector) FederationException(ddf.catalog.federation.FederationException) AttributeInjectorImpl(ddf.catalog.data.inject.AttributeInjectorImpl) DAYS(java.time.temporal.ChronoUnit.DAYS) Query(ddf.catalog.operation.Query) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) PreQueryPlugin(ddf.catalog.plugin.PreQueryPlugin) CatalogStore(ddf.catalog.source.CatalogStore) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Date(java.util.Date) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) MethodRule(org.junit.rules.MethodRule) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) LoggerFactory(org.slf4j.LoggerFactory) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) SourceDescriptor(ddf.catalog.source.SourceDescriptor) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Assert.fail(org.junit.Assert.fail) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) URI(java.net.URI) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FederatedSource(ddf.catalog.source.FederatedSource) MimeTypeToTransformerMapper(ddf.mime.MimeTypeToTransformerMapper) ResultImpl(ddf.catalog.data.impl.ResultImpl) SourceInfoRequestEnterprise(ddf.catalog.operation.impl.SourceInfoRequestEnterprise) ResourceReader(ddf.catalog.resource.ResourceReader) SourceMonitor(ddf.catalog.source.SourceMonitor) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) BundleContext(org.osgi.framework.BundleContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) DeleteRequest(ddf.catalog.operation.DeleteRequest) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) List(java.util.List) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) Entry(java.util.Map.Entry) Optional(java.util.Optional) ActionRegistry(ddf.action.ActionRegistry) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) FederationStrategy(ddf.catalog.federation.FederationStrategy) FilterBuilder(ddf.catalog.filter.FilterBuilder) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) HashMap(java.util.HashMap) Update(ddf.catalog.operation.Update) DefaultAttributeValueRegistry(ddf.catalog.data.DefaultAttributeValueRegistry) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) CreateResponse(ddf.catalog.operation.CreateResponse) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) CollectionUtils(org.apache.commons.collections.CollectionUtils) SecurityConstants(ddf.security.SecurityConstants) MimeType(javax.activation.MimeType) StorageProvider(ddf.catalog.content.StorageProvider) OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) UpdateRequest(ddf.catalog.operation.UpdateRequest) SimpleEntry(java.util.AbstractMap.SimpleEntry) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) FrameworkMethod(org.junit.runners.model.FrameworkMethod) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) Mockito.when(org.mockito.Mockito.when) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) Mockito.verify(org.mockito.Mockito.verify) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) SourceResponse(ddf.catalog.operation.SourceResponse) Rule(org.junit.Rule) CatalogProvider(ddf.catalog.source.CatalogProvider) Ignore(org.junit.Ignore) ThreadContext(org.apache.shiro.util.ThreadContext) QueryOperations(ddf.catalog.impl.operations.QueryOperations) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) InputStream(java.io.InputStream) UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) QueryRequest(ddf.catalog.operation.QueryRequest) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ByteSource(com.google.common.io.ByteSource) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 4 with UpdateStorageRequestImpl

use of ddf.catalog.content.operation.impl.UpdateStorageRequestImpl in project ddf by codice.

the class ContentProducerDataAccessObject method createContentItem.

public void createContentItem(FileSystemPersistenceProvider fileIdMap, ContentEndpoint endpoint, File ingestedFile, WatchEvent.Kind<Path> eventType, String mimeType, Map<String, Object> headers) throws SourceUnavailableException, IngestException {
    LOGGER.debug("Creating content item.");
    if (!eventType.equals(ENTRY_DELETE) && ingestedFile == null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Ingested File was null with eventType [{}]. Doing nothing.", eventType.name());
        }
        return;
    }
    String refKey = (String) headers.get(Constants.STORE_REFERENCE_KEY);
    String safeKey = null;
    String id = null;
    // not null if the file lives outside the content store (external reference)
    if (refKey != null) {
        // guards against impermissible filesystem characters
        safeKey = DigestUtils.sha1Hex(refKey);
        if (fileIdMap.loadAllKeys().contains(safeKey)) {
            id = String.valueOf(fileIdMap.loadFromPersistence(safeKey));
        } else if (!ENTRY_CREATE.equals(eventType)) {
            LOGGER.warn("Unable to look up id for {}, not performing {}", refKey, eventType.name());
            return;
        }
    }
    if (ENTRY_CREATE.equals(eventType)) {
        CreateStorageRequest createRequest = new CreateStorageRequestImpl(Collections.singletonList(new ContentItemImpl(uuidGenerator.generateUuid(), Files.asByteSource(ingestedFile), mimeType, ingestedFile.getName(), ingestedFile.length(), null)), getProperties(headers));
        CatalogFramework catalogFramework = endpoint.getComponent().getCatalogFramework();
        waitForAvailableSource(catalogFramework);
        CreateResponse createResponse = catalogFramework.create(createRequest);
        if (createResponse != null) {
            List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
            if (safeKey != null) {
                fileIdMap.store(safeKey, createdMetacards.get(0).getId());
            }
            logIds(createdMetacards, "created");
        }
    } else if (ENTRY_MODIFY.equals(eventType)) {
        UpdateStorageRequest updateRequest = new UpdateStorageRequestImpl(Collections.singletonList(new ContentItemImpl(id, Files.asByteSource(ingestedFile), mimeType, ingestedFile.getName(), 0, null)), getProperties(headers));
        UpdateResponse updateResponse = endpoint.getComponent().getCatalogFramework().update(updateRequest);
        if (updateResponse != null) {
            List<Update> updatedMetacards = updateResponse.getUpdatedMetacards();
            logIds(updatedMetacards.stream().map(Update::getNewMetacard).collect(Collectors.toList()), "updated");
        }
    } else if (ENTRY_DELETE.equals(eventType)) {
        DeleteRequest deleteRequest = new DeleteRequestImpl(id);
        DeleteResponse deleteResponse = endpoint.getComponent().getCatalogFramework().delete(deleteRequest);
        if (deleteResponse != null) {
            List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards();
            if (safeKey != null) {
                fileIdMap.delete(safeKey);
            }
            logIds(deletedMetacards, "deleted");
        }
    }
}
Also used : UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) CreateResponse(ddf.catalog.operation.CreateResponse) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) CatalogFramework(ddf.catalog.CatalogFramework) List(java.util.List) DeleteRequest(ddf.catalog.operation.DeleteRequest) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl)

Example 5 with UpdateStorageRequestImpl

use of ddf.catalog.content.operation.impl.UpdateStorageRequestImpl in project ddf by codice.

the class UpdateOperations method update.

public UpdateResponse update(UpdateStorageRequest streamUpdateRequest) throws IngestException, SourceUnavailableException {
    Map<String, Metacard> metacardMap = new HashMap<>();
    List<ContentItem> contentItems = new ArrayList<>(streamUpdateRequest.getContentItems().size());
    HashMap<String, Map<String, Path>> tmpContentPaths = new HashMap<>();
    UpdateResponse updateResponse = null;
    UpdateStorageRequest updateStorageRequest = null;
    UpdateStorageResponse updateStorageResponse = null;
    streamUpdateRequest = opsStorageSupport.prepareStorageRequest(streamUpdateRequest, streamUpdateRequest::getContentItems);
    // Operation populates the metacardMap, contentItems, and tmpContentPaths
    opsMetacardSupport.generateMetacardAndContentItems(streamUpdateRequest.getContentItems(), metacardMap, contentItems, tmpContentPaths);
    streamUpdateRequest.getProperties().put(CONTENT_PATHS, tmpContentPaths);
    streamUpdateRequest = applyAttributeOverrides(streamUpdateRequest, metacardMap);
    try {
        if (!contentItems.isEmpty()) {
            updateStorageRequest = new UpdateStorageRequestImpl(contentItems, streamUpdateRequest.getId(), streamUpdateRequest.getProperties());
            updateStorageRequest = processPreUpdateStoragePlugins(updateStorageRequest);
            try {
                updateStorageResponse = sourceOperations.getStorage().update(updateStorageRequest);
                updateStorageResponse.getProperties().put(CONTENT_PATHS, tmpContentPaths);
            } catch (StorageException e) {
                throw new IngestException("Could not store content items. Removed created metacards.", e);
            }
            updateStorageResponse = processPostUpdateStoragePlugins(updateStorageResponse);
            for (ContentItem contentItem : updateStorageResponse.getUpdatedContentItems()) {
                if (StringUtils.isBlank(contentItem.getQualifier())) {
                    Metacard metacard = metacardMap.get(contentItem.getId());
                    Metacard overrideMetacard = contentItem.getMetacard();
                    Metacard updatedMetacard = OverrideAttributesSupport.overrideMetacard(metacard, overrideMetacard, true);
                    updatedMetacard.setAttribute(new AttributeImpl(Metacard.RESOURCE_SIZE, String.valueOf(contentItem.getSize())));
                    metacardMap.put(contentItem.getId(), updatedMetacard);
                }
            }
        }
        UpdateRequestImpl updateRequest = new UpdateRequestImpl(Iterables.toArray(metacardMap.values().stream().map(Metacard::getId).collect(Collectors.toList()), String.class), new ArrayList<>(metacardMap.values()));
        updateRequest.setProperties(streamUpdateRequest.getProperties());
        historian.setSkipFlag(updateRequest);
        updateResponse = doUpdate(updateRequest);
        historian.version(streamUpdateRequest, updateStorageResponse, updateResponse);
    } catch (Exception e) {
        if (updateStorageRequest != null) {
            try {
                sourceOperations.getStorage().rollback(updateStorageRequest);
            } catch (StorageException e1) {
                LOGGER.info("Unable to remove temporary content for id: {}", updateStorageRequest.getId(), e1);
            }
        }
        throw new IngestException("Unable to store products for request: " + streamUpdateRequest.getId(), e);
    } finally {
        opsStorageSupport.commitAndCleanup(updateStorageRequest, tmpContentPaths);
    }
    updateResponse = doPostIngest(updateResponse);
    return updateResponse;
}
Also used : UpdateStorageRequestImpl(ddf.catalog.content.operation.impl.UpdateStorageRequestImpl) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) StorageException(ddf.catalog.content.StorageException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) StorageException(ddf.catalog.content.StorageException) ContentItem(ddf.catalog.content.data.ContentItem)

Aggregations

UpdateStorageRequestImpl (ddf.catalog.content.operation.impl.UpdateStorageRequestImpl)11 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)10 Metacard (ddf.catalog.data.Metacard)7 ContentItem (ddf.catalog.content.data.ContentItem)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6 IngestException (ddf.catalog.source.IngestException)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)5 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)5 CreateResponse (ddf.catalog.operation.CreateResponse)4 UpdateRequest (ddf.catalog.operation.UpdateRequest)4 MimeType (javax.activation.MimeType)4 Test (org.junit.Test)4 ByteSource (com.google.common.io.ByteSource)3 CatalogFramework (ddf.catalog.CatalogFramework)3 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)3 UpdateResponse (ddf.catalog.operation.UpdateResponse)3 HashMap (java.util.HashMap)3 Sets (com.google.common.collect.Sets)2 ActionRegistry (ddf.action.ActionRegistry)2