Search in sources :

Example 1 with ReportDto

use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.

the class RunReportPopupPanel method runConfirmPerformed.

//    private void addFormUpdatingBehavior(FormComponent parent, String id, final IModel<JasperReportParameterDto> model) {
//        Component c = parent.get(id);
//        if (c == null) {
//            return;
//        }
//        c.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
//    }
private void runConfirmPerformed(AjaxRequestTarget target, IModel<ReportDto> model) {
    ReportDto reportDto = model.getObject();
    PrismContainerDefinition<ReportParameterType> paramContainerDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByElementName(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
    PrismContainer<ReportParameterType> paramContainer;
    try {
        paramContainer = paramContainerDef.instantiate();
        ReportParameterType reportParam = new ReportParameterType();
        PrismContainerValue<ReportParameterType> reportParamValue = reportParam.asPrismContainerValue();
        reportParamValue.revive(getPrismContext());
        paramContainer.add(reportParamValue);
        List<JasperReportParameterDto> params = getParametersView().getModelObject();
        for (JasperReportParameterDto paramDto : params) {
            if (paramDto.getValue() == null) {
                continue;
            }
            List<JasperReportValueDto> values = paramDto.getValue();
            Class<?> paramClass = paramDto.getType();
            boolean multivalue = false;
            if (List.class.isAssignableFrom(paramClass)) {
                paramClass = paramDto.getNestedType();
                if (paramClass == null) {
                    getSession().error("Nested type for list must be defined!");
                    target.add(getPageBase().getFeedbackPanel());
                    return;
                }
            }
            QName typeName = getPrismContext().getSchemaRegistry().determineTypeForClass(paramClass);
            PrismPropertyDefinitionImpl<?> def = new PrismPropertyDefinitionImpl<>(new QName(ReportConstants.NS_EXTENSION, paramDto.getName()), typeName, getPrismContext());
            def.setDynamic(true);
            def.setRuntimeSchema(true);
            // TODO multivalue is always 'false' here ...
            def.setMaxOccurs(multivalue ? -1 : 1);
            PrismProperty prop = def.instantiate();
            for (JasperReportValueDto paramValue : values) {
                Object realValue = paramValue.getValue();
                if (realValue == null) {
                    continue;
                }
                if (AuditEventType.class.isAssignableFrom(paramClass)) {
                    paramClass = AuditEventTypeType.class;
                    realValue = AuditEventType.fromAuditEventType((AuditEventType) realValue);
                } else if (AuditEventStage.class.isAssignableFrom(paramClass)) {
                    paramClass = AuditEventStageType.class;
                    realValue = AuditEventStage.fromAuditEventStage((AuditEventStage) realValue);
                }
                prop.addRealValue(realValue);
            }
            if (!prop.isEmpty()) {
                reportParamValue.add(prop);
            }
        }
    } catch (SchemaException | ClassNotFoundException e) {
        OperationResult result = new OperationResult("Parameters serialization");
        result.recordFatalError("Could not serialize parameters");
        getPageBase().showResult(result);
        return;
    }
    runConfirmPerformed(target, reportDto.getObject().asObjectable(), paramContainer);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) QName(javax.xml.namespace.QName) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) ReportDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) JasperReportParameterDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterDto) JasperReportValueDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportValueDto) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismObject(com.evolveum.midpoint.prism.PrismObject) AuditEventStageType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType)

Example 2 with ReportDto

use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.

the class PageReport method loadReport.

private ReportDto loadReport() {
    StringValue reportOid = getPageParameters().get(OnePageParameterEncoder.PARAMETER);
    Task task = createSimpleTask(OPERATION_LOAD_REPORT);
    OperationResult result = task.getResult();
    PrismObject<ReportType> prismReport = WebModelServiceUtils.loadObject(ReportType.class, reportOid.toString(), this, task, result);
    if (prismReport == null) {
        LOGGER.error("Couldn't load report.");
        throw new RestartResponseException(PageReports.class);
    }
    return new ReportDto(prismReport.asObjectable());
//        return prismReport;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) ReportDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) StringValue(org.apache.wicket.util.string.StringValue) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)

Example 3 with ReportDto

use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.

the class JasperReportConfigurationPanel method addParameterPerformed.

private void addParameterPerformed(AjaxRequestTarget target) {
    ReportDto dto = getModel().getObject();
    JasperReportParameterDto parameter = new JasperReportParameterDto();
    parameter.setEditing(true);
    dto.getJasperReportDto().getParameters().add(parameter);
    BoxedTablePanel<JasperReportParameterDto> parametersTable = getParametersTable();
    adjustParametersTablePage(parametersTable, dto);
    target.add(getParametersTable());
}
Also used : ReportDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto) JasperReportParameterDto(com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterDto)

Example 4 with ReportDto

use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto in project midpoint by Evolveum.

the class PageNewReport method importReportFromStreamPerformed.

private void importReportFromStreamPerformed(AjaxRequestTarget target) {
    String xml = xmlEditorModel.getObject();
    if (StringUtils.isEmpty(xml)) {
        error(getString("PageNewReport.message.emptyXml"));
        target.add(getFeedbackPanel());
        return;
    }
    OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT_XML);
    InputStream stream = null;
    try {
        setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(xml.getBytes()))));
    } catch (Exception ex) {
        result.recordFatalError("Couldn't import object.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Error occured during xml import", ex);
    } finally {
        if (stream != null) {
            IOUtils.closeQuietly(stream);
        }
    }
    if (result.isSuccess()) {
        xmlEditorModel.setObject(null);
    }
    showResult(result);
    target.add(getFeedbackPanel());
}
Also used : 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)

Example 5 with ReportDto

use of com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto 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)

Aggregations

ReportDto (com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 JasperReportParameterDto (com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterDto)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)1 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)1 Task (com.evolveum.midpoint.task.api.Task)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 JasperReportFieldDto (com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportFieldDto)1 JasperReportValueDto (com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportValueDto)1 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)1 WebApplicationConfiguration (com.evolveum.midpoint.web.security.WebApplicationConfiguration)1 AuditEventStageType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType)1 ReportParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType)1 ReportType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)1