Search in sources :

Example 31 with TranslatableJsonException

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

the class MaintenanceEventEmportDefinition method doImport.

@Override
public void doImport(JsonValue jsonValue, ImportContext importContext) throws JsonException {
    MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();
    JsonObject maintenanceEvent = jsonValue.toJsonObject();
    String xid = maintenanceEvent.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = maintenanceEventDao.generateUniqueXid();
    MaintenanceEventVO vo = maintenanceEventDao.getMaintenanceEvent(xid);
    if (vo == null) {
        vo = new MaintenanceEventVO();
        vo.setXid(xid);
    }
    try {
        importContext.getReader().readInto(vo, maintenanceEvent);
        // 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.maintenanceEvent.prefix", xid);
        else {
            // Sweet. Save it.
            boolean isnew = vo.isNew();
            RTMDefinition.instance.saveMaintenanceEvent(vo);
            importContext.addSuccessMessage(isnew, "emport.maintenanceEvent.prefix", xid);
        }
    } catch (TranslatableJsonException e) {
        importContext.getResult().addGenericMessage("emport.maintenanceEvent.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        importContext.getResult().addGenericMessage("emport.maintenanceEvent.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 32 with TranslatableJsonException

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

the class EnvCanPointLocatorVO 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 33 with TranslatableJsonException

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

the class ImageSetComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonValue jsonImageId = jsonObject.get("imageSet");
    if (jsonImageId != null) {
        String id = jsonImageId.toString();
        imageSet = Common.getImageSet(id);
        if (imageSet == null)
            throw new TranslatableJsonException("emport.error.component.unknownImageSet", id, Common.getImageSetIds());
    }
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 34 with TranslatableJsonException

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

the class ViewComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("updatePeriodType");
    if (text == null) {
        // Disable the update feature
        updatePeriodType = Common.TimePeriods.MINUTES;
        updatePeriods = 0;
    } else {
        updatePeriodType = Common.TIME_PERIOD_CODES.getId(text, Common.TimePeriods.MILLISECONDS, Common.TimePeriods.MONTHS, Common.TimePeriods.YEARS);
        if (updatePeriodType == -1)
            throw new TranslatableJsonException("emport.error.component.invalid", "updatePeriodType", text, Common.TIME_PERIOD_CODES.getCodeList(Common.TimePeriods.MILLISECONDS, Common.TimePeriods.MONTHS, Common.TimePeriods.YEARS));
    }
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 35 with TranslatableJsonException

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

the class DynamicGraphicComponent method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    super.jsonRead(reader, jsonObject);
    JsonValue jsonImageId = jsonObject.get("dynamicImage");
    if (jsonImageId != null) {
        String id = jsonImageId.toString();
        dynamicImage = Common.getDynamicImage(id);
        if (dynamicImage == null)
            throw new TranslatableJsonException("emport.error.component.unknownDynamicImage", id, Common.getDynamicImageIds());
    }
}
Also used : JsonValue(com.serotonin.json.type.JsonValue) 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