Пример #1
0
        /**
         * Allowed end-points /activities/{userId}/{groupId}/{optionalActvityId}+
         * /activities/{userId}+/{groupId}
         *
         * examples: /activities/john.doe/@self/1 /activities/john.doe/@self
         * /activities/john.doe,jane.doe/@friends
         */
        protected override object handleGet(RequestItem request)
        {
            request.applyUrlTemplate(ACTIVITY_ID_PATH);

            HashSet <UserId> userIds             = request.getUsers();
            HashSet <String> optionalActivityIds = new HashSet <string>(request.getListParameter("activityId"));

            // Preconditions
            Preconditions <UserId> .requireNotEmpty(userIds, "No userId specified");

            if (userIds.Count > 1 && optionalActivityIds.Count != 0)
            {
                throw new ArgumentException("Cannot fetch same activityIds for multiple userIds");
            }

            CollectionOptions options = new CollectionOptions();

            options.setSortBy(request.getSortBy());
            options.setSortOrder(request.getSortOrder());
            options.setFilter(request.getFilterBy());
            options.setFilterOperation(request.getFilterOperation());
            options.setFilterValue(request.getFilterValue());
            options.setFirst(request.getStartIndex());
            options.setMax(request.getCount() ?? RequestItem.DEFAULT_COUNT);

            if (optionalActivityIds.Count != 0)
            {
                if (optionalActivityIds.Count == 1)
                {
                    IEnumerator <UserId> iuserid = userIds.GetEnumerator();
                    iuserid.MoveNext();
                    IEnumerator <string> iactivity = optionalActivityIds.GetEnumerator();
                    iactivity.MoveNext();
                    return(service.getActivity(iuserid.Current, request.getGroup(),
                                               request.getAppId(), options, request.getFields(), iactivity.Current,
                                               request.getToken()));
                }
                else
                {
                    IEnumerator <UserId> iuserid = userIds.GetEnumerator();
                    iuserid.MoveNext();
                    return(service.getActivities(iuserid.Current, request.getGroup(),
                                                 request.getAppId(), request.getFields(), optionalActivityIds, request.getToken()));
                }
            }

            return(service.getActivities(userIds, request.getGroup(), request.getAppId(), options,
                                         request.getFields(), request.getToken()));
        }
Пример #2
0
        /**
         * Allowed end-points /people/{userId}+/{groupId} /people/{userId}/{groupId}/{optionalPersonId}+
         *
         * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self
         */
        protected override object handleGet(RequestItem request)
        {
            request.applyUrlTemplate(PEOPLE_PATH);

            GroupId          groupId          = request.getGroup();
            HashSet <String> optionalPersonId = new HashSet <string>(request.getListParameter("personId"));
            HashSet <String> fields           = request.getFields(Person.DEFAULT_FIELDS);
            HashSet <UserId> userIds          = request.getUsers();

            // Preconditions
            Preconditions <UserId> .requireNotEmpty(userIds, "No userId specified");

            if (userIds.Count > 1 && optionalPersonId.Count != 0)
            {
                throw new ArgumentException("Cannot fetch personIds for multiple userIds");
            }

            // handle supportedFields request
            if (userIds.Contains(new UserId(UserId.Type.userId, "@supportedFields")))
            {
                var supported = JsonContainerConfig.Instance.GetJsonObject(request.getToken().getContainer() ?? "default", "gadgets.features")
                                .getJSONObject("opensocial-0.8")
                                .getJSONObject("supportedFields")["person"] as JsonArray;
                var collection = new RestfulCollection <object>();
                if (supported != null && supported.Count > 0)
                {
                    foreach (var value in supported)
                    {
                        collection.entry.Add(value);
                    }
                    collection.totalResults = supported.Count;
                }
                return(collection);
            }

            CollectionOptions options = new CollectionOptions();

            options.setSortBy(request.getSortBy());
            options.setSortOrder(request.getSortOrder());
            options.setFilter(request.getFilterBy());
            options.setFilterOperation(request.getFilterOperation());
            options.setFilterValue(request.getFilterValue());
            options.setFirst(request.getStartIndex());
            options.setMax(request.getCount() ?? RequestItem.DEFAULT_COUNT);

            if (userIds.Count == 1)
            {
                if (optionalPersonId.Count == 0)
                {
                    if (groupId.getType() == GroupId.Type.self)
                    {
                        IEnumerator <UserId> iuserid = userIds.GetEnumerator();
                        iuserid.MoveNext();
                        return(personService.getPerson(iuserid.Current, fields, request.getToken()));
                    }
                    return(personService.getPeople(userIds, groupId, options, fields, request.getToken()));
                }
                if (optionalPersonId.Count == 1)
                {
                    IEnumerator <string> ipersonid = optionalPersonId.GetEnumerator();
                    ipersonid.MoveNext();
                    return(personService.getPerson(new UserId(UserId.Type.userId,
                                                              ipersonid.Current), fields, request.getToken()));
                }
                HashSet <UserId> personIds = new HashSet <UserId>();
                foreach (String pid in optionalPersonId)
                {
                    personIds.Add(new UserId(UserId.Type.userId, pid));
                }
                // Every other case is a collection response of optional person ids
                var result = personService.getPeople(personIds, new GroupId(GroupId.Type.self, null),
                                                     options, fields, request.getToken());
                if (request.getCount() != null)
                {
                    result.itemsPerPage = request.getCount().Value;
                }
                return(result);
            }

            // Every other case is a collection response.
            var result2 = personService.getPeople(userIds, groupId, options, fields, request.getToken());

            if (request.getCount() != null)
            {
                result2.itemsPerPage = request.getCount().Value;
            }
            return(result2);
        }