Search in sources :

Example 1 with SurveyBackupInfo

use of org.openforis.collect.io.SurveyBackupInfo 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 SurveyBackupInfo

use of org.openforis.collect.io.SurveyBackupInfo 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 3 with SurveyBackupInfo

use of org.openforis.collect.io.SurveyBackupInfo 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 4 with SurveyBackupInfo

use of org.openforis.collect.io.SurveyBackupInfo in project collect by openforis.

the class DataRestoreController method startRestoreJob.

private DataRestoreJob startRestoreJob(InputStream fileInputStream, boolean newSurvey, String expectedSurveyName, User user, boolean validateRecords, boolean deleteAllRecords, OverwriteStrategy recordOverwriteStrategy) throws IOException, FileNotFoundException, ZipException {
    File tempFile = File.createTempFile("ofc_data_restore", ".collect-backup");
    FileUtils.copyInputStreamToFile(fileInputStream, tempFile);
    SurveyBackupInfo info = extractInfo(tempFile);
    CollectSurvey publishedSurvey = findPublishedSurvey(info);
    if (newSurvey) {
        checkPackagedNewSurveyValidity(info);
    } else {
        checkPackagedSurveyValidity(info, expectedSurveyName);
    }
    UserGroup newSurveyUserGroup = userGroupManager.getDefaultPublicUserGroup();
    DataRestoreJob job = jobManager.createJob(DataRestoreJob.JOB_NAME, DataRestoreJob.class);
    job.setUser(user);
    job.setStoreRestoredFile(true);
    job.setPublishedSurvey(publishedSurvey);
    job.setNewSurveyUserGroup(newSurveyUserGroup);
    job.setFile(tempFile);
    job.setRecordOverwriteStrategy(recordOverwriteStrategy);
    job.setRestoreUploadedFiles(true);
    job.setValidateRecords(validateRecords);
    job.setDeleteAllRecordsBeforeRestore(deleteAllRecords);
    String lockId = extractSurveyUri(tempFile);
    jobManager.start(job, lockId);
    return job;
}
Also used : SurveyBackupInfo(org.openforis.collect.io.SurveyBackupInfo) CollectSurvey(org.openforis.collect.model.CollectSurvey) DataRestoreJob(org.openforis.collect.io.data.DataRestoreJob) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) UserGroup(org.openforis.collect.model.UserGroup)

Example 5 with SurveyBackupInfo

use of org.openforis.collect.io.SurveyBackupInfo in project collect by openforis.

the class SurveyImportVM method onSummaryCreationComplete.

protected void onSummaryCreationComplete() {
    SurveyBackupInfo info = summaryJob.getInfo();
    Version version = VERSION;
    if (version != null && version.compareTo(info.getCollectVersion(), VERSION_SIGNIFICANCE) < 0) {
        MessageUtil.showError("survey.import_survey.error.outdated_system_version");
    } else {
        survey = summaryJob.getSurvey();
        uploadedSurveyUri = info.getSurveyUri();
        uploadedSurveyName = info.getSurveyName();
        summaryJob = null;
        notifyChange("uploadedSurveyUri");
        updateForm();
    }
}
Also used : SurveyBackupInfo(org.openforis.collect.io.SurveyBackupInfo) Version(org.openforis.commons.versioning.Version)

Aggregations

SurveyBackupInfo (org.openforis.collect.io.SurveyBackupInfo)7 BackupFileExtractor (org.openforis.collect.io.BackupFileExtractor)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 DataRestoreJob (org.openforis.collect.io.data.DataRestoreJob)1 UserGroup (org.openforis.collect.model.UserGroup)1 Version (org.openforis.commons.versioning.Version)1