Search in sources :

Example 6 with MidPointApplication

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);
    }
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) PrismContext(com.evolveum.midpoint.prism.PrismContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 7 with MidPointApplication

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;
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) RestartResponseException(org.apache.wicket.RestartResponseException) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PageBase(com.evolveum.midpoint.gui.api.page.PageBase) File(org.apache.wicket.util.file.File) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 8 with MidPointApplication

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ReportDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) FileInputStream(java.io.FileInputStream) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) File(org.apache.wicket.util.file.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 9 with MidPointApplication

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);
    }
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) PrismContext(com.evolveum.midpoint.prism.PrismContext)

Example 10 with MidPointApplication

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);
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ServletContext(javax.servlet.ServletContext) MalformedURLException(java.net.MalformedURLException) ServletException(javax.servlet.ServletException) DescriptorLoader(com.evolveum.midpoint.web.application.DescriptorLoader) Test(org.testng.annotations.Test)

Aggregations

MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)10 PrismContext (com.evolveum.midpoint.prism.PrismContext)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 WebApplicationConfiguration (com.evolveum.midpoint.web.security.WebApplicationConfiguration)3 File (org.apache.wicket.util.file.File)3 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 FileUpload (org.apache.wicket.markup.html.form.upload.FileUpload)2 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 Task (com.evolveum.midpoint.task.api.Task)1 DescriptorLoader (com.evolveum.midpoint.web.application.DescriptorLoader)1 AjaxDownloadBehaviorFromFile (com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile)1 ObjectViewDto (com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto)1 ReportDto (com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto)1