use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class InventoryController method exportInventory.
public void exportInventory(ActionRequest request, ActionResponse response) {
try {
Inventory inventory = request.getContext().asType(Inventory.class);
inventory = Beans.get(InventoryRepository.class).find(inventory.getId());
String name = I18n.get("Inventory") + " " + inventory.getInventorySeq();
MetaFile metaFile = Beans.get(InventoryService.class).exportInventoryAsCSV(inventory);
response.setView(ActionView.define(name).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + metaFile.getId() + "/content/download?v=" + metaFile.getVersion()).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class DataBackupRestoreService method restore.
/* Restore the Data using provided zip File and prepare Log File and Return it*/
public File restore(MetaFile zipedBackupFile) {
Logger LOG = LoggerFactory.getLogger(getClass());
File tempDir = Files.createTempDir();
String dirPath = tempDir.getAbsolutePath();
StringBuilder sb = new StringBuilder();
try {
unZip(zipedBackupFile, dirPath);
String configFName = tempDir.getAbsolutePath() + File.separator + DataBackupServiceImpl.CONFIG_FILE_NAME;
CSVImporter csvImporter = new CSVImporter(configFName, tempDir.getAbsolutePath());
csvImporter.addListener(new Listener() {
String modelName;
StringBuilder sb1 = new StringBuilder();
@Override
public void handle(Model bean, Exception e) {
if (e.getMessage() != null && !e.getMessage().equals("null")) {
if (bean != null) {
sb1.append(bean.getClass().getSimpleName() + " : \n" + e.getMessage() + "\n\n");
} else {
sb1.append(e.getMessage() + "\n\n");
}
}
}
@Override
public void imported(Model model) {
modelName = model.getClass().getSimpleName();
}
@Override
public void imported(Integer total, Integer count) {
String str = "", strError = "";
if (!StringUtils.isBlank(sb1)) {
strError = "Errors : \n" + sb1.toString();
}
str = "Total Records : {" + total + "} - Success Records : {" + count + "} \n";
if (total != 0 && count != 0) {
sb.append(modelName + " : \n");
}
sb.append(strError).append(str + "-----------------------------------------\n");
sb1.setLength(0);
}
});
csvImporter.run();
LOG.info("Data Restore Completed");
FileUtils.cleanDirectory(new File(tempDir.getAbsolutePath()));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmSS");
String logFileName = "DataBackupLog_" + LocalDateTime.now().format(formatter) + ".log";
File file = new File(tempDir.getAbsolutePath(), logFileName);
PrintWriter pw = new PrintWriter(file);
pw.write(sb.toString());
pw.close();
return file;
} catch (IOException e) {
TraceBackService.trace(e);
return null;
}
}
use of com.axelor.meta.db.MetaFile in project axelor-open-suite by axelor.
the class DataBackupRestoreService method unZip.
private boolean unZip(MetaFile zipMetaFile, String destinationDirectoryPath) throws IOException {
File zipFile = MetaFiles.getPath(zipMetaFile).toFile();
try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)))) {
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;
while ((ze = zis.getNextEntry()) != null) {
try (FileOutputStream fout = new FileOutputStream(new File(destinationDirectoryPath, ze.getName()))) {
while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
}
zis.closeEntry();
}
return true;
}
}
use of com.axelor.meta.db.MetaFile 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.meta.db.MetaFile in project axelor-open-suite by axelor.
the class AppController method generateAccessTemplate.
public void generateAccessTemplate(ActionRequest request, ActionResponse response) throws AxelorException {
MetaFile accesssFile = Beans.get(AccessTemplateService.class).generateTemplate();
if (accesssFile == null) {
return;
}
response.setView(ActionView.define(I18n.get("Export file")).model(App.class.getName()).add("html", "ws/rest/com.axelor.meta.db.MetaFile/" + accesssFile.getId() + "/content/download?v=" + accesssFile.getVersion()).param("download", "true").map());
}
Aggregations