Search in sources :

Example 1 with MetacardBackupStorageProvider

use of org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider in project ddf by codice.

the class MetacardBackupPlugin method backupData.

private void backupData(BinaryContent content, String metacardId) throws PluginExecutionException {
    byte[] contentBytes = getContentBytes(content, metacardId);
    LOGGER.trace("Writing backup from {} to backup provider(s)", metacardId);
    for (MetacardBackupStorageProvider storageProvider : storageBackupPlugins) {
        if (metacardOutputProviderIds.contains(storageProvider.getId())) {
            try {
                storageProvider.store(metacardId, contentBytes);
            } catch (IOException | MetacardBackupException e) {
                LOGGER.debug("Unable to backup {} to backup provider: {}.", metacardId, storageProvider.getId(), e);
            }
        }
    }
}
Also used : MetacardBackupException(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException) MetacardBackupStorageProvider(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider) IOException(java.io.IOException)

Example 2 with MetacardBackupStorageProvider

use of org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider in project ddf by codice.

the class MetacardBackupPluginTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    metacardTransformer = mock(MetacardTransformer.class);
    BinaryContent binaryContent = new BinaryContentImpl(new ByteArrayInputStream(XML_METADATA.getBytes(StandardCharsets.UTF_8)));
    when(metacardTransformer.transform(any(Metacard.class), anyMap())).thenReturn(binaryContent);
    doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).store(any(), any());
    doThrow(new MetacardBackupException("Not Implemented")).when(mockProvider).delete(any());
    doReturn(MOCK_ID).when(mockProvider).getId();
    metacardBackupPlugin = new MetacardBackupPlugin();
    metacardBackupPlugin.setMetacardTransformerId(METACARD_TRANSFORMER_ID);
    metacardBackupPlugin.setMetacardTransformer(metacardTransformer);
    createRequest = generateProcessRequest(ProcessCreateItem.class, true);
    updateRequest = generateProcessRequest(ProcessUpdateItem.class, true);
    deleteRequest = generateDeleteRequest();
    fileStorageProvider.setId(FILE_STORAGE_PROVIDER_ID);
    fileStorageProvider.setOutputDirectory(OUTPUT_DIRECTORY);
    metacardBackupPlugin.setMetacardOutputProviderIds(Collections.singletonList(FILE_STORAGE_PROVIDER_ID));
    metacardBackupPlugin.setStorageBackupPlugins(Arrays.asList(new MetacardBackupStorageProvider[] { fileStorageProvider }));
}
Also used : MetacardBackupException(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException) Metacard(ddf.catalog.data.Metacard) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessCreateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem) BinaryContentImpl(ddf.catalog.data.impl.BinaryContentImpl) MetacardBackupStorageProvider(org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider) BinaryContent(ddf.catalog.data.BinaryContent) ProcessUpdateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessUpdateItem) Before(org.junit.Before)

Aggregations

MetacardBackupException (org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException)2 MetacardBackupStorageProvider (org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupStorageProvider)2 BinaryContent (ddf.catalog.data.BinaryContent)1 Metacard (ddf.catalog.data.Metacard)1 BinaryContentImpl (ddf.catalog.data.impl.BinaryContentImpl)1 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ProcessCreateItem (org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem)1 ProcessUpdateItem (org.codice.ddf.catalog.async.data.api.internal.ProcessUpdateItem)1 Before (org.junit.Before)1