use of org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException 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);
}
}
}
}
use of org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException 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 }));
}
use of org.codice.ddf.catalog.plugin.metacard.backup.storage.internal.MetacardBackupException in project ddf by codice.
the class MetacardBackupFileStorage method store.
@Override
public void store(String id, byte[] data) throws IOException, MetacardBackupException {
if (StringUtils.isEmpty(outputDirectory)) {
throw new MetacardBackupException("Unable to store data; no output directory specified.");
}
if (data == null) {
throw new MetacardBackupException("No data to store");
}
Path metacardPath = getMetacardDirectory(id);
if (metacardPath == null) {
String message = String.format("Unable to create metacard path directory for %s", id);
LOGGER.debug(message);
throw new MetacardBackupException(message);
}
try {
Path parent = metacardPath.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
Files.createFile(metacardPath);
} catch (IOException e) {
LOGGER.trace("Unable to create empty backup file {}. File may already exist.", metacardPath, e);
}
try (OutputStream outputStream = new FileOutputStream(metacardPath.toFile())) {
IOUtils.write(data, outputStream);
}
}
Aggregations