Skip to content

Commit

Permalink
Simplify and add ElectricalConnectionPermitted
Browse files Browse the repository at this point in the history
- Remove delete option from updates via ID, use update via filter if needed
- Add support for ElectricalConnectionPermittedValueSet updates
  • Loading branch information
DerAndereAndi committed Oct 1, 2024
1 parent 5f72326 commit 51d4e2c
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 78 deletions.
45 changes: 33 additions & 12 deletions api/featuresserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ type DeviceDiagnosisServerInterface interface {
SetLocalState(operatingState *model.DeviceDiagnosisStateDataType)
}

type ElectricalConnectionPermittedValueSetForID struct {
Data model.ElectricalConnectionPermittedValueSetDataType
ElectricalConnectionId model.ElectricalConnectionIdType
ParameterId model.ElectricalConnectionParameterIdType
}

type ElectricalConnectionPermittedValueSetForFilter struct {
Data model.ElectricalConnectionPermittedValueSetDataType
Filter model.ElectricalConnectionParameterDescriptionDataType
}

type ElectricalConnectionServerInterface interface {
ElectricalConnectionCommonInterface

Expand Down Expand Up @@ -77,6 +88,24 @@ type ElectricalConnectionServerInterface interface {
data model.ElectricalConnectionCharacteristicDataType,
deleteElements *model.ElectricalConnectionCharacteristicDataElementsType,
) error

// Set or update data set for a parameterId
//
// Will return an error if the data set could not be updated
UpdatePermittedValueSetForIds(
data []ElectricalConnectionPermittedValueSetForID,
) error

// Set or update data set for a filter
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdatePermittedValueSetForFilters(
data []ElectricalConnectionPermittedValueSetForFilter,
deleteSelector *model.ElectricalConnectionPermittedValueSetListDataSelectorsType,
deleteElements *model.ElectricalConnectionPermittedValueSetDataElementsType,
) error
}

type LoadControlLimitDataForID struct {
Expand All @@ -100,19 +129,15 @@ type LoadControlServerInterface interface {
) *model.LoadControlLimitIdType

// Set or update data set for a limitId
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdateLimitDataForIds(
data []LoadControlLimitDataForID,
deleteId *model.LoadControlLimitIdType,
deleteElements *model.LoadControlLimitDataElementsType,
) error

// Set or update data set for a filter
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdateLimitDataForFilter(
Expand Down Expand Up @@ -143,19 +168,15 @@ type MeasurementServerInterface interface {
) *model.MeasurementIdType

// Set or update data set for a measurementId
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdateDataForIds(
data []MeasurementDataForID,
deleteId *model.MeasurementIdType,
deleteElements *model.MeasurementDataElementsType,
) error

// Set or update data set for a filter
// Selector provided in deleteSelector will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Selector
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
UpdateDataForFilters(
Expand Down
73 changes: 73 additions & 0 deletions features/server/electricalconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"errors"

"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/features/internal"
spineapi "github.com/enbility/spine-go/api"
"github.com/enbility/spine-go/model"
Expand Down Expand Up @@ -183,3 +184,75 @@ func (e *ElectricalConnection) UpdateCharacteristic(

return nil
}

// Set or update data set for a electricalConnectiontId
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (e *ElectricalConnection) UpdatePermittedValueSetForIds(
data []api.ElectricalConnectionPermittedValueSetForID,
) (resultErr error) {
var filterData []api.ElectricalConnectionPermittedValueSetForFilter
for index, item := range data {
filterData = append(filterData, api.ElectricalConnectionPermittedValueSetForFilter{
Data: item.Data,
Filter: model.ElectricalConnectionParameterDescriptionDataType{
ElectricalConnectionId: &data[index].ElectricalConnectionId,
ParameterId: &data[index].ParameterId,
},
})
}

return e.UpdatePermittedValueSetForFilters(filterData, nil, nil)
}

// Set or update data set for a filter
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (e *ElectricalConnection) UpdatePermittedValueSetForFilters(
data []api.ElectricalConnectionPermittedValueSetForFilter,
deleteSelector *model.ElectricalConnectionPermittedValueSetListDataSelectorsType,
deleteElements *model.ElectricalConnectionPermittedValueSetDataElementsType,
) (resultErr error) {
resultErr = api.ErrDataNotAvailable

var permittedData []model.ElectricalConnectionPermittedValueSetDataType

for _, item := range data {
descriptions, err := e.GetParameterDescriptionsForFilter(item.Filter)
if err != nil || descriptions == nil || len(descriptions) != 1 {
return
}

description := descriptions[0]
item.Data.ParameterId = description.ParameterId

permittedData = append(permittedData, item.Data)
}

partial := model.NewFilterTypePartial()

datalist := &model.ElectricalConnectionPermittedValueSetListDataType{
ElectricalConnectionPermittedValueSetData: permittedData,
}

var deleteFilter *model.FilterType
if deleteSelector != nil {
deleteFilter = &model.FilterType{
ElectricalConnectionPermittedValueSetListDataSelectors: deleteSelector,
}

if deleteElements != nil {
deleteFilter.ElectricalConnectionPermittedValueSetDataElements = deleteElements
}
}

if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, datalist, partial, deleteFilter); err != nil {
return errors.New(err.String())
}

return nil
}
17 changes: 3 additions & 14 deletions features/server/loadcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ func (l *LoadControl) AddLimitDescription(
}

// Set or update data set for a limitId
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (l *LoadControl) UpdateLimitDataForIds(
data []api.LoadControlLimitDataForID,
deleteId *model.LoadControlLimitIdType,
deleteElements *model.LoadControlLimitDataElementsType,
) (resultErr error) {
var filterData []api.LoadControlLimitDataForFilter
for index, item := range data {
Expand All @@ -88,19 +84,12 @@ func (l *LoadControl) UpdateLimitDataForIds(
})
}

var deleteSelector *model.LoadControlLimitListDataSelectorsType
if deleteId != nil {
deleteSelector = &model.LoadControlLimitListDataSelectorsType{
LimitId: deleteId,
}
}

return l.UpdateLimitDataForFilters(filterData, deleteSelector, deleteElements)
return l.UpdateLimitDataForFilters(filterData, nil, nil)
}

// Set or update data set for a filter
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (l *LoadControl) UpdateLimitDataForFilters(
Expand Down
7 changes: 5 additions & 2 deletions features/server/loadcontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,14 @@ func (s *LoadControlSuite) Test_GetLimitData() {
assert.NotNil(s.T(), err)
assert.Nil(s.T(), result)

dataIds := []api.LoadControlLimitDataForID{}
dataIds := []api.LoadControlLimitDataForFilter{}
deleteSelectors := &model.LoadControlLimitListDataSelectorsType{
LimitId: limitId,
}
deleteElements := &model.LoadControlLimitDataElementsType{
TimePeriod: &model.TimePeriodElementsType{},
}
err = s.sut.UpdateLimitDataForIds(dataIds, limitId, deleteElements)
err = s.sut.UpdateLimitDataForFilters(dataIds, deleteSelectors, deleteElements)
assert.Nil(s.T(), err)

result, err = s.sut.GetLimitDataForId(*limitId)
Expand Down
17 changes: 3 additions & 14 deletions features/server/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,10 @@ func (m *Measurement) AddDescription(
}

// Set or update data set for a measurementId
// Id provided in deleteId will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (m *Measurement) UpdateDataForIds(
data []api.MeasurementDataForID,
deleteId *model.MeasurementIdType,
deleteElements *model.MeasurementDataElementsType,
) (resultErr error) {
var filterData []api.MeasurementDataForFilter
for index, item := range data {
Expand All @@ -90,19 +86,12 @@ func (m *Measurement) UpdateDataForIds(
})
}

var deleteSelector *model.MeasurementListDataSelectorsType
if deleteId != nil {
deleteSelector = &model.MeasurementListDataSelectorsType{
MeasurementId: deleteId,
}
}

return m.UpdateDataForFilters(filterData, deleteSelector, deleteElements)
return m.UpdateDataForFilters(filterData, nil, nil)
}

// Set or update data set for a filter
// Selector provided in deleteSelector will trigger removal of matching items from the data set before the update
// Elements provided in deleteElement will limit the fields to be removed using Selector
// deleteSelector will trigger removal of matching items from the data set before the update
// deleteElement will limit the fields to be removed using Id
//
// Will return an error if the data set could not be updated
func (m *Measurement) UpdateDataForFilters(
Expand Down
7 changes: 5 additions & 2 deletions features/server/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,14 @@ func (s *MeasurementSuite) Test_GetLimitData() {
assert.NotNil(s.T(), err)
assert.Nil(s.T(), result)

dataIds := []api.MeasurementDataForID{}
dataIds := []api.MeasurementDataForFilter{}
deleteSelectors := &model.MeasurementListDataSelectorsType{
MeasurementId: mId,
}
deleteElements := &model.MeasurementDataElementsType{
Value: util.Ptr(model.ElementTagType{}),
}
err = s.sut.UpdateDataForIds(dataIds, mId, deleteElements)
err = s.sut.UpdateDataForFilters(dataIds, deleteSelectors, deleteElements)
assert.Nil(s.T(), err)

result, err = s.sut.GetDataForId(*mId)
Expand Down
100 changes: 98 additions & 2 deletions mocks/ElectricalConnectionServerInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 51d4e2c

Please sign in to comment.