public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new OrganizationsClient(connection);

                var filters = new OrganizationFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 0,
                };

                await client.GetAllForUserId(123, filters);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <Organization>(
                        Arg.Is <Uri>(u => u.ToString() == "organizations"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                              d["user_id"] == "123"),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0));
                });
            }
예제 #2
0
        /**********************************************************************************************************
        * METHODS
        **********************************************************************************************************/

        /// <summary>Builds the queries.</summary>
        /// <param name="context">The context.</param>
        /// <param name="request">The request.</param>
        /// <returns>The search queries.</returns>
        public override IEnumerable <IExternalSearchQuery> BuildQueries(ExecutionContext context, IExternalSearchRequest request)
        {
            if (!this.Accepts(request.EntityMetaData.EntityType))
            {
                yield break;
            }

            var existingResults = request.GetQueryResults <MappingResponse>(this).ToList();

            Func <string, bool> nameFilter = value => OrganizationFilters.NameFilter(context, value) || existingResults.Any(r => string.Equals(r.Data.Response.Name, value, StringComparison.InvariantCultureIgnoreCase));

            // Query Input
            //For companies use CluedInOrganization vocab, for people use CluedInPerson and so on for different types.
            var entityType         = request.EntityMetaData.EntityType;
            var organizationTicker = request.QueryParameters.GetValue(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.TickerSymbol, new HashSet <string>());

            if (organizationTicker != null)
            {
                var values = organizationTicker.Select(NameNormalization.Normalize).ToHashSet();

                foreach (var value in values.Where(v => !nameFilter(v)))
                {
                    yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Identifier, value));
                }
            }
        }
            public async Task ReturnsCorrectCountWithoutStart()
            {
                var pipedrive = Helper.GetAuthenticatedClient();

                var options = new OrganizationFilters
                {
                    PageSize  = 3,
                    PageCount = 1
                };

                var persons = await pipedrive.Organization.GetPersons(5, options);

                Assert.Equal(3, persons.Count);
            }
            public async Task ReturnsCorrectCountWithStart()
            {
                var pipedrive = Helper.GetAuthenticatedClient();

                var options = new OrganizationFilters
                {
                    PageSize  = 2,
                    PageCount = 1,
                    StartPage = 1
                };

                var organizations = await pipedrive.Organization.GetAll(options);

                Assert.Equal(2, organizations.Count);
            }
예제 #5
0
        /**********************************************************************************************************
        * METHODS
        **********************************************************************************************************/

        /// <inheritdoc/>
        public override IEnumerable <IExternalSearchQuery> BuildQueries(ExecutionContext context, IExternalSearchRequest request)
        {
            if (!this.Accepts(request.EntityMetaData.EntityType))
            {
                yield break;
            }

            //if (string.IsNullOrEmpty(this.TokenProvider.ApiToken))
            //    throw new InvalidOperationException("PermId ApiToken have not been configured");

            var existingResults = request.GetQueryResults <PermIdSocialResponse>(this).ToList();

            Func <string, bool> existingDataFilter = value => existingResults.Any(r => string.Equals(r.Data.OrganizationName.First(), value, StringComparison.InvariantCultureIgnoreCase));
            Func <string, bool> nameFilter         = value => OrganizationFilters.NameFilter(context, value) || existingResults.Any(r => string.Equals(r.Data.OrganizationName.First(), value, StringComparison.InvariantCultureIgnoreCase));

            // Query Input
            var entityType       = request.EntityMetaData.EntityType;
            var organizationName = request.QueryParameters.GetValue(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.OrganizationName, new HashSet <string>());

            if (!string.IsNullOrEmpty(request.EntityMetaData.Name))
            {
                organizationName.Add(request.EntityMetaData.Name);
            }
            if (!string.IsNullOrEmpty(request.EntityMetaData.DisplayName))
            {
                organizationName.Add(request.EntityMetaData.DisplayName);
            }

            if (organizationName != null)
            {
                var values = organizationName.GetOrganizationNameVariants()
                             .Select(NameNormalization.Normalize)
                             .ToHashSetEx();

                foreach (var value in values)
                {
                    if (existingDataFilter(value) || nameFilter(value))
                    {
                        continue;
                    }

                    yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Name, value));
                }
            }
        }
            public async Task ReturnsDistinctInfosBasedOnStartPage()
            {
                var pipedrive = Helper.GetAuthenticatedClient();

                var startOptions = new OrganizationFilters
                {
                    PageSize  = 1,
                    PageCount = 1
                };

                var firstPage = await pipedrive.Organization.GetAll(startOptions);

                var skipStartOptions = new OrganizationFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 1
                };

                var secondPage = await pipedrive.Organization.GetAll(skipStartOptions);

                Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
            }
예제 #7
0
        public async Task <CustomerProviderOrganizationSummary> GetProviderOrganizationSummary(IOrganizationCustomer cu, OrganizationFilters filters)
        {
            var categories = await Repository.Queryable()
                             .Include(x => x.ProviderOrganization)
                             .Where(x => x.OrganizationType.HasFlag(OrganizationType.Provider) && x.ProviderOrganization.Discoverable &&
                                    x.Id != cu.OrganizationId)
                             .ApplyWhereFilters(filters)

                             .Include(x => x.Category)
                             .Select(s => s.Category).Distinct()
                             .ProjectTo <CategoryOutput>(ProjectionMapping)
                             .ToListAsync();

            var skills = await Repository.Queryable()
                         .Include(x => x.ProviderOrganization)
                         .Where(x => x.OrganizationType.HasFlag(OrganizationType.Provider) &&
                                x.ProviderOrganization.Discoverable &&
                                x.Id != cu.OrganizationId)
                         .Include(x => x.ProviderOrganization.Skills)
                         .SelectMany(x => x.ProviderOrganization.Skills)
                         .ProjectTo <SkillOutput>(ProjectionMapping)
                         .ToListAsync();

            var resp = new CustomerProviderOrganizationSummary
            {
                Organizations       = await GetProviderOrganizations <CustomerProviderOrganizationOutput>(cu, filters),
                AvailableCategories = categories,
                AvailableSkills     = skills
            };

            return(resp);
        }
예제 #8
0
        public async Task <List <T> > GetProviderOrganizations <T>(IOrganizationCustomer cu, OrganizationFilters filters) where T : CustomerProviderOrganizationOutput
        {
            var org = await Repository.Queryable()
                      .Include(x => x.BuyerCustomerAccounts)
                      .Where(x => x.Id == cu.OrganizationId)
                      .FirstAsync();

            var existingAccountOrgs = org.BuyerCustomerAccounts.Select(x => x.AccountManagerOrganizationId)
                                      .ToArray();

            var orgs = await Repository.Queryable()
                       .Include(x => x.ProviderOrganization)
                       .Where(x => x.ProviderOrganization.Discoverable &&
                              x.OrganizationType.HasFlag(OrganizationType.Provider) &&
                              x.Id != cu.OrganizationId)
                       .Where(x => !existingAccountOrgs.Contains(x.Id))
                       .ApplyWhereFilters(filters)

                       .ProjectTo <T>(ProjectionMapping)
                       .ToListAsync();

            return(orgs);
        }
        public async Task <IActionResult> GetProviderOrganizationSummary([FromRoute] Guid organizationId, [FromQuery] OrganizationFilters filters)
        {
            var vm = await _organizationService
                     .GetProviderOrganizationSummary(_customer, filters);

            return(Ok(vm));
        }
예제 #10
0
        /**********************************************************************************************************
        * METHODS
        **********************************************************************************************************/

        /// <summary>Builds the queries.</summary>
        /// <param name="context">The context.</param>
        /// <param name="request">The request.</param>
        /// <returns>The search queries.</returns>
        public override IEnumerable <IExternalSearchQuery> BuildQueries(ExecutionContext context, IExternalSearchRequest request)
        {
            if (!this.Accepts(request.EntityMetaData.EntityType))
            {
                yield break;
            }

            var existingResults = request.GetQueryResults <CompanyAutocompleteResult>(this).ToList();

            Func <string, bool> domainFilter = value => existingResults.Any(r => string.Equals(r.Data.Domain, value, StringComparison.InvariantCultureIgnoreCase));
            Func <string, bool> nameFilter   = value => OrganizationFilters.NameFilter(context, value);

            // Query Input
            var entityType       = request.EntityMetaData.EntityType;
            var website          = request.QueryParameters.GetValue(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.Website, new HashSet <string>()).ToHashSetEx();
            var organizationName = request.QueryParameters.GetValue(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.OrganizationName, new HashSet <string>()).ToHashSetEx();
            var emailDomainNames = request.QueryParameters.GetValue(CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInOrganization.EmailDomainNames, new HashSet <string>()).ToHashSetEx();

            emailDomainNames.AddRange(website.GetDomainNamesFromUris());

            if (!string.IsNullOrEmpty(request.EntityMetaData.Name))
            {
                organizationName.Add(request.EntityMetaData.Name);
            }
            if (!string.IsNullOrEmpty(request.EntityMetaData.DisplayName))
            {
                organizationName.Add(request.EntityMetaData.DisplayName);
            }

            request.EntityMetaData.Aliases.ForEach(a => organizationName.Add(a));

            if (website.Any())
            {
                var values = website;

                foreach (var value in values)
                {
                    Uri uri;

                    if (Uri.TryCreate(value, UriKind.Absolute, out uri))
                    {
                        if (!domainFilter(uri.Host))
                        {
                            yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Domain, uri.Host));
                        }
                    }
                    else if (!domainFilter(value))
                    {
                        yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Domain, value));
                    }
                }
            }

            if (emailDomainNames.Any())
            {
                var values = emailDomainNames.SelectMany(v => v.Split(new[] { ",", ";", "|" }, StringSplitOptions.RemoveEmptyEntries)).Select(v => v.ToLowerInvariant()).ToHashSetEx();

                foreach (var value in values.Where(v => !domainFilter(v)))
                {
                    Uri uri;

                    if (Uri.TryCreate(value, UriKind.Absolute, out uri))
                    {
                        if (!domainFilter(uri.Host))
                        {
                            yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Domain, uri.Host));
                        }
                    }
                    else if (!domainFilter(value))
                    {
                        yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Domain, value));
                    }
                }
            }

            if (organizationName.Any())
            {
                var values = organizationName.GetOrganizationNameVariants()
                             .Select(NameNormalization.Normalize)
                             .ToHashSetEx();

                foreach (var value in values.Where(v => !nameFilter(v)))
                {
                    yield return(new ExternalSearchQuery(this, entityType, ExternalSearchQueryParameter.Name, value));
                }
            }
        }