Package org.apache.syncope.core.persistence.beans

Examples of org.apache.syncope.core.persistence.beans.ReportExec


        reportTO.setId(report.getId());
        BeanUtils.copyProperties(report, reportTO, IGNORE_REPORT_PROPERTIES);

        copyReportletConfs(report, reportTO);

        ReportExec latestExec = reportExecDAO.findLatestStarted(report);
        reportTO.setLatestExecStatus(latestExec == null
                ? ""
                : latestExec.getStatus());

        reportTO.setStartDate(latestExec == null
                ? null
                : latestExec.getStartDate());

        reportTO.setEndDate(latestExec == null
                ? null
                : latestExec.getEndDate());

        for (ReportExec reportExec : report.getExecs()) {
            reportTO.addExecution(getReportExecTO(reportExec));
        }
View Full Code Here


        return entityManager.merge(execution);
    }

    @Override
    public void delete(final Long id) {
        ReportExec execution = find(id);
        if (execution == null) {
            return;
        }

        delete(execution);
View Full Code Here

    }

    @Override
    public Response exportExecutionResult(final Long executionId, final ReportExecExportFormat fmt) {
        final ReportExecExportFormat format = (fmt == null) ? ReportExecExportFormat.XML : fmt;
        final ReportExec reportExec = reportController.getAndCheckReportExecInternal(executionId);
        StreamingOutput sout = new StreamingOutput() {

            @Override
            public void write(final OutputStream os) throws IOException {
                reportController.exportExecutionResultInternal(os, reportExec, format);
            }
        };
        String disposition = "attachment; filename=" + reportExec.getReport().getName() + "." + format.name().
                toLowerCase();
        return Response.ok(sout)
                .header(SyncopeConstants.CONTENT_DISPOSITION_HEADER, disposition)
                .build();
    }
View Full Code Here

    public void save() {
        Report report = reportDAO.find(1L);
        assertNotNull(report);
        assertEquals(1, report.getExecs().size());

        ReportExec reportExec = new ReportExec();
        reportExec.setReport(report);
        reportExec.setStartDate(new Date());
        reportExec.setEndDate(new Date());
        reportExec.setStatus(ReportExecStatus.SUCCESS);

        report.addExec(reportExec);

        reportExec = reportExecDAO.save(reportExec);
        assertNotNull(reportExec);
        assertNotNull(reportExec.getId());

        reportExecDAO.flush();

        report = reportDAO.find(1L);
        assertNotNull(report);
View Full Code Here

        assertNull(reportExecDAO.find(1L));
    }

    @Test
    public void deleteReportExecution() {
        ReportExec execution = reportExecDAO.find(1L);
        int executionNumber = execution.getReport().getExecs().size();

        reportExecDAO.delete(1L);

        reportExecDAO.flush();
View Full Code Here

        if (report == null) {
            throw new JobExecutionException("Report " + reportId + " not found");
        }

        // 1. create execution
        ReportExec execution = new ReportExec();
        execution.setStatus(ReportExecStatus.STARTED);
        execution.setStartDate(new Date());
        execution.setReport(report);
        execution = reportExecDAO.save(execution);

        report.addExec(execution);
        report = reportDAO.save(report);

        // 2. define a SAX handler for generating result as XML
        TransformerHandler handler;

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(baos);
        zos.setLevel(Deflater.BEST_COMPRESSION);
        try {
            SAXTransformerFactory tFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
            handler = tFactory.newTransformerHandler();
            Transformer serializer = handler.getTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, SyncopeConstants.DEFAULT_ENCODING);
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");

            // a single ZipEntry in the ZipOutputStream
            zos.putNextEntry(new ZipEntry(report.getName()));

            // streaming SAX handler in a compressed byte array stream
            handler.setResult(new StreamResult(zos));
        } catch (Exception e) {
            throw new JobExecutionException("While configuring for SAX generation", e, true);
        }

        execution.setStatus(ReportExecStatus.RUNNING);
        execution = reportExecDAO.save(execution);

        // 3. actual report execution
        StringBuilder reportExecutionMessage = new StringBuilder();
        StringWriter exceptionWriter = new StringWriter();
        try {
            // report header
            handler.startDocument();
            AttributesImpl atts = new AttributesImpl();
            atts.addAttribute("", "", ATTR_NAME, XSD_STRING, report.getName());
            handler.startElement("", "", ELEMENT_REPORT, atts);

            // iterate over reportlet instances defined for this report
            for (ReportletConf reportletConf : report.getReportletConfs()) {
                Class<Reportlet> reportletClass =
                        dataBinder.findReportletClassHavingConfClass(reportletConf.getClass());
                if (reportletClass != null) {
                    Reportlet autowired = (Reportlet) ApplicationContextProvider.getBeanFactory().
                            createBean(reportletClass, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
                    autowired.setConf(reportletConf);

                    // invoke reportlet
                    try {
                        autowired.extract(handler);
                    } catch (Exception e) {
                        execution.setStatus(ReportExecStatus.FAILURE);

                        Throwable t = e instanceof ReportException
                                ? e.getCause()
                                : e;
                        exceptionWriter.write(t.getMessage() + "\n\n");
                        t.printStackTrace(new PrintWriter(exceptionWriter));
                        reportExecutionMessage.append(exceptionWriter.toString()).append("\n==================\n");
                    }
                }
            }

            // report footer
            handler.endElement("", "", ELEMENT_REPORT);
            handler.endDocument();

            if (!ReportExecStatus.FAILURE.name().equals(execution.getStatus())) {
                execution.setStatus(ReportExecStatus.SUCCESS);
            }
        } catch (Exception e) {
            execution.setStatus(ReportExecStatus.FAILURE);

            exceptionWriter.write(e.getMessage() + "\n\n");
            e.printStackTrace(new PrintWriter(exceptionWriter));
            reportExecutionMessage.append(exceptionWriter.toString());

            throw new JobExecutionException(e, true);
        } finally {
            try {
                zos.closeEntry();
                zos.close();
                baos.close();
            } catch (IOException e) {
                LOG.error("While closing StreamResult's backend", e);
            }

            execution.setExecResult(baos.toByteArray());
            execution.setMessage(reportExecutionMessage.toString());
            execution.setEndDate(new Date());
            reportExecDAO.save(execution);
        }
    }
View Full Code Here

    @PreAuthorize("hasRole('REPORT_READ')")
    @RequestMapping(method = RequestMethod.GET, value = "/execution/read/{executionId}")
    @Transactional(readOnly = true)
    public ReportExecTO readExecution(@PathVariable("executionId") final Long executionId) {
        ReportExec reportExec = reportExecDAO.find(executionId);
        if (reportExec == null) {
            throw new NotFoundException("Report execution " + executionId);
        }

        auditManager.audit(Category.report, ReportSubCategory.readExecution, Result.success,
                "Successfully read report execution: " + reportExec.getId());

        return binder.getReportExecTO(reportExec);
    }
View Full Code Here

        try {
            os = response.getOutputStream();
        } catch (IOException e) {
            throw new IllegalStateException("Could not get output stream", e);
        }
        ReportExec reportExec = getAndCheckReportExecInternal(executionId);

        ReportExecExportFormat format = (fmt == null) ? ReportExecExportFormat.XML : fmt;

        response.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        response.addHeader(SyncopeConstants.CONTENT_DISPOSITION_HEADER,
                "attachment; filename=" + reportExec.getReport().getName() + "." + format.name().toLowerCase());

        exportExecutionResultInternal(os, reportExec, format);
    }
View Full Code Here

                "Successfully exported report execution: " + reportExec.getId());
    }

    @PreAuthorize("hasRole('REPORT_READ')")
    public ReportExec getAndCheckReportExecInternal(final Long executionId) {
        ReportExec reportExec = reportExecDAO.find(executionId);
        if (reportExec == null) {
            throw new NotFoundException("Report execution " + executionId);
        }
        if (!ReportExecStatus.SUCCESS.name().equals(reportExec.getStatus()) || reportExec.getExecResult() == null) {
            SyncopeClientCompositeErrorException sccee =
                    new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
            SyncopeClientException sce = new SyncopeClientException(SyncopeClientExceptionType.InvalidReportExec);
            sce.addElement(reportExec.getExecResult() == null
                    ? "No report data produced"
                    : "Report did not run successfully");
            sccee.addException(sce);
            throw sccee;
        }
View Full Code Here

    }

    @PreAuthorize("hasRole('REPORT_DELETE')")
    @RequestMapping(method = RequestMethod.GET, value = "/execution/delete/{executionId}")
    public ReportExecTO deleteExecution(@PathVariable("executionId") final Long executionId) {
        ReportExec reportExec = reportExecDAO.find(executionId);
        if (reportExec == null) {
            throw new NotFoundException("Report execution " + executionId);
        }

        ReportExecTO reportExecToDelete = binder.getReportExecTO(reportExec);

        reportExecDAO.delete(reportExec);

        auditManager.audit(Category.report, ReportSubCategory.deleteExecution, Result.success,
                "Successfully deleted report execution: " + reportExec.getId());

        return reportExecToDelete;
    }
View Full Code Here

TOP

Related Classes of org.apache.syncope.core.persistence.beans.ReportExec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.