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