use of com.evolveum.midpoint.web.security.MidPointApplication in project midpoint by Evolveum.
the class TaskDto method getObjectQuery.
public String getObjectQuery() {
QueryType queryType = getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY, QueryType.class);
PrismContext prismContext = ((MidPointApplication) Application.get()).getPrismContext();
try {
return prismContext.xmlSerializer().serializeAnyData(queryType, SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
} catch (SchemaException e) {
throw new SystemException("Couldn't serialize query: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.web.security.MidPointApplication 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 com.evolveum.midpoint.web.security.MidPointApplication 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.MidPointApplication in project midpoint by Evolveum.
the class TaskDto method getObjectDelta.
public String getObjectDelta() {
ObjectDeltaType objectDeltaType = getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA, ObjectDeltaType.class);
PrismContext prismContext = ((MidPointApplication) Application.get()).getPrismContext();
try {
return prismContext.xmlSerializer().serializeAnyData(objectDeltaType, SchemaConstants.MODEL_EXTENSION_OBJECT_DELTA);
} catch (SchemaException e) {
throw new SystemException("Couldn't serialize delta: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.web.security.MidPointApplication in project midpoint by Evolveum.
the class TestDescriptorLoader method testDescriptorLoader.
@Test(enabled = false)
public void testDescriptorLoader() {
final String TEST_NAME = "testDescriptorLoader";
TestUtil.displayTestTile(TEST_NAME);
MidPointApplication midPointApplication = new MidPointApplication();
ServletContext mockServletContext = new ServletContext() {
@Override
public void setAttribute(String arg0, Object arg1) {
}
@Override
public void removeAttribute(String arg0) {
}
@Override
public void log(String msg, Throwable e) {
LOGGER.error("{}", msg, e);
}
@Override
public void log(Exception e, String msg) {
LOGGER.error("{}", msg, e);
}
@Override
public void log(String msg) {
LOGGER.trace("{}", msg);
}
@Override
public Enumeration getServlets() {
return null;
}
@Override
public Enumeration getServletNames() {
return null;
}
@Override
public String getServletContextName() {
return "mock";
}
@Override
public Servlet getServlet(String arg0) throws ServletException {
return null;
}
@Override
public String getServerInfo() {
return null;
}
@Override
public Set getResourcePaths(String arg0) {
return null;
}
@Override
public InputStream getResourceAsStream(String name) {
return this.getClass().getClassLoader().getResourceAsStream(name);
}
@Override
public URL getResource(String name) throws MalformedURLException {
return this.getClass().getClassLoader().getResource(name);
}
@Override
public RequestDispatcher getRequestDispatcher(String arg0) {
return null;
}
@Override
public String getRealPath(String arg0) {
return null;
}
@Override
public RequestDispatcher getNamedDispatcher(String arg0) {
return null;
}
@Override
public int getMinorVersion() {
return 2;
}
@Override
public String getMimeType(String arg0) {
return null;
}
@Override
public int getMajorVersion() {
return 4;
}
@Override
public Enumeration getInitParameterNames() {
return null;
}
@Override
public String getInitParameter(String arg0) {
return null;
}
@Override
public String getContextPath() {
return null;
}
@Override
public ServletContext getContext(String arg0) {
return this;
}
@Override
public Enumeration getAttributeNames() {
return null;
}
@Override
public Object getAttribute(String arg0) {
return null;
}
};
midPointApplication.setServletContext(mockServletContext);
DescriptorLoader descriptorLoader = new DescriptorLoader();
// TODO: this test does not really work. This needs to be cleaned up
// to make it testable
// WHEN
descriptorLoader.loadData(midPointApplication);
// THEN
display("initialized loader", descriptorLoader);
}
Aggregations