use of com.serotonin.m2m2.reports.ReportDao 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.reports.ReportDao 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.reports.ReportDao in project ma-modules-public by infiniteautomation.
the class ReportsDwr method deleteReportInstance.
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public List<ReportInstance> deleteReportInstance(int instanceId) {
User user = Common.getUser();
ReportDao reportDao = ReportDao.instance;
reportDao.deleteReportInstance(instanceId, user.getId());
return getReportInstances(user);
}
use of com.serotonin.m2m2.reports.ReportDao in project ma-modules-public by infiniteautomation.
the class ReportExportBase method execute.
protected void execute(HttpServletRequest request, HttpServletResponse response, int content) throws IOException {
// Get the report instance id
int instanceId = Integer.parseInt(request.getParameter("instanceId"));
// Get the report instance
ReportDao reportDao = ReportDao.instance;
ReportInstance instance = reportDao.getReportInstance(instanceId);
// Ensure the user is allowed access.
ReportCommon.ensureReportInstancePermission(Common.getUser(request), instance);
// Stream the content.
response.setContentType("text/csv");
Translations translations = Common.getTranslations();
if (content == CONTENT_REPORT) {
ExportCsvStreamer creator = new ExportCsvStreamer(request.getServerName(), request.getLocalPort(), response.getWriter(), translations);
if (Common.databaseProxy.getNoSQLProxy() == null)
reportDao.reportInstanceDataSQL(instanceId, creator);
else
reportDao.reportInstanceDataNoSQL(instanceId, creator);
} else if (content == CONTENT_EVENTS)
new EventCsvStreamer(response.getWriter(), reportDao.getReportInstanceEvents(instanceId), translations);
else if (content == CONTENT_COMMENTS)
new UserCommentCsvStreamer(response.getWriter(), reportDao.getReportInstanceUserComments(instanceId), translations);
}
use of com.serotonin.m2m2.reports.ReportDao in project ma-modules-public by infiniteautomation.
the class M2MReportImportDwr method migrate.
@DwrPermission(admin = true)
public ProcessResult migrate(String driverClassname, String connectionUrl, String username, String password) {
ProcessResult result = new ProcessResult();
// Validate the connection
try {
DriverManager.registerDriver((Driver) Class.forName(driverClassname).newInstance());
Connection connection = DriverManager.getConnection(connectionUrl, username, password);
connection.setAutoCommit(false);
// Test the connection.
DatabaseMetaData md = connection.getMetaData();
String productName = md.getDatabaseProductName();
DatabaseType type = DatabaseType.DERBY;
if (productName.equalsIgnoreCase("mysql")) {
type = DatabaseType.MYSQL;
} else if (productName.equalsIgnoreCase("Apache Derby")) {
type = DatabaseType.DERBY;
} else if (productName.contains("Microsoft")) {
type = DatabaseType.MSSQL;
} else if (productName.equalsIgnoreCase("h2")) {
type = DatabaseType.H2;
} else if (productName.equalsIgnoreCase("postgressql")) {
type = DatabaseType.MYSQL;
}
// Get the reports
M2MReportDao dao = new M2MReportDao(connection, type);
List<M2MReportVO> legacyReports = dao.getReports();
// Convert the reports to our VOs
List<ReportVO> reports = new ArrayList<ReportVO>();
for (M2MReportVO legacyReport : legacyReports) {
try {
ReportVO report = legacyReport.convert(dao);
report.validate(result);
reports.add(report);
} catch (Exception e) {
result.addGenericMessage("common.default", e.getMessage());
}
}
if (!result.getHasMessages()) {
ReportDao reportDao = ReportDao.instance;
for (ReportVO vo : reports) {
vo.validate(result);
reportDao.saveReport(vo);
}
}
result.addData("reports", reports);
} catch (Exception e) {
result.addContextualMessage("connectionUrl", "common.default", e.getMessage());
return result;
}
return result;
}
Aggregations