Search in sources :

Example 1 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 2 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 3 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 4 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.

the class ReportsDwr method purgeAllNow.

/**
 * Purge all Reports Now
 * @return
 */
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult purgeAllNow() {
    ProcessResult response = new ProcessResult();
    int deleteCount = ReportDao.instance.purgeReportsBefore(Common.timer.currentTimeMillis());
    LOG.info("Report purge ended, " + deleteCount + " report instances deleted");
    response.addData("purgeMessage", new TranslatableMessage("systemSettings.reports.reportsPurged", deleteCount).translate(Common.getTranslations()));
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 5 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-modules-public by infiniteautomation.

the class ReportsDwr method purgeNow.

/**
 * Purge Reports using settings
 * @param reportPurgePeriods
 * @param reportPurgePeriodType
 * @return
 */
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ProcessResult purgeNow() {
    ProcessResult response = new ProcessResult();
    DateTime cutoff = DateUtils.truncateDateTime(new DateTime(), Common.TimePeriods.DAYS);
    cutoff = DateUtils.minus(cutoff, SystemSettingsDao.getIntValue(ReportPurgeDefinition.REPORT_PURGE_PERIOD_TYPE, Common.TimePeriods.MONTHS), SystemSettingsDao.getIntValue(ReportPurgeDefinition.REPORT_PURGE_PERIODS, 1));
    int deleteCount = ReportDao.instance.purgeReportsBefore(cutoff.getMillis());
    LOG.info("Report purge ended, " + deleteCount + " report instances deleted");
    response.addData("purgeMessage", new TranslatableMessage("systemSettings.reports.reportsPurged", deleteCount).translate(Common.getTranslations()));
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) DateTime(org.joda.time.DateTime) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)220 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)126 User (com.serotonin.m2m2.vo.User)56 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)47 ArrayList (java.util.ArrayList)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)24 HashMap (java.util.HashMap)21 StringStringPair (com.serotonin.db.pair.StringStringPair)11 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)11 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)10 IOException (java.io.IOException)9 DateTime (org.joda.time.DateTime)9 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)9 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)8 LinkedHashMap (java.util.LinkedHashMap)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7 ShareUser (com.serotonin.m2m2.view.ShareUser)7 ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)6