Search in sources :

Example 36 with TranslatableJsonException

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

the class ImageChartComponent 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.chart.missing", "durationType", Common.TIME_PERIOD_CODES.getCodeList());
    durationType = Common.TIME_PERIOD_CODES.getId(text);
    if (durationType == -1)
        throw new TranslatableJsonException("emport.error.chart.invalid", "durationType", text, Common.TIME_PERIOD_CODES.getCodeList());
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 37 with TranslatableJsonException

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

the class GraphicalView method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    if (isNew()) {
        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 components = jsonObject.getJsonArray("viewComponents");
    if (components != null) {
        viewComponents.clear();
        for (JsonValue jv : components) addViewComponent(reader.read(ViewComponent.class, jv));
    }
    String text = jsonObject.getString("anonymousAccess");
    if (text != null) {
        anonymousAccess = ShareUser.ACCESS_CODES.getId(text);
        if (anonymousAccess == -1)
            throw new TranslatableJsonException("emport.error.invalid", "anonymousAccess", text, ShareUser.ACCESS_CODES.getCodeList());
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) ShareUser(com.serotonin.m2m2.view.ShareUser) User(com.serotonin.m2m2.vo.User) JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 38 with TranslatableJsonException

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

the class GraphicalViewEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    JsonObject viewJson = jsonValue.toJsonObject();
    String xid = viewJson.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = graphicalViewDao.generateUniqueXid();
    ensureDao();
    GraphicalView view = graphicalViewDao.getViewByXid(xid);
    if (view == null) {
        view = new GraphicalView();
        view.setXid(xid);
    }
    try {
        importContext.getReader().readInto(view, viewJson);
        // Now validate it. Use a new response object so we can distinguish errors in this view from other
        // errors.
        ProcessResult viewResponse = new ProcessResult();
        view.validate(viewResponse);
        if (viewResponse.getHasMessages())
            // Too bad. Copy the errors into the actual response.
            importContext.copyValidationMessages(viewResponse, "emport.view.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = view.isNew();
            graphicalViewDao.saveView(view);
            importContext.addSuccessMessage(isnew, "emport.view.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.view.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.view.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 39 with TranslatableJsonException

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

the class CompoundComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonObject jsonChildren = jsonObject.getJsonObject("children");
    if (jsonChildren != null) {
        for (Map.Entry<String, JsonValue> jsonChild : jsonChildren.entrySet()) {
            CompoundChild child = getChild(jsonChild.getKey());
            if (child == null || !child.getViewComponent().isPointComponent())
                throw new TranslatableJsonException("emport.error.compound.invalidChildId", jsonChild.getKey(), definition().getId(), getPointComponentChildIds());
            jsonReadDataPoint(jsonChild.getValue(), (PointComponent) child.getViewComponent());
        }
    }
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with TranslatableJsonException

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

the class MultistateGraphicComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonArray jsonStateList = jsonObject.getJsonArray("stateImageMappings");
    if (jsonStateList != null) {
        stateImageMap.clear();
        for (JsonValue jv : jsonStateList) {
            JsonObject jsonMapping = jv.toJsonObject();
            Integer state = jsonMapping.getInt("state");
            if (state == null)
                throw new TranslatableJsonException("emport.error.missingValue", "state");
            Integer index = jsonMapping.getInt("imageIndex");
            if (index == null)
                throw new TranslatableJsonException("emport.error.missingValue", "index");
            stateImageMap.put(state, index);
        }
    }
}
Also used : JsonArray(com.serotonin.json.type.JsonArray) JsonValue(com.serotonin.json.type.JsonValue) 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