/// <summary> /// Builds the values of the relationships object on a resource object. /// The server serializer only populates the "data" member when the relationship is included, /// and adds links unless these are turned off. This means that if a relationship is not included /// and links are turned off, the entry would be completely empty, ie { }, which is not conform /// json:api spec. In that case we return null which will omit the entry from the output. /// </summary> protected override RelationshipEntry GetRelationshipData(RelationshipAttribute relationship, IIdentifiable entity) { RelationshipEntry relationshipEntry = null; List <List <RelationshipAttribute> > relationshipChains = null; if (relationship == _requestRelationship || ShouldInclude(relationship, out relationshipChains)) { relationshipEntry = base.GetRelationshipData(relationship, entity); if (relationshipChains != null && relationshipEntry.HasResource) { foreach (var chain in relationshipChains) { // traverses (recursively) and extracts all (nested) related entities for the current inclusion chain. _includedBuilder.IncludeRelationshipChain(chain, entity); } } } var links = _linkBuilder.GetRelationshipLinks(relationship, entity); if (links != null) { // if links relationshipLinks should be built for this entry, populate the "links" field. (relationshipEntry = relationshipEntry ?? new RelationshipEntry()).Links = links; } // if neither "links" nor "data" was popupated, return null, which will omit this entry from the output. // (see the NullValueHandling settings on <see cref="ResourceObject"/>) return(relationshipEntry); }
/// <summary> /// We only need an empty relationship object entry here. It will be populated in the /// ProcessRelationships method. /// </summary> protected override RelationshipEntry GetRelationshipData(RelationshipAttribute relationship, IIdentifiable resource) { ArgumentGuard.NotNull(relationship, nameof(relationship)); ArgumentGuard.NotNull(resource, nameof(resource)); return(new RelationshipEntry { Links = _linkBuilder.GetRelationshipLinks(relationship, resource) }); }
/// <summary> /// We only need an empty relationship object entry here. It will be populated in the /// ProcessRelationships method. /// </summary> protected override RelationshipEntry GetRelationshipData(RelationshipAttribute relationship, IIdentifiable resource) { if (relationship == null) { throw new ArgumentNullException(nameof(relationship)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } return(new RelationshipEntry { Links = _linkBuilder.GetRelationshipLinks(relationship, resource) }); }
/// <summary> /// Builds the values of the relationships object on a resource object. /// The server serializer only populates the "data" member when the relationship is included, /// and adds links unless these are turned off. This means that if a relationship is not included /// and links are turned off, the entry would be completely empty, ie { }, which is not conform /// JSON:API spec. In that case we return null which will omit the entry from the output. /// </summary> protected override RelationshipEntry GetRelationshipData(RelationshipAttribute relationship, IIdentifiable resource) { if (relationship == null) { throw new ArgumentNullException(nameof(relationship)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } RelationshipEntry relationshipEntry = null; List <IReadOnlyCollection <RelationshipAttribute> > relationshipChains = null; if (Equals(relationship, _requestRelationship) || ShouldInclude(relationship, out relationshipChains)) { relationshipEntry = base.GetRelationshipData(relationship, resource); if (relationshipChains != null && relationshipEntry.HasResource) { foreach (var chain in relationshipChains) { // traverses (recursively) and extracts all (nested) related resources for the current inclusion chain. _includedBuilder.IncludeRelationshipChain(chain, resource); } } } if (!IsRelationshipInSparseFieldSet(relationship)) { return(null); } var links = _linkBuilder.GetRelationshipLinks(relationship, resource); if (links != null) { // if relationshipLinks should be built for this entry, populate the "links" field. relationshipEntry ??= new RelationshipEntry(); relationshipEntry.Links = links; } // if neither "links" nor "data" was populated, return null, which will omit this entry from the output. // (see the NullValueHandling settings on <see cref="ResourceObject"/>) return(relationshipEntry); }
/// <summary> /// We only need a empty relationship object entry here. It will be populated in the /// ProcessRelationships method. /// </summary> /// <param name="relationship"></param> /// <param name="entity"></param> /// <returns></returns> protected override RelationshipEntry GetRelationshipData(RelationshipAttribute relationship, IIdentifiable entity) { return(new RelationshipEntry { Links = _linkBuilder.GetRelationshipLinks(relationship, entity) }); }
/// <summary> /// Builds the values of the relationships object on a resource object. /// The server serializer only populates the "data" member when the relationship is included, /// and adds links unless these are turned off. This means that if a relationship is not included /// and links are turned off, the entry would be completely empty, ie { }, which is not conform /// json:api spec. In that case we return null which will omit the entry from the output. /// </summary> protected override RelationshipEntry GetRelationshipData(RelationshipAttribute relationship, IIdentifiable entity) { RelationshipEntry relationshipEntry = null; List <List <RelationshipAttribute> > relationshipChains = null; relationshipEntry = base.GetRelationshipData(relationship, entity); // sven if (Equals(relationship, _requestRelationship) || ShouldInclude(relationship, out relationshipChains) || true) { if (relationshipChains != null && relationshipChains.Count != 0 && relationshipEntry.HasResource) { // sven //if (relationshipChains.Count == 0) { // relationshipChains = _fieldsToSerialize.GetAllowedRelationships(relationship.RightType) // .Select(x => new List<RelationshipAttribute> { x }).ToList(); //} // every chain in relationshipChains has the same on first position = the relationship requested var allowedRelations = _fieldsToSerialize.GetAllowedRelationships(relationship.RightType); //var fakeChains = relationshipChains.ToList(); var fakeChains = new List <List <RelationshipAttribute> >(); var singleOneIndex = fakeChains.FindIndex(x => x.Count == 1 && x.First().Equals(relationship)); if (singleOneIndex != -1) { fakeChains.RemoveAt(singleOneIndex); } foreach (var relation in allowedRelations) { bool isIncluded = fakeChains.Any(x => x.Last().Equals(relation)); if (!isIncluded) { var subList = new List <RelationshipAttribute> { relationship, relation }; fakeChains.Add(subList); } } // sven foreach (var chain in fakeChains) { // traverses (recursively) and extracts all (nested) related entities for the current inclusion chain. _includedBuilder.IncludeRelationshipChain(chain, entity); } } } var links = _linkBuilder.GetRelationshipLinks(relationship, entity); // sven // omit links everytime //if (links != null) // // if links relationshipLinks should be built for this entry, populate the "links" field. // (relationshipEntry ??= new RelationshipEntry()).Links = links; // if neither "links" nor "data" was populated, return null, which will omit this entry from the output. // (see the NullValueHandling settings on <see cref="ResourceObject"/>) return(relationshipEntry); }