public void updatePersonData(UserId userId, GroupId groupId, String appId, HashSet <String> fields, Dictionary <String, String> values, ISecurityToken token) { if (userId.getUserId(token) == null) { throw new ProtocolException(ResponseError.NOT_FOUND, "Unknown person id."); } switch (groupId.getType()) { case GroupId.Type.self: foreach (var key in fields) { var value = values[key]; #if AZURE using (var db = new AzureDbFetcher()) #else using (var db = new RayaDbFetcher()) #endif { if (!db.SetAppData(userId.getUserId(token), key, value, token.getAppId())) { throw new ProtocolException(ResponseError.INTERNAL_ERROR, "Internal server error"); } } } break; default: throw new ProtocolException(ResponseError.NOT_IMPLEMENTED, "We don't support updating data in batches yet"); } }
private HashSet <String> GetIdSet(UserId user, GroupId group, ISecurityToken token) { String userId = user.getUserId(token); if (group == null) { return(new HashSet <string> { userId }); } HashSet <string> returnVal = new HashSet <string>(); switch (group.getType()) { case GroupId.Type.all: case GroupId.Type.friends: case GroupId.Type.groupId: #if AZURE using (var db = new AzureDbFetcher()) #else using (var db = new RayaDbFetcher()) #endif { var friendIds = db.GetFriendIds(userId).ToList(); for (int i = 0; i < friendIds.Count; i++) { returnVal.Add(friendIds[i]); } } break; case GroupId.Type.self: returnVal.Add(userId); break; } return(returnVal); }
/** * Get the set of user id's from a user and group */ private HashSet <String> GetIdSet(UserId user, GroupId group, ISecurityToken token) { String userId = user.getUserId(token); if (group == null) { return(new HashSet <string> { userId }); } HashSet <String> returnVal = new HashSet <string>(); switch (group.getType()) { case GroupId.Type.all: case GroupId.Type.friends: case GroupId.Type.groupId: if (db[FRIEND_LINK_TABLE].ToString().Contains(userId)) { JsonArray friends = ((JsonObject)db[FRIEND_LINK_TABLE])[userId] as JsonArray; if (friends != null) { for (int i = 0; i < friends.Length; i++) { returnVal.Add(friends[i] as string); } } } break; case GroupId.Type.self: returnVal.Add(userId); break; } return(returnVal); }
/** * 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); }