Search in sources :

Example 61 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class EmailRecipientResolver method resolve.

@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
    if (jsonValue == null)
        return null;
    JsonObject json = jsonValue.toJsonObject();
    String text = json.getString("recipientType");
    if (text == null)
        throw new TranslatableJsonException("emport.error.recipient.missing", "recipientType", EmailRecipient.TYPE_CODES);
    int type = EmailRecipient.TYPE_CODES.getId(text);
    if (!EmailRecipient.TYPE_CODES.isValidId(type))
        throw new TranslatableJsonException("emport.error.recipient.invalid", "recipientType", text, EmailRecipient.TYPE_CODES.getCodeList());
    if (type == EmailRecipient.TYPE_MAILING_LIST)
        return MailingList.class;
    if (type == EmailRecipient.TYPE_USER)
        return UserEntry.class;
    return AddressEntry.class;
}
Also used : JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 62 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class UserEntry method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String username = jsonObject.getString("username");
    if (username == null)
        throw new TranslatableJsonException("emport.error.recipient.missing.reference", "username");
    user = UserDao.instance.getUser(username);
    if (user == null)
        throw new TranslatableJsonException("emport.error.recipient.invalid.reference", "username", username);
    userId = user.getId();
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 63 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class TimeoutDetectorVO 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.ped.missing", "durationType", Common.TIME_PERIOD_CODES.getCodeList());
    durationType = Common.TIME_PERIOD_CODES.getId(text);
    if (!Common.TIME_PERIOD_CODES.isValidId(durationType))
        throw new TranslatableJsonException("emport.error.ped.invalid", "durationType", text, Common.TIME_PERIOD_CODES.getCodeList());
    duration = getInt(jsonObject, "duration");
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 64 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class PointFolder method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    JsonArray jsonPoints = jsonObject.getJsonArray("points");
    if (jsonPoints != null) {
        points.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonPoints) {
            String xid = jv.toString();
            DataPointVO dp = dataPointDao.getDataPoint(xid);
            if (dp == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            points.add(new DataPointSummary(dp));
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointSummary(com.serotonin.m2m2.vo.DataPointSummary) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 65 with TranslatableJsonException

use of com.serotonin.m2m2.i18n.TranslatableJsonException in project ma-core-public by infiniteautomation.

the class DataSourceVO method readUpdatePeriodType.

protected Integer readUpdatePeriodType(JsonObject json) throws JsonException {
    String text = json.getString("updatePeriodType");
    if (text == null)
        return null;
    int value = Common.TIME_PERIOD_CODES.getId(text);
    if (value == -1)
        throw new TranslatableJsonException("emport.error.invalid", "updatePeriodType", text, Common.TIME_PERIOD_CODES.getCodeList());
    return value;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)79 JsonObject (com.serotonin.json.type.JsonObject)24 JsonException (com.serotonin.json.JsonException)21 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)17 JsonValue (com.serotonin.json.type.JsonValue)15 JsonArray (com.serotonin.json.type.JsonArray)14 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)8 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)8 User (com.serotonin.m2m2.vo.User)7 ArrayList (java.util.ArrayList)5 ExportCodes (com.serotonin.m2m2.util.ExportCodes)4 IntStringPair (com.serotonin.db.pair.IntStringPair)3 TypeDefinition (com.serotonin.json.util.TypeDefinition)3 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)3 IOException (java.io.IOException)3 List (java.util.List)3 JsonBoolean (com.serotonin.json.type.JsonBoolean)2 JsonString (com.serotonin.json.type.JsonString)2