Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.neo4j.causalclustering.routing.load_balancing.filters.Filter<ServerInfo> filterFor(String filterName, String[] args) throws InvalidFilterSpecification
        private static Filter <ServerInfo> FilterFor(string filterName, string[] args)
        {
            switch (filterName)
            {
            case "groups":
                if (args.Length < 1)
                {
                    throw new InvalidFilterSpecification(format("Invalid number of arguments for filter '%s': %d", filterName, args.Length));
                }
                foreach (string group in args)
                {
                    if (group.matches("\\W"))
                    {
                        throw new InvalidFilterSpecification(format("Invalid group for filter '%s': '%s'", filterName, group));
                    }
                }
                return(new AnyGroupFilter(args));

            case "min":
                if (args.Length != 1)
                {
                    throw new InvalidFilterSpecification(format("Invalid number of arguments for filter '%s': %d", filterName, args.Length));
                }
                int minCount;
                try
                {
                    minCount = int.Parse(args[0]);
                }
                catch (System.FormatException e)
                {
                    throw new InvalidFilterSpecification(format("Invalid argument for filter '%s': '%s'", filterName, args[0]), e);
                }
                return(new MinimumCountFilter <ServerInfo>(minCount));

            case "all":
                if (args.Length != 0)
                {
                    throw new InvalidFilterSpecification(format("Invalid number of arguments for filter '%s': %d", filterName, args.Length));
                }
                return(IdentityFilter.@as());

            case "halt":
                if (args.Length != 0)
                {
                    throw new InvalidFilterSpecification(format("Invalid number of arguments for filter '%s': %d", filterName, args.Length));
                }
                return(HaltFilter.Instance);

            default:
                throw new InvalidFilterSpecification("Unknown filter: " + filterName);
            }
        }
Beispiel #2
0
        public Task <IList <Identity> > List(IdentityFilter filter)
        {
            var builder = _requestProvider.BuildUpon(_url)
                          .Uri("/api/identity/list")
                          .AddInterceptor(new JsonDeserializerInterceptor());

            if (!string.IsNullOrEmpty(filter.Name))
            {
                builder.AddParam("name", filter.Name.Trim());
            }

            if (!string.IsNullOrEmpty(filter.Email))
            {
                builder.AddParam("email", filter.Email.Trim());
            }

            if ((filter.RequestTypes?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.RequestTypes.Length; i++)
                {
                    builder.AddParam($"requestTypes[{i}]", $"{(int)filter.RequestTypes[i]}");
                }
            }

            if ((filter.Permissions?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.Permissions.Length; i++)
                {
                    builder.AddParam($"permissions[{i}]", $"{(int)filter.Permissions[i]}");
                }
            }

            if ((filter.Clusters?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.Clusters.Length; i++)
                {
                    builder.AddParam($"clusters[{i}]", $"{filter.Clusters[i]}");
                }
            }

            if ((filter.Nodes?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.Nodes.Length; i++)
                {
                    builder.AddParam($"nodes[{i}]", $"{filter.Nodes[i]}");
                }
            }

            builder.AddParam($"status", $"{(int)filter.Status}");

            return(builder.Execute <IList <Identity> >());
        }
Beispiel #3
0
        public Task <Identity> GetCertAuditor(string ClusterNode, IdentityFilter filter)
        {
            var builder = new HttpRequest.Builder().BaseURL(_url)
                          .Uri("/api/identity/CertAuditor")
                          .AddParam("ClusterNode", ClusterNode)
                          .AddInterceptor(new JsonDeserializerInterceptor());

            if (!string.IsNullOrEmpty(filter.Name))
            {
                builder.AddParam("name", filter.Name.Trim());
            }

            if (!string.IsNullOrEmpty(filter.Email))
            {
                builder.AddParam("email", filter.Email.Trim());
            }

            if ((filter.RequestTypes?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.RequestTypes.Length; i++)
                {
                    builder.AddParam($"requestTypes[{i}]", $"{(int)filter.RequestTypes[i]}");
                }
            }

            if ((filter.Permissions?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.Permissions.Length; i++)
                {
                    builder.AddParam($"permissions[{i}]", $"{(int)filter.Permissions[i]}");
                }
            }

            if ((filter.Clusters?.Length ?? 0) > 0)
            {
                for (int i = 0; i < filter.Clusters.Length; i++)
                {
                    builder.AddParam($"clusters[{i}]", $"{filter.Clusters[i]}");
                }
            }

            return(builder.Execute <Identity>());
        }
Beispiel #4
0
        public async Task <long> FOCFinalLetter(long caseID, CaseFOCParam data)
        {
            IdentityFilter identityFilter = new IdentityFilter
            {
                Permissions = new Permission[] { Permission.CaseFOCReviewer }
            };

            data.Reviewer = await _apiClient.IdentitySdk.List(identityFilter);

            if (!data.Reviewer.Any())
            {
                throw new BadRequestException("Unable to submit FOC for approval. " +
                                              "No user with Case.FOCReviewer permission. " +
                                              "Please contact administrator");
            }

            var result = await _apiClient.CaseSdk.FOCFinalLetter(caseID, data);

            return(result);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static org.neo4j.causalclustering.routing.load_balancing.filters.Filter<ServerInfo> parse(String filterConfig) throws InvalidFilterSpecification
        public static Filter <ServerInfo> Parse(string filterConfig)
        {
            if (filterConfig.Length == 0)
            {
                throw new InvalidFilterSpecification("Filter config is empty");
            }

            IList <FilterChain <ServerInfo> > rules = new List <FilterChain <ServerInfo> >();

            string[] ruleSpecs = filterConfig.Split(";", true);

            if (ruleSpecs.Length == 0)
            {
                throw new InvalidFilterSpecification("No rules specified");
            }

            bool haltFilterEncountered = false;

            foreach (string ruleSpec in ruleSpecs)
            {
                ruleSpec = ruleSpec.Trim();

                IList <Filter <ServerInfo> > filterChain = new List <Filter <ServerInfo> >();
                string[] filterSpecs          = ruleSpec.Split("->", true);
                bool     allFilterEncountered = false;
                foreach (string filterSpec in filterSpecs)
                {
                    filterSpec = filterSpec.Trim();

                    string namePart;
                    string argsPart;
                    {
                        string[] nameAndArgs = filterSpec.Split("\\(", true);

                        if (nameAndArgs.Length != 2)
                        {
                            throw new InvalidFilterSpecification(format("Syntax error filter specification: '%s'", filterSpec));
                        }

                        namePart = nameAndArgs[0].Trim();
                        argsPart = nameAndArgs[1].Trim();
                    }

                    if (!argsPart.EndsWith(")", StringComparison.Ordinal))
                    {
                        throw new InvalidFilterSpecification(format("No closing parenthesis: '%s'", filterSpec));
                    }
                    argsPart = argsPart.Substring(0, argsPart.Length - 1);

                    string filterName = namePart.Trim();
                    if (!filterName.matches("\\w+"))
                    {
                        throw new InvalidFilterSpecification(format("Syntax error filter name: '%s'", filterName));
                    }

                    string[] nonEmptyArgs = java.util.argsPart.Split(",", true).Select(string.Trim).Where(s => !s.Empty).ToList().ToArray(new string[0]);

                    foreach (string arg in nonEmptyArgs)
                    {
                        if (!arg.matches("[\\w-]+"))
                        {
                            throw new InvalidFilterSpecification(format("Syntax error argument: '%s'", arg));
                        }
                    }

                    if (haltFilterEncountered)
                    {
                        if (filterChain.Count > 0)
                        {
                            throw new InvalidFilterSpecification(format("Filter 'halt' may not be followed by other filters: '%s'", ruleSpec));
                        }
                        else
                        {
                            throw new InvalidFilterSpecification(format("Rule 'halt' may not followed by other rules: '%s'", filterConfig));
                        }
                    }

                    Filter <ServerInfo> filter = FilterFor(filterName, nonEmptyArgs);

                    if (filter == HaltFilter.Instance)
                    {
                        if (filterChain.Count != 0)
                        {
                            throw new InvalidFilterSpecification(format("Filter 'halt' must be the only filter in a rule: '%s'", ruleSpec));
                        }
                        haltFilterEncountered = true;
                    }
                    else if (filter == IdentityFilter.INSTANCE)
                    {
                        /* The all() filter is implicit and unnecessary, but still allowed in the beginning of a rule for clarity
                         * and for allowing the actual rule consisting of only all() to be specified. */

                        if (allFilterEncountered || filterChain.Count != 0)
                        {
                            throw new InvalidFilterSpecification(format("Filter 'all' is implicit but allowed only first in a rule: '%s'", ruleSpec));
                        }

                        allFilterEncountered = true;
                    }
                    else
                    {
                        filterChain.Add(filter);
                    }
                }

                if (filterChain.Count > 0)
                {
                    rules.Add(new FilterChain <>(filterChain));
                }
            }

            if (!haltFilterEncountered)
            {
                /* we implicitly add the all() rule to the end if there was no explicit halt() */
                rules.Add(new FilterChain <>(singletonList(IdentityFilter.@as())));
            }

            return(new FirstValidRule <ServerInfo>(rules));
        }
Beispiel #6
0
 internal virtual FilterBuilder All()
 {
     _current.Add(IdentityFilter.@as());
     return(this);
 }
 public GetCAToAssignAppCommand(IdentityFilter filter, string ClusterNode)
 {
     _filter      = filter;
     _clusterNode = ClusterNode;
 }
        public async Task <IList <Model.Identity> > Query(IdentityFilter filter)
        {
            var requestTypes = new DataTable();

            requestTypes.Columns.Add("Val", typeof(int));

            if ((filter.RequestTypes?.Length ?? 0) > 0)
            {
                foreach (var requestType in filter.RequestTypes)
                {
                    requestTypes.Rows.Add((int)requestType);
                }
            }

            var clusters = new DataTable();

            clusters.Columns.Add("Val", typeof(long));

            if ((filter.Clusters?.Length ?? 0) > 0)
            {
                foreach (var cluster in filter.Clusters)
                {
                    clusters.Rows.Add(cluster);
                }
            }

            var permissions = new DataTable();

            permissions.Columns.Add("Val", typeof(int));

            if ((filter.Permissions?.Length ?? 0) > 0)
            {
                foreach (var permission in filter.Permissions)
                {
                    permissions.Rows.Add((int)permission);
                }
            }

            var ids = new DataTable();

            ids.Columns.Add("Val", typeof(Guid));

            if ((filter.IDs?.Length ?? 0) > 0)
            {
                foreach (var id in filter.IDs)
                {
                    ids.Rows.Add(id);
                }
            }

            var nodes = new DataTable();

            nodes.Columns.Add("Val", typeof(string));

            if ((filter.Nodes?.Length ?? 0) > 0)
            {
                foreach (var node in filter.Nodes)
                {
                    nodes.Rows.Add(node);
                }
            }

            var param = new DynamicParameters();

            param.Add("@Name", filter.Name);
            param.Add("@Email", filter.Email);
            param.Add("@Status", filter.Status);
            param.Add("Permissions", permissions.AsTableValuedParameter("dbo.SmallIntType"));
            param.Add("IDs", ids.AsTableValuedParameter("dbo.UniqueIdentifierType"));
            param.Add("RequestTypes", requestTypes.AsTableValuedParameter("dbo.SmallIntType"));
            param.Add("Clusters", clusters.AsTableValuedParameter("dbo.BigIntType"));
            param.Add("Nodes", nodes.AsTableValuedParameter("dbo.NvarcharType"));

            var mapper = new IdentityMapper();

            return((await SqlMapper.QueryAsync(_unitOfWork.Connection,
                                               "SelectIdentity",
                                               new[]
            {
                typeof(Model.Identity),
                typeof(RequestType?),
                typeof(Cluster),
                typeof(string)
            },
                                               obj =>
            {
                var identity = obj[0] as Model.Identity;
                var requestType = obj[1] as RequestType?;
                var cluster = obj[2] as Cluster;
                var node = obj[3] as string;

                return mapper.Map(identity, requestType, cluster, node);
            },
                                               param,
                                               splitOn: "ID,RequestType,ClusterID,Node",
                                               commandType: CommandType.StoredProcedure,
                                               transaction: _unitOfWork.Transaction)).Distinct().ToList());
        }
 public ListOfIdentityCommand(IdentityFilter filter)
 {
     _filter = filter;
 }