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);
}
}
}
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;
}
Aggregations