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