dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/device_history.go (about) 1 // 2 // Copyright (C) 2020-2021 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 DeviceHistory struct { 13 DBTimestamp `json:",inline"` 14 Version int64 `json:"version,omitempty" validate:"omitempty"` 15 Device 16 HistoryUser string `json:"historyUser,omitempty"` 17 HistoryNotes string `json:"historyNotes,omitempty"` 18 HistoryType string `json:"historyType" validate:"required"` 19 HistoryDate int64 `json:"historyDate" validate:"required"` 20 Model string `json:"model,omitempty"` 21 Manufacturer string `json:"manufacturer,omitempty"` 22 } 23 24 type UpdateDeviceHistory struct { 25 Version *int64 `json:"version"` 26 Id *string `json:"id" validate:"required,edgex-dto-uuid"` 27 Name *string `json:"name" validate:"required_without=deviceId,edgex-dto-none-empty-string"` 28 Description *string `json:"description" validate:"omitempty"` 29 AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"` 30 OperatingState *string `json:"operatingState" validate:"omitempty,oneof='UP' 'DOWN' 'UNKNOWN'"` 31 Created *int64 `json:"created"` // Deprecated: will be replaced by Metrics in v3 32 Modified *int64 `json:"modified"` // Deprecated: will be replaced by Metrics in v3 33 ServiceName *string `json:"serviceName" validate:"omitempty,edgex-dto-none-empty-string"` 34 ProfileName *string `json:"profileName" validate:"omitempty,edgex-dto-none-empty-string"` 35 Labels []string `json:"labels"` 36 Location interface{} `json:"location"` 37 AutoEvents []AutoEvent `json:"autoEvents" validate:"dive"` 38 Tags map[string]any `json:"tags,omitempty" yaml:"tags,omitempty"` 39 Protocols map[string]ProtocolProperties `json:"protocols" validate:"omitempty,gt=0"` 40 HistoryUser *string `json:"historyUser"` 41 HistoryNotes *string `json:"historyNotes"` 42 HistoryType *string `json:"historyType" validate:"required"` 43 HistoryDate *int64 `json:"historyDate" validate:"required"` 44 Model *string `json:"model,omitempty"` 45 Manufacturer *string `json:"manufacturer,omitempty"` 46 } 47 48 // ToDeviceModel transforms the Device DTO to the Device Model 49 func ToDeviceHistoryModel(dto DeviceHistory) models.DeviceHistory { 50 var d models.DeviceHistory 51 d.Version = dto.Version 52 d.Id = dto.Id 53 d.Name = dto.Name 54 d.Description = dto.Description 55 d.ServiceName = dto.ServiceName 56 d.ProfileName = dto.ProfileName 57 d.AdminState = models.AdminState(dto.AdminState) 58 d.OperatingState = models.OperatingState(dto.OperatingState) 59 d.Created = dto.Created 60 d.Modified = dto.Modified 61 d.Labels = dto.Labels 62 d.Location = dto.Location 63 d.AutoEvents = ToAutoEventModels(dto.AutoEvents) 64 d.Tags = dto.Tags 65 d.Protocols = ToProtocolModels(dto.Protocols) 66 d.HistoryUser = dto.HistoryUser 67 d.HistoryNotes = dto.HistoryNotes 68 d.HistoryType = dto.HistoryType 69 d.HistoryDate = dto.HistoryDate 70 d.Model = dto.Model 71 d.Manufacturer = dto.Manufacturer 72 return d 73 } 74 75 // FromDeviceModelToDTO transforms the Device Model to the Device DTO 76 func FromDeviceHistoryModelToDTO(d models.DeviceHistory) DeviceHistory { 77 var dto DeviceHistory 78 dto.DBTimestamp = DBTimestamp(d.DBTimestamp) 79 dto.Version = d.Version 80 dto.Id = d.Id 81 dto.Name = d.Name 82 dto.Description = d.Description 83 dto.ServiceName = d.ServiceName 84 dto.ProfileName = d.ProfileName 85 dto.AdminState = string(d.AdminState) 86 dto.OperatingState = string(d.OperatingState) 87 dto.Created = d.Created 88 dto.Modified = d.Modified 89 dto.Labels = d.Labels 90 dto.Location = d.Location 91 dto.AutoEvents = FromAutoEventModelsToDTOs(d.AutoEvents) 92 dto.Tags = d.Tags 93 dto.Protocols = FromProtocolModelsToDTOs(d.Protocols) 94 dto.HistoryUser = d.HistoryUser 95 dto.HistoryNotes = d.HistoryNotes 96 dto.HistoryType = d.HistoryType 97 dto.HistoryDate = d.HistoryDate 98 dto.Model = d.Model 99 dto.Manufacturer = d.Manufacturer 100 return dto 101 } 102 103 // FromDeviceModelToUpdateDTO transforms the Device Model to the UpdateDevice DTO 104 func FromDeviceHistoryModelToUpdateDTO(d models.DeviceHistory) UpdateDeviceHistory { 105 adminState := string(d.AdminState) 106 operatingState := string(d.OperatingState) 107 dto := UpdateDeviceHistory{ 108 Id: &d.Id, 109 Version: &d.Version, 110 Name: &d.Name, 111 Description: &d.Description, 112 AdminState: &adminState, 113 OperatingState: &operatingState, 114 ServiceName: &d.ServiceName, 115 ProfileName: &d.ProfileName, 116 Created: &d.Created, 117 Modified: &d.Modified, 118 Location: d.Location, 119 Tags: d.Tags, 120 //AutoEvents: FromAutoEventModelsToDTOs(d.AutoEvents), 121 Protocols: FromProtocolModelsToDTOs(d.Protocols), 122 Labels: d.Labels, 123 HistoryUser: &d.HistoryUser, 124 HistoryNotes: &d.HistoryNotes, 125 HistoryType: &d.HistoryType, 126 HistoryDate: &d.HistoryDate, 127 Model: &d.Model, 128 Manufacturer: &d.Manufacturer, 129 } 130 return dto 131 }