Search in sources :

Example 6 with UpdateStorageResponse

use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.

the class HistorianTest method testUpdateStorageResponse.

@Test
public void testUpdateStorageResponse() throws UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException, StorageException {
    // The metacard and updated metacard
    List<Metacard> metacards = getMetacardUpdatePair();
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    storeMetacard(metacards.get(0));
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    storageProvider.update(storageRequest);
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    // Verify that the metacard updated
    Metacard update = readMetacard();
    assertThat(update, equalTo(metacards.get(1)));
    assertThat(storageResponse.getUpdatedContentItems().get(0).getUri(), not(equalTo(RESOURCE_URI)));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Test(org.junit.Test)

Example 7 with UpdateStorageResponse

use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.

the class HistorianTest method testTryCommitStorageException.

@Test(expected = IngestException.class)
public void testTryCommitStorageException() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
    List<Metacard> metacards = getMetacardUpdatePair();
    // Mock out a bad storage provider
    StorageProvider exceptionStorageProvider = mock(StorageProvider.class);
    doThrow(StorageException.class).when(exceptionStorageProvider).commit(any());
    ContentItem item = mock(ContentItem.class);
    when(item.getId()).thenReturn(METACARD_ID);
    when(item.getUri()).thenReturn(RESOURCE_URI);
    when(item.getMetacard()).thenReturn(metacards.get(0));
    ReadStorageResponse readStorageResponse = mock(ReadStorageResponse.class);
    when(readStorageResponse.getContentItem()).thenReturn(item);
    when(exceptionStorageProvider.read(any())).thenReturn(readStorageResponse);
    when(exceptionStorageProvider.create(any())).thenReturn(mock(CreateStorageResponse.class));
    historian.setStorageProviders(Collections.singletonList(exceptionStorageProvider));
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    verify(exceptionStorageProvider).rollback(any(StorageRequest.class));
}
Also used : CreateStorageResponse(ddf.catalog.content.operation.CreateStorageResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) StorageRequest(ddf.catalog.content.operation.StorageRequest) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) ReadStorageResponse(ddf.catalog.content.operation.ReadStorageResponse) StorageProvider(ddf.catalog.content.StorageProvider) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 8 with UpdateStorageResponse

use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.

the class HistorianTest method testUpdateStorageResponseNoContentItems.

@Test
public void testUpdateStorageResponseNoContentItems() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
    // The metacard and updated metacard
    List<Metacard> metacards = getMetacardUpdatePair();
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    assertThat(storageProvider.storageMap.size(), equalTo(0));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Test(org.junit.Test)

Example 9 with UpdateStorageResponse

use of ddf.catalog.content.operation.UpdateStorageResponse 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, 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)

Example 10 with UpdateStorageResponse

use of ddf.catalog.content.operation.UpdateStorageResponse in project ddf by codice.

the class TestVideoThumbnailPlugin method testUpdatedItemNotVideoFile.

@Test
public void testUpdatedItemNotVideoFile() throws Exception {
    mockContentItem = mock(ContentItem.class);
    doReturn(new MimeType("application/pdf")).when(mockContentItem).getMimeType();
    Metacard mockMetacard = new MetacardImpl();
    doReturn(mockMetacard).when(mockContentItem).getMetacard();
    final UpdateStorageResponse mockUpdateResponse = mock(UpdateStorageResponse.class);
    doReturn(Collections.singletonList(mockContentItem)).when(mockUpdateResponse).getUpdatedContentItems();
    final UpdateStorageResponse processedUpdateResponse = videoThumbnailPlugin.process(mockUpdateResponse);
    assertThat(processedUpdateResponse.getUpdatedContentItems().get(0).getMetacard().getAttribute(Metacard.THUMBNAIL), CoreMatchers.is(nullValue()));
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) ContentItem(ddf.catalog.content.data.ContentItem) MimeType(javax.activation.MimeType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)16 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)14 Metacard (ddf.catalog.data.Metacard)13 Test (org.junit.Test)12 UpdateResponse (ddf.catalog.operation.UpdateResponse)11 ContentItem (ddf.catalog.content.data.ContentItem)9 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)8 StorageProvider (ddf.catalog.content.StorageProvider)4 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)4 ReadStorageRequest (ddf.catalog.content.operation.ReadStorageRequest)4 HashMap (java.util.HashMap)4 StorageException (ddf.catalog.content.StorageException)3 ReadStorageResponse (ddf.catalog.content.operation.ReadStorageResponse)3 StorageRequest (ddf.catalog.content.operation.StorageRequest)3 UpdateStorageRequestImpl (ddf.catalog.content.operation.impl.UpdateStorageRequestImpl)3 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)3 ArrayList (java.util.ArrayList)3 ByteSource (com.google.common.io.ByteSource)2 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)2 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)2