use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class Restorer method restore.
/**
* Restore the object based on the Audit Trail
* @return
*/
public T restore() {
T vo = null;
try {
// Follow the trail
for (AuditEventInstanceVO audit : trail) {
JsonObject context = audit.getContext();
JsonReader reader = new JsonReader(Common.JSON_CONTEXT, context);
if (audit.getChangeType() == AuditEventInstanceVO.CHANGE_TYPE_CREATE) {
vo = this.build(audit.getObjectId(), context, reader);
} else if (audit.getChangeType() == AuditEventInstanceVO.CHANGE_TYPE_MODIFY) {
if (vo == null)
vo = getExisting(audit.getObjectId());
vo = this.build(vo, context, reader);
}
}
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
copyValidationMessages(voResponse, "restore.prefix", vo.getXid());
else {
addSuccessMessage(vo.isNew(), "restore.prefix", vo.getXid());
}
} catch (TranslatableJsonException e) {
addFailureMessage("restore.prefix", "need-to-fill-in", e.getMsg());
} catch (JsonException e) {
addFailureMessage("restoring.prefix", "need-to-fill-in", getJsonExceptionMessage(e));
} catch (Exception e) {
addFailureMessage("restoring.prefix", "need-to-fill-in", e.getMessage());
}
return vo;
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class AbstractDataSourceModel method setAlarmLevels.
@JsonSetter(value = "alarmLevels")
public void setAlarmLevels(Map<String, String> alarmCodeLevels) throws TranslatableJsonException {
if (alarmCodeLevels != null) {
ExportCodes eventCodes = this.data.getEventCodes();
if (eventCodes != null && eventCodes.size() > 0) {
for (String code : alarmCodeLevels.keySet()) {
int eventId = eventCodes.getId(code);
if (!eventCodes.isValidId(eventId))
throw new TranslatableJsonException("emport.error.eventCode", code, eventCodes.getCodeList());
String text = alarmCodeLevels.get(code);
int level = AlarmLevels.CODES.getId(text);
if (!AlarmLevels.CODES.isValidId(level))
throw new TranslatableJsonException("emport.error.alarmLevel", text, code, AlarmLevels.CODES.getCodeList());
this.data.setAlarmLevel(eventId, level);
}
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class VarNames method jsonReadVarContext.
public static void jsonReadVarContext(JsonObject json, List<IntStringPair> context) throws JsonException {
JsonArray jsonContext = json.getJsonArray("context");
if (jsonContext != null) {
context.clear();
DataPointDao dataPointDao = DataPointDao.instance;
for (JsonValue jv : jsonContext) {
JsonObject jo = jv.toJsonObject();
String xid = jo.getString("dataPointXid");
if (xid == null)
throw new TranslatableJsonException("emport.error.meta.missing", "dataPointXid");
Integer dpid = dataPointDao.getIdByXid(xid);
if (dpid == null)
throw new TranslatableJsonException("emport.error.missingPoint", xid);
String var = jo.getString("varName");
if (var == null)
throw new TranslatableJsonException("emport.error.meta.missing", "varName");
context.add(new IntStringPair(dpid, var));
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class TimePeriodChartRenderer method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = jsonObject.getString("timePeriodType");
if (text == null)
throw new TranslatableJsonException("emport.error.chart.missing", "timePeriodType", Common.TIME_PERIOD_CODES.getCodeList());
timePeriod = Common.TIME_PERIOD_CODES.getId(text);
if (timePeriod == -1)
throw new TranslatableJsonException("emport.error.chart.invalid", "timePeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.
the class DataSourceImporter method importImpl.
@Override
protected void importImpl() {
String xid = json.getString("xid");
if (StringUtils.isBlank(xid))
xid = ctx.getDataSourceDao().generateUniqueXid();
DataSourceVO<?> vo = ctx.getDataSourceDao().getDataSource(xid);
if (vo == null) {
String typeStr = json.getString("type");
if (StringUtils.isBlank(typeStr))
addFailureMessage("emport.dataSource.missingType", xid, ModuleRegistry.getDataSourceDefinitionTypes());
else {
DataSourceDefinition def = ModuleRegistry.getDataSourceDefinition(typeStr);
if (def == null)
addFailureMessage("emport.dataSource.invalidType", xid, typeStr, ModuleRegistry.getDataSourceDefinitionTypes());
else {
vo = def.baseCreateDataSourceVO();
vo.setXid(xid);
}
}
}
if (vo != null) {
try {
// The VO was found or successfully created. Finish reading it in.
ctx.getReader().readInto(vo, json);
// Now validate it. Use a new response object so we can distinguish errors in this vo from
// other errors.
ProcessResult voResponse = new ProcessResult();
vo.validate(voResponse);
if (voResponse.getHasMessages())
setValidationMessages(voResponse, "emport.dataSource.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
Common.runtimeManager.saveDataSource(vo);
addSuccessMessage(isnew, "emport.dataSource.prefix", xid);
} else {
addFailureMessage(new ProcessMessage("Runtime manager not running, data source with xid: " + xid + "not saved."));
}
}
} catch (TranslatableJsonException e) {
addFailureMessage("emport.dataSource.prefix", xid, e.getMsg());
} catch (JsonException e) {
addFailureMessage("emport.dataSource.prefix", xid, getJsonExceptionMessage(e));
}
}
}
Aggregations