use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class MaintenanceEventVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("dataSourceXid");
if (text != null) {
DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(text);
if (ds == null)
throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "dataSourceXid", text);
dataSourceId = ds.getId();
}
text = jsonObject.getString("alarmLevel");
if (text != null) {
alarmLevel = AlarmLevels.CODES.getId(text);
if (!AlarmLevels.CODES.isValidId(alarmLevel))
throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "alarmLevel", text, AlarmLevels.CODES.getCodeList());
}
text = jsonObject.getString("scheduleType");
if (text != null) {
scheduleType = TYPE_CODES.getId(text);
if (!TYPE_CODES.isValidId(scheduleType))
throw new TranslatableJsonException("emport.error.maintenanceEvent.invalid", "scheduleType", text, TYPE_CODES.getCodeList());
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ViewComponent method jsonReadDataPoint.
protected void jsonReadDataPoint(JsonValue jsonXid, PointComponent comp) throws JsonException {
if (jsonXid != null) {
String xid = jsonXid.toString();
DataPointVO dataPoint = DataPointDao.instance.getDataPoint(xid);
if (dataPoint == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
if (!comp.definition().supports(dataPoint.getPointLocator().getDataTypeId()))
throw new TranslatableJsonException("emport.error.component.incompatibleDataType", xid, definition().getExportName());
comp.tsetDataPoint(dataPoint);
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class MBusDataSourceVO method jsonRead.
/* (non-Javadoc)
* @see com.serotonin.m2m2.vo.dataSource.DataSourceVO#jsonRead(com.serotonin.json.JsonReader, com.serotonin.json.type.JsonObject)
*/
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
Integer value = readUpdatePeriodType(jsonObject);
if (value != null)
updatePeriodType = value;
String s = jsonObject.getString("connectionType");
if (s == null) {
List<String> codes = new ArrayList<String>();
codes.add("mbusSerial");
codes.add("mbusTcpIp");
throw new TranslatableJsonException("emport.error.missing", "connectionType", codes);
} else {
int bitPerSecond = jsonObject.getInt("bitPerSecond");
int responseTimeoutOffset = jsonObject.getInt("responseTimeoutOffset");
switch(s) {
case "mbusSerial":
String portName = jsonObject.getString("portName");
connection = new SerialPortConnection(portName, bitPerSecond, responseTimeoutOffset);
break;
case "mbusTcpIp":
String host = jsonObject.getString("host");
int port = jsonObject.getInt("port");
connection = new TcpIpConnection(host, port, bitPerSecond, responseTimeoutOffset);
break;
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class MaintenanceEventType method jsonRead.
//
//
// Serialization
//
@Override
public void jsonRead(JsonReader reader, com.serotonin.json.type.JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String xid = jsonObject.getString("XID");
if (xid == null)
throw new TranslatableJsonException("emport.error.eventType.missing.reference", "XID");
MaintenanceEventVO me = new MaintenanceEventDao().getMaintenanceEvent(xid);
if (me == null)
throw new TranslatableJsonException("emport.error.eventType.invalid.reference", "XID", xid);
maintenanceId = me.getId();
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException 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));
}
}
Aggregations