use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class M2MRecipientListEntryBean method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
String text = jsonObject.getString("recipientType");
if (text == null)
throw new TranslatableJsonException("emport.error.recipient.missing", "recipientType", EmailRecipient.TYPE_CODES.getCodeList());
recipientType = EmailRecipient.TYPE_CODES.getId(text);
if (recipientType == -1)
throw new TranslatableJsonException("emport.error.recipient.invalid", "recipientType", text, EmailRecipient.TYPE_CODES.getCodeList());
if (recipientType == EmailRecipient.TYPE_MAILING_LIST) {
text = jsonObject.getString("mailingList");
if (text == null)
throw new TranslatableJsonException("emport.error.recipient.missing.reference", "mailingList");
MailingList ml = MailingListDao.instance.getMailingList(text);
if (ml == null)
throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "mailingList", text);
referenceId = ml.getId();
} else if (recipientType == EmailRecipient.TYPE_USER) {
text = jsonObject.getString("username");
if (text == null)
throw new TranslatableJsonException("emport.error.recipient.missing.reference", "username");
User user = UserDao.instance.getUser(text);
if (user == null)
throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "user", text);
referenceId = user.getId();
} else if (recipientType == EmailRecipient.TYPE_ADDRESS) {
referenceAddress = jsonObject.getString("address");
if (referenceAddress == null)
throw new TranslatableJsonException("emport.error.recipient.missing.reference", "address");
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ReportVO method jsonRead.
/* (non-Javadoc)
* @see com.serotonin.json.spi.JsonSerializable#jsonRead(com.serotonin.json.JsonReader, com.serotonin.json.type.JsonObject)
*/
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
if (jsonObject.containsKey("userId")) {
userId = jsonObject.getInt("userId");
} else if (jsonObject.containsKey("user")) {
String username = jsonObject.getString("user");
if (org.apache.commons.lang3.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();
}
String text = jsonObject.getString("includeEvents");
if (text != null) {
includeEvents = EVENT_CODES.getId(text);
if (includeEvents == -1)
throw new TranslatableJsonException("emport.error.invalid", "includeEvents", text, EVENT_CODES.getCodeList());
}
text = jsonObject.getString("dateRangeType");
if (text != null) {
dateRangeType = DATE_RANGE_TYPES.getId(text);
if (dateRangeType == -1)
throw new TranslatableJsonException("emport.error.invalid", "dateRangeType", text, DATE_RANGE_TYPES.getCodeList());
}
if (dateRangeType == DATE_RANGE_TYPE_RELATIVE) {
text = jsonObject.getString("relativeDateType");
if (text != null) {
relativeDateType = DATE_RELATIVE_TYPES.getId(text);
if (relativeDateType == -1)
throw new TranslatableJsonException("emport.error.invalid", "relativeDateType", text, DATE_RELATIVE_TYPES.getCodeList());
}
if (relativeDateType == RELATIVE_DATE_TYPE_PREVIOUS) {
text = jsonObject.getString("previousPeriodType");
if (text != null) {
previousPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (previousPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "previousPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
previousPeriodCount = jsonObject.getInt("previousPeriods");
} else {
// FOR legacy bug where previousPeriodType was misspelled
text = jsonObject.getString("perviousPeriodType");
if (text != null) {
previousPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (previousPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "previousPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
previousPeriodCount = jsonObject.getInt("previousPeriods");
}
}
} else if (relativeDateType == RELATIVE_DATE_TYPE_PREVIOUS) {
text = jsonObject.getString("pastPeriodType");
if (text != null) {
pastPeriodType = Common.TIME_PERIOD_CODES.getId(text);
if (pastPeriodType == -1)
throw new TranslatableJsonException("emport.error.invalid", "pastPeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
pastPeriodCount = jsonObject.getInt("pastPeriods");
}
}
} else if (dateRangeType == DATE_RANGE_TYPE_SPECIFIC) {
fromNone = jsonObject.getBoolean("fromInception");
if (!fromNone) {
fromYear = jsonObject.getInt("fromYear");
fromMonth = jsonObject.getInt("fromMonth");
fromDay = jsonObject.getInt("fromDay");
fromHour = jsonObject.getInt("fromHour");
fromMinute = jsonObject.getInt("fromMinute");
}
toNone = jsonObject.getBoolean("toLatest");
if (!toNone) {
toYear = jsonObject.getInt("toYear");
toMonth = jsonObject.getInt("toMonth");
toDay = jsonObject.getInt("toDay");
toHour = jsonObject.getInt("toHour");
toMinute = jsonObject.getInt("toMinute");
}
}
schedule = jsonObject.getBoolean("schedule");
if (schedule) {
text = jsonObject.getString("schedulePeriod");
if (text != null) {
schedulePeriod = SCHEDULE_CODES.getId(text);
if (schedulePeriod == -1)
throw new TranslatableJsonException("emport.error.invalid", "schedulePeriod", text, SCHEDULE_CODES.getCodeList());
if (schedulePeriod == SCHEDULE_CRON) {
scheduleCron = jsonObject.getString("scheduleCron");
try {
new CronTimerTrigger(scheduleCron);
} catch (ParseException e) {
throw new TranslatableJsonException("emport.error.invalid", "scheduleCron", scheduleCron, "cron expressions");
}
}
} else {
throw new TranslatableJsonException("emport.error.invalid", "schedulePeriod", "null", SCHEDULE_CODES.getCodeList());
}
}
email = jsonObject.getBoolean("email");
if (email) {
JsonArray recipientsArray = jsonObject.getJsonArray("recipients");
boolean add = true;
if (recipientsArray != null) {
for (JsonValue jv : recipientsArray) {
RecipientListEntryBean recipient = new RecipientListEntryBean();
reader.readInto(recipient, jv);
for (RecipientListEntryBean existing : recipients) {
if (existing.equals(recipient)) {
reader.readInto(existing, jv);
add = false;
break;
}
}
if (add) {
recipients.add(recipient);
} else {
add = true;
}
}
} else {
throw new TranslatableJsonException("emport.error.invalid", "recipients", "null", "valid users, email addresses or mailing lists");
}
includeData = jsonObject.getBoolean("includeData");
if (includeData)
zipData = jsonObject.getBoolean("zipData");
}
JsonArray pointsArray = jsonObject.getJsonArray("points");
if (pointsArray != null) {
points = new ArrayList<ReportPointVO>();
for (JsonValue jv : pointsArray) {
ReportPointVO reportPoint = new ReportPointVO();
reader.readInto(reportPoint, jv);
// TODO prevent adding the same point twice?
points.add(reportPoint);
}
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ScheduledEventEmportDefinition method doImport.
@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
JsonObject scheduledEvent = jsonValue.toJsonObject();
String xid = scheduledEvent.getString("xid");
if (StringUtils.isBlank(xid))
xid = ScheduledEventDao.instance.generateUniqueXid();
ScheduledEventVO vo = ScheduledEventDao.instance.getScheduledEvent(xid);
if (vo == null) {
vo = new ScheduledEventVO();
vo.setXid(xid);
}
try {
importContext.getReader().readInto(vo, scheduledEvent);
// 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.scheduledEvent.prefix", xid);
else {
// Sweet. Save it.
boolean isnew = vo.isNew();
RTMDefinition.instance.saveScheduledEvent(vo);
importContext.addSuccessMessage(isnew, "emport.scheduledEvent.prefix", xid);
}
} catch (TranslatableJsonException e) {
importContext.getResult().addGenericMessage("emport.scheduledEvent.prefix", xid, e.getMsg());
} catch (JsonException e) {
importContext.getResult().addGenericMessage("emport.scheduledEvent.prefix", xid, importContext.getJsonExceptionMessage(e));
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class VMStatDataSourceVO method jsonRead.
@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
super.jsonRead(reader, jsonObject);
String text = jsonObject.getString("outputScale");
if (text != null) {
outputScale = OUTPUT_SCALE_CODES.getId(text);
if (outputScale == -1)
throw new TranslatableJsonException("emport.error.invalid", "outputScale", text, OUTPUT_SCALE_CODES.getCodeList());
}
}
use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-modules-public by infiniteautomation.
the class ScheduledEventType method jsonRead.
//
//
// Serialization
//
@Override
public void jsonRead(JsonReader reader, 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");
ScheduledEventVO se = ScheduledEventDao.instance.getScheduledEvent(xid);
if (se == null)
throw new TranslatableJsonException("emport.error.eventType.invalid.reference", "XID", xid);
scheduleId = se.getId();
}
Aggregations