Search in sources :

Example 1 with BackupFileExtractor

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);
    }
}
Also used : SurveyBackupInfo(org.openforis.collect.io.SurveyBackupInfo) BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with 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();
}
Also used : BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor)

Example 3 with BackupFileExtractor

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);
    }
}
Also used : SurveyBackupInfo(org.openforis.collect.io.SurveyBackupInfo) BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 4 with 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);
    }
}
Also used : SurveyBackupInfo(org.openforis.collect.io.SurveyBackupInfo) BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor)

Example 5 with 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);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) BackupFileExtractor(org.openforis.collect.io.BackupFileExtractor) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

BackupFileExtractor (org.openforis.collect.io.BackupFileExtractor)8 SurveyBackupInfo (org.openforis.collect.io.SurveyBackupInfo)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 DataUnmarshaller (org.openforis.collect.persistence.xml.DataUnmarshaller)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1