Skip to content
Snippets Groups Projects
Commit cd27431f authored by florian's avatar florian
Browse files

FIX: Use correct ValueCase in getValue

parent cd37d913
No related branches found
No related tags found
1 merge request!1ENH: Add property and entity classes
...@@ -37,23 +37,15 @@ function _getScalarValue(value) { ...@@ -37,23 +37,15 @@ function _getScalarValue(value) {
return value.getBooleanValue(); return value.getBooleanValue();
case valueCases.STRING_VALUE: case valueCases.STRING_VALUE:
return value.getStringValue(); return value.getStringValue();
case valueCases.SPECIAL_VALUE:
return value.getSpecialValue();
default: default:
throw `Unkown value type ${value.getScalarValueCase()}.`; throw `Unkown value type ${value.getScalarValueCase()}.`;
} }
} }
function _getListValue(listDataType, values) { function _getListValue(values) {
const listCases = api.v1.ListDataType.ListDataTypeCase;
switch (listDataType.getListDataTypeCase()) {
case listCases.LIST_DATA_TYPE_NOT_SET:
return undefined;
case listCases.ATOMIC_DATA_TYPE:
return values.map(value => _getScalarValue(value));
case listCases.REFERENCE_DATA_TYPE:
return values.map(value => _getScalarValue(value)); return values.map(value => _getScalarValue(value));
default:
throw `Unknown list data type ${listDataType.getListDataTypeCase()}.`
}
} }
export class Property { export class Property {
...@@ -80,19 +72,16 @@ export class Property { ...@@ -80,19 +72,16 @@ export class Property {
// Empty values are undefined regardless of data type // Empty values are undefined regardless of data type
return undefined; return undefined;
} }
const wrappedDataType = this.wrappedProperty.getDataType(); const valueCases = api.v1.Value.ValueCase;
const dtypeCases = api.v1.DataType.DataTypeCase; switch (wrappedValue.getValueCase()) {
switch (wrappedDataType.getDataTypeCase()) { case valueCases.VALUE_NOT_SET:
case dtypeCases.DATA_TYPE_NOT_SET:
return undefined; return undefined;
case dtypeCases.ATOMIC_DATA_TYPE: case valueCases.SCALAR_VALUE:
return _getScalarValue(wrappedValue.getScalarValue());
case dtypeCases.LIST_DATA_TYPE:
return _getListValue(wrappedDataType.getListDataType(), wrappedValue.getListValues().getValuesList());
case dtypeCases.REFERENCE_DATA_TYPE:
return _getScalarValue(wrappedValue.getScalarValue()); return _getScalarValue(wrappedValue.getScalarValue());
case valueCases.LIST_VALUES:
return _getListValue(wrappedValue.getListValues().getValuesList());
default: default:
throw `Unknown data type ${wrappedDataType.getDataTypeCase()}.`; throw `Unknown value type ${wrappedValue.getValueCase()}.`;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment