Search in sources :

Example 11 with ReportVO

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;
}
Also used : DatabaseType(com.serotonin.m2m2.db.DatabaseProxy.DatabaseType) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) DatabaseMetaData(java.sql.DatabaseMetaData) ReportDao(com.serotonin.m2m2.reports.ReportDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 12 with ReportVO

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);
}
Also used : HashMap(java.util.HashMap) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) ReportDao(com.serotonin.m2m2.reports.ReportDao)

Example 13 with ReportVO

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 14 with ReportVO

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 15 with ReportVO

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;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ReportPointVO(com.serotonin.m2m2.reports.vo.ReportPointVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

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