Skip to content

Commit

Permalink
Merge pull request #952 from jinlinGuan/issue-591
Browse files Browse the repository at this point in the history
feat: Add more extendable fields to dtos/models for v4
  • Loading branch information
cloudxxx8 authored Nov 19, 2024
2 parents d6cbbad + b4b29ec commit 32807ec
Show file tree
Hide file tree
Showing 38 changed files with 594 additions and 285 deletions.
13 changes: 13 additions & 0 deletions clients/http/deviceservicecommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ func TestSetCommandWithObject(t *testing.T) {
assert.Equal(t, requestId, res.RequestId)
}

func TestDiscovery(t *testing.T) {
requestId := uuid.New().String()
expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusAccepted)
ts := newTestServer(http.MethodPost, common.ApiDiscoveryRoute, expectedResponse)
defer ts.Close()

client := NewDeviceServiceCommandClient(NewNullAuthenticationInjector(), false)
res, err := client.Discovery(context.Background(), ts.URL)

require.NoError(t, err)
assert.Equal(t, requestId, res.RequestId)
}

func TestProfileScan(t *testing.T) {
requestId := uuid.New().String()
expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusAccepted)
Expand Down
53 changes: 48 additions & 5 deletions clients/http/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"path"
"strconv"
"strings"

"github.com/edgexfoundry/go-mod-core-contracts/v4/clients/http/utils"
"github.com/edgexfoundry/go-mod-core-contracts/v4/clients/interfaces"
Expand Down Expand Up @@ -66,11 +67,12 @@ func (client *NotificationClient) DeleteNotificationById(ctx context.Context, id
}

// NotificationsByCategory queries notifications with category, offset and limit
func (client *NotificationClient) NotificationsByCategory(ctx context.Context, category string, offset int, limit int) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
func (client *NotificationClient) NotificationsByCategory(ctx context.Context, category string, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := path.Join(common.ApiNotificationRoute, common.Category, category)
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
requestParams.Set(common.Ack, ack)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
Expand All @@ -79,11 +81,12 @@ func (client *NotificationClient) NotificationsByCategory(ctx context.Context, c
}

// NotificationsByLabel queries notifications with label, offset and limit
func (client *NotificationClient) NotificationsByLabel(ctx context.Context, label string, offset int, limit int) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
func (client *NotificationClient) NotificationsByLabel(ctx context.Context, label string, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := path.Join(common.ApiNotificationRoute, common.Label, label)
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
requestParams.Set(common.Ack, ack)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
Expand All @@ -92,11 +95,12 @@ func (client *NotificationClient) NotificationsByLabel(ctx context.Context, labe
}

// NotificationsByStatus queries notifications with status, offset and limit
func (client *NotificationClient) NotificationsByStatus(ctx context.Context, status string, offset int, limit int) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
func (client *NotificationClient) NotificationsByStatus(ctx context.Context, status string, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := path.Join(common.ApiNotificationRoute, common.Status, status)
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
requestParams.Set(common.Ack, ack)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
Expand All @@ -105,11 +109,12 @@ func (client *NotificationClient) NotificationsByStatus(ctx context.Context, sta
}

// NotificationsByTimeRange query notifications with time range, offset and limit
func (client *NotificationClient) NotificationsByTimeRange(ctx context.Context, start int64, end int64, offset int, limit int) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
func (client *NotificationClient) NotificationsByTimeRange(ctx context.Context, start int64, end int64, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := path.Join(common.ApiNotificationRoute, common.Start, strconv.FormatInt(start, 10), common.End, strconv.FormatInt(end, 10))
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
requestParams.Set(common.Ack, ack)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
Expand All @@ -118,11 +123,12 @@ func (client *NotificationClient) NotificationsByTimeRange(ctx context.Context,
}

// NotificationsBySubscriptionName query notifications with subscriptionName, offset and limit
func (client *NotificationClient) NotificationsBySubscriptionName(ctx context.Context, subscriptionName string, offset int, limit int) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
func (client *NotificationClient) NotificationsBySubscriptionName(ctx context.Context, subscriptionName string, offset int, limit int, ack string) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestPath := path.Join(common.ApiNotificationRoute, common.Subscription, common.Name, subscriptionName)
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
requestParams.Set(common.Ack, ack)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
Expand Down Expand Up @@ -161,3 +167,40 @@ func (client *NotificationClient) DeleteProcessedNotificationsByAge(ctx context.
}
return res, nil
}

// NotificationsByQueryConditions queries notifications with offset, limit, acknowledgement status, category and time range
func (client *NotificationClient) NotificationsByQueryConditions(ctx context.Context, offset, limit int, ack string, conditionReq requests.GetNotificationRequest) (res responses.MultiNotificationsResponse, err errors.EdgeX) {
requestParams := url.Values{}
requestParams.Set(common.Offset, strconv.Itoa(offset))
requestParams.Set(common.Limit, strconv.Itoa(limit))
requestParams.Set(common.Ack, ack)
err = utils.GetRequestWithBodyRawData(ctx, &res, client.baseUrl, common.ApiNotificationRoute, requestParams, conditionReq, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
}
return res, nil
}

// DeleteNotificationByIds deletes notifications by ids
func (client *NotificationClient) DeleteNotificationByIds(ctx context.Context, ids []string) (res dtoCommon.BaseResponse, err errors.EdgeX) {
path := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Ids, strings.Join(ids, common.CommaSeparator))
err = utils.DeleteRequest(ctx, &res, client.baseUrl, path, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
}
return res, nil
}

// UpdateNotificationAckStatusByIds updates existing notification's acknowledgement status
func (client *NotificationClient) UpdateNotificationAckStatusByIds(ctx context.Context, ack bool, ids []string) (res dtoCommon.BaseResponse, err errors.EdgeX) {
pathAck := common.Unacknowledge
if ack {
pathAck = common.Acknowledge
}
path := utils.EscapeAndJoinPath(common.ApiNotificationRoute, pathAck, common.Ids, strings.Join(ids, common.CommaSeparator))
err = utils.PutRequest(ctx, &res, client.baseUrl, path, nil, nil, client.authInjector)
if err != nil {
return res, errors.NewCommonEdgeXWrapper(err)
}
return res, nil
}
45 changes: 39 additions & 6 deletions clients/http/notification_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2021 IOTech Ltd
// Copyright (C) 2021-2024 IOTech Ltd
// Copyright (C) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -11,8 +11,10 @@ import (
"net/http"
"path"
"strconv"
"strings"
"testing"

"github.com/edgexfoundry/go-mod-core-contracts/v4/clients/http/utils"
"github.com/edgexfoundry/go-mod-core-contracts/v4/common"
"github.com/edgexfoundry/go-mod-core-contracts/v4/dtos"
dtoCommon "github.com/edgexfoundry/go-mod-core-contracts/v4/dtos/common"
Expand Down Expand Up @@ -61,7 +63,7 @@ func TestNotificationClient_NotificationsByCategory(t *testing.T) {
ts := newTestServer(http.MethodGet, urlPath, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.NotificationsByCategory(context.Background(), category, 0, 10)
res, err := client.NotificationsByCategory(context.Background(), category, 0, 10, "")
require.NoError(t, err)
require.IsType(t, responses.MultiNotificationsResponse{}, res)
}
Expand All @@ -72,7 +74,7 @@ func TestNotificationClient_NotificationsByLabel(t *testing.T) {
ts := newTestServer(http.MethodGet, urlPath, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.NotificationsByLabel(context.Background(), label, 0, 10)
res, err := client.NotificationsByLabel(context.Background(), label, 0, 10, "")
require.NoError(t, err)
require.IsType(t, responses.MultiNotificationsResponse{}, res)
}
Expand All @@ -83,7 +85,7 @@ func TestNotificationClient_NotificationsByStatus(t *testing.T) {
ts := newTestServer(http.MethodGet, urlPath, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.NotificationsByStatus(context.Background(), status, 0, 10)
res, err := client.NotificationsByStatus(context.Background(), status, 0, 10, "")
require.NoError(t, err)
require.IsType(t, responses.MultiNotificationsResponse{}, res)
}
Expand All @@ -94,7 +96,7 @@ func TestNotificationClient_NotificationsBySubscriptionName(t *testing.T) {
ts := newTestServer(http.MethodGet, urlPath, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.NotificationsBySubscriptionName(context.Background(), subscriptionName, 0, 10)
res, err := client.NotificationsBySubscriptionName(context.Background(), subscriptionName, 0, 10, "")
require.NoError(t, err)
require.IsType(t, responses.MultiNotificationsResponse{}, res)
}
Expand All @@ -106,7 +108,7 @@ func TestNotificationClient_NotificationsByTimeRange(t *testing.T) {
ts := newTestServer(http.MethodGet, urlPath, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.NotificationsByTimeRange(context.Background(), start, end, 0, 10)
res, err := client.NotificationsByTimeRange(context.Background(), start, end, 0, 10, "")
require.NoError(t, err)
require.IsType(t, responses.MultiNotificationsResponse{}, res)
}
Expand Down Expand Up @@ -152,3 +154,34 @@ func TestNotificationClient_DeleteProcessedNotificationsByAge(t *testing.T) {
require.NoError(t, err)
require.IsType(t, dtoCommon.BaseResponse{}, res)
}

func TestNotificationClient_NotificationsByQueryConditions(t *testing.T) {
ts := newTestServer(http.MethodGet, common.ApiNotificationRoute, responses.MultiNotificationsResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.NotificationsByQueryConditions(context.Background(), 0, 10, "", requests.GetNotificationRequest{})
require.NoError(t, err)
require.IsType(t, responses.MultiNotificationsResponse{}, res)
}

func TestNotificationClient_DeleteNotificationByIds(t *testing.T) {
ids := []string{ExampleUUID}
path := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Ids, strings.Join(ids, common.CommaSeparator))
ts := newTestServer(http.MethodDelete, path, dtoCommon.BaseResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.DeleteNotificationByIds(context.Background(), ids)
require.NoError(t, err)
require.IsType(t, dtoCommon.BaseResponse{}, res)
}

func TestNotificationClient_UpdateNotificationAckStatusByIds(t *testing.T) {
ids := []string{ExampleUUID}
path := utils.EscapeAndJoinPath(common.ApiNotificationRoute, common.Acknowledge, common.Ids, strings.Join(ids, common.CommaSeparator))
ts := newTestServer(http.MethodPut, path, dtoCommon.BaseResponse{})
defer ts.Close()
client := NewNotificationClient(ts.URL, NewNullAuthenticationInjector(), false)
res, err := client.UpdateNotificationAckStatusByIds(context.Background(), true, ids)
require.NoError(t, err)
require.IsType(t, dtoCommon.BaseResponse{}, res)
}
Loading

0 comments on commit 32807ec

Please sign in to comment.