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());
}
}
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;
}
Aggregations