/
DigitalTwinsAsyncClient.java
2413 lines (2261 loc) · 122 KB
/
DigitalTwinsAsyncClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.digitaltwins.core;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.models.JsonPatchDocument;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.JsonSerializer;
import com.azure.core.util.serializer.SerializerAdapter;
import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImpl;
import com.azure.digitaltwins.core.implementation.AzureDigitalTwinsAPIImplBuilder;
import com.azure.digitaltwins.core.implementation.converters.DigitalTwinsModelDataConverter;
import com.azure.digitaltwins.core.implementation.converters.EventRouteConverter;
import com.azure.digitaltwins.core.implementation.converters.IncomingRelationshipConverter;
import com.azure.digitaltwins.core.implementation.converters.OptionsConverter;
import com.azure.digitaltwins.core.implementation.models.QuerySpecification;
import com.azure.digitaltwins.core.implementation.serializer.DeserializationHelpers;
import com.azure.digitaltwins.core.implementation.serializer.DigitalTwinsStringSerializer;
import com.azure.digitaltwins.core.implementation.serializer.SerializationHelpers;
import com.azure.digitaltwins.core.models.CreateOrReplaceDigitalTwinOptions;
import com.azure.digitaltwins.core.models.CreateOrReplaceRelationshipOptions;
import com.azure.digitaltwins.core.models.DeleteDigitalTwinOptions;
import com.azure.digitaltwins.core.models.DeleteRelationshipOptions;
import com.azure.digitaltwins.core.models.DigitalTwinsEventRoute;
import com.azure.digitaltwins.core.models.DigitalTwinsModelData;
import com.azure.digitaltwins.core.models.DigitalTwinsResponse;
import com.azure.digitaltwins.core.models.DigitalTwinsResponseHeaders;
import com.azure.digitaltwins.core.models.IncomingRelationship;
import com.azure.digitaltwins.core.models.ListDigitalTwinsEventRoutesOptions;
import com.azure.digitaltwins.core.models.ListModelsOptions;
import com.azure.digitaltwins.core.models.PublishComponentTelemetryOptions;
import com.azure.digitaltwins.core.models.PublishTelemetryOptions;
import com.azure.digitaltwins.core.models.QueryOptions;
import com.azure.digitaltwins.core.models.UpdateComponentOptions;
import com.azure.digitaltwins.core.models.UpdateDigitalTwinOptions;
import com.azure.digitaltwins.core.models.UpdateRelationshipOptions;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.azure.core.util.FluxUtil.withContext;
/**
* This class provides a client for interacting asynchronously with an Azure Digital Twins instance.
* This client is instantiated through {@link DigitalTwinsClientBuilder}.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.instantiation -->
* <pre>
* DigitalTwinsAsyncClient digitalTwinsAsyncClient = new DigitalTwinsClientBuilder()
* .credential(
* new ClientSecretCredentialBuilder()
* .tenantId(tenantId)
* .clientId(clientId)
* .clientSecret(clientSecret)
* .build())
* .endpoint(digitalTwinsEndpointUrl)
* .buildAsyncClient();
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.instantiation -->
*
* <p>
* This client allows for management of digital twins, their components, and their relationships. It also allows for managing
* the digital twin models and event routes tied to your Azure Digital Twins instance.
* </p>
*/
@ServiceClient(builder = DigitalTwinsClientBuilder.class, isAsync = true)
public final class DigitalTwinsAsyncClient {
private static final ClientLogger LOGGER = new ClientLogger(DigitalTwinsAsyncClient.class);
private static final Boolean INCLUDE_MODEL_DEFINITION_ON_GET = true;
private static final SerializerAdapter SERIALIZER_ADAPTER;
private static final ObjectMapper MAPPER;
private final DigitalTwinsServiceVersion serviceVersion;
private final AzureDigitalTwinsAPIImpl protocolLayer;
private final JsonSerializer serializer;
static {
final SimpleModule stringModule = new SimpleModule("String Serializer");
JacksonAdapter jacksonAdapter = new JacksonAdapter();
MAPPER = jacksonAdapter.serializer(); // Use the same mapper in this layer that the generated layer will use
stringModule.addSerializer(new DigitalTwinsStringSerializer(String.class, MAPPER));
jacksonAdapter.serializer().registerModule(stringModule);
SERIALIZER_ADAPTER = jacksonAdapter;
}
DigitalTwinsAsyncClient(String serviceEndpoint, HttpPipeline pipeline, DigitalTwinsServiceVersion serviceVersion, JsonSerializer jsonSerializer) {
this.serviceVersion = serviceVersion;
// Is null by default. If not null, then the user provided a custom json serializer for the convenience layer to use.
// If null, then mapper will be used instead. See DeserializationHelpers for more details
this.serializer = jsonSerializer;
this.protocolLayer = new AzureDigitalTwinsAPIImplBuilder()
.host(serviceEndpoint)
.pipeline(pipeline)
.serializerAdapter(SERIALIZER_ADAPTER)
.buildClient();
}
/**
* Gets the Azure Digital Twins service API version that this client is configured to use for all service requests.
* Unless configured while building this client through {@link DigitalTwinsClientBuilder#serviceVersion(DigitalTwinsServiceVersion)},
* this value will be equal to the latest service API version supported by this client.
*
* @return The Azure Digital Twins service API version.
*/
public DigitalTwinsServiceVersion getServiceVersion() {
return this.serviceVersion;
}
//region Digital twin APIs
/**
* Creates a digital twin. If the provided digital twin Id is already in use, then this will attempt
* to replace the existing digital twin with the provided digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p> You can provide a strongly typed digital twin object such as {@link BasicDigitalTwin} as the input parameter:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwins#String-Object-Class#BasicDigitalTwin -->
* <pre>
* String modelId = "dtmi:com:samples:Building;1";
*
* BasicDigitalTwin basicTwin = new BasicDigitalTwin("myDigitalTwinId")
* .setMetadata(
* new BasicDigitalTwinMetadata()
* .setModelId(modelId)
* );
*
* digitalTwinsAsyncClient.createOrReplaceDigitalTwin(basicTwin.getId(), basicTwin, BasicDigitalTwin.class)
* .subscribe(response -> System.out.println("Created digital twin Id: " + response.getId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwins#String-Object-Class#BasicDigitalTwin -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwins#String-Object-Class#String -->
* <pre>
* digitalTwinsAsyncClient.createOrReplaceDigitalTwin("myDigitalTwinId", digitalTwinStringPayload, String.class)
* .subscribe(stringResponse -> System.out.println("Created digital twin: " + stringResponse));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwins#String-Object-Class#String -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param digitalTwin The application/json object representing the digital twin to create.
* @param clazz The model class to serialize the request with and deserialize the response with.
* @param <T> The generic type to serialize the request with and deserialize the response with.
* @return The deserialized application/json object representing the digital twin created.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<T> createOrReplaceDigitalTwin(String digitalTwinId, T digitalTwin, Class<T> clazz) {
return createOrReplaceDigitalTwinWithResponse(digitalTwinId, digitalTwin, clazz, null)
.map(DigitalTwinsResponse::getValue);
}
/**
* Creates a digital twin. If the provided digital twin Id is already in use, then this will attempt
* to replace the existing digital twin with the provided digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p> You can provide a strongly typed digital twin object such as {@link BasicDigitalTwin} as the input parameter:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwinsWithResponse#String-Object-Class-Options#BasicDigitalTwin -->
* <pre>
* String modelId = "dtmi:com:samples:Building;1";
*
* BasicDigitalTwin basicDigitalTwin = new BasicDigitalTwin("myDigitalTwinId")
* .setMetadata(
* new BasicDigitalTwinMetadata()
* .setModelId(modelId)
* );
*
* digitalTwinsAsyncClient.createOrReplaceDigitalTwinWithResponse(
* basicDigitalTwin.getId(),
* basicDigitalTwin,
* BasicDigitalTwin.class,
* new CreateOrReplaceDigitalTwinOptions())
* .subscribe(resultWithResponse ->
* System.out.println(
* "Response http status: "
* + resultWithResponse.getStatusCode()
* + " created digital twin Id: "
* + resultWithResponse.getValue().getId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwinsWithResponse#String-Object-Class-Options#BasicDigitalTwin -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwinsWithResponse#String-Object-Class-Options#String -->
* <pre>
* digitalTwinsAsyncClient.createOrReplaceDigitalTwinWithResponse(
* basicDigitalTwin.getId(),
* stringPayload,
* String.class,
* new CreateOrReplaceDigitalTwinOptions())
* .subscribe(stringWithResponse ->
* System.out.println(
* "Response http status: "
* + stringWithResponse.getStatusCode()
* + " created digital twin: "
* + stringWithResponse.getValue()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createDigitalTwinsWithResponse#String-Object-Class-Options#String -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param digitalTwin The application/json object representing the digital twin to create.
* @param clazz The model class to serialize the request with and deserialize the response with.
* @param <T> The generic type to serialize the request with and deserialize the response with.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse} containing the deserialized application/json object representing the digital twin created.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<DigitalTwinsResponse<T>> createOrReplaceDigitalTwinWithResponse(String digitalTwinId, T digitalTwin, Class<T> clazz, CreateOrReplaceDigitalTwinOptions options) {
return withContext(context -> createOrReplaceDigitalTwinWithResponse(digitalTwinId, digitalTwin, clazz, options, context));
}
<T> Mono<DigitalTwinsResponse<T>> createOrReplaceDigitalTwinWithResponse(String digitalTwinId, T digitalTwin, Class<T> clazz, CreateOrReplaceDigitalTwinOptions options, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.addWithResponseAsync(
digitalTwinId,
digitalTwin,
OptionsConverter.toProtocolLayerOptions(options),
context)
.flatMap(response -> {
T genericResponse;
try {
genericResponse = DeserializationHelpers.deserializeObject(MAPPER, response.getValue(), clazz, this.serializer);
} catch (JsonProcessingException e) {
LOGGER.error("JsonProcessingException occurred while deserializing the response: ", e);
return Mono.error(e);
}
DigitalTwinsResponseHeaders twinHeaders = MAPPER.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
return Mono.just(new DigitalTwinsResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), genericResponse, twinHeaders));
});
}
/**
* Gets a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p>
* A Strongly typed object type such as {@link BasicDigitalTwin} can be provided as an input parameter for {@code clazz}
* to indicate what type is used to deserialize the response.
* </p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwin#String-Class#BasicDigitalTwin -->
* <pre>
* digitalTwinsAsyncClient.getDigitalTwin("myDigitalTwinId", BasicDigitalTwin.class)
* .subscribe(
* basicDigitalTwin -> System.out.println("Retrieved digital twin with Id: " + basicDigitalTwin.getId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwin#String-Class#BasicDigitalTwin -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwin#String-Class#String -->
* <pre>
* digitalTwinsAsyncClient.getDigitalTwin("myDigitalTwinId", String.class)
* .subscribe(stringResult -> System.out.println("Retrieved digital twin: " + stringResult));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwin#String-Class#String -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param clazz The model class to deserialize the response with.
* @param <T> The generic type to deserialize the digital twin with.
* @return The deserialized application/json object representing the digital twin
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<T> getDigitalTwin(String digitalTwinId, Class<T> clazz) {
return getDigitalTwinWithResponse(digitalTwinId, clazz)
.map(DigitalTwinsResponse::getValue);
}
/**
* Gets a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p>
* A Strongly typed object type such as {@link BasicDigitalTwin} can be provided as an input parameter for {@code clazz}
* to indicate what type is used to deserialize the response.
* </p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwinWithResponse#String-Class-Options#BasicDigitalTwin -->
* <pre>
* digitalTwinsAsyncClient.getDigitalTwinWithResponse(
* "myDigitalTwinId",
* BasicDigitalTwin.class)
* .subscribe(
* basicDigitalTwinWithResponse -> System.out.println(
* "Retrieved digital twin with Id: " + basicDigitalTwinWithResponse.getValue().getId()
* + " Http Status Code: " + basicDigitalTwinWithResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwinWithResponse#String-Class-Options#BasicDigitalTwin -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwinWithResponse#String-Class-Options#String -->
* <pre>
* digitalTwinsAsyncClient.getDigitalTwinWithResponse(
* "myDigitalTwinId",
* String.class)
* .subscribe(
* basicDigitalTwinWithResponse -> System.out.println(
* "Retrieved digital twin: " + basicDigitalTwinWithResponse.getValue()
* + " Http Status Code: " + basicDigitalTwinWithResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getDigitalTwinWithResponse#String-Class-Options#String -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param clazz The model class to deserialize the response with.
* @param <T> The generic type to deserialize the digital twin with.
* @return A {@link DigitalTwinsResponse} containing the deserialized application/json object representing the digital twin.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<DigitalTwinsResponse<T>> getDigitalTwinWithResponse(String digitalTwinId, Class<T> clazz) {
return withContext(context -> getDigitalTwinWithResponse(digitalTwinId, clazz, context));
}
<T> Mono<DigitalTwinsResponse<T>> getDigitalTwinWithResponse(String digitalTwinId, Class<T> clazz, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.getByIdWithResponseAsync(
digitalTwinId,
null,
context)
.flatMap(response -> {
T genericResponse;
try {
genericResponse = DeserializationHelpers.deserializeObject(MAPPER, response.getValue(), clazz, this.serializer);
} catch (JsonProcessingException e) {
LOGGER.error("JsonProcessingException occurred while deserializing the digital twin get response: ", e);
return Mono.error(e);
}
DigitalTwinsResponseHeaders twinHeaders = MAPPER.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
return Mono.just(new DigitalTwinsResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), genericResponse, twinHeaders));
});
}
/**
* Updates a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p>Update digital twin by providing list of intended patch operations.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateDigitalTwin#String-JsonPatchDocument -->
* <pre>
* JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
* jsonPatchDocument.appendReplace("Prop1", "newValue");
*
* digitalTwinsAsyncClient.updateDigitalTwin(
* "myDigitalTwinId",
* jsonPatchDocument)
* .subscribe();
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateDigitalTwin#String-JsonPatchDocument -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param jsonPatch The JSON patch to apply to the specified digital twin.
* This argument can be created using {@link JsonPatchDocument}.
* @return An empty Mono
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateDigitalTwin(String digitalTwinId, JsonPatchDocument jsonPatch) {
return updateDigitalTwinWithResponse(digitalTwinId, jsonPatch, null)
.flatMap(voidResponse -> Mono.empty());
}
/**
* Updates a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p>Update digital twin by providing list of intended patch operations.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateDigitalTwinWithResponse#String-JsonPatchDocument-UpdateDigitalTwinOptions -->
* <pre>
* JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
* jsonPatchDocument.appendReplace("Prop1", "newValue");
*
* digitalTwinsAsyncClient.updateDigitalTwinWithResponse(
* "myDigitalTwinId",
* jsonPatchDocument,
* new UpdateDigitalTwinOptions())
* .subscribe(updateResponse ->
* System.out.println("Update completed with HTTP status code: " + updateResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateDigitalTwinWithResponse#String-JsonPatchDocument-UpdateDigitalTwinOptions -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param jsonPatch The JSON patch to apply to the specified digital twin.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse}. This response object includes an HTTP header that gives you the updated
* ETag for this resource.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options) {
return withContext(context -> updateDigitalTwinWithResponse(digitalTwinId, jsonPatch, options, context));
}
Mono<DigitalTwinsResponse<Void>> updateDigitalTwinWithResponse(String digitalTwinId, JsonPatchDocument jsonPatch, UpdateDigitalTwinOptions options, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.updateWithResponseAsync(
digitalTwinId,
jsonPatch,
OptionsConverter.toProtocolLayerOptions(options),
context)
.map(response -> {
DigitalTwinsResponseHeaders twinHeaders = MAPPER.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
return new DigitalTwinsResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), response.getValue(), twinHeaders);
});
}
/**
* Deletes a digital twin. All relationships referencing the digital twin must already be deleted.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteDigitalTwin#String -->
* <pre>
* digitalTwinsAsyncClient.deleteDigitalTwin("myDigitalTwinId")
* .subscribe();
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteDigitalTwin#String -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @return An empty Mono
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> deleteDigitalTwin(String digitalTwinId) {
return deleteDigitalTwinWithResponse(digitalTwinId, null)
.flatMap(voidResponse -> Mono.empty());
}
/**
* Deletes a digital twin. All relationships referencing the digital twin must already be deleted.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteDigitalTwinWithResponse#String-DeleteDigitalTwinOptions -->
* <pre>
* digitalTwinsAsyncClient.deleteDigitalTwinWithResponse(
* "myDigitalTwinId",
* new DeleteDigitalTwinOptions())
* .subscribe(deleteResponse ->
* System.out.println("Deleted digital twin. HTTP response status code: " + deleteResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteDigitalTwinWithResponse#String-DeleteDigitalTwinOptions -->
*
* @param digitalTwinId The Id of the digital twin. The Id is unique within the service and case sensitive.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return The Http response
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> deleteDigitalTwinWithResponse(String digitalTwinId, DeleteDigitalTwinOptions options) {
return withContext(context -> deleteDigitalTwinWithResponse(digitalTwinId, options, context));
}
Mono<Response<Void>> deleteDigitalTwinWithResponse(String digitalTwinId, DeleteDigitalTwinOptions options, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.deleteWithResponseAsync(
digitalTwinId,
OptionsConverter.toProtocolLayerOptions(options),
context);
}
//endregion Digital twin APIs
//region Relationship APIs
/**
* Creates a relationship on a digital twin. If the provided relationship Id is already in use, then this will
* attempt to replace the existing relationship with the provided relationship.
*
* <p><strong>Code Samples</strong></p>
*
* <p>A strongly typed digital twin object such as {@link BasicRelationship} can be provided as the input parameter to deserialize the response into.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationship#String-String-Object-Class#BasicRelationship -->
* <pre>
* BasicRelationship buildingToFloorBasicRelationship = new BasicRelationship(
* "myRelationshipId",
* "mySourceDigitalTwinId",
* "myTargetDigitalTwinId",
* "contains")
* .addProperty("Prop1", "Prop1 value")
* .addProperty("Prop2", 6);
*
* digitalTwinsAsyncClient.createOrReplaceRelationship(
* "mySourceDigitalTwinId",
* "myRelationshipId",
* buildingToFloorBasicRelationship,
* BasicRelationship.class)
* .subscribe(createdRelationship -> System.out.println(
* "Created relationship with Id: "
* + createdRelationship.getId()
* + " from: " + createdRelationship.getSourceId()
* + " to: " + createdRelationship.getTargetId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationship#String-String-Object-Class#BasicRelationship -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationship#String-String-Object-Class#String -->
* <pre>
* String relationshipPayload = getRelationshipPayload();
*
* digitalTwinsAsyncClient.createOrReplaceRelationship(
* "mySourceDigitalTwinId",
* "myRelationshipId",
* relationshipPayload,
* String.class)
* .subscribe(createRelationshipString ->
* System.out.println("Created relationship: " + createRelationshipString));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationship#String-String-Object-Class#String -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be created.
* @param relationship The relationship to be created.
* @param clazz The model class of the relationship.
* @param <T> The generic type of the relationship.
* @return The relationship created.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<T> createOrReplaceRelationship(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz) {
return createOrReplaceRelationshipWithResponse(digitalTwinId, relationshipId, relationship, clazz, null)
.map(DigitalTwinsResponse::getValue);
}
/**
* Creates a relationship on a digital twin. If the provided relationship Id is already in use, then this will
* attempt to replace the existing relationship with the provided relationship.
*
* <p><strong>Code Samples</strong></p>
*
* <p>A strongly typed digital twin object such as {@link BasicRelationship} can be provided as the input parameter to deserialize the response into.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse#String-String-Object-Class-Options#BasicRelationship -->
* <pre>
* BasicRelationship buildingToFloorBasicRelationship = new BasicRelationship(
* "myRelationshipId",
* "mySourceDigitalTwinId",
* "myTargetDigitalTwinId",
* "contains")
* .addProperty("Prop1", "Prop1 value")
* .addProperty("Prop2", 6);
*
* digitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse(
* "mySourceDigitalTwinId",
* "myRelationshipId",
* buildingToFloorBasicRelationship,
* BasicRelationship.class,
* new CreateOrReplaceRelationshipOptions())
* .subscribe(createdRelationshipWithResponse -> System.out.println(
* "Created relationship with Id: "
* + createdRelationshipWithResponse.getValue().getId()
* + " from: " + createdRelationshipWithResponse.getValue().getSourceId()
* + " to: " + createdRelationshipWithResponse.getValue().getTargetId()
* + " Http status code: "
* + createdRelationshipWithResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse#String-String-Object-Class-Options#BasicRelationship -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse#String-String-Object-Class-Options#String -->
* <pre>
* String relationshipPayload = getRelationshipPayload();
*
* digitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse(
* "mySourceDigitalTwinId",
* "myRelationshipId",
* relationshipPayload,
* String.class,
* new CreateOrReplaceRelationshipOptions())
* .subscribe(createdRelationshipStringWithResponse -> System.out.println(
* "Created relationship: "
* + createdRelationshipStringWithResponse
* + " With HTTP status code: "
* + createdRelationshipStringWithResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.createOrReplaceRelationshipWithResponse#String-String-Object-Class-Options#String -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be created.
* @param relationship The relationship to be created.
* @param clazz The model class of the relationship.
* @param <T> The generic type of the relationship.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse} containing the relationship created.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<DigitalTwinsResponse<T>> createOrReplaceRelationshipWithResponse(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz, CreateOrReplaceRelationshipOptions options) {
return withContext(context -> createOrReplaceRelationshipWithResponse(digitalTwinId, relationshipId, relationship, clazz, options, context));
}
<T> Mono<DigitalTwinsResponse<T>> createOrReplaceRelationshipWithResponse(String digitalTwinId, String relationshipId, T relationship, Class<T> clazz, CreateOrReplaceRelationshipOptions options, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.addRelationshipWithResponseAsync(
digitalTwinId,
relationshipId,
relationship,
OptionsConverter.toProtocolLayerOptions(options),
context)
.flatMap(response -> {
T genericResponse;
try {
genericResponse = DeserializationHelpers.deserializeObject(MAPPER, response.getValue(), clazz, this.serializer);
} catch (JsonProcessingException e) {
LOGGER.error("JsonProcessingException occurred while deserializing the create relationship response: ", e);
return Mono.error(e);
}
DigitalTwinsResponseHeaders twinHeaders = MAPPER.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
return Mono.just(new DigitalTwinsResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), genericResponse, twinHeaders));
});
}
/**
* Gets a relationship on a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p>A strongly typed digital twin object such as {@link BasicRelationship} can be provided as the input parameter to deserialize the response into.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationship#String#BasicRelationship -->
* <pre>
* digitalTwinsAsyncClient.getRelationship(
* "myDigitalTwinId",
* "myRelationshipName",
* BasicRelationship.class)
* .subscribe(retrievedRelationship -> System.out.println(
* "Retrieved relationship with Id: "
* + retrievedRelationship.getId()
* + " from: "
* + retrievedRelationship.getSourceId()
* + " to: " + retrievedRelationship.getTargetId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationship#String#BasicRelationship -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationship#String#String -->
* <pre>
* digitalTwinsAsyncClient.getRelationship(
* "myDigitalTwinId",
* "myRelationshipName",
* String.class)
* .subscribe(retrievedRelationshipString ->
* System.out.println("Retrieved relationship: " + retrievedRelationshipString));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationship#String#String -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to retrieve.
* @param clazz The model class to deserialize the relationship into.
* @param <T> The generic type to deserialize the relationship into.
* @return The deserialized relationship.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<T> getRelationship(String digitalTwinId, String relationshipId, Class<T> clazz) {
return getRelationshipWithResponse(digitalTwinId, relationshipId, clazz)
.map(DigitalTwinsResponse::getValue);
}
/**
* Gets a relationship on a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <p>A strongly typed digital twin object such as {@link BasicRelationship} can be provided as the input parameter to deserialize the response into.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationshipWithResponse#String-String-Class-Options#BasicRelationship -->
* <pre>
* digitalTwinsAsyncClient.getRelationshipWithResponse(
* "myDigitalTwinId",
* "myRelationshipName",
* BasicRelationship.class)
* .subscribe(retrievedRelationshipWithResponse -> System.out.println(
* "Retrieved relationship with Id: "
* + retrievedRelationshipWithResponse.getValue().getId()
* + " from: "
* + retrievedRelationshipWithResponse.getValue().getSourceId()
* + " to: " + retrievedRelationshipWithResponse.getValue().getTargetId()
* + "HTTP status code: " + retrievedRelationshipWithResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationshipWithResponse#String-String-Class-Options#BasicRelationship -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationshipWithResponse#String-String-Class-Options#String -->
* <pre>
* digitalTwinsAsyncClient.getRelationshipWithResponse(
* "myDigitalTwinId",
* "myRelationshipName",
* String.class)
* .subscribe(retrievedRelationshipStringWithResponse -> System.out.println(
* "Retrieved relationship: "
* + retrievedRelationshipStringWithResponse
* + " HTTP status code: "
* + retrievedRelationshipStringWithResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.getRelationshipWithResponse#String-String-Class-Options#String -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to retrieve.
* @param clazz The model class to deserialize the relationship into.
* @param <T> The generic type to deserialize the relationship into.
* @return A {@link DigitalTwinsResponse} containing the deserialized relationship.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T> Mono<DigitalTwinsResponse<T>> getRelationshipWithResponse(String digitalTwinId, String relationshipId, Class<T> clazz) {
return withContext(context -> getRelationshipWithResponse(digitalTwinId, relationshipId, clazz, context));
}
<T> Mono<DigitalTwinsResponse<T>> getRelationshipWithResponse(String digitalTwinId, String relationshipId, Class<T> clazz, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.getRelationshipByIdWithResponseAsync(
digitalTwinId,
relationshipId,
null,
context)
.flatMap(response -> {
T genericResponse;
try {
genericResponse = DeserializationHelpers.deserializeObject(MAPPER, response.getValue(), clazz, this.serializer);
} catch (JsonProcessingException e) {
LOGGER.error("JsonProcessingException occurred while deserializing the get relationship response: ", e);
return Mono.error(e);
}
DigitalTwinsResponseHeaders twinHeaders = MAPPER.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
return Mono.just(new DigitalTwinsResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), genericResponse, twinHeaders));
});
}
/**
* Updates the properties of a relationship on a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateRelationship#String-String-JsonPatchDocument -->
* <pre>
* JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
* jsonPatchDocument.appendReplace("/relationshipProperty1", "new property value");
*
* digitalTwinsAsyncClient.updateRelationship(
* "myDigitalTwinId",
* "myRelationshipId",
* jsonPatchDocument)
* .subscribe();
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateRelationship#String-String-JsonPatchDocument -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be updated.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link JsonPatchDocument}.
* @return An empty Mono.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateRelationship(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch) {
return updateRelationshipWithResponse(digitalTwinId, relationshipId, jsonPatch, null)
.flatMap(voidResponse -> Mono.empty());
}
/**
* Updates the properties of a relationship on a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateRelationshipWithResponse#String-String-JsonPatchDocument-UpdateRelationshipOptions -->
* <pre>
* JsonPatchDocument jsonPatchDocument = new JsonPatchDocument();
* jsonPatchDocument.appendReplace("/relationshipProperty1", "new property value");
*
* digitalTwinsAsyncClient.updateRelationshipWithResponse(
* "myDigitalTwinId",
* "myRelationshipId",
* jsonPatchDocument,
* new UpdateRelationshipOptions())
* .subscribe(updateResponse ->
* System.out.println(
* "Relationship updated with status code: "
* + updateResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.updateRelationshipWithResponse#String-String-JsonPatchDocument-UpdateRelationshipOptions -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to be updated.
* @param jsonPatch The JSON patch to apply to the specified digital twin's relationship.
* This argument can be created using {@link JsonPatchDocument}.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link DigitalTwinsResponse} containing no parsed payload object. This response object includes an
* HTTP header that gives you the updated ETag for this resource.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options) {
return withContext(context -> updateRelationshipWithResponse(digitalTwinId, relationshipId, jsonPatch, options, context));
}
Mono<DigitalTwinsResponse<Void>> updateRelationshipWithResponse(String digitalTwinId, String relationshipId, JsonPatchDocument jsonPatch, UpdateRelationshipOptions options, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.updateRelationshipWithResponseAsync(
digitalTwinId,
relationshipId,
jsonPatch,
OptionsConverter.toProtocolLayerOptions(options),
context)
.map(response -> {
DigitalTwinsResponseHeaders twinHeaders = MAPPER.convertValue(response.getDeserializedHeaders(), DigitalTwinsResponseHeaders.class);
return new DigitalTwinsResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), response.getValue(), twinHeaders);
});
}
/**
* Deletes a relationship on a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteRelationship#String-String -->
* <pre>
* digitalTwinsAsyncClient.deleteRelationship("myDigitalTwinId", "myRelationshipId")
* .subscribe();
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteRelationship#String-String -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to delete.
* @return An empty Mono.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> deleteRelationship(String digitalTwinId, String relationshipId) {
return deleteRelationshipWithResponse(digitalTwinId, relationshipId, null)
.flatMap(voidResponse -> Mono.empty());
}
/**
* Deletes a relationship on a digital twin.
*
* <p><strong>Code Samples</strong></p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteRelationshipWithResponse#String-String-DeleteRelationshipOptions -->
* <pre>
* digitalTwinsAsyncClient.deleteRelationshipWithResponse(
* "myDigitalTwinId",
* "myRelationshipId",
* new DeleteRelationshipOptions())
* .subscribe(deleteResponse ->
* System.out.println(
* "Deleted relationship with HTTP status code: "
* + deleteResponse.getStatusCode()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.deleteRelationshipWithResponse#String-String-DeleteRelationshipOptions -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param relationshipId The Id of the relationship to delete.
* @param options The optional parameters for this request. If null, the default option values will be used.
* @return A {@link Response} containing no parsed payload object.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> deleteRelationshipWithResponse(String digitalTwinId, String relationshipId, DeleteRelationshipOptions options) {
return withContext(context -> deleteRelationshipWithResponse(digitalTwinId, relationshipId, options, context));
}
Mono<Response<Void>> deleteRelationshipWithResponse(String digitalTwinId, String relationshipId, DeleteRelationshipOptions options, Context context) {
if (context == null) {
context = Context.NONE;
}
return protocolLayer
.getDigitalTwins()
.deleteRelationshipWithResponseAsync(
digitalTwinId,
relationshipId,
OptionsConverter.toProtocolLayerOptions(options),
context);
}
/**
* Gets all the relationships on a digital twin by iterating through a collection.
*
* <p>A strongly typed digital twin object such as {@link BasicRelationship} can be provided as the input parameter to deserialize the response into.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-Class-Options#BasicRelationship#IterateByItem -->
* <pre>
* digitalTwinsAsyncClient.listRelationships("myDigitalTwinId", BasicRelationship.class)
* .doOnNext(basicRel -> System.out.println("Retrieved relationship with Id: " + basicRel.getId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-Class-Options#BasicRelationship#IterateByItem -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-Class-Options#String#IterateByItem -->
* <pre>
* digitalTwinsAsyncClient.listRelationships("myDigitalTwinId", String.class)
* .doOnNext(rel -> System.out.println("Retrieved relationship: " + rel));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-Class-Options#String#IterateByItem -->
*
* @param digitalTwinId The Id of the source digital twin.
* @param clazz The model class to convert the relationship to. Since a digital twin might have relationships conforming to different models, it is advisable to convert them to a generic model like {@link BasicRelationship}.
* @param <T> The generic type to convert the relationship to.
* @return A {@link PagedFlux} of relationships belonging to the specified digital twin and the http response.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public <T> PagedFlux<T> listRelationships(String digitalTwinId, Class<T> clazz) {
return listRelationships(digitalTwinId, null, clazz);
}
/**
* Gets all the relationships on a digital twin filtered by the relationship name, by iterating through a collection.
*
* <p>A strongly typed digital twin object such as {@link BasicRelationship} can be provided as the input parameter to deserialize the response into.</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-String-Class-Options#BasicRelationship#IterateByItem -->
* <pre>
* digitalTwinsAsyncClient.listRelationships(
* "myDigitalTwinId",
* "myRelationshipName",
* BasicRelationship.class)
* .doOnNext(rel -> System.out.println("Retrieved relationship with Id: " + rel.getId()));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-String-Class-Options#BasicRelationship#IterateByItem -->
*
* <p>Or alternatively String can be used as input and output deserialization type:</p>
*
* <!-- src_embed com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-String-Class-Options#String#IterateByItem -->
* <pre>
* digitalTwinsAsyncClient.listRelationships(
* "myDigitalTwinId",
* "myRelationshipId",
* String.class)
* .doOnNext(rel -> System.out.println("Retrieved relationship: " + rel));
* </pre>
* <!-- end com.azure.digitaltwins.core.DigitalTwinsAsyncClient.listRelationships#String-String-Class-Options#String#IterateByItem -->
*