public final static String TYPE_PARAM_RESOURCES = "resources";
public void onMessage(Message message) {
ExportMessage msg = (ExportMessage)message;
VosaoContext.getInstance().setUser(UserHelper.ADMIN);
ZipOutStreamTaskAdapter zipOutStreamTaskAdapter =
new ZipOutStreamTaskAdapterImpl(getBusiness());
if (msg.getCurrentFile() == null) {
removeExportFile(msg.getFilename());
getBusiness().getSystemService().getCache().remove(
msg.getFilename());
}
zipOutStreamTaskAdapter.setFileCounter(Integer.valueOf(
msg.getFileCounter()));
try {
openStream(zipOutStreamTaskAdapter, msg.getFilename());
zipOutStreamTaskAdapter.setStartFile(msg.getCurrentFile());
logger.info("Export " + msg.getExportType() + " "
+ msg.getCurrentFile() + " " + msg.getFileCounter());
if (msg.getExportType().equals(TYPE_PARAM_THEME)) {
List<TemplateEntity> templates = getDao().getTemplateDao()
.getById(msg.getIds());
List<StructureEntity> structures = getDao().getStructureDao()
.getById(msg.getStructureIds());
getImportExportBusiness().createTemplateExportFile(
zipOutStreamTaskAdapter, templates, structures);
}
if (msg.getExportType().equals(TYPE_PARAM_FOLDER)) {
FolderEntity folder = getDao().getFolderDao().getById(
msg.getFolderId());
getImportExportBusiness().createExportFile(
zipOutStreamTaskAdapter, folder);
}
if (msg.getExportType().equals(TYPE_PARAM_SITE)) {
getImportExportBusiness().createSiteExportFile(
zipOutStreamTaskAdapter);
}
if (msg.getExportType().equals(TYPE_PARAM_FULL)) {
getImportExportBusiness().createFullExportFile(
zipOutStreamTaskAdapter);
}
if (msg.getExportType().equals(TYPE_PARAM_RESOURCES)) {
getImportExportBusiness().createResourcesExportFile(
zipOutStreamTaskAdapter);
}
saveZip(zipOutStreamTaskAdapter, msg.getFilename(), true);
getBusiness().getFileBusiness().saveFile("/tmp/"
+ msg.getFilename() + ".txt", "OK".getBytes());
logger.info("Export finished. " + zipOutStreamTaskAdapter
.getFileCounter());
} catch (TaskTimeoutException e) {
try {
saveZip(zipOutStreamTaskAdapter, msg.getFilename(), false);
}
catch (Exception e2) {
e2.printStackTrace();
}
getMessageQueue().publish(new ExportMessage.Builder()
.setFilename(msg.getFilename())
.setCurrentFile(zipOutStreamTaskAdapter.getCurrentFile())
.setFileCounter(zipOutStreamTaskAdapter.getFileCounter())
.setExportType(msg.getExportType()).create());
logger.info("Added new export task "
+ zipOutStreamTaskAdapter.getCurrentFile());
} catch (Exception e) {
logger.error(e.toString() + " " + e.getMessage() + "\n"
+ ExceptionUtils.getFullStackTrace(e));
}
}