Search in sources :

Example 1 with ReportDefinition

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);
    }
}
Also used : Report(org.activityinfo.legacy.shared.reports.model.Report) ReportDTO(org.activityinfo.legacy.shared.model.ReportDTO) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 2 with ReportDefinition

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"));
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) Report(org.activityinfo.legacy.shared.reports.model.Report) ReportSubscription(org.activityinfo.server.database.hibernate.entity.ReportSubscription) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 3 with ReportDefinition

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());
    }
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) JAXBException(javax.xml.bind.JAXBException) Database(org.activityinfo.server.database.hibernate.entity.Database) ParseException(org.activityinfo.legacy.shared.exception.ParseException) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Example 4 with ReportDefinition

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;
}
Also used : Query(javax.persistence.Query) IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException) UnexpectedCommandException(org.activityinfo.legacy.shared.exception.UnexpectedCommandException) JAXBException(javax.xml.bind.JAXBException) ReportDefinition(org.activityinfo.server.database.hibernate.entity.ReportDefinition)

Aggregations

ReportDefinition (org.activityinfo.server.database.hibernate.entity.ReportDefinition)4 JAXBException (javax.xml.bind.JAXBException)2 Report (org.activityinfo.legacy.shared.reports.model.Report)2 Query (javax.persistence.Query)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)1 ParseException (org.activityinfo.legacy.shared.exception.ParseException)1 UnexpectedCommandException (org.activityinfo.legacy.shared.exception.UnexpectedCommandException)1 ReportDTO (org.activityinfo.legacy.shared.model.ReportDTO)1 Database (org.activityinfo.server.database.hibernate.entity.Database)1 ReportSubscription (org.activityinfo.server.database.hibernate.entity.ReportSubscription)1 User (org.activityinfo.server.database.hibernate.entity.User)1