use of org.activityinfo.server.database.hibernate.entity.ReportDefinition in project activityinfo by bedatadriven.
the class GetReportModelHandler method execute.
@Override
public void execute(final GetReportModel cmd, final ExecutionContext context, final AsyncCallback<ReportDTO> callback) {
LOGGER.finest("Loading model for report id = " + cmd.getReportId());
Preconditions.checkNotNull(cmd.getReportId());
ReportDTO cachedReport = (ReportDTO) memcacheService.get(cmd);
if (cachedReport != null) {
callback.onSuccess(cachedReport);
return;
}
// always load report
ReportDefinition entity = em.find(ReportDefinition.class, cmd.getReportId());
Report report = parseReport(entity).setId(cmd.getReportId());
ReportDTO reportDTO = new ReportDTO(report);
if (cmd.isLoadMetadata()) {
loadMetadataAndCallback(cmd, context, reportDTO, callback);
} else {
// report object without metadata
memcache(cmd, reportDTO);
callback.onSuccess(reportDTO);
}
}
use of org.activityinfo.server.database.hibernate.entity.ReportDefinition in project activityinfo by bedatadriven.
the class ReportMailerTest method testEmail.
private void testEmail(String locale) {
User user = new User();
user.setEmail("akbertram@gmail.com");
user.setName("alex");
user.setLocale(locale);
ReportSubscription sub = new ReportSubscription();
sub.setTemplate(new ReportDefinition());
sub.getTemplate().setId(5040);
sub.setUser(user);
sub.setEmailDelivery(EmailDelivery.WEEKLY);
sub.setEmailDay(1);
Report report = new Report();
report.setTitle("Rapport RRM Mensuelle");
String text = ReportMailerHelper.composeTextEmail(sub, report);
System.out.println(text);
Assert.assertTrue("user name is present", text.contains(user.getName()));
Assert.assertTrue("link is correct without comma", text.contains("#report/5040"));
}
use of org.activityinfo.server.database.hibernate.entity.ReportDefinition in project activityinfo by bedatadriven.
the class CreateReportHandler method execute.
@Override
public CommandResult execute(CreateReport cmd, User user) {
// verify that the XML is valid
try {
ReportDefinition reportDef = new ReportDefinition();
String xml = ReportParserJaxb.createXML(cmd.getReport());
reportDef.setXml(xml);
if (cmd.getDatabaseId() != null) {
reportDef.setDatabase(em.getReference(Database.class, cmd.getDatabaseId()));
}
reportDef.setTitle(cmd.getReport().getTitle());
reportDef.setDescription(cmd.getReport().getDescription());
reportDef.setOwner(user);
reportDef.setVisibility(1);
em.persist(reportDef);
return new CreateResult(reportDef.getId());
} catch (JAXBException e) {
throw new ParseException(e.getMessage());
}
}
use of org.activityinfo.server.database.hibernate.entity.ReportDefinition 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");
}
// Invalidate the cache BEFORE attempting to update the database,
// otherwise, we will leave the system in an inconsistent state if
// the database update succeeds, but the memcache delete fails.
invalidateMemcache(cmd.getModel().getId());
// Now that we're sure that the memcache is clear of the old copy,
// we can safely update the underlying persistant datastore
result.setTitle(cmd.getModel().getTitle());
try {
result.setXml(ReportParserJaxb.createXML(cmd.getModel()));
} catch (JAXBException e) {
throw new UnexpectedCommandException(e);
}
em.persist(result);
return null;
}
Aggregations