use of com.serotonin.m2m2.reports.vo.ReportVO 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;
}
use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.
the class Upgrade1 method upgrade.
@Override
protected void upgrade() throws Exception {
runScript(new String[] { "alter table reports add xid varchar(50);" });
// Now generate XIDs for all entries in the table
ReportDao dao = ReportDao.instance;
List<ReportVO> reports = dao.getReports();
for (ReportVO report : reports) {
report.setXid(dao.generateUniqueXid());
dao.saveReport(report);
}
// Alter the column back to have no default
Map<String, String[]> scripts = new HashMap<String, String[]>();
scripts.put(DatabaseProxy.DatabaseType.DERBY.name(), new String[] { "alter table reports alter column xid NOT NULL;" });
scripts.put(DatabaseProxy.DatabaseType.MYSQL.name(), new String[] { "ALTER TABLE reports CHANGE COLUMN `xid` `xid` VARCHAR(50) NOT NULL;" });
scripts.put(DatabaseProxy.DatabaseType.MSSQL.name(), new String[] { "alter table reports alter column xid varchar(50) NOT NULL;" });
scripts.put(DatabaseProxy.DatabaseType.H2.name(), new String[] { "alter table reports alter column xid varchar(50) NOT NULL;" });
runScript(scripts);
}
use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.
the class ReportEventHandlerRT method eventRaised.
/* (non-Javadoc)
* @see com.serotonin.m2m2.rt.event.handlers.EventHandlerRT#eventRaised(com.serotonin.m2m2.rt.event.EventInstance)
*/
@Override
public void eventRaised(EventInstance evt) {
try {
if (vo.getActiveReportId() != Common.NEW_ID) {
// Schedule the Active Report To Run
ReportVO report = ReportDao.instance.get(vo.getActiveReportId());
if (report != null) {
String host = InetAddress.getLocalHost().getHostName();
int port = Common.envProps.getInt("web.port", 8080);
ReportWorkItem.queueReport(host, port, report);
}
}
} catch (UnknownHostException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.
the class ReportEventHandlerRT method eventInactive.
/* (non-Javadoc)
* @see com.serotonin.m2m2.rt.event.handlers.EventHandlerRT#eventInactive(com.serotonin.m2m2.rt.event.EventInstance)
*/
@Override
public void eventInactive(EventInstance evt) {
try {
if (vo.getInactiveReportId() != Common.NEW_ID) {
// Schedule the Inactive Report to run
ReportVO report = ReportDao.instance.get(vo.getInactiveReportId());
if (report != null) {
String host = InetAddress.getLocalHost().getHostName();
int port = Common.envProps.getInt("web.port", 8080);
ReportWorkItem.queueReport(host, port, report);
}
}
} catch (UnknownHostException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.
the class ReportsDwr method createReportFromWatchlist.
@DwrPermission(custom = ReportPermissionDefinition.PERMISSION)
public ReportVO createReportFromWatchlist(String name, int[] dataPointIds) {
ReportVO report = new ReportVO();
User user = Common.getUser();
report.setName(new TranslatableMessage("common.copyPrefix", name).translate(getTranslations()));
report.setXid(Common.generateXid("REP_"));
DataPointDao dataPointDao = DataPointDao.instance;
for (int id : dataPointIds) {
DataPointVO dp = dataPointDao.getDataPoint(id, false);
if (dp == null || !Permissions.hasDataPointReadPermission(user, dp))
continue;
ReportPointVO rp = new ReportPointVO();
rp.setPointId(dp.getId());
rp.setPointKey("p" + dp.getId());
rp.setColour(dp.getChartColour());
rp.setConsolidatedChart(true);
rp.setPlotType(dp.getPlotType());
report.getPoints().add(rp);
}
return report;
}
Aggregations