use of com.evolveum.midpoint.web.security.WebApplicationConfiguration in project midpoint by Evolveum.
the class PageImportObject method getInputStream.
private InputStream getInputStream(boolean raw) throws Exception {
if (raw) {
return IOUtils.toInputStream(xmlEditorModel.getObject(), "utf-8");
}
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();
}
FileUpload uploadedFile = getUploadedFile();
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
newFile.createNewFile();
uploadedFile.writeTo(newFile);
InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8");
return new ReaderInputStream(reader, reader.getEncoding());
} finally {
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
}
use of com.evolveum.midpoint.web.security.WebApplicationConfiguration in project midpoint by Evolveum.
the class PageImportObject method getInputDescription.
@NotNull
private InputDescription getInputDescription(boolean editor) throws Exception {
if (editor) {
return new InputDescription(IOUtils.toInputStream(xmlEditorModel.getObject(), StandardCharsets.UTF_8), dataLanguage);
}
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();
}
FileUpload uploadedFile = getUploadedFile();
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
newFile.createNewFile();
FileUtils.copyInputStreamToFile(uploadedFile.getInputStream(), newFile);
String language = getPrismContext().detectLanguage(newFile);
return new InputDescription(new FileInputStream(newFile), language);
} finally {
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
}
use of com.evolveum.midpoint.web.security.WebApplicationConfiguration in project midpoint by Evolveum.
the class ProgressReporter method create.
/**
* Creates and initializes a progress reporter instance. Should be called during initialization
* of respective wicket page.
*
* @param parentPage The parent page (user, org, role, ...)
* @param id Wicket ID of the progress panel
* @return Progress reporter instance
*/
public static ProgressReporter create(String id, ProgressReportingAwarePage parentPage) {
ProgressReporter reporter = new ProgressReporter();
reporter.progressPanel = new ProgressPanel(id, new Model<>(new ProgressDto()), reporter, parentPage);
reporter.progressPanel.setOutputMarkupId(true);
reporter.progressPanel.hide();
WebApplicationConfiguration config = parentPage.getWebApplicationConfiguration();
reporter.refreshInterval = config.getProgressRefreshInterval();
reporter.asynchronousExecution = config.isProgressReportingEnabled();
reporter.abortEnabled = config.isAbortEnabled();
reporter.parentPage = parentPage;
return reporter;
}
use of com.evolveum.midpoint.web.security.WebApplicationConfiguration 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 com.evolveum.midpoint.web.security.WebApplicationConfiguration in project midpoint by Evolveum.
the class ImportReportPopupPanel method importConfirmPerformed.
private void importConfirmPerformed(AjaxRequestTarget target, Model<String> nameModel, Model<String> fileStringImport) {
String dataName;
if (nameModel == null || StringUtils.isEmpty(nameModel.getObject())) {
dataName = getModelObject().getName().getOrig() + "-IMPORT " + getDataTime();
} else {
dataName = nameModel.getObject();
}
// Create new file
MidPointApplication application = getPageBase().getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
String midpointHome = System.getProperty(MidpointConfiguration.MIDPOINT_HOME_PROPERTY);
File importDir = new File(midpointHome, "import");
if (!importDir.exists() || !importDir.isDirectory()) {
if (!importDir.mkdir()) {
LOGGER.error("Couldn't create import dir {}", importDir);
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportDir", importDir).getString());
target.add(feedback);
return;
}
}
FileUpload uploadedFile = getUploadedFile();
if (uploadedFile == null && StringUtils.isEmpty(fileStringImport.getObject())) {
LOGGER.error("Please upload file for import");
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.uploadFile", importDir).getString());
target.add(feedback);
return;
}
String newFilePath;
if (uploadedFile != null) {
String fileName = FilenameUtils.removeExtension(uploadedFile.getClientFileName()) + " " + getDataTime() + "." + FilenameUtils.getExtension(uploadedFile.getClientFileName());
File newFile = new File(importDir, fileName);
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
try {
newFile.createNewFile();
FileUtils.copyInputStreamToFile(uploadedFile.getInputStream(), newFile);
newFilePath = newFile.getAbsolutePath();
} catch (IOException e) {
LOGGER.error("Couldn't create new file " + newFile.getAbsolutePath(), e);
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportFile", newFile.getAbsolutePath()).getString());
target.add(feedback);
return;
}
} else {
newFilePath = new File(importDir, dataName).getAbsolutePath();
try {
Files.write(Paths.get(newFilePath), fileStringImport.getObject().getBytes());
} catch (IOException e) {
LOGGER.error("Couldn't create new file " + newFilePath, e);
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportFile", newFilePath).getString());
target.add(feedback);
return;
}
}
ReportDataType reportImportData = null;
try {
@NotNull PrismObject<ReportDataType> prismObject = getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ReportDataType.class).instantiate();
reportImportData = prismObject.asObjectable();
} catch (SchemaException e) {
LOGGER.error("Couldn't instantiate new Report Data from definition", e);
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createInstantiateReportData").getString());
target.add(feedback);
return;
}
reportImportData.setName(new PolyStringType(dataName));
reportImportData.setFilePath(newFilePath);
ObjectReferenceType reportRef = new ObjectReferenceType();
reportRef.setType(ReportType.COMPLEX_TYPE);
reportRef.setOid(getModelObject().getOid());
reportImportData.setReportRef(reportRef);
Collection<ObjectDelta<? extends ObjectType>> deltas = Collections.singleton(reportImportData.asPrismObject().createAddDelta());
Task task = getPageBase().createSimpleTask(OPERATION_CREATE_REPORT_DATA);
try {
Collection<ObjectDeltaOperation<? extends ObjectType>> retDeltas = getPageBase().getModelService().executeChanges(deltas, null, task, task.getResult());
reportImportData = (ReportDataType) retDeltas.iterator().next().getObjectDelta().getObjectToAdd().asObjectable();
} catch (ObjectAlreadyExistsException e) {
LOGGER.error("Report Data with name " + dataName + " already exists", e);
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.importReportDataAlreadyExists", dataName).getString());
target.add(feedback);
return;
} catch (Exception e) {
LOGGER.error("Couldn't create new Report Data with name " + dataName, e);
FeedbackAlerts feedback = getFeedbackPanel();
feedback.error(getPageBase().createStringResource("ImportReportPopupPanel.message.error.createImportReportData", dataName).getString());
target.add(feedback);
return;
}
importConfirmPerformed(target, reportImportData);
}
Aggregations