diff --git a/go.mod b/go.mod index 5e230c3740..bc7c7c9d90 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/eclipse/paho.mqtt.golang v1.5.0 github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.66 github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.19 - github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.51 + github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.53 github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.40 github.com/edgexfoundry/go-mod-secrets/v3 v3.2.0-dev.18 github.com/fxamacker/cbor/v2 v2.7.0 diff --git a/go.sum b/go.sum index 0908b37137..9e6f3662c9 100644 --- a/go.sum +++ b/go.sum @@ -88,8 +88,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.66 h1:kmBEAhNi4ftrJMXM3Iv github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.66/go.mod h1:3IXVpc5Qez5nwFJ8IkMyJMba8Iavj620E0XB42BQzfQ= github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.19 h1:274NZdVBkJBuQP6yT3tVrb7psTFuIPogX/DLQqv7OCQ= github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.19/go.mod h1:BG6hCDxXizpgMdNEljwNfLWSsd4Op7GAHd3Pis1dVv8= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.51 h1:X73zP3/kgOGTXIRRxOMSGr174GrhxwuCfeBs+cCIudM= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.51/go.mod h1:MLk37/79M26+bZr3IptNZuYmQBEVbXwzDp1VHQkFhIk= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.53 h1:aHnYwqpg0LcnMrgNQlkRQjzHAS/IML/9GI368OmNCz4= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.53/go.mod h1:MLk37/79M26+bZr3IptNZuYmQBEVbXwzDp1VHQkFhIk= github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.40 h1:YyB21HEapV5pENG01vFlpjPI6UkmKpJuaWFfgGFVUsY= github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.40/go.mod h1:8NpZ6/eAsiyZHgn/s3DRIpcOjUrve+ZONIgvcDvA3Yg= github.com/edgexfoundry/go-mod-registry/v3 v3.2.0-dev.18 h1:AzILZ/xcEmSYVhIwSF4zkWpXyFoBA733E/j8ttzlNnI= diff --git a/internal/core/data/controller/http/event_test.go b/internal/core/data/controller/http/event_test.go index 3c4428e940..a1e1661dc1 100644 --- a/internal/core/data/controller/http/event_test.go +++ b/internal/core/data/controller/http/event_test.go @@ -38,7 +38,6 @@ import ( var expectedEventId = uuid.New().String() -var testReadingValue = "45" var testReading = dtos.BaseReading{ DeviceName: TestDeviceName, ResourceName: TestDeviceResourceName, @@ -46,7 +45,7 @@ var testReading = dtos.BaseReading{ Origin: TestOriginTime, ValueType: common.ValueTypeUint8, SimpleReading: dtos.SimpleReading{ - Value: &testReadingValue, + Value: "45", }, } @@ -163,8 +162,7 @@ func TestAddEvent(t *testing.T) { noSimpleValue := validRequest noSimpleValue.Event.Readings = []dtos.BaseReading{testReading} - emptyStr := "" - noSimpleValue.Event.Readings[0].Value = &emptyStr + noSimpleValue.Event.Readings[0].Value = "" noBinaryValue := validRequest noBinaryValue.Event.Readings = []dtos.BaseReading{{ DeviceName: TestDeviceName, diff --git a/internal/pkg/infrastructure/redis/reading.go b/internal/pkg/infrastructure/redis/reading.go index c4022926d6..9d3067ba6d 100644 --- a/internal/pkg/infrastructure/redis/reading.go +++ b/internal/pkg/infrastructure/redis/reading.go @@ -121,6 +121,13 @@ func addReading(conn redis.Conn, r models.Reading) (reading models.Reading, edge } m, err = json.Marshal(newReading) reading = newReading + case models.NullReading: + baseReading = &newReading.BaseReading + if err = checkReadingValue(baseReading); err != nil { + return nil, errors.NewCommonEdgeXWrapper(err) + } + m, err = json.Marshal(newReading) + reading = newReading default: return nil, errors.NewCommonEdgeX(errors.KindContractInvalid, "unsupported reading type", nil) } @@ -277,6 +284,7 @@ func readingsByDeviceNameAndTimeRange(conn redis.Conn, deviceName string, startT func convertObjectsToReadings(objects [][]byte) (readings []models.Reading, edgeXerr errors.EdgeX) { readings = make([]models.Reading, len(objects)) var alias struct { + Value any ValueType string } for i, in := range objects { @@ -284,7 +292,15 @@ func convertObjectsToReadings(objects [][]byte) (readings []models.Reading, edge if err != nil { return []models.Reading{}, errors.NewCommonEdgeX(errors.KindDatabaseError, "reading format parsing failed from the database", err) } - if alias.ValueType == common.ValueTypeBinary { + if alias.Value == nil { + var nullReading models.NullReading + err = json.Unmarshal(in, &nullReading) + if err != nil { + return []models.Reading{}, errors.NewCommonEdgeX(errors.KindDatabaseError, "simple reading format parsing failed from the database", err) + } + readings[i] = nullReading + continue + } else if alias.ValueType == common.ValueTypeBinary { var binaryReading models.BinaryReading err = json.Unmarshal(in, &binaryReading) if err != nil { diff --git a/internal/pkg/infrastructure/redis/reading_test.go b/internal/pkg/infrastructure/redis/reading_test.go index e59199476e..45ca34e199 100644 --- a/internal/pkg/infrastructure/redis/reading_test.go +++ b/internal/pkg/infrastructure/redis/reading_test.go @@ -68,10 +68,25 @@ func objectReadingData() models.ObjectReading { } } +func nullReadingData() models.NullReading { + return models.NullReading{ + BaseReading: models.BaseReading{ + Id: exampleUUID, + Origin: 1616728256236000000, + DeviceName: testDeviceName, + ProfileName: testProfileName, + ResourceName: testResourceName, + ValueType: common.ValueTypeFloat32, + }, + Value: nil, + } +} + func TestConvertObjectsToReadings(t *testing.T) { simpleReading := simpleReadingData() binaryReading := binaryReadingData() objectReading := objectReadingData() + nullReading := nullReadingData() simpleReadingBytes, err := json.Marshal(simpleReading) require.NoError(t, err) @@ -79,10 +94,12 @@ func TestConvertObjectsToReadings(t *testing.T) { require.NoError(t, err) objectReadingBytes, err := json.Marshal(objectReading) require.NoError(t, err) + nullReadingBytes, err := json.Marshal(nullReading) + require.NoError(t, err) - readingsData := [][]byte{simpleReadingBytes, binaryReadingBytes, objectReadingBytes} + readingsData := [][]byte{simpleReadingBytes, binaryReadingBytes, objectReadingBytes, nullReadingBytes} expectedReadings := []models.Reading{ - simpleReading, binaryReading, objectReading, + simpleReading, binaryReading, objectReading, nullReading, } events, err := convertObjectsToReadings(readingsData)