use of org.openforis.collect.io.BackupFileExtractor in project collect by openforis.
the class DataRestoreServiceImpl method extractSurveyUri.
private String extractSurveyUri(File tempFile) {
BackupFileExtractor backupFileExtractor = null;
try {
backupFileExtractor = new BackupFileExtractor(tempFile);
File infoFile = backupFileExtractor.extractInfoFile();
SurveyBackupInfo backupInfo = SurveyBackupInfo.parse(new FileInputStream(infoFile));
String surveyUri = backupInfo.getSurveyUri();
return surveyUri;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(backupFileExtractor);
}
}
use of org.openforis.collect.io.BackupFileExtractor in project collect by openforis.
the class DataRestoreBaseJob method createInternalVariables.
@Override
public void createInternalVariables() throws Throwable {
super.createInternalVariables();
newSurvey = publishedSurvey == null;
backupFileExtractor = new BackupFileExtractor(file);
oldBackupFormat = backupFileExtractor.isOldFormat();
dataSummaryFile = extractDataSummaryFile();
surveyName = newSurvey ? extractSurveyName() : publishedSurvey.getName();
}
use of org.openforis.collect.io.BackupFileExtractor in project collect by openforis.
the class DataRestoreBaseJob method validateInput.
@Override
protected void validateInput() throws Throwable {
super.validateInput();
BackupFileExtractor backupFileExtractor = null;
try {
backupFileExtractor = new BackupFileExtractor(file);
if (backupFileExtractor.isOldFormat()) {
if (publishedSurvey == null) {
throw new IllegalArgumentException("Please specify a published survey to witch restore data into");
}
} else {
SurveyBackupInfo backupInfo = backupFileExtractor.extractInfo();
CollectSurvey existingPublishedSurvey = findExistingPublishedSurvey(backupInfo);
boolean newSurvey = publishedSurvey == null;
if (newSurvey) {
if (existingPublishedSurvey != null) {
throw new IllegalArgumentException(String.format("The backup file is associated to an already published survey: %s", existingPublishedSurvey.getName()));
}
} else {
String publishedSurveyUri = publishedSurvey.getUri();
String packagedSurveyUri = backupInfo.getSurveyUri();
if (!publishedSurveyUri.equals(packagedSurveyUri)) {
throw new RuntimeException(String.format("Packaged survey uri (%s) is different from the expected one (%s)", packagedSurveyUri, publishedSurveyUri));
}
}
}
} finally {
IOUtils.closeQuietly(backupFileExtractor);
}
}
use of org.openforis.collect.io.BackupFileExtractor in project collect by openforis.
the class DataRestoreController method extractInfo.
private SurveyBackupInfo extractInfo(File tempFile) throws ZipException, IOException {
BackupFileExtractor backupFileExtractor = null;
try {
backupFileExtractor = new BackupFileExtractor(tempFile);
SurveyBackupInfo info = backupFileExtractor.extractInfo();
return info;
} finally {
IOUtils.closeQuietly(backupFileExtractor);
}
}
use of org.openforis.collect.io.BackupFileExtractor in project collect by openforis.
the class CollectMobileBackupConvertTask method createOutpuFile.
/**
* Compress the database file
*/
private void createOutpuFile() throws IOException, FileNotFoundException {
ZipOutputStream zipOutputStream = null;
BackupFileExtractor backupFileExtractor = null;
try {
backupFileExtractor = new BackupFileExtractor(collectBackupFile);
outputFile = File.createTempFile("collect_" + surveyName, ".zip");
zipOutputStream = new ZipOutputStream(new FileOutputStream(outputFile));
// include collect.db file
zipOutputStream.putNextEntry(new ZipEntry(COLLECT_DB_FILE_NAME));
FileInputStream dbFileIS = new FileInputStream(outputDbFile);
IOUtils.copy(dbFileIS, zipOutputStream);
zipOutputStream.closeEntry();
// include info.properties file
File infoFile = backupFileExtractor.extract(SurveyBackupJob.INFO_FILE_NAME);
zipOutputStream.putNextEntry(new ZipEntry(SurveyBackupJob.INFO_FILE_NAME));
IOUtils.copy(new FileInputStream(infoFile), zipOutputStream);
zipOutputStream.closeEntry();
} finally {
IOUtils.closeQuietly(backupFileExtractor);
IOUtils.closeQuietly(zipOutputStream);
}
}
Aggregations