use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ImageChartComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = jsonObject.getString("durationType");
if (text == null)
throw new TranslatableJsonException("emport.error.chart.missing", "durationType", Common.TIME_PERIOD_CODES.getCodeList());
durationType = Common.TIME_PERIOD_CODES.getId(text);
if (durationType == -1)
throw new TranslatableJsonException("emport.error.chart.invalid", "durationType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class GraphicalView method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
if (isNew()) {
String username = jsonObject.getString("user");
if (StringUtils.isBlank(username))
throw new TranslatableJsonException("emport.error.missingValue", "user");
User user = UserDao.instance.getUser(username);
if (user == null)
throw new TranslatableJsonException("emport.error.missingUser", username);
userId = user.getId();
}
JsonArray components = jsonObject.getJsonArray("viewComponents");
if (components != null) {
viewComponents.clear();
for (JsonValue jv : components) addViewComponent(reader.read(ViewComponent.class, jv));
}
String text = jsonObject.getString("anonymousAccess");
if (text != null) {
anonymousAccess = ShareUser.ACCESS_CODES.getId(text);
if (anonymousAccess == -1)
throw new TranslatableJsonException("emport.error.invalid", "anonymousAccess", text, ShareUser.ACCESS_CODES.getCodeList());
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class GraphicalViewEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject viewJson = jsonValue.toJsonObject();
String xid = viewJson.getString("xid");
if (StringUtils.isBlank(xid))
xid = graphicalViewDao.generateUniqueXid();
ensureDao();
GraphicalView view = graphicalViewDao.getViewByXid(xid);
if (view == null) {
view = new GraphicalView();
view.setXid(xid);
}
try {
importContext.getReader().readInto(view, viewJson);
// Now validate it. Use a new response object so we can distinguish errors in this view from other
// errors.
ProcessResult viewResponse = new ProcessResult();
view.validate(viewResponse);
if (viewResponse.getHasMessages())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(viewResponse, "emport.view.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = view.isNew();
graphicalViewDao.saveView(view);
importContext.addSuccessMessage(isnew, "emport.view.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.view.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.view.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class CompoundComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
JsonObject jsonChildren = jsonObject.getJsonObject("children");
if (jsonChildren != null) {
for (Map.Entry<String, JsonValue> jsonChild : jsonChildren.entrySet()) {
CompoundChild child = getChild(jsonChild.getKey());
if (child == null || !child.getViewComponent().isPointComponent())
throw new TranslatableJsonException("emport.error.compound.invalidChildId", jsonChild.getKey(), definition().getId(), getPointComponentChildIds());
jsonReadDataPoint(jsonChild.getValue(), (PointComponent) child.getViewComponent());
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class MultistateGraphicComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
JsonArray jsonStateList = jsonObject.getJsonArray("stateImageMappings");
if (jsonStateList != null) {
stateImageMap.clear();
for (JsonValue jv : jsonStateList) {
JsonObject jsonMapping = jv.toJsonObject();
Integer state = jsonMapping.getInt("state");
if (state == null)
throw new TranslatableJsonException("emport.error.missingValue", "state");
Integer index = jsonMapping.getInt("imageIndex");
if (index == null)
throw new TranslatableJsonException("emport.error.missingValue", "index");
stateImageMap.put(state, index);
}
}
}
Aggregations