Search in sources :

Example 6 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class RTMDefinition method initialize.

@Override
public void initialize(boolean safe) {
    List<ReportVO> reports = ReportDao.instance.getReports();
    for (ReportVO report : reports) {
        try {
            String host = InetAddress.getLocalHost().getHostName();
            int port = Common.envProps.getInt("web.port", 8080);
            ReportJob.scheduleReportJob(host, port, report);
        } catch (ShouldNeverHappenException | UnknownHostException e) {
            // Don't stop the startup if there is an error. Just log it.
            LOG.error("Error starting report " + report.getName(), e);
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 7 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject reportJson = jsonValue.toJsonObject();
    String xid = reportJson.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = ReportDao.instance.generateUniqueXid();
    ReportVO report = null;
    try {
        report = ReportDao.instance.getReport(xid);
    } catch (IncorrectResultSizeDataAccessException e) {
        importContext.getResult().addGenericMessage("reports.emport.duplicateXids", xid);
        return;
    }
    if (report == null) {
        report = new ReportVO();
        report.setXid(xid);
    }
    try {
        importContext.getReader().readInto(report, reportJson);
        // Now validate it. Use a new response object so we can distinguish errors in this user from other
        // errors.
        ProcessResult reportResponse = new ProcessResult();
        report.validate(reportResponse);
        if (reportResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(reportResponse, "emport.report.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = report.getId() == Common.NEW_ID;
            ReportDao.instance.saveReport(report);
            importContext.addSuccessMessage(isnew, "emport.report.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.report.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.report.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 8 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportEventHandlerVO method jsonRead.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.vo.event.AbstractEventHandlerVO#jsonRead(com.serotonin.json.JsonReader, com.serotonin.json.type.JsonObject)
	 */
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String text = jsonObject.getString("activeReportXid");
    if (text != null) {
        ReportVO report = ReportDao.instance.getByXid(text);
        if (report != null)
            this.activeReportId = report.getId();
    } else
        this.activeReportId = Common.NEW_ID;
    text = jsonObject.getString("inActiveReportXid");
    if (text != null) {
        ReportVO report = ReportDao.instance.getByXid(text);
        if (report != null)
            this.inactiveReportId = report.getId();
    } else
        this.inactiveReportId = Common.NEW_ID;
}
Also used : ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 9 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportEventHandlerVO method jsonWrite.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.vo.event.AbstractEventHandlerVO#jsonWrite(com.serotonin.json.ObjectWriter)
	 */
@Override
public void jsonWrite(ObjectWriter writer) throws IOException, JsonException {
    super.jsonWrite(writer);
    ReportVO report = ReportDao.instance.get(activeReportId);
    if (report != null)
        writer.writeEntry("activeReportXid", report.getXid());
    report = ReportDao.instance.get(inactiveReportId);
    if (report != null)
        writer.writeEntry("inActiveReportXid", report.getXid());
}
Also used : ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

Example 10 with ReportVO

use of com.serotonin.m2m2.reports.vo.ReportVO in project ma-modules-public by infiniteautomation.

the class ReportEventHandlerVO method validate.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.vo.event.AbstractEventHandlerVO#validate(com.serotonin.m2m2.i18n.ProcessResult)
	 */
@Override
public void validate(ProcessResult response) {
    super.validate(response);
    if (activeReportId != Common.NEW_ID) {
        ReportVO vo = ReportDao.instance.get(activeReportId);
        if (vo == null)
            response.addContextualMessage("activeReportId", "validate.invalidValue");
    }
    if (inactiveReportId != Common.NEW_ID) {
        ReportVO vo = ReportDao.instance.get(inactiveReportId);
        if (vo == null)
            response.addContextualMessage("inactiveReportId", "validate.invalidValue");
    }
    if ((inactiveReportId != Common.NEW_ID) && (activeReportId != Common.NEW_ID)) {
        response.addContextualMessage("activeReportId", "validate.atLeast1");
        response.addContextualMessage("inactiveReportId", "validate.atLeast1");
    }
}
Also used : ReportVO(com.serotonin.m2m2.reports.vo.ReportVO)

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