Exemplo n.º 1
0
    override public RestfulCollection <Person> getPeople(HashSet <UserId> userId, GroupId groupId,
                                                         CollectionOptions options, HashSet <String> fields, ISecurityToken token)
    {
        int first = options.getFirst();
        int max   = options.getMax();
        Dictionary <string, Person> allPeople;
        HashSet <String>            ids = GetIdSet(userId, groupId, token);

#if AZURE
        using (var db = new AzureDbFetcher())
#else
        using (var db = new RayaDbFetcher())
#endif
        {
            allPeople = db.GetPeople(ids, fields, options);
        }
        var totalSize = allPeople.Count;

        var result = new List <Person>();
        if (first < totalSize)
        {
            foreach (var id in ids)
            {
                if (!allPeople.ContainsKey(id))
                {
                    continue;
                }

                Person person = allPeople[id];
                if (!token.isAnonymous() && id == token.getViewerId())
                {
                    person.isViewer = true;
                }
                if (!token.isAnonymous() && id == token.getOwnerId())
                {
                    person.isOwner = true;
                }
                result.Add(person);
            }

            // We can pretend that by default the people are in top friends order
            if (options.getSortBy().Equals(Person.Field.NAME.ToDescriptionString()))
            {
                result.Sort(new NameComparator());
            }

            if (options.getSortOrder().Equals(SortOrder.descending))
            {
                result.Reverse();
            }
            result = result.GetRange(first,
                                     Math.Min(max,
                                              totalSize - first > 0
                                                      ? totalSize - first
                                                      : 1));
        }

        return(new RestfulCollection <Person>(result, options.getFirst(), totalSize));
    }
    public override RestfulCollection <Person> getPeople(HashSet <UserId> userIds, GroupId groupId,
                                                         CollectionOptions options, HashSet <String> fields, ISecurityToken token)
    {
        List <Person> result = new List <Person>();

        try
        {
            JsonArray people = db[PEOPLE_TABLE] as JsonArray;

            HashSet <String> idSet = GetIdSet(userIds, groupId, token);

            if (people != null)
            {
                for (int i = 0; i < people.Length; i++)
                {
                    JsonObject person = people[i] as JsonObject;
                    if (person != null && !idSet.Contains(person[Person.Field.ID.ToDescriptionString()] as string))
                    {
                        continue;
                    }
                    // Add group support later
                    result.Add(ConvertToPerson(person, fields));
                }
            }
            // We can pretend that by default the people are in top friends order
            if (options.getSortBy().Equals(Person.Field.NAME.ToDescriptionString()))
            {
                result.Sort(new NameComparator());
            }

            if (options.getSortOrder().Equals(SortOrder.descending))
            {
                result.Reverse();
            }

            // TODO: The samplecontainer doesn't really have the concept of HAS_APP so
            // we can't support any filters yet. We should fix this.

            int totalSize = result.Count;
            int last      = options.getFirst() + options.getMax();
            result = result.GetRange(options.getFirst(), Math.Min(last, totalSize) - options.getFirst());

            return(new RestfulCollection <Person>(result, options.getFirst(), totalSize));
        }
        catch (Exception je)
        {
            throw new ProtocolException(ResponseError.INTERNAL_ERROR, je.Message);
        }
    }