Repository navigation
Expand file tree
/
Copy pathFamilySearchFamilyTree.cs
More file actions
753 lines (700 loc) · 46.5 KB
/
Copy pathFamilySearchFamilyTree.cs
File metadata and controls
753 lines (700 loc) · 46.5 KB
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
using RestSharp;
using System;
using System.Xml.Serialization;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gx.Rs.Api.Util;
using Gx.Rs.Api;
using Gx.Types;
using Gx.Conclusion;
using Gx.Fs.Tree;
using Gx.Common;
using Gx.Links;
using Gx.Fs;
using FamilySearch.Api.Util;
using Tavis.UriTemplates;
using System.Net;
using Gedcomx.Support;
namespace FamilySearch.Api.Ft
{
/// <summary>
/// The FamilySearchFamilyTree is a collection of FamilySearch records and exposes management of those records.
/// </summary>
public class FamilySearchFamilyTree : FamilySearchCollectionState
{
/// <summary>
/// The default production environment URI for this collection.
/// </summary>
public static readonly String URI = "https://familysearch.org/platform/collections/tree";
/// <summary>
/// The default sandbox environment URI for this collection.
/// </summary>
public static readonly String SANDBOX_URI = "https://sandbox.familysearch.org/platform/collections/tree";
/// <summary>
/// The default beta environment URI for this collection.
/// </summary>
public static readonly String BETA_URI = "https://beta.familysearch.org/platform/collections/tree";
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class using the production environment URI.
/// </summary>
public FamilySearchFamilyTree()
: this(false)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class.
/// </summary>
/// <param name="sandbox">If set to <c>true</c> this will use the sandbox environment URI; otherwise, it will use production.</param>
public FamilySearchFamilyTree(bool sandbox)
: this(new Uri(sandbox ? SANDBOX_URI : URI))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class supporting the beta environment
/// </summary>
/// <param name="environment"></param>
public FamilySearchFamilyTree(EnvironmentEnum environment)
: this(new Uri(
environment == EnvironmentEnum.Sandbox ? SANDBOX_URI :
environment == EnvironmentEnum.Beta ? BETA_URI :
URI))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class.
/// </summary>
/// <param name="uri">The URI where the target collection resides.</param>
public FamilySearchFamilyTree(Uri uri)
: this(uri, new FamilyTreeStateFactory())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class.
/// </summary>
/// <param name="uri">The URI where the target resides.</param>
/// <param name="stateFactory">The state factory to use for state instantiation.</param>
private FamilySearchFamilyTree(Uri uri, FamilyTreeStateFactory stateFactory)
: this(uri, stateFactory.LoadDefaultClientInt(uri), stateFactory)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class.
/// </summary>
/// <param name="uri">The URI where the target resides.</param>
/// <param name="client">The REST API client to use for API calls.</param>
/// <param name="stateFactory">The state factory to use for state instantiation.</param>
private FamilySearchFamilyTree(Uri uri, IFilterableRestClient client, FamilyTreeStateFactory stateFactory)
: this(new RedirectableRestRequest().Accept(MediaTypes.GEDCOMX_JSON_MEDIA_TYPE).Build(uri, Method.GET), client, stateFactory)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class.
/// </summary>
/// <param name="request">The REST API request that will be used to instantiate this state instance.</param>
/// <param name="client">The REST API client to use for API calls.</param>
/// <param name="stateFactory">The state factory to use for state instantiation.</param>
private FamilySearchFamilyTree(IRestRequest request, IFilterableRestClient client, FamilyTreeStateFactory stateFactory)
: this(request, client.Handle(request), client, null, stateFactory)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="FamilySearchFamilyTree"/> class.
/// </summary>
/// <param name="request">The REST API request that will be used to instantiate this state instance.</param>
/// <param name="response">The REST API response that was produced from the REST API request.</param>
/// <param name="client">The REST API client to use for API calls.</param>
/// <param name="accessToken">The access token to use for subsequent invocations of the REST API client.</param>
/// <param name="stateFactory">The state factory to use for state instantiation.</param>
internal FamilySearchFamilyTree(IRestRequest request, IRestResponse response, IFilterableRestClient client, String accessToken, FamilyTreeStateFactory stateFactory)
: base(request, response, client, accessToken, stateFactory)
{
}
/// <summary>
/// Clones the current state instance.
/// </summary>
/// <param name="request">The REST API request used to create this state instance.</param>
/// <param name="response">The REST API response used to create this state instance.</param>
/// <param name="client">The REST API client used to create this state instance.</param>
/// <returns>A cloned instance of the current state instance.</returns>
protected override GedcomxApplicationState Clone(IRestRequest request, IRestResponse response, IFilterableRestClient client)
{
return new FamilySearchFamilyTree(request, response, client, this.CurrentAccessToken, (FamilyTreeStateFactory)this.stateFactory);
}
/// <summary>
/// Creates a state instance without authentication. It will produce an access token, but only good for requests that do not need authentication.
/// </summary>
/// <param name="clientId">The client identifier.</param>
/// <param name="ipAddress">The ip address.</param>
/// <returns>A <see cref="FamilySearchFamilyTree"/> instance containing the REST API response.</returns>
/// <remarks>See https://familysearch.org/developers/docs/guides/oauth2 for more information.</remarks>
public FamilySearchFamilyTree AuthenticateViaUnauthenticatedAccess(String clientId, String ipAddress)
{
IDictionary<String, String> formData = new Dictionary<String, String>();
formData.Add("grant_type", "unauthenticated_session");
formData.Add("client_id", clientId);
formData.Add("ip_address", ipAddress);
return (FamilySearchFamilyTree)this.AuthenticateViaOAuth2(formData);
}
/// <summary>
/// Adds relationship to the collection.
/// </summary>
/// <param name="relationship">The relationship to add.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="RelationshipState" /> instance containing the REST API response.
/// </returns>
/// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if this collection does not have a link to the resource.</exception>
public override RelationshipState AddRelationship(Relationship relationship, params IStateTransitionOption[] options)
{
if (relationship.KnownType == RelationshipType.ParentChild)
{
throw new GedcomxApplicationException("FamilySearch Family Tree doesn't support adding parent-child relationships. You must instead add a child-and-parents relationship.");
}
return base.AddRelationship(relationship);
}
/// <summary>
/// Adds the array of relationships to the collection.
/// </summary>
/// <param name="relationships">The relationships to add.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="RelationshipsState" /> instance containing the REST API response.
/// </returns>
/// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if this collection does not have a link to the resource.</exception>
public override RelationshipsState AddRelationships(List<Relationship> relationships, params IStateTransitionOption[] options)
{
foreach (Relationship relationship in relationships)
{
if (relationship.KnownType == RelationshipType.ParentChild)
{
throw new GedcomxApplicationException("FamilySearch Family Tree doesn't support adding parent-child relationships. You must instead add a child-and-parents relationship.");
}
}
return base.AddRelationships(relationships);
}
/// <summary>
/// Adds a child and parents relationship to the collection.
/// </summary>
/// <param name="child">The child to add in the relationship.</param>
/// <param name="father">The father to add in the relationship.</param>
/// <param name="mother">The mother to add in the relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="ChildAndParentsRelationshipState"/> instance containing the REST API response.
/// </returns>
public ChildAndParentsRelationshipState AddChildAndParentsRelationship(PersonState child, PersonState father, PersonState mother, params IStateTransitionOption[] options)
{
ChildAndParentsRelationship chap = new ChildAndParentsRelationship();
chap.Child = new ResourceReference(child.GetSelfUri());
if (father != null)
{
chap.Father = new ResourceReference(father.GetSelfUri());
}
if (mother != null)
{
chap.Mother = new ResourceReference(mother.GetSelfUri());
}
return AddChildAndParentsRelationship(chap, options);
}
/// <summary>
/// Adds a child and parents relationship to the collection.
/// </summary>
/// <param name="chap">The child and parent relationship to add.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="ChildAndParentsRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if a link to the required resource cannot be found.</exception>
public ChildAndParentsRelationshipState AddChildAndParentsRelationship(ChildAndParentsRelationship chap, params IStateTransitionOption[] options)
{
Link link = GetLink(Rel.RELATIONSHIPS);
if (link == null || link.Href == null)
{
throw new GedcomxApplicationException(String.Format("FamilySearch Family Tree at {0} didn't provide a 'relationships' link.", GetUri()));
}
FamilySearchPlatform entity = new FamilySearchPlatform();
entity.ChildAndParentsRelationships = new List<ChildAndParentsRelationship>() { chap };
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.POST);
request.SetEntity(entity);
return ((FamilyTreeStateFactory)this.stateFactory).NewChildAndParentsRelationshipState(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
}
/// <summary>
/// Adds the child and parents relationships to the collection.
/// </summary>
/// <param name="chaps">The child and parent relationships to add.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="RelationshipsState"/> instance containing the REST API response.
/// </returns>
/// <exception cref="Gx.Rs.Api.GedcomxApplicationException">Thrown if a link to the required resource cannot be found.</exception>
public RelationshipsState AddChildAndParentsRelationships(List<ChildAndParentsRelationship> chaps, params IStateTransitionOption[] options)
{
Link link = GetLink(Rel.RELATIONSHIPS);
if (link == null || link.Href == null)
{
throw new GedcomxApplicationException(String.Format("FamilySearch Family Tree at {0} didn't provide a 'relationships' link.", GetUri()));
}
FamilySearchPlatform entity = new FamilySearchPlatform();
entity.ChildAndParentsRelationships = chaps;
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(link.Href, Method.POST);
request.SetEntity(entity);
return ((FamilyTreeStateFactory)this.stateFactory).NewRelationshipsStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
}
/// <summary>
/// Reads the person by the specified ID.
/// </summary>
/// <param name="id">The ID of the person to read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="FamilyTreePersonState"/> instance containing the REST API response.
/// </returns>
public FamilyTreePersonState ReadPersonById(String id, params IStateTransitionOption[] options)
{
Link link = GetLink(Rel.PERSON);
if (link == null || link.Template == null)
{
return null;
}
String template = link.Template;
String uri = new UriTemplate(template).AddParameter("pid", id).Resolve();
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.GET);
return (FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
}
/// <summary>
/// Reads the person by the specified ID and includes relationship details in the response.
/// </summary>
/// <param name="id">The ID of the person to read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="FamilyTreePersonState"/> instance containing the REST API response.
/// </returns>
public FamilyTreePersonState ReadPersonWithRelationshipsById(String id, params IStateTransitionOption[] options)
{
Link link = GetLink(Rel.PERSON_WITH_RELATIONSHIPS);
if (link == null || link.Template == null)
{
return null;
}
String template = link.Template;
String uri = new UriTemplate(template).AddParameter("person", id).Resolve();
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.GET);
return (FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
}
/// <summary>
/// Reads the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="user">The user for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred spouse relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <remarks>Tree users can have varying spouse relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.</remarks>
public IPreferredRelationshipState ReadPreferredSpouseRelationship(UserState user, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return ReadPreferredRelationship(Rel.PREFERRED_SPOUSE_RELATIONSHIP, user.User.TreeUserId, person.Person.Id, options);
}
/// <summary>
/// Reads the preferred parent relationship for the specified person.
/// </summary>
/// <param name="user">The user for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred parent relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <remarks>Tree users can have varying parent relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.</remarks>
public IPreferredRelationshipState ReadPreferredParentRelationship(UserState user, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return ReadPreferredRelationship(Rel.PREFERRED_PARENT_RELATIONSHIP, user.User.TreeUserId, person.Person.Id, options);
}
/// <summary>
/// Reads the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred spouse relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <remarks>Tree users can have varying spouse relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.</remarks>
public IPreferredRelationshipState ReadPreferredSpouseRelationship(String treeUserId, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return ReadPreferredRelationship(Rel.PREFERRED_SPOUSE_RELATIONSHIP, treeUserId, person.Person.Id, options);
}
/// <summary>
/// Reads the preferred parent relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred parent relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <remarks>Tree users can have varying parent relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.</remarks>
public IPreferredRelationshipState ReadPreferredParentRelationship(String treeUserId, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return ReadPreferredRelationship(Rel.PREFERRED_PARENT_RELATIONSHIP, treeUserId, person.Person.Id, options);
}
/// <summary>
/// Reads the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred spouse relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <remarks>Tree users can have varying spouse relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.</remarks>
public IPreferredRelationshipState ReadPreferredSpouseRelationship(String treeUserId, String personId, params IStateTransitionOption[] options)
{
return ReadPreferredRelationship(Rel.PREFERRED_SPOUSE_RELATIONSHIP, treeUserId, personId, options);
}
/// <summary>
/// Reads the preferred parent relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred parent relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState"/> instance containing the REST API response.
/// </returns>
/// <remarks>Tree users can have varying parent relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.</remarks>
public IPreferredRelationshipState ReadPreferredParentRelationship(String treeUserId, String personId, params IStateTransitionOption[] options)
{
return ReadPreferredRelationship(Rel.PREFERRED_PARENT_RELATIONSHIP, treeUserId, personId, options);
}
/// <summary>
/// Reads the preferred relationship for the specified person.
/// </summary>
/// <param name="rel">The rel name of the link to use to perform this operation.</param>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId" /> for which the preference will be read. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying relationship preferences; therefore, this method will only read what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
protected IPreferredRelationshipState ReadPreferredRelationship(String rel, String treeUserId, String personId, IStateTransitionOption[] options)
{
Link link = GetLink(rel);
if (link == null || link.Template == null)
{
return null;
}
String template = link.Template;
String uri = new UriTemplate(template).AddParameter("pid", personId).AddParameter("uid", treeUserId).Resolve();
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.GET);
IRestResponse response = Invoke(request, options);
if (response.StatusCode == HttpStatusCode.NoContent)
{
return null;
}
FamilySearchPlatform fsp = response.ToIRestResponse<FamilySearchPlatform>().Data;
if (fsp != null && fsp.ChildAndParentsRelationships != null && fsp.ChildAndParentsRelationships.Count > 0)
{
return ((FamilyTreeStateFactory)this.stateFactory).NewChildAndParentsRelationshipState(request, response, this.Client, this.CurrentAccessToken);
}
else
{
return (IPreferredRelationshipState)((FamilyTreeStateFactory)this.stateFactory).NewRelationshipStateInt(request, response, this.Client, this.CurrentAccessToken);
}
}
/// <summary>
/// Sets the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="user">The user for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred spouse relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying spouse relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState UpdatePreferredSpouseRelationship(UserState user, FamilyTreePersonState person, IPreferredRelationshipState relationshipState, params IStateTransitionOption[] options)
{
return UpdatePreferredRelationship(Rel.PREFERRED_SPOUSE_RELATIONSHIP, user.User.TreeUserId, person.Person.Id, relationshipState, options);
}
/// <summary>
/// Sets the preferred parent relationship for the specified person.
/// </summary>
/// <param name="user">The user for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred parent relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying parent relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState UpdatePreferredParentRelationship(UserState user, FamilyTreePersonState person, IPreferredRelationshipState relationshipState, params IStateTransitionOption[] options)
{
return UpdatePreferredRelationship(Rel.PREFERRED_PARENT_RELATIONSHIP, user.User.TreeUserId, person.Person.Id, relationshipState, options);
}
/// <summary>
/// Sets the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred spouse relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying spouse relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState UpdatePreferredSpouseRelationship(String treeUserId, FamilyTreePersonState person, IPreferredRelationshipState relationshipState, params IStateTransitionOption[] options)
{
return UpdatePreferredRelationship(Rel.PREFERRED_SPOUSE_RELATIONSHIP, treeUserId, person.Person.Id, relationshipState, options);
}
/// <summary>
/// Sets the preferred parent relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred parent relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying parent relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState UpdatePreferredParentRelationship(String treeUserId, FamilyTreePersonState person, IPreferredRelationshipState relationshipState, params IStateTransitionOption[] options)
{
return UpdatePreferredRelationship(Rel.PREFERRED_PARENT_RELATIONSHIP, treeUserId, person.Person.Id, relationshipState, options);
}
/// <summary>
/// Sets the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred spouse relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying spouse relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState UpdatePreferredSpouseRelationship(String treeUserId, String personId, IPreferredRelationshipState relationshipState, params IStateTransitionOption[] options)
{
return UpdatePreferredRelationship(Rel.PREFERRED_SPOUSE_RELATIONSHIP, treeUserId, personId, relationshipState, options);
}
/// <summary>
/// Sets the preferred parent relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred parent relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying parent relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState UpdatePreferredParentRelationship(String treeUserId, String personId, IPreferredRelationshipState relationshipState, params IStateTransitionOption[] options)
{
return UpdatePreferredRelationship(Rel.PREFERRED_PARENT_RELATIONSHIP, treeUserId, personId, relationshipState, options);
}
/// <summary>
/// Sets the preferred relationship for the specified person.
/// </summary>
/// <param name="rel">The rel name of the link to use to perform this operation.</param>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId" /> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred relationship will be read.</param>
/// <param name="relationshipState">The relationship state instance with the relationship to set as the preferred relationship.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying relationship preferences; therefore, this method will only set what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
protected FamilyTreePersonState UpdatePreferredRelationship(String rel, String treeUserId, String personId, IPreferredRelationshipState relationshipState, IStateTransitionOption[] options)
{
Link link = GetLink(rel);
if (link == null || link.Template == null)
{
return null;
}
String template = link.Template;
String uri = new UriTemplate(template).AddParameter("pid", personId).AddParameter("uid", treeUserId).Resolve();
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).AddHeader("Location", relationshipState.GetSelfUri()).Build(uri, Method.PUT);
return (FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
}
/// <summary>
/// Deletes the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="user">The user for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred spouse relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying spouse relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState DeletePreferredSpouseRelationship(UserState user, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return DeletePreferredRelationship(user.User.TreeUserId, person.Person.Id, Rel.PREFERRED_SPOUSE_RELATIONSHIP, options);
}
/// <summary>
/// Deletes the preferred parent relationship for the specified person.
/// </summary>
/// <param name="user">The user for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred parent relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying parent relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState DeletePreferredParentRelationship(UserState user, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return DeletePreferredRelationship(user.User.TreeUserId, person.Person.Id, Rel.PREFERRED_PARENT_RELATIONSHIP, options);
}
/// <summary>
/// Deletes the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred spouse relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying spouse relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState DeletePreferredSpouseRelationship(String treeUserId, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return DeletePreferredRelationship(treeUserId, person.Person.Id, Rel.PREFERRED_SPOUSE_RELATIONSHIP, options);
}
/// <summary>
/// Deletes the preferred parent relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="person">The person, represented by the FamilyTreePersonState, for which the preferred parent relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying parent relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState DeletePreferredParentRelationship(String treeUserId, FamilyTreePersonState person, params IStateTransitionOption[] options)
{
return DeletePreferredRelationship(treeUserId, person.Person.Id, Rel.PREFERRED_PARENT_RELATIONSHIP, options);
}
/// <summary>
/// Deletes the preferred spouse relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred spouse relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying spouse relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState DeletePreferredSpouseRelationship(String treeUserId, String personId, params IStateTransitionOption[] options)
{
return DeletePreferredRelationship(treeUserId, personId, Rel.PREFERRED_SPOUSE_RELATIONSHIP, options);
}
/// <summary>
/// Deletes the preferred parent relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId"/> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred parent relationship will be read.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying parent relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
public FamilyTreePersonState DeletePreferredParentRelationship(String treeUserId, String personId, params IStateTransitionOption[] options)
{
return DeletePreferredRelationship(treeUserId, personId, Rel.PREFERRED_PARENT_RELATIONSHIP, options);
}
/// <summary>
/// Deletes the preferred relationship for the specified person.
/// </summary>
/// <param name="treeUserId">The <see cref="P:User.TreeUserId" /> for which the preference will be set. This is typically the current tree user. An API error may result if the user specified
/// is someone other than the current tree user (due to a lack of permissions).</param>
/// <param name="personId">The person ID for which the preferred relationship will be read.</param>
/// <param name="rel">The rel name of the link to use to perform this operation.</param>
/// <param name="options">The options to apply before executing the REST API call.</param>
/// <returns>
/// A <see cref="IPreferredRelationshipState" /> instance containing the REST API response.
/// </returns>
/// <remarks>
/// Tree users can have varying relationship preferences; therefore, this method will only delete what the specified user prefers to
/// see for the specified relationship.
/// </remarks>
protected FamilyTreePersonState DeletePreferredRelationship(String treeUserId, String personId, String rel, IStateTransitionOption[] options)
{
Link link = GetLink(rel);
if (link == null || link.Template == null)
{
return null;
}
String template = link.Template;
String uri = new UriTemplate(template).AddParameter("pid", personId).AddParameter("uid", treeUserId).Resolve();
IRestRequest request = RequestUtil.ApplyFamilySearchConneg(CreateAuthenticatedRequest()).Build(uri, Method.DELETE);
return (FamilyTreePersonState)((FamilyTreeStateFactory)this.stateFactory).NewPersonStateInt(request, Invoke(request, options), this.Client, this.CurrentAccessToken);
}
}
}