Search in sources :

Example 26 with TranslatableJsonException

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

the class ScheduledEventVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("alarmLevel");
    if (text != null) {
        alarmLevel = AlarmLevels.CODES.getId(text);
        if (!AlarmLevels.CODES.isValidId(alarmLevel))
            throw new TranslatableJsonException("emport.error.scheduledEvent.invalid", "alarmLevel", text, AlarmLevels.CODES.getCodeList());
    }
    text = jsonObject.getString("scheduleType");
    if (text != null) {
        scheduleType = TYPE_CODES.getId(text);
        if (!TYPE_CODES.isValidId(scheduleType))
            throw new TranslatableJsonException("emport.error.scheduledEvent.invalid", "scheduleType", text, TYPE_CODES.getCodeList());
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 27 with TranslatableJsonException

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

the class VMStatPointLocatorVO 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());
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 28 with TranslatableJsonException

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

the class PointLinkVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    DataPointDao dataPointDao = DataPointDao.instance;
    String xid = jsonObject.getString("sourcePointId");
    if (xid != null) {
        DataPointVO vo = dataPointDao.getDataPoint(xid);
        if (vo == null)
            throw new TranslatableJsonException("emport.error.missingPoint", xid);
        sourcePointId = vo.getId();
    }
    xid = jsonObject.getString("targetPointId");
    if (xid != null) {
        DataPointVO vo = dataPointDao.getDataPoint(xid);
        if (vo == null)
            throw new TranslatableJsonException("emport.error.missingPoint", xid);
        targetPointId = vo.getId();
    }
    String text = jsonObject.getString("event");
    if (text != null) {
        event = EVENT_CODES.getId(text);
        if (!EVENT_CODES.isValidId(event))
            throw new TranslatableJsonException("emport.error.link.invalid", "event", text, EVENT_CODES.getCodeList());
    }
    text = jsonObject.getString("logLevel");
    if (text != null) {
        logLevel = ScriptLog.LOG_LEVEL_CODES.getId(text);
        if (logLevel == -1)
            throw new TranslatableJsonException("emport.error.invalid", "logLevel", text, ScriptLog.LOG_LEVEL_CODES.getCodeList());
    } else {
        logLevel = ScriptLog.LogLevel.NONE;
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 29 with TranslatableJsonException

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

the class PointLinkEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject pointLink = jsonValue.toJsonObject();
    PointLinkDao pointLinkDao = PointLinkDao.instance;
    String xid = pointLink.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = pointLinkDao.generateUniqueXid();
    PointLinkVO vo = pointLinkDao.getPointLink(xid);
    if (vo == null) {
        vo = new PointLinkVO();
        vo.setXid(xid);
    }
    try {
        importContext.getReader().readInto(vo, pointLink);
        // 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.pointLink.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = vo.isNew();
            RTMDefinition.instance.savePointLink(vo);
            importContext.addSuccessMessage(isnew, "emport.pointLink.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.pointLink.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.pointLink.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 30 with TranslatableJsonException

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

the class WatchlistEmportDefinitionNoCase method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject watchListJson = jsonValue.toJsonObject();
    String xid = watchListJson.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = WatchListDao.instance.generateUniqueXid();
    WatchListVO watchList = WatchListDao.instance.getWatchList(xid);
    if (watchList == null) {
        watchList = new WatchListVO();
        watchList.setXid(xid);
    }
    try {
        importContext.getReader().readInto(watchList, watchListJson);
        // Now validate it. Use a new response object so we can distinguish errors in this user from other
        // errors.
        ProcessResult watchListResponse = new ProcessResult();
        watchList.validate(watchListResponse);
        if (watchListResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(watchListResponse, "emport.watchList.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = watchList.getId() == Common.NEW_ID;
            WatchListDao.instance.saveWatchList(watchList);
            importContext.addSuccessMessage(isnew, "emport.watchList.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.watchList.prefix", xid, importContext.getJsonExceptionMessage(e));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonObject(com.serotonin.json.type.JsonObject) 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