Search in sources :

Example 1 with ReportParameterType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType in project midpoint by Evolveum.

the class ReportCreateHandlerDto method getReportParams.

public String getReportParams() {
    PrismObject<TaskType> taskObject = taskDto.getTaskType().asPrismObject();
    PrismContainer<ReportParameterType> container = taskObject.findContainer(new ItemPath(TaskType.F_EXTENSION, ReportConstants.REPORT_PARAMS_PROPERTY_NAME));
    if (container == null || container.isEmpty()) {
        return null;
    }
    PrismContainerValue<ReportParameterType> pcv = container.getValue();
    PrismContext prismContext = ((MidPointApplication) Application.get()).getPrismContext();
    try {
        return WebXmlUtil.stripNamespaceDeclarations(prismContext.xmlSerializer().serialize(pcv, ReportConstants.REPORT_PARAMS_PROPERTY_NAME));
    } catch (SchemaException e) {
        throw new SystemException("Couldn't serialize report parameters: " + e.getMessage(), e);
    }
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismContext(com.evolveum.midpoint.prism.PrismContext) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with ReportParameterType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType in project midpoint by Evolveum.

the class PageReports method runReportPerformed.

protected void runReportPerformed(AjaxRequestTarget target, ReportType report) {
    RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(getMainPopupBodyId(), report) {

        private static final long serialVersionUID = 1L;

        protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType, PrismContainer<ReportParameterType> reportParam) {
            OperationResult result = new OperationResult(OPERATION_RUN_REPORT);
            try {
                Task task = createSimpleTask(OPERATION_RUN_REPORT);
                getReportManager().runReport(reportType.asPrismObject(), reportParam, task, result);
            } catch (Exception ex) {
                result.recordFatalError(ex);
            } finally {
                result.computeStatusIfUnknown();
            }
            showResult(result);
            target.add(getFeedbackPanel(), get(createComponentPath(ID_MAIN_FORM)));
            hideMainPopup(target);
        }

        ;
    };
    showMainPopup(runReportPopupPanel, target);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Task(com.evolveum.midpoint.task.api.Task) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RunReportPopupPanel(com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)

Example 3 with ReportParameterType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType 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 4 with ReportParameterType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType in project midpoint by Evolveum.

the class ReportCreateTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    // TODO Auto-generated method stub
    OperationResult parentResult = task.getResult();
    OperationResult result = parentResult.createSubresult(ReportCreateTaskHandler.class.getSimpleName() + ".run");
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(result);
    recordProgress(task, 0, result);
    long progress = task.getProgress();
    JRSwapFile swapFile = null;
    // http://community.jaspersoft.com/wiki/virtualizers-jasperreports
    JRAbstractLRUVirtualizer virtualizer = null;
    try {
        ReportType parentReport = objectResolver.resolve(task.getObjectRef(), ReportType.class, null, "resolving report", task, result);
        Map<String, Object> parameters = completeReport(parentReport, task, result);
        JasperReport jasperReport = ReportTypeUtil.loadJasperReport(parentReport);
        LOGGER.trace("compile jasper design, create jasper report : {}", jasperReport);
        PrismContainer<ReportParameterType> reportParams = (PrismContainer) task.getExtensionItem(ReportConstants.REPORT_PARAMS_PROPERTY_NAME);
        if (reportParams != null) {
            PrismContainerValue<ReportParameterType> reportParamsValues = reportParams.getValue();
            List<Item<?, ?>> items = reportParamsValues.getItems();
            if (items != null) {
                for (Item item : items) {
                    PrismProperty pp = (PrismProperty) item;
                    String paramName = ItemPath.getName(pp.getPath().lastNamed()).getLocalPart();
                    Object value = null;
                    if (isSingleValue(paramName, jasperReport.getParameters())) {
                        value = pp.getRealValues().iterator().next();
                    } else {
                        value = pp.getRealValues();
                    }
                    parameters.put(paramName, value);
                }
            }
        }
        String virtualizerS = parentReport.getVirtualizer();
        Integer virtualizerKickOn = parentReport.getVirtualizerKickOn();
        Integer maxPages = parentReport.getMaxPages();
        Integer timeout = parentReport.getTimeout();
        if (maxPages != null && maxPages > 0) {
            LOGGER.trace("Setting hardlimit on number of report pages: " + maxPages);
            jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString());
            jasperReport.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(maxPages));
        }
        if (timeout != null && timeout > 0) {
            LOGGER.trace("Setting timeout on report execution [ms]: " + timeout);
            jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, Boolean.TRUE.toString());
            jasperReport.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT, String.valueOf(timeout));
        }
        if (virtualizerS != null && virtualizerKickOn != null && virtualizerKickOn > 0) {
            String virtualizerClassName = JASPER_VIRTUALIZER_PKG + "." + virtualizerS;
            try {
                Class<?> clazz = Class.forName(virtualizerClassName);
                if (clazz.equals(JRSwapFileVirtualizer.class)) {
                    swapFile = new JRSwapFile(TEMP_DIR, 4096, 200);
                    virtualizer = new JRSwapFileVirtualizer(virtualizerKickOn, swapFile);
                } else if (clazz.equals(JRGzipVirtualizer.class)) {
                    virtualizer = new JRGzipVirtualizer(virtualizerKickOn);
                } else if (clazz.equals(JRFileVirtualizer.class)) {
                    virtualizer = new JRFileVirtualizer(virtualizerKickOn, TEMP_DIR);
                } else {
                    throw new ClassNotFoundException("No support for virtualizer class: " + clazz.getName());
                }
                LOGGER.trace("Setting explicit Jasper virtualizer: " + virtualizer);
                virtualizer.setReadOnly(false);
                parameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
            } catch (ClassNotFoundException e) {
                LOGGER.error("Cannot find Jasper virtualizer: " + e.getMessage());
            }
        }
        LOGGER.trace("All Report parameters : {}", parameters);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
        LOGGER.trace("fill report : {}", jasperPrint);
        String reportFilePath = generateReport(parentReport, jasperPrint);
        LOGGER.trace("generate report : {}", reportFilePath);
        saveReportOutputType(reportFilePath, parentReport, task, result);
        LOGGER.trace("create report output type : {}", reportFilePath);
        result.computeStatus();
    } catch (Exception ex) {
        LOGGER.error("CreateReport: {}", ex.getMessage(), ex);
        result.recordFatalError(ex.getMessage(), ex);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    } finally {
        if (swapFile != null) {
            swapFile.dispose();
        }
        if (virtualizer != null) {
            virtualizer.cleanup();
        }
    }
    // This "run" is finished. But the task goes on ...
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    runResult.setProgress(progress);
    LOGGER.trace("CreateReportTaskHandler.run stopping");
    return runResult;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) JasperReport(net.sf.jasperreports.engine.JasperReport) Item(com.evolveum.midpoint.prism.Item) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) JRFileVirtualizer(net.sf.jasperreports.engine.fill.JRFileVirtualizer) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) JRSwapFileVirtualizer(net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRSwapFile(net.sf.jasperreports.engine.util.JRSwapFile) JRAbstractLRUVirtualizer(net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer) JRGzipVirtualizer(net.sf.jasperreports.engine.fill.JRGzipVirtualizer) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) JRException(net.sf.jasperreports.engine.JRException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 5 with ReportParameterType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType in project midpoint by Evolveum.

the class ReportWebService method getParamsMap.

private Map<QName, Object> getParamsMap(RemoteReportParametersType parametersType) throws SchemaException {
    prismContext.adopt(parametersType);
    Map<QName, Object> parametersMap = new HashMap<>();
    if (parametersType == null || parametersType.getRemoteParameter() == null || parametersType.getRemoteParameter().isEmpty()) {
        return parametersMap;
    }
    List<RemoteReportParameterType> items = parametersType.getRemoteParameter();
    for (RemoteReportParameterType item : items) {
        QName paramName = new QName(SchemaConstants.NS_REPORT, item.getParameterName());
        ReportParameterType param = item.getParameterValue();
        if (param == null) {
            parametersMap.put(paramName, null);
            continue;
        }
        if (param.getAny().size() == 1) {
            parametersMap.put(paramName, param.getAny().get(0));
        } else {
            parametersMap.put(paramName, param.getAny());
        }
    }
    return parametersMap;
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) RemoteReportParameterType(com.evolveum.midpoint.xml.ns._public.report.report_3.RemoteReportParameterType) ReportParameterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType) RemoteReportParameterType(com.evolveum.midpoint.xml.ns._public.report.report_3.RemoteReportParameterType) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Aggregations

ReportParameterType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportParameterType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ReportType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)2 QName (javax.xml.namespace.QName)2 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)1 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)1 Item (com.evolveum.midpoint.prism.Item)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 Task (com.evolveum.midpoint.task.api.Task)1 TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 RunReportPopupPanel (com.evolveum.midpoint.web.page.admin.reports.component.RunReportPopupPanel)1 JasperReportParameterDto (com.evolveum.midpoint.web.page.admin.reports.dto.JasperReportParameterDto)1