Search in sources :

Example 1 with AuditableRunner

use of com.axelor.auth.AuditableRunner 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 AuditableRunner

use of com.axelor.auth.AuditableRunner 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 AuditableRunner

use of com.axelor.auth.AuditableRunner in project axelor-open-suite by axelor.

the class MailServiceMessageImpl method fetch.

@Override
public void fetch() throws MailException {
    final EmailAccount emailAccount = mailAccountService.getDefaultReader();
    if (emailAccount == null) {
        super.fetch();
    } else {
        final MailReader reader = getMailReader(emailAccount);
        final AuditableRunner runner = Beans.get(AuditableRunner.class);
        runner.run(() -> {
            try {
                fetch(reader);
            } catch (Exception e) {
                log.error("Unable to fetch messages", e);
            }
        });
    }
}
Also used : MailReader(com.axelor.mail.MailReader) EmailAccount(com.axelor.apps.message.db.EmailAccount) AuditableRunner(com.axelor.auth.AuditableRunner) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) IOException(java.io.IOException) MailException(com.axelor.mail.MailException)

Aggregations

AuditableRunner (com.axelor.auth.AuditableRunner)3 DataBackup (com.axelor.apps.base.db.DataBackup)2 DataBackupRepository (com.axelor.apps.base.db.repo.DataBackupRepository)2 MetaFile (com.axelor.meta.db.MetaFile)2 Callable (java.util.concurrent.Callable)2 Logger (org.slf4j.Logger)2 EmailAccount (com.axelor.apps.message.db.EmailAccount)1 MailException (com.axelor.mail.MailException)1 MailReader (com.axelor.mail.MailReader)1 Transactional (com.google.inject.persist.Transactional)1 File (java.io.File)1 IOException (java.io.IOException)1 MessagingException (javax.mail.MessagingException)1 AddressException (javax.mail.internet.AddressException)1