use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class MaintenanceEventEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
JsonObject maintenanceEvent = jsonValue.toJsonObject();
String xid = maintenanceEvent.getString("xid");
if (StringUtils.isBlank(xid))
xid = maintenanceEventDao.generateUniqueXid();
MaintenanceEventVO vo = maintenanceEventDao.getMaintenanceEvent(xid);
if (vo == null) {
vo = new MaintenanceEventVO();
vo.setXid(xid);
}
try {
importContext.getReader().readInto(vo, maintenanceEvent);
// 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())
// Too bad. Copy the errors into the actual response.
importContext.copyValidationMessages(voResponse, "emport.maintenanceEvent.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
RTMDefinition.instance.saveMaintenanceEvent(vo);
importContext.addSuccessMessage(isnew, "emport.maintenanceEvent.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class EnvCanPointLocatorVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("attributeId");
if (text == null)
throw new TranslatableJsonException("emport.error.missing", "attributeId", ATTRIBUTE_CODES.getCodeList());
attributeId = ATTRIBUTE_CODES.getId(text);
if (!ATTRIBUTE_CODES.isValidId(attributeId))
throw new TranslatableJsonException("emport.error.invalid", "attributeId", text, ATTRIBUTE_CODES.getCodeList());
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ImageSetComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
JsonValue jsonImageId = jsonObject.get("imageSet");
if (jsonImageId != null) {
String id = jsonImageId.toString();
imageSet = Common.getImageSet(id);
if (imageSet == null)
throw new TranslatableJsonException("emport.error.component.unknownImageSet", id, Common.getImageSetIds());
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ViewComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("updatePeriodType");
if (text == null) {
// Disable the update feature
updatePeriodType = Common.TimePeriods.MINUTES;
updatePeriods = 0;
} else {
updatePeriodType = Common.TIME_PERIOD_CODES.getId(text, Common.TimePeriods.MILLISECONDS, Common.TimePeriods.MONTHS, Common.TimePeriods.YEARS);
if (updatePeriodType == -1)
throw new TranslatableJsonException("emport.error.component.invalid", "updatePeriodType", text, Common.TIME_PERIOD_CODES.getCodeList(Common.TimePeriods.MILLISECONDS, Common.TimePeriods.MONTHS, Common.TimePeriods.YEARS));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class DynamicGraphicComponent method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
JsonValue jsonImageId = jsonObject.get("dynamicImage");
if (jsonImageId != null) {
String id = jsonImageId.toString();
dynamicImage = Common.getDynamicImage(id);
if (dynamicImage == null)
throw new TranslatableJsonException("emport.error.component.unknownDynamicImage", id, Common.getDynamicImageIds());
}
}
Aggregations