use of org.codice.ddf.migration.MigrationException in project ddf by codice.
the class MetacardsMigratable method export.
/**
* Exports all the metacards currently stored in the catalog framework.
* <p>
* {@inheritDoc}
*/
@Override
@NotNull
public MigrationMetadata export(@NotNull Path exportPath) throws MigrationException {
config.setExportPath(exportPath.resolve(this.getId()));
fileWriter.createExportDirectory(config.getExportPath());
Collection<MigrationWarning> warnings = new ArrayList<>();
Map<String, Serializable> props = createMapWithNativeQueryMode();
Filter dumpFilter = filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text("*");
QueryImpl exportQuery = new QueryImpl(dumpFilter);
exportQuery.setPageSize(config.getExportQueryPageSize());
exportQuery.setRequestsTotalResultsCount(false);
QueryRequest exportQueryRequest = new QueryRequestImpl(exportQuery, props);
try {
executeQueryLoop(exportQuery, exportQueryRequest);
} catch (Exception e) {
LOGGER.info("Internal error occurred when exporting catalog: {}", e);
throw new ExportMigrationException(DEFAULT_FAILURE_MESSAGE);
} finally {
cleanup();
}
return new MigrationMetadata(warnings);
}
use of org.codice.ddf.migration.MigrationException in project ddf by codice.
the class ExportCommandTest method testExecuteErrorOccurred.
@Test
public void testExecuteErrorOccurred() throws Exception {
// Setup
when(security.runWithSubjectOrElevate(any(Callable.class))).thenThrow(new InvocationTargetException(new MigrationException(MIGRATION_EXCEPTION_MESSAGE)));
ExportCommand exportCommand = new ExportCommandUnderTest(mockConfigurationMigrationService, mockDefaultExportDirectory);
// Perform Test
exportCommand.execute();
// Verify
assertErrorMessage(MIGRATION_EXCEPTION_MESSAGE);
}
use of org.codice.ddf.migration.MigrationException in project ddf by codice.
the class TestMigratable method exportWhenConfigurationAdminMigratorThrowsConfigurationFileException.
@Test(expected = MigrationException.class)
public void exportWhenConfigurationAdminMigratorThrowsConfigurationFileException() throws Exception {
when(Files.createDirectories(exportPath)).thenReturn(exportPath);
doThrow(new MigrationException("")).when(configurationAdminMigration).export(exportPath);
ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
configurationMigrationManager.export(exportPath);
}
use of org.codice.ddf.migration.MigrationException in project ddf by codice.
the class TestMigratable method exportFailsWhenMigratableThrowsMigrationException.
@Test(expected = MigrationException.class)
public void exportFailsWhenMigratableThrowsMigrationException() throws Exception {
ConfigurationMigrationManager configurationMigrationManager = createConfigurationMigrationManager();
when(configurationMigratable.export(any(Path.class))).thenThrow(new MigrationException(""));
when(dataMigratable.export(any(Path.class))).thenReturn(new MigrationMetadata(ImmutableList.of()));
try {
export(() -> configurationMigrationManager.export(exportPath));
} finally {
verify(configurationMigratable).export(exportPath);
verify(dataMigratable, never()).export(any(Path.class));
}
}
use of org.codice.ddf.migration.MigrationException in project ddf by codice.
the class MigratableUtil method copyFileFromSystemPropertyValue.
/**
* Copies a file, whose path is taken from a {@link System} property value, to a destination
* directory. The file to copy must be a relative path under {@code ddf.home}, and its path
* must not contain any symbolic link, otherwise the file will not be copied and a
* {@link MigrationWarning} will be returned.
*
* @param systemProperty name of the {@link System} property that contains the path to the
* source file
* @param exportDirectory root directory where the file will be copied. If the file'
* relative path included any directories, those will be re-created
* under this directory.
* @param warnings any warnings generated during this operation (e.g., source file outside
* of {@code ddf.home}) will be added to this collection
*/
public void copyFileFromSystemPropertyValue(@NotNull String systemProperty, @NotNull Path exportDirectory, @NotNull Collection<MigrationWarning> warnings) throws MigrationException {
String source = System.getProperty(systemProperty);
notEmpty(source, String.format("Source path property [%s] is invalid: [%s]", systemProperty, source));
Path sourcePath = Paths.get(source);
copy(sourcePath, exportDirectory, warnings, () -> isSourceMigratable(sourcePath, (reason) -> new PathMigrationWarning(systemProperty, sourcePath, reason), warnings));
}
Aggregations