Search in sources :

Example 21 with TranslatableJsonException

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

the class VirtualSerialPortConfigResolver method resolve.

@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
    if (jsonValue == null)
        return null;
    JsonObject json = jsonValue.toJsonObject();
    String text = json.getString("type");
    if (text == null)
        throw new TranslatableJsonException("emport.error.virtual.comm.missing", "type", VirtualSerialPortConfig.PORT_TYPE_CODES);
    return findClass(text);
}
Also used : JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 22 with TranslatableJsonException

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

the class CompoundDetectorEventType method getCompoundEventDetectorId.

protected int getCompoundEventDetectorId(JsonObject json, String name) throws JsonException {
    String xid = json.getString(name);
    if (xid == null)
        throw new TranslatableJsonException("emport.error.eventType.missing.reference", name);
    CompoundEventDetectorVO ced = new CompoundEventDetectorDao().getCompoundEventDetector(xid);
    if (ced == null)
        throw new TranslatableJsonException("emport.error.eventType.invalid.reference", name, xid);
    return ced.getId();
}
Also used : CompoundEventDetectorDao(com.serotonin.m2m2.db.dao.CompoundEventDetectorDao) CompoundEventDetectorVO(com.serotonin.m2m2.vo.event.CompoundEventDetectorVO) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 23 with TranslatableJsonException

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

the class EventType method getPointEventDetectorId.

protected int getPointEventDetectorId(JsonObject json, int dpId, String pedName) throws JsonException {
    String pedXid = json.getString(pedName);
    if (pedXid == null)
        throw new TranslatableJsonException("emport.error.eventType.missing.reference", pedName);
    int id = EventDetectorDao.instance.getId(pedXid, dpId);
    if (id == -1)
        throw new TranslatableJsonException("emport.error.eventType.invalid.reference", pedName, pedXid);
    return id;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 24 with TranslatableJsonException

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

the class EventType method getDataSource.

protected DataSourceVO<?> getDataSource(JsonObject json, String name) throws JsonException {
    String xid = json.getString(name);
    if (xid == null)
        throw new TranslatableJsonException("emport.error.eventType.missing.reference", name);
    DataSourceVO<?> ds = DataSourceDao.instance.getDataSource(xid);
    if (ds == null)
        throw new TranslatableJsonException("emport.error.eventType.invalid.reference", name, xid);
    return ds;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 25 with TranslatableJsonException

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

the class EventTypeResolver method resolve.

@Override
public Type resolve(JsonValue jsonValue) throws JsonException {
    if (jsonValue == null)
        throw new TranslatableJsonException("emport.error.eventType.null");
    JsonObject json = jsonValue.toJsonObject();
    String text = json.getString("sourceType");
    if (text == null)
        throw new TranslatableJsonException("emport.error.eventType.missing", "sourceType", EventType.SOURCE_NAMES.getCodeList());
    if (!EventType.SOURCE_NAMES.hasCode(text))
        throw new TranslatableJsonException("emport.error.eventType.invalid", "sourceType", text, EventType.SOURCE_NAMES.getCodeList());
    if (text.equalsIgnoreCase(EventTypeNames.DATA_POINT))
        return DataPointEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.DATA_SOURCE))
        return DataSourceEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.SYSTEM))
        return SystemEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.PUBLISHER))
        return PublisherEventType.class;
    if (text.equalsIgnoreCase(EventTypeNames.AUDIT))
        return AuditEventType.class;
    EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(text);
    if (def != null)
        return def.getEventTypeClass();
    return null;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonObject(com.serotonin.json.type.JsonObject) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition)

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