public override async Task AllowSync(
            JArray?contentItems,
            IGraphMergeContext context,
            IAllowSync allowSync)
        {
            IAllowSync baseAllowSync = new AllowSync();
            await base.AllowSync(contentItems, context, baseAllowSync);

            var baseBlockersWithoutIncomingTaxonomyBlocker =
                baseAllowSync.SyncBlockers.Where(sb => sb.ContentType != "Taxonomy");

            if (baseBlockersWithoutIncomingTaxonomyBlocker.Any())
            {
                allowSync.AddSyncBlockers(baseBlockersWithoutIncomingTaxonomyBlocker);
            }
        }
예제 #2
0
        public virtual async Task AllowSync(
            JArray?contentItems,
            IGraphMergeContext context,
            IAllowSync allowSync)
        {
            _logger.LogDebug("Do embedded items allow sync?");

            List <CommandRelationship> requiredRelationships = await GetRequiredRelationshipsAndOptionallySync(contentItems, context, allowSync);

            INodeAndOutRelationshipsAndTheirInRelationships?existing = (await context.GraphReplicaSet.Run(
                                                                            new NodeAndOutRelationshipsAndTheirInRelationshipsQuery(
                                                                                context.ReplaceRelationshipsCommand.SourceNodeLabels,
                                                                                context.ReplaceRelationshipsCommand.SourceIdPropertyName !,
                                                                                context.ReplaceRelationshipsCommand.SourceIdPropertyValue !)))
                                                                       .FirstOrDefault();

            if (existing?.OutgoingRelationships.Any() != true)
            {
                // nothing to do here, node is being newly created or existing node has no relationships
                return;
            }

            (string[] embeddableContentTypes, IEnumerable <string> relationshipTypes) =
                await GetEmbeddableContentTypesAndRelationshipTypes(context);

            existing = new NodeAndOutRelationshipsAndTheirInRelationships(
                existing.SourceNode,
                existing.OutgoingRelationships
                .Where(or =>
                       embeddableContentTypes.Contains(
                           context.SyncNameProvider.GetContentTypeFromNodeLabels(
                               or.outgoingRelationship.DestinationNode.Labels)) &&
                       relationshipTypes.Contains(or.outgoingRelationship.Relationship.Type)));

            IEnumerable <CommandRelationship> existingRelationshipsForEmbeddableContentTypes =
                existing.ToCommandRelationships(context.SyncNameProvider);

            _removingRelationships = GetRemovingRelationships(
                existingRelationshipsForEmbeddableContentTypes,
                requiredRelationships,
                context.SyncNameProvider);

            if (!_removingRelationships.Any())
            {
                // nothing to do here, not removing any relationships
                return;
            }

            foreach (var removingRelationship in _removingRelationships)
            {
                foreach (object destinationNodeIdPropertyValue in removingRelationship.DestinationNodeIdPropertyValues)
                {
                    var existingForRemoving = existing.OutgoingRelationships
                                              .Where(er =>
                                                     er.outgoingRelationship.DestinationNode.Properties[
                                                         context.SyncNameProvider.IdPropertyName(
                                                             context.SyncNameProvider.GetContentTypeFromNodeLabels(
                                                                 er.outgoingRelationship.DestinationNode.Labels))] ==
                                                     destinationNodeIdPropertyValue);

                    var nonTwoWayIncomingRelationshipsToEmbeddedItems = existingForRemoving
                                                                        .SelectMany(or => or.incomingRelationships) //todo: null or throws?
                                                                        .Where(ir => !ir.Relationship.Properties.ContainsKey(
                                                                                   NodeWithOutgoingRelationshipsCommand.TwoWayRelationshipPropertyName));

                    allowSync.AddSyncBlockers(
                        nonTwoWayIncomingRelationshipsToEmbeddedItems.Select(r =>
                    {
                        string contentType =
                            context.SyncNameProvider.GetContentTypeFromNodeLabels(r.DestinationNode.Labels);
                        return(new SyncBlocker(
                                   contentType,
                                   r.DestinationNode.Properties[context.SyncNameProvider.IdPropertyName(contentType)],
                                   (string?)r.DestinationNode.Properties[TitlePartGraphSyncer.NodeTitlePropertyName]));
                    }));
                }
            }
        }