Exemple #1
0
    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");
        }
    }
Exemple #2
0
    public void deletePersonData(UserId uid, GroupId groupId,
                                 String appId, HashSet <String> fields, ISecurityToken token)
    {
        var ids = GetIdSet(uid, groupId, token);

        if (ids.Count < 1)
        {
            throw new ProtocolException(ResponseError.BAD_REQUEST, "No _userId specified");
        }
        if (ids.Count > 1)
        {
            throw new ProtocolException(ResponseError.BAD_REQUEST, "Multiple _userIds not supported");
        }
        IEnumerator <string> iuserid = ids.GetEnumerator();

        iuserid.MoveNext();
        string userId = iuserid.Current;

#if AZURE
        using (var db = new AzureDbFetcher())
#else
        using (var db = new RayaDbFetcher())
#endif
        {
            if (!db.DeleteAppData(userId, fields, appId))
            {
                throw new ProtocolException(ResponseError.INTERNAL_ERROR, "Internal server error");
            }
        }
    }
Exemple #3
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));
    }
Exemple #4
0
    public RestfulCollection <Activity> getActivities(HashSet <UserId> userIds,
                                                      GroupId groupId, String appId, CollectionOptions options, HashSet <String> fields, ISecurityToken token)
    {
        var ids = GetIdSet(userIds, groupId, token);

#if AZURE
        using (var db = new AzureDbFetcher())
#else
        using (var db = new RayaDbFetcher())
#endif
        {
            var activities = db.GetActivities(ids, appId, fields, options);

            return(new RestfulCollection <Activity>(activities, options.getFirst(), activities.Count()));
        }
    }
Exemple #5
0
    public DataCollection getPersonData(HashSet <UserId> userId, GroupId groupId,
                                        String appId, HashSet <String> fields, ISecurityToken token)
    {
        var ids = GetIdSet(userId, groupId, token);

#if AZURE
        using (var db = new AzureDbFetcher())
#else
        using (var db = new RayaDbFetcher())
#endif
        {
            var data = db.GetAppData(ids, fields, appId);

            return(data);
        }
    }
Exemple #6
0
    public RestfulCollection <Activity> getActivities(UserId userId, GroupId groupId,
                                                      String appId, HashSet <String> fields, HashSet <String> activityIds, ISecurityToken token)
    {
        var ids = GetIdSet(userId, groupId, token);

#if AZURE
        using (var db = new AzureDbFetcher())
#else
        using (var db = new RayaDbFetcher())
#endif
        {
            var activities = db.GetActivities(ids, appId, fields, activityIds);


            if (activities.Count != 0)
            {
                return(new RestfulCollection <Activity>(activities));
            }
        }
        throw new ProtocolException(ResponseError.NOT_FOUND, "Activity not found");
    }
Exemple #7
0
    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);
    }
Exemple #8
0
    public void createActivity(UserId userId, GroupId groupId, String appId,
                               HashSet <String> fields, Activity activity, ISecurityToken token)
    {
        try
        {
            if (token.getOwnerId() != token.getViewerId())
            {
                throw new ProtocolException(ResponseError.UNAUTHORIZED, "unauthorized: Create activity permission denied.");
            }
#if AZURE
            using (var db = new AzureDbFetcher())
#else
            using (var db = new RayaDbFetcher())
#endif
            {
                db.CreateActivity(userId.getUserId(token), activity, token.getAppId());
            }
        }
        catch (Exception e)
        {
            throw new ProtocolException(ResponseError.INTERNAL_ERROR, "Invalid create activity request: " + e.Message);
        }
    }
Exemple #9
0
    public void deleteActivities(UserId userId, GroupId groupId, String appId,
                                 HashSet <String> activityIds, ISecurityToken token)
    {
        var ids = GetIdSet(userId, groupId, token);

        if (ids.Count < 1 || ids.Count > 1)
        {
            throw new ProtocolException(ResponseError.BAD_REQUEST, "Invalid user id or count");
        }
        IEnumerator <string> iuserid = ids.GetEnumerator();

        iuserid.MoveNext();
#if AZURE
        using (var db = new AzureDbFetcher())
#else
        using (var db = new RayaDbFetcher())
#endif
        {
            if (!db.DeleteActivities(iuserid.Current, appId, activityIds))
            {
                throw new ProtocolException(ResponseError.NOT_IMPLEMENTED, "Invalid activity id(s)");
            }
        }
    }