Search in sources :

Example 1 with DataBackup

use of com.axelor.apps.base.db.DataBackup in project axelor-open-suite by axelor.

the class DataBackupServiceImpl method startRestore.

protected void startRestore(DataBackup dataBackup) throws Exception {
    final AuditableRunner runner = Beans.get(AuditableRunner.class);
    final Callable<Boolean> job = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            Logger LOG = LoggerFactory.getLogger(getClass());
            DataBackup obj = Beans.get(DataBackupRepository.class).find(dataBackup.getId());
            File logFile = restoreService.restore(obj.getBackupMetaFile());
            save(logFile, obj);
            LOG.info("Data Restore Saved");
            return true;
        }

        public void save(File logFile, DataBackup obj) {
            try {
                JPA.em().getTransaction().begin();
                obj = Beans.get(DataBackupRepository.class).find(dataBackup.getId());
                if (logFile != null) {
                    obj.setStatusSelect(DataBackupRepository.DATA_BACKUP_STATUS_RESTORE);
                    obj.setLogMetaFile(metaFiles.upload(logFile));
                } else {
                    obj.setStatusSelect(DataBackupRepository.DATA_BACKUP_STATUS_RESTORE_ERROR);
                }
                Beans.get(DataBackupRepository.class).save(obj);
                JPA.em().getTransaction().commit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    runner.run(job);
}
Also used : DataBackupRepository(com.axelor.apps.base.db.repo.DataBackupRepository) DataBackup(com.axelor.apps.base.db.DataBackup) Logger(org.slf4j.Logger) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) AuditableRunner(com.axelor.auth.AuditableRunner) Callable(java.util.concurrent.Callable)

Example 2 with DataBackup

use of com.axelor.apps.base.db.DataBackup in project axelor-open-suite by axelor.

the class DataBackupServiceImpl method startBackup.

@Transactional(rollbackOn = { Exception.class })
protected void startBackup(DataBackup dataBackup) throws Exception {
    final AuditableRunner runner = Beans.get(AuditableRunner.class);
    final Callable<Boolean> job = new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            Logger LOG = LoggerFactory.getLogger(getClass());
            DataBackup obj = Beans.get(DataBackupRepository.class).find(dataBackup.getId());
            obj = createService.create(obj);
            MetaFile logFile = obj.getLogMetaFile();
            MetaFile zipFile = obj.getBackupMetaFile();
            int status = obj.getStatusSelect();
            obj = dataBackupRepository.find(obj.getId());
            if (status != DataBackupRepository.DATA_BACKUP_STATUS_ERROR) {
                obj.setBackupMetaFile(zipFile);
                obj.setStatusSelect(DataBackupRepository.DATA_BACKUP_STATUS_CREATED);
            } else {
                obj.setStatusSelect(DataBackupRepository.DATA_BACKUP_STATUS_ERROR);
            }
            obj.setLogMetaFile(logFile);
            dataBackupRepository.save(obj);
            LOG.info("Data BackUp Saved");
            return true;
        }
    };
    runner.run(job);
}
Also used : DataBackupRepository(com.axelor.apps.base.db.repo.DataBackupRepository) DataBackup(com.axelor.apps.base.db.DataBackup) MetaFile(com.axelor.meta.db.MetaFile) Logger(org.slf4j.Logger) AuditableRunner(com.axelor.auth.AuditableRunner) Callable(java.util.concurrent.Callable) Transactional(com.google.inject.persist.Transactional)

Example 3 with DataBackup

use of com.axelor.apps.base.db.DataBackup in project axelor-open-suite by axelor.

the class DataBackupServiceImpl method setStatus.

@Transactional
protected DataBackup setStatus(DataBackup dataBackup) {
    DataBackup obj = dataBackupRepository.find(dataBackup.getId());
    obj.setStatusSelect(DataBackupRepository.DATA_BACKUP_STATUS_IN_PROGRESS);
    return dataBackupRepository.save(obj);
}
Also used : DataBackup(com.axelor.apps.base.db.DataBackup) Transactional(com.google.inject.persist.Transactional)

Example 4 with DataBackup

use of com.axelor.apps.base.db.DataBackup in project axelor-open-suite by axelor.

the class DataBackupController method restoreBackup.

public void restoreBackup(ActionRequest req, ActionResponse res) throws IOException {
    DataBackupService dataBackupService = Beans.get(DataBackupService.class);
    DataBackup dataBackup = req.getContext().asType(DataBackup.class);
    if (dataBackupService.sequencesOrMrpLineTypesExist()) {
        res.setError("Remove all Sequences And MrpLineTypes to restore backup");
    } else {
        dataBackupService.restoreBackUp(dataBackup);
    }
    res.setReload(true);
}
Also used : DataBackupService(com.axelor.apps.base.service.app.DataBackupService) DataBackup(com.axelor.apps.base.db.DataBackup)

Example 5 with DataBackup

use of com.axelor.apps.base.db.DataBackup in project axelor-open-suite by axelor.

the class DataBackupController method createBackup.

public void createBackup(ActionRequest req, ActionResponse res) throws IOException {
    DataBackup dataBackup = req.getContext().asType(DataBackup.class);
    Beans.get(DataBackupService.class).createBackUp(dataBackup);
    res.setReload(true);
}
Also used : DataBackupService(com.axelor.apps.base.service.app.DataBackupService) DataBackup(com.axelor.apps.base.db.DataBackup)

Aggregations

DataBackup (com.axelor.apps.base.db.DataBackup)5 DataBackupRepository (com.axelor.apps.base.db.repo.DataBackupRepository)2 DataBackupService (com.axelor.apps.base.service.app.DataBackupService)2 AuditableRunner (com.axelor.auth.AuditableRunner)2 MetaFile (com.axelor.meta.db.MetaFile)2 Transactional (com.google.inject.persist.Transactional)2 Callable (java.util.concurrent.Callable)2 Logger (org.slf4j.Logger)2 File (java.io.File)1