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