use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageDebugDownloadBehaviour method initFile.
@Override
protected File initFile() {
PageBase page = getPage();
OperationResult result = new OperationResult(OPERATION_CREATE_DOWNLOAD_FILE);
MidPointApplication application = page.getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
File folder = new File(config.getExportFolder());
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
String suffix = isUseZip() ? "zip" : "xml";
String fileName = "ExportedData_" + getType().getSimpleName() + "_" + System.currentTimeMillis() + "." + suffix;
File file = new File(folder, fileName);
Writer writer = null;
try {
LOGGER.debug("Creating file '{}'.", new Object[] { file.getAbsolutePath() });
writer = createWriter(file);
LOGGER.debug("Exporting objects.");
dumpHeader(writer);
dumpObjectsToStream(writer, result);
dumpFooter(writer);
LOGGER.debug("Export finished.");
result.recomputeStatus();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't init download link", ex);
result.recordFatalError("Couldn't init download link", ex);
} finally {
if (writer != null) {
IOUtils.closeQuietly(writer);
}
}
if (!WebComponentUtil.isSuccessOrHandledError(result)) {
page.showResult(result);
page.getSession().error(page.getString("pageDebugList.message.createFileException"));
LOGGER.debug("Removing file '{}'.", new Object[] { file.getAbsolutePath() });
Files.remove(file);
throw new RestartResponseException(PageError.class);
}
return file;
}
use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageNewReport method importReportFromFilePerformed.
private void importReportFromFilePerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT);
FileUploadField file = (FileUploadField) get(createComponentPath(ID_MAIN_FORM, ID_INPUT, ID_INPUT_FILE, ID_FILE_INPUT));
final FileUpload uploadedFile = file.getFileUpload();
if (uploadedFile == null) {
error(getString("PageNewReport.message.nullFile"));
target.add(getFeedbackPanel());
return;
}
InputStream stream = null;
File newFile = null;
try {
// Create new file
MidPointApplication application = getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
File folder = new File(config.getImportFolder());
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
// Task task = createSimpleTask(OPERATION_IMPORT_FILE);
newFile.createNewFile();
uploadedFile.writeTo(newFile);
InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8");
// reader.
stream = new ReaderInputStream(reader, reader.getEncoding());
byte[] reportIn = IOUtils.toByteArray(stream);
setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(reportIn))));
} catch (Exception ex) {
result.recordFatalError("Couldn't import file.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file", ex);
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
showResult(result);
target.add(getFeedbackPanel());
}
use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageAccounts method downloadPerformed.
private void downloadPerformed(AjaxRequestTarget target, String fileName, AjaxDownloadBehaviorFromFile downloadBehavior) {
MidpointConfiguration config = getMidpointConfiguration();
downloadFile = new File(config.getMidpointHome() + "/export/" + fileName);
downloadBehavior.initiate(target);
}
use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageAccounts method createFilesModel.
private LoadableModel<List<String>> createFilesModel() {
return new LoadableModel<List<String>>(false) {
@Override
protected List<String> load() {
String[] filesArray;
try {
MidpointConfiguration config = getMidpointConfiguration();
File exportFolder = new File(config.getMidpointHome() + "/export");
filesArray = exportFolder.list(new FilenameFilter() {
@Override
public boolean accept(java.io.File dir, String name) {
return name.endsWith("xml");
}
});
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't list files", ex);
getSession().error("Couldn't list files, reason: " + ex.getMessage());
throw new RestartResponseException(PageDashboard.class);
}
if (filesArray == null) {
return new ArrayList<>();
}
List<String> list = Arrays.asList(filesArray);
Collections.sort(list);
return list;
}
};
}
Aggregations