Search in sources :

Example 1 with RestRecord

use of org.openmuc.framework.lib.rest.objects.RestRecord in project OpenMUC by isc-konstanz.

the class FromJson method convertRecord.

public static Record convertRecord(RestRecord rrc, ValueType type) throws ClassCastException {
    Object value = rrc.getValue();
    Flag flag = rrc.getFlag();
    Value retValue = null;
    if (value != null) {
        retValue = convertValue(value, type);
    }
    if (flag == null) {
        return new Record(retValue, rrc.getTimestamp());
    } else {
        return new Record(retValue, rrc.getTimestamp(), rrc.getFlag());
    }
}
Also used : ByteArrayValue(org.openmuc.framework.data.ByteArrayValue) StringValue(org.openmuc.framework.data.StringValue) Value(org.openmuc.framework.data.Value) FloatValue(org.openmuc.framework.data.FloatValue) DoubleValue(org.openmuc.framework.data.DoubleValue) ByteValue(org.openmuc.framework.data.ByteValue) ShortValue(org.openmuc.framework.data.ShortValue) RestValue(org.openmuc.framework.lib.rest.objects.RestValue) BooleanValue(org.openmuc.framework.data.BooleanValue) LongValue(org.openmuc.framework.data.LongValue) IntValue(org.openmuc.framework.data.IntValue) JsonObject(com.google.gson.JsonObject) RestRecord(org.openmuc.framework.lib.rest.objects.RestRecord) Record(org.openmuc.framework.data.Record) Flag(org.openmuc.framework.data.Flag)

Example 2 with RestRecord

use of org.openmuc.framework.lib.rest.objects.RestRecord in project OpenMUC by isc-konstanz.

the class ToJson method getRestRecord.

private RestRecord getRestRecord(Record rc, ValueType valueType) throws ClassCastException {
    Value value = rc.getValue();
    Flag flag = rc.getFlag();
    RestRecord rrc = new RestRecord();
    rrc.setTimestamp(rc.getTimestamp());
    try {
        flag = getFlag(value, valueType, flag);
    } catch (TypeConversionException e) {
        flag = Flag.DRIVER_ERROR_CHANNEL_VALUE_TYPE_CONVERSION_EXCEPTION;
    }
    if (flag != Flag.VALID) {
        rrc.setFlag(flag);
        rrc.setValue(null);
        return rrc;
    }
    rrc.setFlag(flag);
    if (value == null) {
        rrc.setValue(null);
        return rrc;
    }
    switch(valueType) {
        case FLOAT:
            rrc.setValue(value.asFloat());
            break;
        case DOUBLE:
            rrc.setValue(value.asDouble());
            break;
        case SHORT:
            rrc.setValue(value.asShort());
            break;
        case INTEGER:
            rrc.setValue(value.asInt());
            break;
        case LONG:
            rrc.setValue(value.asLong());
            break;
        case BYTE:
            rrc.setValue(value.asByte());
            break;
        case BOOLEAN:
            rrc.setValue(value.asBoolean());
            break;
        case BYTE_ARRAY:
            rrc.setValue(value.asByteArray());
            break;
        case STRING:
            rrc.setValue(value.asString());
            break;
        default:
            rrc.setValue(null);
            break;
    }
    return rrc;
}
Also used : TypeConversionException(org.openmuc.framework.data.TypeConversionException) Value(org.openmuc.framework.data.Value) Flag(org.openmuc.framework.data.Flag) RestRecord(org.openmuc.framework.lib.rest.objects.RestRecord)

Aggregations

Flag (org.openmuc.framework.data.Flag)2 Value (org.openmuc.framework.data.Value)2 RestRecord (org.openmuc.framework.lib.rest.objects.RestRecord)2 JsonObject (com.google.gson.JsonObject)1 BooleanValue (org.openmuc.framework.data.BooleanValue)1 ByteArrayValue (org.openmuc.framework.data.ByteArrayValue)1 ByteValue (org.openmuc.framework.data.ByteValue)1 DoubleValue (org.openmuc.framework.data.DoubleValue)1 FloatValue (org.openmuc.framework.data.FloatValue)1 IntValue (org.openmuc.framework.data.IntValue)1 LongValue (org.openmuc.framework.data.LongValue)1 Record (org.openmuc.framework.data.Record)1 ShortValue (org.openmuc.framework.data.ShortValue)1 StringValue (org.openmuc.framework.data.StringValue)1 TypeConversionException (org.openmuc.framework.data.TypeConversionException)1 RestValue (org.openmuc.framework.lib.rest.objects.RestValue)1