Search in sources :

Example 1 with UnexpectedCommandException

use of org.activityinfo.shared.exception.UnexpectedCommandException in project activityinfo by bedatadriven.

the class GetReportModelHandler method execute.

@Override
public void execute(final GetReportModel cmd, final ExecutionContext context, final AsyncCallback<ReportDTO> callback) {
    ReportDTO reportDTO = null;
    Integer reportId = cmd.getReportId();
    LOGGER.finest("Loading model for report id = " + reportId);
    if (reportId != null) {
        // always load report
        ReportDefinition entity = em.find(ReportDefinition.class, reportId);
        Report report = new Report();
        try {
            LOGGER.finest("Starting to parse xml (size = " + entity.getXml().length() + ")");
            report = ReportParserJaxb.parseXml(entity.getXml());
            LOGGER.finest("Parsing complete");
        } catch (JAXBException e) {
            throw new UnexpectedCommandException(e);
        }
        report.setId(reportId);
        reportDTO = new ReportDTO(report);
        if (cmd.isLoadMetadata()) {
            // load metadata if specified
            loadMetadata(reportId, context, reportDTO, callback);
        } else {
            // exit handler with only the report object filled
            callback.onSuccess(reportDTO);
        }
    }
}
Also used : Report(org.activityinfo.shared.report.model.Report) UnexpectedCommandException(org.activityinfo.shared.exception.UnexpectedCommandException) JAXBException(javax.xml.bind.JAXBException) ReportDTO(org.activityinfo.shared.dto.ReportDTO) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 2 with UnexpectedCommandException

use of org.activityinfo.shared.exception.UnexpectedCommandException in project activityinfo by bedatadriven.

the class UpdateReportModelHandler method execute.

@Override
public CommandResult execute(final UpdateReportModel cmd, final User user) throws CommandException {
    Query query = em.createQuery("select r from ReportDefinition r where r.id in (:id)").setParameter("id", cmd.getModel().getId());
    ReportDefinition result = (ReportDefinition) query.getSingleResult();
    if (result.getOwner().getId() != user.getId()) {
        throw new IllegalAccessCommandException("Current user does not have the right to edit this report");
    }
    result.setTitle(cmd.getModel().getTitle());
    // result.setJson(cmd.getReportJsonModel());
    try {
        result.setXml(ReportParserJaxb.createXML(cmd.getModel()));
    } catch (JAXBException e) {
        throw new UnexpectedCommandException(e);
    }
    em.persist(result);
    return null;
}
Also used : Query(javax.persistence.Query) IllegalAccessCommandException(org.activityinfo.shared.exception.IllegalAccessCommandException) UnexpectedCommandException(org.activityinfo.shared.exception.UnexpectedCommandException) JAXBException(javax.xml.bind.JAXBException) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Aggregations

JAXBException (javax.xml.bind.JAXBException)2 ReportDefinition (org.activityinfo.server.database.hibernate.entity.ReportDefinition)2 UnexpectedCommandException (org.activityinfo.shared.exception.UnexpectedCommandException)2 Query (javax.persistence.Query)1 ReportDTO (org.activityinfo.shared.dto.ReportDTO)1 IllegalAccessCommandException (org.activityinfo.shared.exception.IllegalAccessCommandException)1 Report (org.activityinfo.shared.report.model.Report)1