@@ -109,15 +109,13 @@ impl DigitalTwinRegistry for DigitalTwinRegistryImpl {
109
109
let request_inner = request. into_inner ( ) ;
110
110
111
111
for entity_access_info in & request_inner. entity_access_info_list {
112
- self . register_entity ( entity_access_info. clone ( ) ) . map_err ( |e| {
113
- Status :: internal ( format ! (
114
- "Failed to register the entity with instance id: {}, error: {}" ,
115
- entity_access_info. instance_id, e
116
- ) )
117
- } ) ?;
112
+ self . register_entity ( & entity_access_info) ?;
113
+
118
114
info ! (
119
- "Registered the entity with model id: {} and instance id: {}" ,
120
- entity_access_info. model_id, entity_access_info. instance_id
115
+ "Registered the entity with provider id: {} instance id: {} model id: {}" ,
116
+ entity_access_info. provider_id,
117
+ entity_access_info. instance_id,
118
+ entity_access_info. model_id
121
119
) ;
122
120
}
123
121
@@ -134,33 +132,33 @@ impl DigitalTwinRegistryImpl {
134
132
///
135
133
/// # Arguments
136
134
/// * `entity` - The entity.
137
- fn register_entity ( & self , entity_access_info : EntityAccessInfo ) -> Result < ( ) , String > {
138
- // This block controls the lifetime of the lock.
139
- {
140
- if entity_access_info. provider_id . is_empty ( ) {
141
- return Err ( "Provider id cannot be empty" . to_string ( ) ) ;
142
- }
135
+ fn register_entity ( & self , entity_access_info : & EntityAccessInfo ) -> Result < ( ) , Status > {
136
+ if entity_access_info. provider_id . is_empty ( ) {
137
+ return Err ( Status :: invalid_argument ( "Provider id is required" ) ) ;
138
+ }
143
139
144
- if entity_access_info. model_id . is_empty ( ) {
145
- return Err ( "Model id cannot be empty" . to_string ( ) ) ;
146
- }
140
+ if entity_access_info. model_id . is_empty ( ) {
141
+ return Err ( Status :: invalid_argument ( "Model id is required" ) ) ;
142
+ }
147
143
148
- if entity_access_info. instance_id . is_empty ( ) {
149
- return Err ( "Instance id cannot be empty" . to_string ( ) ) ;
150
- }
144
+ if entity_access_info. instance_id . is_empty ( ) {
145
+ return Err ( Status :: invalid_argument ( "Instance id is required" ) ) ;
146
+ }
151
147
152
- if entity_access_info. protocol . is_empty ( ) {
153
- return Err ( "Protocol cannot be empty" . to_string ( ) ) ;
154
- }
148
+ if entity_access_info. protocol . is_empty ( ) {
149
+ return Err ( Status :: invalid_argument ( "Protocol is required" ) ) ;
150
+ }
155
151
156
- if entity_access_info. uri . is_empty ( ) {
157
- return Err ( "Uri cannot be empty" . to_string ( ) ) ;
158
- }
152
+ if entity_access_info. uri . is_empty ( ) {
153
+ return Err ( Status :: invalid_argument ( "Uri is required" ) ) ;
154
+ }
159
155
160
- if entity_access_info. operations . is_empty ( ) {
161
- return Err ( "Operations cannot be empty" . to_string ( ) ) ;
162
- }
156
+ if entity_access_info. operations . is_empty ( ) {
157
+ return Err ( Status :: invalid_argument ( "Operations is required" ) ) ;
158
+ }
163
159
160
+ // This block controls the lifetime of the lock.
161
+ {
164
162
// Note: the context is optional.
165
163
166
164
let mut lock: RwLockWriteGuard < HashMap < String , Vec < EntityAccessInfo > > > =
0 commit comments