Search in sources :

Example 6 with DataRestoreJob

use of org.openforis.collect.io.data.DataRestoreJob in project collect by openforis.

the class DataImportService method startImport.

@Secured(CLEANSING)
public JobProxy startImport(List<Integer> entryIdsToImport, boolean validateRecords, boolean processInTransaction) throws Exception {
    if (dataRestoreJob == null || !dataRestoreJob.isRunning()) {
        log.info("Starting data restore");
        DataRestoreJob job;
        if (processInTransaction) {
            job = jobManager.createJob(TransactionalDataRestoreJob.JOB_NAME, TransactionalDataRestoreJob.class);
        } else {
            job = jobManager.createJob(DataRestoreJob.JOB_NAME, DataRestoreJob.class);
        }
        job.setFile(packagedFile);
        job.setValidateRecords(validateRecords);
        job.setRecordProvider(summaryJob.getRecordProvider());
        job.setPackagedSurvey(summaryJob.getPackagedSurvey());
        job.setPublishedSurvey(summaryJob.getPublishedSurvey());
        job.setEntryIdsToImport(entryIdsToImport);
        job.setRecordFilesToBeDeleted(summaryJob.getSummary().getConflictingRecordFiles(entryIdsToImport));
        job.setRestoreUploadedFiles(true);
        job.setValidateRecords(validateRecords);
        resetJobs();
        this.dataRestoreJob = job;
        jobManager.start(job);
    } else {
        log.warn("Data restore job already running");
    }
    return getCurrentJob();
}
Also used : TransactionalDataRestoreJob(org.openforis.collect.io.data.TransactionalDataRestoreJob) TransactionalDataRestoreJob(org.openforis.collect.io.data.TransactionalDataRestoreJob) DataRestoreJob(org.openforis.collect.io.data.DataRestoreJob) Secured(org.springframework.security.access.annotation.Secured)

Example 7 with DataRestoreJob

use of org.openforis.collect.io.data.DataRestoreJob in project collect by openforis.

the class DataRestoreServiceImpl method startSurveyDataRestore.

@Override
public String startSurveyDataRestore(String surveyName, File backupFile) {
    CollectSurvey survey = surveyManager.get(surveyName);
    String surveyUri = extractSurveyUri(backupFile);
    checkValidSurvey(surveyName, surveyUri);
    DataRestoreJob job = jobManager.createJob(DataRestoreJob.JOB_NAME, DataRestoreJob.class);
    job.setStoreRestoredFile(true);
    job.setPublishedSurvey(survey);
    job.setFile(backupFile);
    job.setRecordOverwriteStrategy(OverwriteStrategy.OVERWRITE_ALL);
    job.setRestoreUploadedFiles(true);
    job.setCloseRecordProviderOnComplete(true);
    String lockId = surveyUri;
    jobManager.start(job, lockId);
    return lockId;
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) DataRestoreJob(org.openforis.collect.io.data.DataRestoreJob)

Aggregations

DataRestoreJob (org.openforis.collect.io.data.DataRestoreJob)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 TransactionalDataRestoreJob (org.openforis.collect.io.data.TransactionalDataRestoreJob)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 Job (org.openforis.concurrency.Job)2 Secured (org.springframework.security.access.annotation.Secured)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ZipException (java.util.zip.ZipException)1 SurveyBackupInfo (org.openforis.collect.io.SurveyBackupInfo)1 RecordProvider (org.openforis.collect.io.data.RecordProvider)1 RecordProviderConfiguration (org.openforis.collect.io.data.RecordProviderConfiguration)1 User (org.openforis.collect.model.User)1 UserGroup (org.openforis.collect.model.UserGroup)1 JobView (org.openforis.collect.web.controller.CollectJobController.JobView)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1