Search in sources :

Example 1 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportWorkItem method queueReport.

public static void queueReport(String host, int port, ReportVO report) {
    LOG.debug("Queuing report with id " + report.getId());
    // Verify that the user is not disabled.
    User user = UserDao.instance.getUser(report.getUserId());
    if (user.isDisabled())
        return;
    // User is ok. Continue...
    ReportWorkItem item = new ReportWorkItem(host, port);
    // Create the database record in process.
    item.reportConfig = report;
    ReportInstance reportInstance = new ReportInstance(report);
    item.user = user;
    item.reportDao = ReportDao.instance;
    item.reportDao.saveReportInstance(reportInstance);
    // Start the report work item out of process.
    item.reportInstance = reportInstance;
    Common.backgroundProcessing.addWorkItem(item);
    LOG.debug("Queued report with id " + report.getId() + ", instance id " + reportInstance.getId());
}
Also used : User(com.serotonin.m2m2.vo.User) ReportInstance(com.serotonin.m2m2.reports.vo.ReportInstance)

Example 2 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportsDwr method saveReport.

@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult saveReport(int id, String name, String xid, List<ReportPointVO> points, String template, int includeEvents, boolean includeUserComments, int dateRangeType, int relativeDateType, int previousPeriodCount, int previousPeriodType, int pastPeriodCount, int pastPeriodType, boolean fromNone, int fromYear, int fromMonth, int fromDay, int fromHour, int fromMinute, boolean toNone, int toYear, int toMonth, int toDay, int toHour, int toMinute, boolean schedule, int schedulePeriod, int runDelayMinutes, String scheduleCron, boolean email, boolean includeData, boolean zipData, List<RecipientListEntryBean> recipients) {
    ProcessResult response = new ProcessResult();
    // Basic validation
    validateData(response, name, points, dateRangeType, relativeDateType, previousPeriodCount, pastPeriodCount);
    // Validate XID
    if (StringUtils.isBlank(xid))
        response.addContextualMessage("xid", "validate.required");
    else if (StringValidation.isLengthGreaterThan(xid, 50))
        response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
    else if (!ReportDao.instance.isXidUnique(xid, id))
        response.addContextualMessage("xid", "validate.xidUsed");
    if (schedule) {
        if (schedulePeriod == ReportVO.SCHEDULE_CRON) {
            // Check the cron pattern.
            try {
                new CronTimerTrigger(scheduleCron);
            } catch (Exception e) {
                response.addContextualMessage("scheduleCron", "reports.validate.cron", e.getMessage());
            }
        } else {
            if (runDelayMinutes < 0)
                response.addContextualMessage("runDelayMinutes", "reports.validate.lessThan0");
            else if (runDelayMinutes > 59)
                response.addContextualMessage("runDelayMinutes", "reports.validate.greaterThan59");
        }
    }
    if (email && recipients.isEmpty())
        response.addContextualMessage("recipients", "reports.validate.needRecip");
    if (response.getHasMessages())
        return response;
    User user = Common.getUser();
    ReportDao reportDao = ReportDao.instance;
    ReportVO report;
    if (id == Common.NEW_ID) {
        report = new ReportVO();
        report.setUserId(user.getId());
    } else
        report = reportDao.getReport(id);
    ReportCommon.ensureReportPermission(user, report);
    // Update the new values.
    report.setXid(xid);
    report.setName(name);
    report.setPoints(points);
    report.setTemplate(template);
    report.setIncludeEvents(includeEvents);
    report.setIncludeUserComments(includeUserComments);
    report.setDateRangeType(dateRangeType);
    report.setRelativeDateType(relativeDateType);
    report.setPreviousPeriodCount(previousPeriodCount);
    report.setPreviousPeriodType(previousPeriodType);
    report.setPastPeriodCount(pastPeriodCount);
    report.setPastPeriodType(pastPeriodType);
    report.setFromNone(fromNone);
    report.setFromYear(fromYear);
    report.setFromMonth(fromMonth);
    report.setFromDay(fromDay);
    report.setFromHour(fromHour);
    report.setFromMinute(fromMinute);
    report.setToNone(toNone);
    report.setToYear(toYear);
    report.setToMonth(toMonth);
    report.setToDay(toDay);
    report.setToHour(toHour);
    report.setToMinute(toMinute);
    report.setSchedule(schedule);
    report.setSchedulePeriod(schedulePeriod);
    report.setRunDelayMinutes(runDelayMinutes);
    report.setScheduleCron(scheduleCron);
    report.setEmail(email);
    report.setIncludeData(includeData);
    report.setZipData(zipData);
    report.setRecipients(recipients);
    // Save the report
    reportDao.saveReport(report);
    // Conditionally schedule the report.
    String host = "";
    WebContext webContext = WebContextFactory.get();
    int port;
    if (webContext != null) {
        HttpServletRequest req = webContext.getHttpServletRequest();
        host = req.getServerName();
        port = req.getLocalPort();
    } else {
        port = Common.envProps.getInt("web.port", 8080);
    }
    ReportJob.scheduleReportJob(host, port, report);
    // Send back the report id in case this was new.
    response.addData("reportId", report.getId());
    response.addData("report", report);
    return response;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.serotonin.m2m2.vo.User) WebContext(org.directwebremoting.WebContext) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) CronTimerTrigger(com.serotonin.timer.CronTimerTrigger) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) ReportDao(com.serotonin.m2m2.reports.ReportDao) InvalidArgumentException(com.serotonin.InvalidArgumentException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportsDwr method deleteReport.

@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public void deleteReport(int id) {
    ReportDao reportDao = ReportDao.instance;
    ReportVO report = reportDao.getReport(id);
    if (report != null) {
        ReportCommon.ensureReportPermission(Common.getUser(), report);
        ReportJob.unscheduleReportJob(report);
        reportDao.deleteReport(id);
    }
}
Also used : ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) ReportDao(com.serotonin.m2m2.reports.ReportDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 4 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportsDwr method getReport.

@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ReportVO getReport(int id, boolean copy) {
    ReportVO report;
    if (id == Common.NEW_ID) {
        report = new ReportVO();
        report.setXid(ReportDao.instance.generateUniqueXid());
        report.setName(translate("common.newName"));
    } else {
        report = ReportDao.instance.getReport(id);
        if (copy) {
            report.setId(Common.NEW_ID);
            report.setName(TranslatableMessage.translate(getTranslations(), "common.copyPrefix", report.getName()));
            report.setXid(ReportDao.instance.generateUniqueXid());
        }
        ReportCommon.ensureReportPermission(Common.getUser(), report);
    }
    return report;
}
Also used : ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class M2MReportVO method convert.

/**
 * @return
 */
public ReportVO convert(M2MReportDao legacyDao) {
    ReportVO vo = new ReportVO();
    List<ReportPointVO> newPoints = new ArrayList<ReportPointVO>();
    for (M2MReportPointVO legacyPoint : this.points) newPoints.add(legacyPoint.convert(legacyDao));
    vo.setPoints(newPoints);
    // Find the user from M2M
    String username = legacyDao.getUsername(userId);
    User user = UserDao.instance.getUser(username);
    if (user != null)
        vo.setUserId(user.getId());
    else
        throw new ShouldNeverHappenException("Unable to find User " + username + " in Mango.");
    // Use default vo.setTemplate(template);
    vo.setIncludeEvents(includeEvents);
    vo.setIncludeUserComments(includeUserComments);
    vo.setDateRangeType(dateRangeType);
    vo.setRelativeDateType(relativeDateType);
    vo.setPreviousPeriodCount(previousPeriodCount);
    vo.setPreviousPeriodType(previousPeriodType);
    vo.setPastPeriodCount(pastPeriodCount);
    vo.setPastPeriodType(pastPeriodType);
    vo.setFromNone(fromNone);
    vo.setFromYear(fromYear);
    vo.setFromMonth(fromMonth);
    vo.setFromDay(fromDay);
    vo.setFromHour(fromHour);
    vo.setFromMinute(fromMinute);
    vo.setToNone(toNone);
    vo.setToYear(toYear);
    vo.setToMonth(toMonth);
    vo.setToDay(toDay);
    vo.setToHour(toHour);
    vo.setToMinute(toMinute);
    vo.setSchedule(schedule);
    vo.setSchedulePeriod(schedulePeriod);
    vo.setScheduleCron(scheduleCron);
    vo.setRunDelayMinutes(runDelayMinutes);
    vo.setEmail(email);
    // Convert the Recipient list
    List<RecipientListEntryBean> newRecipients = new ArrayList<RecipientListEntryBean>();
    for (M2MRecipientListEntryBean legacyRecipient : this.recipients) newRecipients.add(legacyRecipient.convert(legacyDao));
    vo.setIncludeData(includeData);
    vo.setZipData(zipData);
    return vo;
}
Also used : User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) ReportPointVO(com.serotonin.m2m2.reports.vo.ReportPointVO) RecipientListEntryBean(com.serotonin.m2m2.web.dwr.beans.RecipientListEntryBean)

Aggregations

ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)17 ReportDao (com.serotonin.m2m2.reports.ReportDao)6 User (com.serotonin.m2m2.vo.User)6 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)6 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 UnknownHostException (java.net.UnknownHostException)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 ReportInstance (com.serotonin.m2m2.reports.vo.ReportInstance)2 ReportPointVO (com.serotonin.m2m2.reports.vo.ReportPointVO)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 WebContext (org.directwebremoting.WebContext)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 JsonException (com.serotonin.json.JsonException)1 JsonObject (com.serotonin.json.type.JsonObject)1 DatabaseType (com.serotonin.m2m2.db.DatabaseProxy.DatabaseType)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 UserDao (com.serotonin.m2m2.db.dao.UserDao)1