Search in sources :

Example 6 with ReportType

use of com.buschmais.jqassistant.core.plugin.schema.v1.ReportType 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 7 with ReportType

use of com.buschmais.jqassistant.core.plugin.schema.v1.ReportType in project midpoint by Evolveum.

the class PageCreatedReports method createSearchDto.

private ReportOutputSearchDto createSearchDto() {
    ReportOutputSearchDto dto = new ReportOutputSearchDto();
    Map<String, String> reportTypeMap = dto.getReportTypeMap();
    List<PrismObject<ReportType>> reportTypes = WebModelServiceUtils.searchObjects(ReportType.class, null, null, getPageBase());
    LOGGER.debug("Found {} report types.", reportTypes.size());
    for (PrismObject o : reportTypes) {
        ReportType reportType = (ReportType) o.asObjectable();
        if (reportType.isParent()) {
            String name = WebComponentUtil.getName(o);
            reportTypeMap.put(name, reportType.getOid());
        }
    }
    StringValue param = getPage().getPageParameters().get(OnePageParameterEncoder.PARAMETER);
    if (param != null) {
        for (String key : dto.getReportTypeMap().keySet()) {
            if (reportTypeMap.get(key).equals(param.toString())) {
                dto.setReportType(key);
            }
        }
    }
    return dto;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ReportOutputSearchDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportOutputSearchDto) StringValue(org.apache.wicket.util.string.StringValue) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)

Example 8 with ReportType

use of com.buschmais.jqassistant.core.plugin.schema.v1.ReportType in project midpoint by Evolveum.

the class ReportDto method getObject.

public PrismObject<ReportType> getObject() {
    if (reportType == null) {
        reportType = new ReportType();
        //TODO FIXME temporary every new report will be set as parent report
        reportType.setParent(Boolean.TRUE);
    }
    reportType.setName(new PolyStringType(name));
    reportType.setExport(exportType);
    reportType.setTemplate(jasperReportDto.getTemplate());
    reportType.setTemplateStyle(templateStyle);
    reportType.setDescription(description);
    reportType.setVirtualizer(virtualizer);
    reportType.setVirtualizerKickOn(virtualizerKickOn);
    reportType.setMaxPages(maxPages);
    reportType.setTimeout(timeout);
    return reportType.asPrismObject();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)

Example 9 with ReportType

use of com.buschmais.jqassistant.core.plugin.schema.v1.ReportType in project midpoint by Evolveum.

the class PageReport method onSavePerformed.

protected void onSavePerformed(AjaxRequestTarget target) {
    Task task = createSimpleTask(OPERATION_SAVE_REPORT);
    OperationResult result = task.getResult();
    try {
        //TODO TODO TODO
        PrismObject<ReportType> newReport = model.getObject().getObject();
        ObjectDelta<ReportType> delta = null;
        if (newReport.getOid() == null) {
            getPrismContext().adopt(newReport);
            delta = ObjectDelta.createAddDelta(newReport);
            delta.setPrismContext(getPrismContext());
        } else {
            PrismObject<ReportType> oldReport = WebModelServiceUtils.loadObject(ReportType.class, newReport.getOid(), this, task, result);
            if (oldReport != null) {
                delta = oldReport.diff(newReport);
            }
        }
        if (delta != null) {
            getPrismContext().adopt(delta);
            getModelService().executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task, result);
        }
    } catch (Exception e) {
        result.recordFatalError("Couldn't save report.", e);
    } finally {
        result.computeStatusIfUnknown();
    }
    if (WebComponentUtil.isSuccessOrHandledError(result)) {
        showResult(result);
        redirectBack();
    } else {
        showResult(result);
        target.add(getFeedbackPanel());
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ReportType(com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 10 with ReportType

use of com.buschmais.jqassistant.core.plugin.schema.v1.ReportType in project jqa-core-framework by buschmais.

the class ReportPluginRepositoryImpl method getReportPlugins.

private Map<String, ReportPlugin> getReportPlugins(List<JqassistantPlugin> plugins) throws PluginRepositoryException {
    Map<String, ReportPlugin> reportPlugins = new HashMap<>();
    for (JqassistantPlugin plugin : plugins) {
        ReportType reportType = plugin.getReport();
        if (reportType != null) {
            for (IdClassType classType : reportType.getClazz()) {
                ReportPlugin reportPlugin = createInstance(classType.getValue());
                if (reportPlugin != null) {
                    try {
                        reportPlugin.initialize();
                    } catch (ReportException e) {
                        throw new PluginRepositoryException("Cannot initialize report plugin " + reportPlugin, e);
                    }
                    String id = classType.getId();
                    if (id == null) {
                        id = reportPlugin.getClass().getSimpleName();
                    }
                    reportPlugins.put(id, reportPlugin);
                }
            }
        }
    }
    return reportPlugins;
}
Also used : IdClassType(com.buschmais.jqassistant.core.plugin.schema.v1.IdClassType) PluginRepositoryException(com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException) ReportPlugin(com.buschmais.jqassistant.core.report.api.ReportPlugin) HashMap(java.util.HashMap) JqassistantPlugin(com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin) ReportException(com.buschmais.jqassistant.core.report.api.ReportException) ReportType(com.buschmais.jqassistant.core.plugin.schema.v1.ReportType)

Aggregations

ReportType (com.evolveum.midpoint.xml.ns._public.common.common_3.ReportType)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 Task (com.evolveum.midpoint.task.api.Task)3 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 HashMap (java.util.HashMap)2 JasperReport (net.sf.jasperreports.engine.JasperReport)2 RestartResponseException (org.apache.wicket.RestartResponseException)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 StringValue (org.apache.wicket.util.string.StringValue)2 PluginRepositoryException (com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException)1 IdClassType (com.buschmais.jqassistant.core.plugin.schema.v1.IdClassType)1 JqassistantPlugin (com.buschmais.jqassistant.core.plugin.schema.v1.JqassistantPlugin)1 ReportType (com.buschmais.jqassistant.core.plugin.schema.v1.ReportType)1 ReportException (com.buschmais.jqassistant.core.report.api.ReportException)1 ReportPlugin (com.buschmais.jqassistant.core.report.api.ReportPlugin)1 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 Item (com.evolveum.midpoint.prism.Item)1 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)1