예제 #1
0
 public override async Task <(bool validated, string failureReason)> ValidateSyncComponent(
     JObject content,
     IValidateAndRepairContext context)
 {
     return(await _contentFieldsGraphSyncer.ValidateSyncComponent(
                content, context));
 }
 public override Task <(bool validated, string failureReason)> ValidateSyncComponent(
     JObject content,
     IValidateAndRepairContext context)
 {
     return(_embeddedContentItemsGraphSyncer.ValidateSyncComponent(
                (JArray?)content[ContainerName], context));
 }
예제 #3
0
 //todo: we now need to validate any 2 way incoming relationships we created
 public override Task <(bool validated, string failureReason)> ValidateSyncComponent(
     JObject content,
     IValidateAndRepairContext context)
 {
     _embeddedContentItemsGraphSyncer.IsNonLeafEmbeddedTerm = false;
     return(ValidateSyncComponentImplementation(content, context));
 }
예제 #4
0
 public async Task <(bool validated, string failureReason)> ValidateSyncComponentForNonLeafEmbeddedTerm(
     JObject content,
     IValidateAndRepairContext context)
 {
     _embeddedContentItemsGraphSyncer.IsNonLeafEmbeddedTerm = true;
     return(await ValidateSyncComponentImplementation(content, context));
 }
예제 #5
0
        public async Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject contentItemField,
            IValidateAndRepairContext context)
        {
            //todo: check for null
            ContentItem?taxonomyContentItem = await GetTaxonomyContentItem(
                contentItemField, context.ContentItemVersion, context.ContentManager);

            var    taxonomyPartContent = taxonomyContentItem !.Content[nameof(TaxonomyPart)];
            string termContentType     = taxonomyPartContent[TermContentType];

            string termRelationshipType = TermRelationshipType(termContentType);

            IOutgoingRelationship[] actualRelationships = context.NodeWithOutgoingRelationships.OutgoingRelationships
                                                          .Where(r => r.Relationship.Type == termRelationshipType)
                                                          .ToArray();

            var contentItemIds = (JArray)contentItemField[TermContentItemIds] !;

            if (contentItemIds.Count != actualRelationships.Length)
            {
                return(false, $"expecting {contentItemIds.Count} relationships of type {termRelationshipType} in graph, but found {actualRelationships.Length}");
            }

            ISyncNameProvider relatedSyncNameProvider = _serviceProvider.GetSyncNameProvider(termContentType);

            var flattenedTermsContentItems = GetFlattenedTermsContentItems(taxonomyPartContent);

            foreach (JToken item in contentItemIds)
            {
                string contentItemId = (string)item !;

                object?destinationId = GetNodeId(
                    contentItemId, flattenedTermsContentItems, relatedSyncNameProvider, context.ContentItemVersion) !;

                (bool validated, string failureReason) = context.GraphValidationHelper.ValidateOutgoingRelationship(
                    context.NodeWithOutgoingRelationships,
                    termRelationshipType,
                    relatedSyncNameProvider !.IdPropertyName(),
                    destinationId);

                if (!validated)
                {
                    return(false, failureReason);
                }

                // keep a count of how many relationships of a type we expect to be in the graph
                context.ExpectedRelationshipCounts.IncreaseCount(termRelationshipType);
            }

            // return context.GraphValidationHelper.StringArrayContentPropertyMatchesNodeProperty(
            //     TagNames,
            //     contentItemField,
            //     TaxonomyTermsNodePropertyName,
            //     context.NodeWithOutgoingRelationships.SourceNode);

            return(true, "");
        }
예제 #6
0
 public override Task <(bool validated, string failureReason)> ValidateSyncComponent(
     JObject content,
     IValidateAndRepairContext context)
 {
     return(Task.FromResult(context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                                _contentTitlePropertyName,
                                content,
                                NodeTitlePropertyName,
                                context.NodeWithOutgoingRelationships.SourceNode)));
 }
예제 #7
0
        public override async Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject content,
            IValidateAndRepairContext context)
        {
            using var _ = context.SyncNameProvider.PushPropertyNameTransform(_pageLocationPropertyNameTransform);

            (bool matched, string failureReason) = context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                UrlNamePropertyName,
                content,
                await context.SyncNameProvider.PropertyName(UrlNamePropertyName),
                context.NodeWithOutgoingRelationships.SourceNode);

            if (!matched)
            {
                return(false, $"{UrlNamePropertyName} did not validate: {failureReason}");
            }

            (matched, failureReason) = context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                FullUrlPropertyName,
                content,
                await context.SyncNameProvider.PropertyName(FullUrlPropertyName),
                context.NodeWithOutgoingRelationships.SourceNode);

            if (!matched)
            {
                return(false, $"{FullUrlPropertyName} did not validate: {failureReason}");
            }

            var settings = context.ContentTypePartDefinition.GetSettings <PageLocationPartSettings>();

            if (settings.DisplayRedirectLocationsAndDefaultPageForLocation)
            {
                (matched, failureReason) = context.GraphValidationHelper.BoolContentPropertyMatchesNodeProperty(
                    DefaultPageForLocationPropertyName,
                    content,
                    await context.SyncNameProvider.PropertyName(DefaultPageForLocationPropertyName),
                    context.NodeWithOutgoingRelationships.SourceNode);

                if (!matched)
                {
                    return(false, $"{DefaultPageForLocationPropertyName} did not validate: {failureReason}");
                }

                (matched, failureReason) = context.GraphValidationHelper.ContentMultilineStringPropertyMatchesNodeProperty(
                    RedirectLocationsPropertyName,
                    content,
                    await context.SyncNameProvider.PropertyName(RedirectLocationsPropertyName),
                    context.NodeWithOutgoingRelationships.SourceNode);

                return(matched ? (true, "") : (false, $"{RedirectLocationsPropertyName} did not validate: {failureReason}"));
            }

            return(true, "");
        }
        public override async Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject content,
            IValidateAndRepairContext context)
        {
            // prefix field property names, so there's no possibility of a clash with the eponymous fields property names
            using var _ = context.SyncNameProvider.PushPropertyNameTransform(_htmlBodyFieldsPropertyNameTransform);

            return(context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                       HtmlPropertyName,
                       content,
                       await context.SyncNameProvider !.PropertyName(HtmlPropertyName),
                       context.NodeWithOutgoingRelationships.SourceNode));
        }
예제 #9
0
        private async Task <(bool validated, string failureReason)> ValidateSyncComponentImplementation(
            JObject content,
            IValidateAndRepairContext context)
        {
            (bool validated, string failureReason) =
                await _embeddedContentItemsGraphSyncer.ValidateSyncComponent(
                    (JArray?)content[ContainerName], context);

            if (!validated)
            {
                return(validated, failureReason);
            }

            return(context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                       TermContentTypePropertyName,
                       content,
                       TermContentTypePropertyName,
                       context.NodeWithOutgoingRelationships.SourceNode));
        }
        public async Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject contentItemField,
            IValidateAndRepairContext context)
        {
            string nodePropertyName = await context.SyncNameProvider.PropertyName(context.ContentPartFieldDefinition !.Name);

            if (SyncMultilineToArray(context.ContentPartFieldDefinition))
            {
                return(context.GraphValidationHelper.ContentMultilineStringPropertyMatchesNodeProperty(
                           ContentKey,
                           contentItemField,
                           nodePropertyName,
                           context.NodeWithRelationships.SourceNode !));
            }

            return(context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                       ContentKey,
                       contentItemField,
                       nodePropertyName,
                       context.NodeWithRelationships.SourceNode !));
        }
예제 #11
0
        public async Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject contentItemField,
            IValidateAndRepairContext context)
        {
            //todo: use/move to GraphValidationHelper?

            string nodePropertyName = await context.SyncNameProvider.PropertyName(context.ContentPartFieldDefinition !.Name);

            context.NodeWithRelationships.SourceNode !.Properties.TryGetValue(nodePropertyName, out object?nodePropertyValue);

            JToken?contentItemFieldValue = contentItemField[ContentKey];

            if (contentItemFieldValue == null || contentItemFieldValue.Type == JTokenType.Null)
            {
                bool bothNull = nodePropertyValue == null;
                return(bothNull, "content property value was null, but node property value was not null");
            }

            if (nodePropertyValue == null)
            {
                return(false, "node property value was null, but content property value was not null");
            }

            var fieldSettings = context.ContentPartFieldDefinition.GetSettings <NumericFieldSettings>();

            if (fieldSettings.Scale == 0)
            {
                bool longsSame = nodePropertyValue is long nodePropertyValueInt &&
                                 nodePropertyValueInt == (long)contentItemFieldValue;
                return(longsSame, longsSame?"":$"long content property value was '{contentItemFieldValue}', but node property value was '{nodePropertyValue}'");
            }

            // calculate allowable tolerance from scale setting
            double allowableDifference = 1d / Math.Pow(10d, fieldSettings.Scale + 2);

            bool doublesSame = nodePropertyValue is double nodePropertyValueFloat &&
                               Math.Abs(nodePropertyValueFloat - (double)contentItemFieldValue) <= allowableDifference;

            return(doublesSame, doublesSame?"":$"double content property value was '{contentItemFieldValue}', but node property value was '{nodePropertyValue}' and allowable difference was {allowableDifference}");
        }
예제 #12
0
        public FieldGraphSyncer_ValidateSyncComponentTestsBase()
        {
            ContentItemField = JObject.Parse("{}");

            ContentTypePartDefinition = A.Fake <ContentTypePartDefinition>();

            ContentPartFieldDefinition = A.Fake <IContentPartFieldDefinition>();
            A.CallTo(() => ContentPartFieldDefinition.Name).Returns(FieldNameBase);

            ContentManager = A.Fake <IContentManager>();

            SourceNode            = A.Fake <INode>();
            NodeWithRelationships = A.Fake <ISubgraph>();
            A.CallTo(() => NodeWithRelationships.SourceNode).Returns(SourceNode);

            SyncNameProvider = A.Fake <ISyncNameProvider>();
            A.CallTo(() => SyncNameProvider.PropertyName(FieldNameBase)).Returns(FieldNameTransformed);

            GraphValidationHelper = A.Fake <IGraphValidationHelper>();

            ExpectedRelationshipCounts = new Dictionary <string, int>();

            ContentItemVersion = A.Fake <IContentItemVersion>();

            ValidateAndRepairGraph = A.Fake <IValidateAndRepairGraph>();

            ValidateAndRepairContext = A.Fake <IValidateAndRepairContext>();
            A.CallTo(() => ValidateAndRepairContext.SyncNameProvider).Returns(SyncNameProvider);
            A.CallTo(() => ValidateAndRepairContext.ContentManager).Returns(ContentManager);
            A.CallTo(() => ValidateAndRepairContext.ContentItemVersion).Returns(ContentItemVersion);
            A.CallTo(() => ValidateAndRepairContext.ContentTypePartDefinition).Returns(ContentTypePartDefinition);
            A.CallTo(() => ValidateAndRepairContext.ContentPartFieldDefinition).Returns(ContentPartFieldDefinition);
            A.CallTo(() => ValidateAndRepairContext.NodeWithRelationships).Returns(NodeWithRelationships);
            A.CallTo(() => ValidateAndRepairContext.GraphValidationHelper).Returns(GraphValidationHelper);
            A.CallTo(() => ValidateAndRepairContext.ExpectedRelationshipCounts).Returns(ExpectedRelationshipCounts);
            A.CallTo(() => ValidateAndRepairContext.ValidateAndRepairGraph).Returns(ValidateAndRepairGraph);
        }
예제 #13
0
        //todo: would need to add AddSyncComponentsDetaching if we start using this

        public override Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject content,
            IValidateAndRepairContext context)
        {
            throw new NotImplementedException();
        }
        public override async Task <(bool validated, string failureReason)> ValidateSyncComponent(JObject content,
                                                                                                  IValidateAndRepairContext context)
        {
            using var _ = context.SyncNameProvider.PushPropertyNameTransform(_sitemapPropertyNameTransform);

            (bool matched, string failureReason) = context.GraphValidationHelper.BoolContentPropertyMatchesNodeProperty(
                OverrideSitemapConfigPropertyName,
                content,
                await context.SyncNameProvider.PropertyName(OverrideSitemapConfigPropertyName),
                context.NodeWithOutgoingRelationships.SourceNode);

            if (!matched)
            {
                return(false, $"{OverrideSitemapConfigPropertyName} did not validate: {failureReason}");
            }

            (matched, failureReason) = context.GraphValidationHelper.EnumContentPropertyMatchesNodeProperty <ChangeFrequency>(
                ChangeFrequencyPropertyName,
                content,
                await context.SyncNameProvider.PropertyName(ChangeFrequencyPropertyName),
                context.NodeWithOutgoingRelationships.SourceNode);

            if (!matched)
            {
                return(false, $"{ChangeFrequencyPropertyName} did not validate: {failureReason}");
            }

            (matched, failureReason) = context.GraphValidationHelper.LongContentPropertyMatchesNodeProperty(
                PriorityPropertyName,
                content,
                await context.SyncNameProvider.PropertyName(PriorityPropertyName),
                context.NodeWithOutgoingRelationships.SourceNode);

            if (!matched)
            {
                return(false, $"{PriorityPropertyName} did not validate: {failureReason}");
            }

            (matched, failureReason) = context.GraphValidationHelper.BoolContentPropertyMatchesNodeProperty(
                ExcludePropertyName,
                content,
                await context.SyncNameProvider.PropertyName(ExcludePropertyName),
                context.NodeWithOutgoingRelationships.SourceNode);

            return(matched ? (true, "") : (false, $"{ExcludePropertyName} did not validate: {failureReason}"));
        }
        public override async Task <(bool validated, string failureReason)> ValidateSyncComponent(JObject content,
                                                                                                  IValidateAndRepairContext context)
        {
            (bool validated, string failureReason) =
                await base.ValidateSyncComponent(content, context);

            if (!validated)
            {
                return(validated, failureReason);
            }

            using var _ = context.SyncNameProvider.PushPropertyNameTransform(_flowFieldsPropertyNameTransform);

            return(await _contentFieldsGraphSyncer.ValidateSyncComponent(
                       content, context));
        }
예제 #16
0
 public abstract Task <(bool validated, string failureReason)> ValidateSyncComponent(
     JObject content,
     IValidateAndRepairContext context);
        public async Task <(bool validated, string failureReason)> ValidateSyncComponent(
            JObject contentItemField,
            IValidateAndRepairContext context)
        {
            ContentPickerFieldSettings contentPickerFieldSettings =
                context.ContentPartFieldDefinition !.GetSettings <ContentPickerFieldSettings>();

            string relationshipType = await RelationshipTypeContentPicker(contentPickerFieldSettings, context.SyncNameProvider);

            IRelationship[] actualRelationships = context.NodeWithRelationships.OutgoingRelationships
                                                  .Where(r => r.Type == relationshipType)
                                                  .ToArray();

            var contentItemIds = (JArray)contentItemField[ContentItemIdsKey] !;

            ContentItem[] destinationContentItems = await GetContentItemsFromIds(
                contentItemIds,
                context.ContentManager,
                context.ContentItemVersion);

            //todo: separate check for missing items, before check relationships
            //todo: move into helper?

            //todo: have to allow for published picker referencing draft item
            if (destinationContentItems.Count() != actualRelationships.Length)
            {
                return(false, $"expecting {destinationContentItems.Count()} relationships of type {relationshipType} in graph, but found {actualRelationships.Length}");
            }

            long ordinal = 0;

            foreach (ContentItem destinationContentItem in destinationContentItems)
            {
                //todo: should logically be called using destination ContentType, but it makes no difference atm
                object destinationId = context.SyncNameProvider.GetNodeIdPropertyValue(
                    destinationContentItem.Content.GraphSyncPart, context.ContentItemVersion);

                string destinationIdPropertyName =
                    context.SyncNameProvider.IdPropertyName(destinationContentItem.ContentType);

                var expectedRelationshipProperties =
                    ContentPickerRelationshipProperties.Concat(
                        new[] { new KeyValuePair <string, object>("Ordinal", ordinal++) });

                //todo: we might want to check that all the supplied relationship properties are there,
                // whilst not failing validation if other properties are present?
                (bool validated, string failureReason) = context.GraphValidationHelper.ValidateOutgoingRelationship(
                    context.NodeWithRelationships,
                    relationshipType,
                    destinationIdPropertyName,
                    destinationId,
                    expectedRelationshipProperties);

                if (!validated)
                {
                    return(false, failureReason);
                }

                // keep a count of how many relationships of a type we expect to be in the graph
                context.ExpectedRelationshipCounts.IncreaseCount(relationshipType);
            }

            return(true, "");
        }
예제 #18
0
        public async Task <(bool validated, string failureReason)> ValidateSyncComponent(JObject contentItemField,
                                                                                         IValidateAndRepairContext context)
        {
            string nodeBasePropertyName = await context.SyncNameProvider.PropertyName(context.ContentPartFieldDefinition !.Name);

            string nodeUrlPropertyName = $"{nodeBasePropertyName}{LinkUrlPostfix}";

            (bool matched, string failureReason) = context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                UrlFieldKey,
                contentItemField,
                nodeUrlPropertyName,
                context.NodeWithRelationships.SourceNode !);

            if (!matched)
            {
                return(false, $"url did not validate: {failureReason}");
            }

            string nodeTextPropertyName = $"{nodeBasePropertyName}{LinkTextPostfix}";

            (matched, failureReason) = context.GraphValidationHelper.StringContentPropertyMatchesNodeProperty(
                TextFieldKey,
                contentItemField,
                nodeTextPropertyName,
                context.NodeWithRelationships.SourceNode !);

            return(matched, matched ? "" : $"text did not validate: {failureReason}");
        }
        public async Task <(bool validated, string failureReason)> ValidateSyncComponent(JObject contentItemField,
                                                                                         IValidateAndRepairContext context)
        {
            string nodePropertyName = await context.SyncNameProvider.PropertyName(context.ContentPartFieldDefinition !.Name);

            return(context.GraphValidationHelper.DateTimeContentPropertyMatchesNodeProperty(
                       ContentKey,
                       contentItemField,
                       nodePropertyName,
                       context.NodeWithOutgoingRelationships.SourceNode));
        }