Search in sources :

Example 51 with TranslatableJsonException

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

the class AnalogAttractorChangeVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    String text = jsonObject.getString("attractionPointId");
    if (text != null) {
        DataPointVO dp = DataPointDao.instance.getDataPoint(text);
        if (dp == null)
            throw new TranslatableJsonException("virtual.error.attractor.missingPoint", "attractionPointId", text);
        attractionPointId = dp.getId();
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 52 with TranslatableJsonException

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

the class WatchListEmportDefinition 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.save(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)

Example 53 with TranslatableJsonException

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

the class VirtualPointLocatorVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    Integer value = readDataType(jsonObject, DataTypes.IMAGE);
    if (value != null)
        dataTypeId = value;
    JsonObject ctjson = jsonObject.getJsonObject("changeType");
    if (ctjson == null)
        throw new TranslatableJsonException("emport.error.missingObject", "changeType");
    String text = ctjson.getString("type");
    if (text == null)
        throw new TranslatableJsonException("emport.error.missing", "type", ChangeTypeVO.CHANGE_TYPE_CODES.getCodeList());
    changeTypeId = ChangeTypeVO.CHANGE_TYPE_CODES.getId(text);
    if (changeTypeId == -1)
        throw new TranslatableJsonException("emport.error.invalid", "changeType", text, ChangeTypeVO.CHANGE_TYPE_CODES.getCodeList());
    reader.readInto(getChangeType(), ctjson);
}
Also used : JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 54 with TranslatableJsonException

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

the class WatchListVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    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 jsonDataPoints = jsonObject.getJsonArray("dataPoints");
    if (jsonDataPoints != null) {
        pointList.clear();
        DataPointDao dataPointDao = DataPointDao.instance;
        for (JsonValue jv : jsonDataPoints) {
            String xid = jv.toString();
            DataPointVO dpVO = dataPointDao.getDataPoint(xid);
            if (dpVO == null)
                throw new TranslatableJsonException("emport.error.missingPoint", xid);
            pointList.add(dpVO);
        }
    }
    JsonObject o = jsonObject.getJsonObject("data");
    if (o != null)
        this.data = o.toMap();
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject)

Example 55 with TranslatableJsonException

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

the class EmportDwr method importData.

@DwrPermission(admin = true)
public ProcessResult importData(String data) {
    ProcessResult response = new ProcessResult();
    Translations translations = getTranslations();
    User user = Common.getHttpUser();
    JsonTypeReader reader = new JsonTypeReader(data);
    try {
        JsonValue value = reader.read();
        if (value instanceof JsonObject) {
            JsonObject root = value.toJsonObject();
            ImportTask importTask = new ImportTask(root, translations, user, true);
            user.setImportTask(importTask);
            response.addData("importStarted", true);
        } else {
            response.addGenericMessage("emport.invalidImportData");
        }
    } catch (ClassCastException e) {
        response.addGenericMessage("emport.parseError", e.getMessage());
    } catch (TranslatableJsonException e) {
        response.addMessage(e.getMsg());
    } catch (IOException e) {
        response.addGenericMessage("emport.parseError", e.getMessage());
    } catch (JsonException e) {
        response.addGenericMessage("emport.parseError", e.getMessage());
    }
    return response;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) User(com.serotonin.m2m2.vo.User) ImportTask(com.serotonin.m2m2.web.dwr.emport.ImportTask) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) IOException(java.io.IOException) Translations(com.serotonin.m2m2.i18n.Translations) JsonTypeReader(com.serotonin.json.type.JsonTypeReader) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

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