Exemplo n.º 1
0
        private RelationshipCheckResponse Check(ICypherFluentQuery q, IRelationshipCheckRequest request)
        {
            q = q.With("ID(e) as nodeId, count(rel) as relationshipCount");

            switch (request.ThresholdType)
            {
                case RelationshipThresholdType.ReturnIfGreaterThan:
                    q = q.Where($"relationshipCount > {request.Threshold}");
                    break;

                case RelationshipThresholdType.ReturnIfNotExact:
                    q = q.Where($"relationshipCount <> {request.Threshold}");
                    break;
                case RelationshipThresholdType.ReturnIfEqual:
                    q = q.Where($"relationshipCount = {request.Threshold}");
                    break;

                default:
                    throw new Exception("<INSERT PR HERE>");
            }

            var responses = q.Return((nodeId, relationshipCount) =>
            new Violation
            {
                NodeId = nodeId.As<long>()
            });

            var response = new RelationshipCheckResponse();
            response.Request = request;
            response.Violations.AddRange(responses.Results.ToList());
            return response;
        }
        /// <summary>
        /// For a given label and relationship, returns anything that doesn't conform to expected count
        /// </summary>
        public RelationshipCheckResponse Check(IRelationshipCheckRequest request)
        {
            var q = CypherQuery
                .Match($"(e:{request.FromLabel})")
                .OptionalMatch($"(e)-[rel:{request.RelationshipLabel}]-()");

            return Check(q, request);
        }
Exemplo n.º 3
0
        /// <summary>
        /// For a given label and relationship, returns anything that doesn't conform to expected count
        /// </summary>
        public RelationshipCheckResponse Check(IRelationshipCheckRequest request)
        {
            var inboundRequirement = request.RelationshipDirection == RelationshipDirection.Inbound ? "<" : "";
            var outboundRequirement = request.RelationshipDirection == RelationshipDirection.Outbound ? ">" : "";
            
            var q = CypherQuery
                .Match($"(e:{request.NodeLabel})")
                .OptionalMatch($"(e){inboundRequirement}-[rel:{request.RelationshipLabel}]-{outboundRequirement}()");

            return Check(q, request);
        }