dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/provisionwatcher.go (about) 1 // 2 // Copyright (C) 2021-2023 IOTech Ltd 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 6 package dtos 7 8 import ( 9 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/models" 10 ) 11 12 type ProvisionWatcher struct { 13 DBTimestamp `json:",inline"` 14 Id string `json:"id,omitempty" yaml:"id,omitempty" validate:"omitempty,uuid"` 15 Name string `json:"name" yaml:"name" validate:"required,edgex-dto-none-empty-string"` 16 ServiceName string `json:"serviceName" yaml:"serviceName" validate:"required,edgex-dto-none-empty-string"` 17 Labels []string `json:"labels,omitempty" yaml:"labels,omitempty"` 18 Identifiers map[string]string `json:"identifiers" yaml:"identifiers" validate:"gt=0,dive,keys,required,endkeys,required"` 19 BlockingIdentifiers map[string][]string `json:"blockingIdentifiers,omitempty" yaml:"blockingIdentifiers,omitempty"` 20 AdminState string `json:"adminState" yaml:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"` 21 DiscoveredDevice DiscoveredDevice `json:"discoveredDevice" yaml:"discoveredDevice"` 22 } 23 24 type UpdateProvisionWatcher struct { 25 Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"` 26 Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"` 27 ServiceName *string `json:"serviceName" validate:"omitempty,edgex-dto-none-empty-string"` 28 Labels []string `json:"labels"` 29 Identifiers map[string]string `json:"identifiers" validate:"omitempty,gt=0,dive,keys,required,endkeys,required"` 30 BlockingIdentifiers map[string][]string `json:"blockingIdentifiers"` 31 AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"` 32 DiscoveredDevice UpdateDiscoveredDevice `json:"discoveredDevice"` 33 } 34 35 // ToProvisionWatcherModel transforms the ProvisionWatcher DTO to the ProvisionWatcher model 36 func ToProvisionWatcherModel(dto ProvisionWatcher) models.ProvisionWatcher { 37 return models.ProvisionWatcher{ 38 DBTimestamp: models.DBTimestamp(dto.DBTimestamp), 39 Id: dto.Id, 40 Name: dto.Name, 41 ServiceName: dto.ServiceName, 42 Labels: dto.Labels, 43 Identifiers: dto.Identifiers, 44 BlockingIdentifiers: dto.BlockingIdentifiers, 45 AdminState: models.AdminState(dto.AdminState), 46 DiscoveredDevice: ToDiscoveredDeviceModel(dto.DiscoveredDevice), 47 } 48 } 49 50 // FromProvisionWatcherModelToDTO transforms the ProvisionWatcher Model to the ProvisionWatcher DTO 51 func FromProvisionWatcherModelToDTO(pw models.ProvisionWatcher) ProvisionWatcher { 52 return ProvisionWatcher{ 53 DBTimestamp: DBTimestamp(pw.DBTimestamp), 54 Id: pw.Id, 55 Name: pw.Name, 56 ServiceName: pw.ServiceName, 57 Labels: pw.Labels, 58 Identifiers: pw.Identifiers, 59 BlockingIdentifiers: pw.BlockingIdentifiers, 60 AdminState: string(pw.AdminState), 61 DiscoveredDevice: FromDiscoveredDeviceModelToDTO(pw.DiscoveredDevice), 62 } 63 } 64 65 // FromProvisionWatcherModelToUpdateDTO transforms the ProvisionWatcher Model to the UpdateProvisionWatcher DTO 66 func FromProvisionWatcherModelToUpdateDTO(pw models.ProvisionWatcher) UpdateProvisionWatcher { 67 adminState := string(pw.AdminState) 68 dto := UpdateProvisionWatcher{ 69 Id: &pw.Id, 70 Name: &pw.Name, 71 ServiceName: &pw.ServiceName, 72 Labels: pw.Labels, 73 Identifiers: pw.Identifiers, 74 BlockingIdentifiers: pw.BlockingIdentifiers, 75 AdminState: &adminState, 76 DiscoveredDevice: FromDiscoveredDeviceModelToUpdateDTO(pw.DiscoveredDevice), 77 } 78 return dto 79 }