pub use self::importer::{ImportResult, ImportValidationReport, V2ImportConfig, V2Importer};
pub use self::snapshot::{
SnapshotImportConfig, SnapshotImportResult, SnapshotImportValidationReport, SnapshotImporter,
};
pub use self::validation::{ImportValidator, PostImportValidator};
pub mod importer;
pub mod snapshot;
pub mod validation;
pub struct ImportFactory;
impl ImportFactory {
pub fn create_importer(
export_dir: &std::path::Path,
target_graph_path: &std::path::Path,
import_config: V2ImportConfig,
) -> crate::backend::native::types::NativeResult<V2Importer> {
V2Importer::from_export_dir(export_dir, target_graph_path, import_config)
}
pub fn create_fresh_importer(
export_dir: &std::path::Path,
target_graph_path: &std::path::Path,
) -> crate::backend::native::types::NativeResult<V2Importer> {
let config = V2ImportConfig {
target_graph_path: target_graph_path.to_path_buf(),
export_dir_path: export_dir.to_path_buf(),
import_mode: ImportMode::Fresh,
validate_recovery: true,
force_checkpoint_after_import: true,
};
Self::create_importer(export_dir, target_graph_path, config)
}
pub fn create_merge_importer(
export_dir: &std::path::Path,
target_graph_path: &std::path::Path,
) -> crate::backend::native::types::NativeResult<V2Importer> {
let config = V2ImportConfig {
target_graph_path: target_graph_path.to_path_buf(),
export_dir_path: export_dir.to_path_buf(),
import_mode: ImportMode::Merge,
validate_recovery: true,
force_checkpoint_after_import: true,
};
Self::create_importer(export_dir, target_graph_path, config)
}
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum ImportMode {
Fresh,
Merge,
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
#[test]
fn test_import_factory_creation() {
let temp_dir = tempdir().unwrap();
let export_dir = temp_dir.path().join("export");
let target_path = temp_dir.path().join("imported.v2");
let result = ImportFactory::create_fresh_importer(&export_dir, &target_path);
assert!(result.is_err() || result.is_ok()); }
}