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);
}
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);
}
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);
}
});
}
}
Aggregations