Beispiel #1
0
        public List<Activity> GetActivities(HashSet<string> ids, string appId, HashSet<String> fields, CollectionOptions options)
        {
            var activityList = new List<ActivityRow>();
            using (var db = new AzureRayaDataContext())
            {
                foreach (var id in ids)
                {
                    if (string.IsNullOrEmpty(appId))
                    {
                        var activities = db.activities
                            .Where(x => x.PartitionKey == id);
                        foreach (var row in activities)
                        {
                            activityList.Add(row);
                        }

                    }
                    else
                    {
                        var activities = db.activities
                            .Where(x => x.PartitionKey == id && x.app_id == appId);
                        foreach (var row in activities)
                        {
                            activityList.Add(row);
                        }
                    }

                }
            }
            
            IEnumerable<ActivityRow> ordered = activityList.OrderByDescending(x => x.id);
            int first = options.getFirst();
            int max = options.getMax();
            if (first != 0)
            {
                ordered = ordered.Skip(first);
            }
            if (max != 0)
            {
                ordered = ordered.Take(max);
            }
            List<Activity> actList = new List<Activity>();
            foreach (var row in ordered)
            {
                actList.Add(ConvertToActivity(row));
            }
            return actList;
        }
Beispiel #2
0
        // These are overriden so that EasyMock doesn't throw a fit
        public override bool Equals(Object o)
        {
            if (!(o is CollectionOptions))
            {
                return(false);
            }

            CollectionOptions actual = (CollectionOptions)o;

            return(this.sortBy.Equals(actual.sortBy) &&
                   this.sortOrder == actual.sortOrder &&
                   this.filter.Equals(actual.filter) &&
                   this.filterOperation == actual.filterOperation &&
                   this.filterValue.Equals(actual.filterValue) &&
                   this.first == actual.first &&
                   this.max == actual.max);
        }
Beispiel #3
0
 /**
  * Returns a list of people that correspond to the passed in person ids.
  *
  * @param userIds A set of users
  * @param groupId The group
  * @param collectionOptions How to filter, sort and paginate the collection being fetched
  * @param fields The profile details to fetch. Empty set implies all
  * @param token The gadget token @return a list of people.
  */
 abstract public RestfulCollection<Person> getPeople(HashSet<UserId> userIds, GroupId groupId,
                                                     CollectionOptions collectionOptions, HashSet<String> fields, ISecurityToken token);
Beispiel #4
0
        public Dictionary<string, Person> GetPeople(HashSet<String> ids, HashSet<String> fields, CollectionOptions options)
        {
            var result = new Dictionary<string, Person>();
            using (var db = new AzureRayaDataContext())
            {
                // TODO filter first then fill dictionary
                foreach (var id in ids)
                {
                    var p = db.persons.Where(x => x.PartitionKey == id).SingleOrDefault();
                    if (p == null)
                    {
                        continue;
                    }
                    string personId = p.id;
                    var name = new Name();
                    var person = new Person();

                    name.givenName = p.first_name;
                    name.familyName = p.last_name;
                    name.formatted = p.first_name + " " + p.last_name;
                    person.displayName = name.formatted;
                    person.name = name;
                    person.id = personId;
                    if (fields.Contains("about_me") || fields.Contains("@all"))
                    {
                        person.aboutMe = p.about_me;
                    }
                    if (fields.Contains("age") || fields.Contains("@all"))
                    {
                        person.age = p.age;
                    }
                    if (fields.Contains("children") || fields.Contains("@all"))
                    {
                        person.children = p.children;
                    }
                    if (fields.Contains("date_of_birth") || fields.Contains("@all"))
                    {
                        if (p.date_of_birth.HasValue)
                        {
                            person.birthday = UnixTime.ToDateTime(p.date_of_birth.Value);
                        }
                    }
                    if (fields.Contains("ethnicity") || fields.Contains("@all"))
                    {
                        person.ethnicity = p.ethnicity;
                    }
                    if (fields.Contains("fashion") || fields.Contains("@all"))
                    {
                        person.fashion = p.fashion;
                    }
                    if (fields.Contains("happiest_when") || fields.Contains("@all"))
                    {
                        person.happiestWhen = p.happiest_when;
                    }
                    if (fields.Contains("humor") || fields.Contains("@all"))
                    {
                        person.humor = p.humor;
                    }
                    if (fields.Contains("job_interests") || fields.Contains("@all"))
                    {
                        person.jobInterests = p.job_interests;
                    }
                    if (fields.Contains("living_arrangement") || fields.Contains("@all"))
                    {
                        person.livingArrangement = p.living_arrangement;
                    }
                    if (fields.Contains("looking_for") || fields.Contains("@all"))
                    {
                        person._lookingFor = p.looking_for;
                    }
                    if (fields.Contains("nickname") || fields.Contains("@all"))
                    {
                        person.nickname = p.nickname;
                    }
                    if (fields.Contains("pets") || fields.Contains("@all"))
                    {
                        person.pets = p.pets;
                    }
                    if (fields.Contains("political_views") || fields.Contains("@all"))
                    {
                        person.politicalViews = p.political_views;
                    }
                    if (fields.Contains("profile_song") || fields.Contains("@all"))
                    {
                        if (!string.IsNullOrEmpty(p.profile_song))
                        {
                            person.profileSong = new Url(p.profile_song, "", "");
                        }
                    }
                    if (fields.Contains("profileUrl") || fields.Contains("@all"))
                    {
                        person.profileUrl = urlPrefix + "/profile/" + personId;
                    }
                    if (fields.Contains("profile_video") || fields.Contains("@all"))
                    {
                        if (!string.IsNullOrEmpty(p.profile_video))
                        {
                            person.profileVideo = new Url(p.profile_video, "", "");
                        }
                    }
                    if (fields.Contains("relationship_status") || fields.Contains("@all"))
                    {
                        person.relationshipStatus = p.relationship_status;
                    }
                    if (fields.Contains("religion") || fields.Contains("@all"))
                    {
                        person.religion = p.religion;
                    }
                    if (fields.Contains("romance") || fields.Contains("@all"))
                    {
                        person.romance = p.romance;
                    }
                    if (fields.Contains("scared_of") || fields.Contains("@all"))
                    {
                        person.scaredOf = p.scared_of;
                    }
                    if (fields.Contains("sexual_orientation") || fields.Contains("@all"))
                    {
                        person.sexualOrientation = p.sexual_orientation;
                    }
                    if (fields.Contains("status") || fields.Contains("@all"))
                    {
                        person.status = p.status;
                    }
                    if (fields.Contains("thumbnailUrl") || fields.Contains("@all"))
                    {
                        person.thumbnailUrl = !string.IsNullOrEmpty(p.thumbnail_url) ? urlPrefix + p.thumbnail_url : "";
                        if (!string.IsNullOrEmpty(p.thumbnail_url))
                        {
                            person.photos = new List<ListField>
                                                {
                                                    new Url(urlPrefix + p.thumbnail_url, "thumbnail", "thumbnail")
                                                };
                        }
                    }
                    if (fields.Contains("time_zone") || fields.Contains("@all"))
                    {
                        person.utcOffset = p.time_zone; // force "-00:00" utc-offset format
                    }
                    if (fields.Contains("drinker") || fields.Contains("@all"))
                    {
                        if (!String.IsNullOrEmpty(p.drinker))
                        {
                            person.drinker = (Drinker)Enum.Parse(typeof(Drinker), p.drinker);
                        }
                    }
                    if (fields.Contains("gender") || fields.Contains("@all"))
                    {
                        if (!String.IsNullOrEmpty(p.gender))
                        {
                            person.gender = (Person.Gender)Enum.Parse(typeof(Person.Gender), p.gender, true);
                        }
                    }
                    if (fields.Contains("smoker") || fields.Contains("@all"))
                    {
                        if (!String.IsNullOrEmpty(p.smoker))
                        {
                            person.smoker = (Smoker)Enum.Parse(typeof(Smoker), p.smoker);
                        }
                    }
                    if (fields.Contains("activities") || fields.Contains("@all"))
                    {
                        var activities = db.activities.Where(a => a.PartitionKey == personId);
                        person.activities = new List<string>();
                        foreach (var act in activities)
                        {
                            person.activities.Add(act.title);
                        }
                    }

                    if (fields.Contains("addresses") || fields.Contains("@all"))
                    {
                        var personAddresses = db.addressesPerson
                            .Where(x => x.PartitionKey == personId);
                        List<Address> addresses = new List<Address>();
                        foreach (var row in personAddresses)
                        {
                            if (String.IsNullOrEmpty(row.unstructured_address))
                            {
                                row.unstructured_address = (row.street_address + " " + row.region + " " + row.country).Trim();
                            }
                            var addr = new Address(row.unstructured_address);
                            addr.country = row.country;
                            addr.latitude = row.latitude;
                            addr.longitude = row.longitude;
                            addr.locality = row.locality;
                            addr.postalCode = row.postal_code;
                            addr.region = row.region;
                            addr.streetAddress = row.street_address;
                            addr.type = row.address_type;
                            //FIXME quick and dirty hack to demo PC
                            addr.primary = true;
                            addresses.Add(addr);
                        }
                        person.addresses = addresses;
                    }

                    if (fields.Contains("bodyType") || fields.Contains("@all"))
                    {
                        var row = db.personBodyTypes.Where(x => x.PartitionKey == personId).SingleOrDefault();
                        if (row != null)
                        {
                            BodyType bodyType = new BodyType();
                            bodyType.build = row.build;
                            bodyType.eyeColor = row.eye_color;
                            bodyType.hairColor = row.hair_color;
                            bodyType.height = row.height;
                            bodyType.weight = row.weight;
                            person.bodyType = bodyType;
                        }
                    }

                    if (fields.Contains("books") || fields.Contains("@all"))
                    {
                        var books = db.personBooks.Where(x => x.PartitionKey == personId);
                        var bookList = new List<string>();
                        foreach (var book in books)
                        {
                            bookList.Add(book.book);
                        }
                        person.books = bookList;
                    }

                    if (fields.Contains("cars") || fields.Contains("@all"))
                    {
                        var cars = db.personCars.Where(x => x.PartitionKey == personId);
                        var carList = new List<string>();
                        foreach (var car in cars)
                        {
                            carList.Add(car.car);
                        }
                        person.cars = carList;
                    }

                    if (fields.Contains("currentLocation") || fields.Contains("@all"))
                    {
                        var row = db.personCurrentLocations
                            .Where(x => x.PartitionKey == personId).SingleOrDefault();
                        if (row != null)
                        {
                            if (string.IsNullOrEmpty(row.unstructured_address))
                            {
                                row.unstructured_address = (row.street_address + " " + row.region + " " + row.country).Trim();
                            }
                            var addr = new Address(row.unstructured_address);
                            addr.country = row.country;
                            addr.latitude = row.latitude;
                            addr.longitude = row.longitude;
                            addr.locality = row.locality;
                            addr.postalCode = row.postal_code;
                            addr.region = row.region;
                            addr.streetAddress = row.street_address;
                            addr.type = row.address_type;
                            person.currentLocation = addr;
                        }
                    }

                    if (fields.Contains("emails") || fields.Contains("@all"))
                    {
                        var emails = db.personEmails.Where(x => x.PartitionKey == personId);
                        List<ListField> emailList = new List<ListField>();
                        foreach (var email in emails)
                        {
                            emailList.Add(new ListField(email.email_type, email.address)); // TODO: better email canonicalization; remove dups
                        }
                        person.emails = emailList;
                    }

                    if (fields.Contains("food") || fields.Contains("@all"))
                    {
                        var foods = db.personFoods.Where(x => x.PartitionKey == personId);
                        var foodList = new List<string>();
                        foreach (var food in foods)
                        {
                            foodList.Add(food.food);
                        }
                        person.food = foodList;
                    }

                    if (fields.Contains("heroes") || fields.Contains("@all"))
                    {
                        var heroes = db.personHeroes.Where(x => x.PartitionKey == personId);
                        var heroList = new List<string>();
                        foreach (var hero in heroes)
                        {
                            heroList.Add(hero.hero);
                        }
                        person.heroes = heroList;
                    }

                    if (fields.Contains("interests") || fields.Contains("@all"))
                    {
                        var interests = db.personInterests.Where(x => x.PartitionKey == personId);
                        var interestList = new List<string>();
                        foreach (var interest in interests)
                        {
                            interestList.Add(interest.interest);
                        }
                        person.interests = interestList;
                    }
                    List<Organization> organizations = new List<Organization>();
                    bool fetchedOrg = false;
                    if (fields.Contains("jobs") || fields.Contains("@all"))
                    {
                        var jobs = db.personJobs
                            .Where(x => x.PartitionKey == personId);
                        foreach (var job in jobs)
                        {
                            var organization = new Organization();
                            organization.description = job.description;
                            if (job.end_date.HasValue)
                                organization.endDate = UnixTime.ToDateTime(job.end_date.Value);
                            organization.field = job.field;
                            organization.name = job.name;
                            organization.salary = job.salary;
                            if (job.start_date.HasValue)
                                organization.startDate = UnixTime.ToDateTime(job.start_date.Value);
                            organization.subField = job.sub_field;
                            organization.title = job.title;
                            organization.webpage = job.webpage;
                            organization.type = "job";
                            if (!string.IsNullOrEmpty(job.id))
                            {
                                var addresses = db.addressesOrganization.Where(x => x.organization_id == job.id).Single();
                                if (string.IsNullOrEmpty(addresses.unstructured_address))
                                {
                                    addresses.unstructured_address = (addresses.street_address + " " + addresses.region + " " + addresses.country).Trim();
                                }
                                var addr = new Address(addresses.unstructured_address);
                                addr.country = addresses.country;
                                addr.latitude = addresses.latitude;
                                addr.longitude = addresses.longitude;
                                addr.locality = addresses.locality;
                                addr.postalCode = addresses.postal_code;
                                addr.region = addresses.region;
                                addr.streetAddress = addresses.street_address;
                                addr.type = addresses.address_type;
                                organization.address = addr;
                            }
                            organizations.Add(organization);
                        }
                        fetchedOrg = true;
                    }

                    if (fields.Contains("schools") || fields.Contains("@all"))
                    {
                        var schools = db.personSchools
                            .Where(x => x.PartitionKey == personId);
                        foreach (var school in schools)
                        {
                            var organization = new Organization();
                            organization.description = school.description;
                            if (school.end_date.HasValue)
                                organization.endDate = UnixTime.ToDateTime(school.end_date.Value);
                            organization.field = school.field;
                            organization.name = school.name;
                            organization.salary = school.salary;
                            if (school.start_date.HasValue)
                                organization.startDate = UnixTime.ToDateTime(school.start_date.Value);
                            organization.subField = school.sub_field;
                            organization.title = school.title;
                            organization.webpage = school.webpage;
                            organization.type = "school";
                            if (!string.IsNullOrEmpty(school.id))
                            {
                                var res3 = db.addressesOrganization.Where(x => x.organization_id == school.id).Single();
                                if (string.IsNullOrEmpty(res3.unstructured_address))
                                {
                                    res3.unstructured_address = (res3.street_address + " " + res3.region + " " + res3.country).Trim();
                                }
                                var addres = new Address(res3.unstructured_address);
                                addres.country = res3.country;
                                addres.latitude = res3.latitude;
                                addres.longitude = res3.longitude;
                                addres.locality = res3.locality;
                                addres.postalCode = res3.postal_code;
                                addres.region = res3.region;
                                addres.streetAddress = res3.street_address;
                                addres.type = res3.address_type;
                                organization.address = addres;
                            }
                            organizations.Add(organization);
                        }
                        fetchedOrg = true;
                    }
                    if (fetchedOrg)
                    {
                        person.organizations = organizations;
                    }
                    //TODO languagesSpoken, currently missing the languages / countries tables so can"t do this yet

                    if (fields.Contains("movies") || fields.Contains("@all"))
                    {
                        var movies = db.personMovies.Where(x => x.PartitionKey == personId);
                        var movieList = new List<string>();
                        foreach (var movie in movies)
                        {
                            movieList.Add(movie.movie);
                        }
                        person.movies = movieList;
                    }
                    if (fields.Contains("music") || fields.Contains("@all"))
                    {
                        var musics = db.personMusics.Where(x => x.PartitionKey == personId);
                        var musicList = new List<string>();
                        foreach (var music in musics)
                        {
                            musicList.Add(music.music);
                        }
                        person.music = musicList;
                    }
                    if (fields.Contains("phoneNumbers") || fields.Contains("@all"))
                    {
                        List<ListField> numList = new List<ListField>();
                        var numbers = db.personPhoneNumbers.Where(x => x.PartitionKey == personId);
                        foreach (var number in numbers)
                        {
                            numList.Add(new ListField(number.number_type, number.number));
                        }
                        person.phoneNumbers = numList;
                    }
                    /*
                    if (_fields.Contains("ims") || _fields.Contains("@all")) 
                    {
                        var _ims = array();
                        _res2 = mysqli_query(this._db, "select value, value_type from person_ims where person_id = " + _person_id);
                        while (list(_value, _type) = @mysqli_fetch_row(_res2)) 
                        {
                        _ims[] = new Im(_value, _type);
                        }
                        _person.Ims = _ims;
                    }
                    if (_fields.Contains("accounts") || _fields.Contains("@all")) {
                    _accounts = array();
                    _res2 = mysqli_query(this._db, "select domain, userid, username from person_accounts where person_id = " + _person_id);
                    while (list(_domain, _userid, _username) = @mysqli_fetch_row(_res2)) {
                    _accounts[] = new Account(_domain, _userid, _username);
                    }
                    _person.Accounts = _accounts;
                    }*/
                    /*
                    if (fields.Contains("quotes") || fields.Contains("@all"))
                    {
                        var _strings = db.person_quotes.Where(x => x.person_id == personId).Select(x => x.quote);
                        person.quotes = _strings.ToList();
                    }
                    if (fields.Contains("sports") || fields.Contains("@all"))
                    {
                        var _strings = db.person_sports.Where(x => x.person_id == personId).Select(x => x.sport);
                        person.sports = _strings.ToList();
                    }
                
                    if (fields.Contains("tags") || fields.Contains("@all"))
                    {
                        var _strings = db.person_tags.Where(x => x.person_id == personId).Select(x => x.tag);
                        person.tags = _strings.ToList();
                    }

                    if (fields.Contains("turnOns") || fields.Contains("@all"))
                    {
                        var _strings = db.person_turn_ons.Where(x => x.person_id == personId).Select(x => x.turn_on);
                        person.turnOns = _strings.ToList();
                    }
                    if (fields.Contains("turnOffs") || fields.Contains("@all"))
                    {
                        var _strings = db.person_turn_offs.Where(x => x.person_id == personId).Select(x => x.turn_off);
                        person.turnOffs = _strings.ToList();
                    }
                     * */
                    if (fields.Contains("urls") || fields.Contains("@all"))
                    {
                        var urls = db.personUrls.Where(x => x.PartitionKey == personId);
                        List<ListField> urllist = new List<ListField>();
                        foreach (var u in urls)
                        {
                            var url = new Url(u.url, null, null);
                            urllist.Add(url);
                        }
                        //urllist.Add(new Url(urlPrefix + "/profile/" + personId, null, "profile"));
                        person.urls = urllist;
                    }

                    result.Add(personId, person);
                } // foreach
            }

            return result;
        }
Beispiel #5
0
        protected override object handleGet(RequestItem request)
        {
            request.applyUrlTemplate(MESSAGE_PATH);

            HashSet<UserId> userIds = request.getUsers();
            String msgCollId = request.getParameter("msgCollId");
            HashSet<String> messageIds = request.getListParameter("messageIds");

            CollectionOptions options = new CollectionOptions(request);

            Preconditions<UserId>.requireNotEmpty(userIds, "No userId specified");
            Preconditions<UserId>.requireSingular(userIds, "Multiple userIds not supported");
            
            IEnumerator<UserId> iuserid = userIds.GetEnumerator();
            iuserid.MoveNext();
            UserId user = iuserid.Current;

            if (msgCollId == null)
            {
                // No message collection specified, return list of message collections
                return service.getMessageCollections(user, MessageCollection.ALL_FIELDS,
                    options, request.getToken());
            }
            // If messageIds are specified return them, otherwise return entries in the given collection.
            return service.getMessages(user, msgCollId,
                Message.ALL_FIELDS, messageIds, options, request.getToken());
        }
Beispiel #6
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());
        }
Beispiel #7
0
        public Dictionary<string,Person> GetPeople(HashSet<String> ids, HashSet<String> fields, CollectionOptions options)
        {
            var result = new Dictionary<string, Person>();
            var persons = db.persons.Where(x => ids.AsEnumerable().Contains(x.id.ToString()));

            // TODO filter first then fill dictionary

            foreach (var p in persons)
            {
                int personId = p.id;
                var name = new Name();
                var person = new Person();
                
                name.givenName = p.first_name;
                name.familyName = p.last_name;
                name.formatted = p.first_name + " " + p.last_name;
                person.displayName = name.formatted;
                person.name = name;
                person.id = personId.ToString();
                if (fields.Contains("about_me") || fields.Contains("@all"))
                {
                    person.aboutMe = p.about_me;
                }
                if (fields.Contains("age") || fields.Contains("@all"))
                {
                    person.age = p.age;
                }
                if (fields.Contains("children") || fields.Contains("@all"))
                {
                    person.children = p.children;
                }
                if (fields.Contains("date_of_birth") || fields.Contains("@all"))
                {
                    if (p.date_of_birth.HasValue)
                    {
                        person.birthday = UnixTime.ToDateTime(p.date_of_birth.Value);
                    }
                }
                if (fields.Contains("ethnicity") || fields.Contains("@all"))
                {
                    person.ethnicity = p.ethnicity;
                }
                if (fields.Contains("fashion") || fields.Contains("@all"))
                {
                    person.fashion = p.fashion;
                }
                if (fields.Contains("happiest_when") || fields.Contains("@all"))
                {
                    person.happiestWhen = p.happiest_when;
                }
                if (fields.Contains("humor") || fields.Contains("@all"))
                {
                    person.humor = p.humor;
                }
                if (fields.Contains("job_interests") || fields.Contains("@all"))
                {
                    person.jobInterests = p.job_interests;
                }
                if (fields.Contains("living_arrangement") || fields.Contains("@all"))
                {
                    person.livingArrangement = p.living_arrangement;
                }
                if (fields.Contains("looking_for") || fields.Contains("@all"))
                {
                    person._lookingFor = p.looking_for;
                }
                if (fields.Contains("nickname") || fields.Contains("@all"))
                {
                    person.nickname = p.nickname;
                }
                if (fields.Contains("pets") || fields.Contains("@all"))
                {
                    person.pets = p.pets;
                }
                if (fields.Contains("political_views") || fields.Contains("@all"))
                {
                    person.politicalViews = p.political_views;
                }
                if (fields.Contains("profile_song") || fields.Contains("@all"))
                {
                    if (!string.IsNullOrEmpty(p.profile_song))
                    {
                        person.profileSong = new Url(p.profile_song, "", "");
                    }
                }
                if (fields.Contains("profileUrl") || fields.Contains("@all"))
                {
                    person.profileUrl = urlPrefix + "/profile/" + personId;
                }
                if (fields.Contains("profile_video") || fields.Contains("@all"))
                {
                    if (!string.IsNullOrEmpty(p.profile_video))
                    {
                        person.profileVideo = new Url(p.profile_video, "", "");
                    }
                }
                if (fields.Contains("relationship_status") || fields.Contains("@all"))
                {
                    person.relationshipStatus = p.relationship_status;
                }
                if (fields.Contains("religion") || fields.Contains("@all"))
                {
                    person.religion = p.religion;
                }
                if (fields.Contains("romance") || fields.Contains("@all"))
                {
                    person.romance = p.romance;
                }
                if (fields.Contains("scared_of") || fields.Contains("@all"))
                {
                    person.scaredOf = p.scared_of;
                }
                if (fields.Contains("sexual_orientation") || fields.Contains("@all"))
                {
                    person.sexualOrientation = p.sexual_orientation;
                }
                if (fields.Contains("status") || fields.Contains("@all"))
                {
                    person.status = p.status;
                }
                if (fields.Contains("thumbnailUrl") || fields.Contains("@all"))
                {
                    person.thumbnailUrl = !string.IsNullOrEmpty(p.thumbnail_url) ? urlPrefix + p.thumbnail_url : "";
                    if (!string.IsNullOrEmpty(p.thumbnail_url))
                    {
                        person.photos = new List<ListField>
                                            {
                                                new Url(urlPrefix + p.thumbnail_url, "thumbnail", "thumbnail")
                                            };
                    }
                }
                if (fields.Contains("time_zone") || fields.Contains("@all"))
                {
                    person.utcOffset = p.time_zone; // force "-00:00" utc-offset format
                }
                if (fields.Contains("drinker") || fields.Contains("@all"))
                {
                    if (!String.IsNullOrEmpty(p.drinker))
                    {
                        person.drinker = (Drinker)Enum.Parse(typeof(Drinker), p.drinker);
                    }
                }
                if (fields.Contains("gender") || fields.Contains("@all"))
                {
                    if (!String.IsNullOrEmpty(p.gender))
                    {
                        person.gender = (Person.Gender)Enum.Parse(typeof(Person.Gender), p.gender, true);
                    }
                }
                if (fields.Contains("smoker") || fields.Contains("@all"))
                {
                    if (!String.IsNullOrEmpty(p.smoker))
                    {
                        person.smoker = (Smoker)Enum.Parse(typeof(Smoker), p.smoker); 
                    }
                }
                if (fields.Contains("activities") || fields.Contains("@all"))
                {
                    var activities = db.person_activities.Where(a => a.person_id == personId).Select(a => a.activity);
                    person.activities = activities.ToList();
                }

                if (fields.Contains("addresses") || fields.Contains("@all"))
                {
                    var person_addresses = db.addresses.
                        Join(db.person_addresses, a => a.id, b => b.address_id, (a, b) => new { a, b }).
                        Where(x => x.b.person_id == personId).
                        Select(x => x.a);
                    List<Address> _addresses = new List<Address>();
                    foreach (address _row in person_addresses)
                    {
                        if (String.IsNullOrEmpty(_row.unstructured_address))
                        {
                            _row.unstructured_address = (_row.street_address + " " + _row.region + " " + _row.country).Trim();
                        }
                        var _addres = new Address(_row.unstructured_address);
                        _addres.country = _row.country;
                        _addres.latitude = _row.latitude;
                        _addres.longitude = _row.longitude;
                        _addres.locality = _row.locality;
                        _addres.postalCode = _row.postal_code;
                        _addres.region = _row.region;
                        _addres.streetAddress = _row.street_address;
                        _addres.type = _row.address_type;
                        //FIXME quick and dirty hack to demo PC
                        _addres.primary = true;
                        _addresses.Add(_addres);
                    }
                    person.addresses = _addresses;
                }

                if (fields.Contains("bodyType") || fields.Contains("@all"))
                {
                    var _row = db.person_body_types.Where(x => x.person_id == personId).SingleOrDefault();
                    if (_row != null)
                    {
                        BodyType _bodyType = new BodyType();
                        _bodyType.build = _row.build;
                        _bodyType.eyeColor = _row.eye_color;
                        _bodyType.hairColor = _row.hair_color;
                        if (_row.height.HasValue)
                            _bodyType.height = float.Parse(_row.height.Value.ToString());
                        if (_row.weight.HasValue)
                            _bodyType.weight = float.Parse(_row.weight.Value.ToString());
                        person.bodyType = _bodyType;
                    }
                }

                if (fields.Contains("books") || fields.Contains("@all"))
                {
                    var books = db.person_books.Where(x => x.person_id == personId).Select(x => x.book);
                    person.books = books.ToList();
                }

                if (fields.Contains("cars") || fields.Contains("@all"))
                {
                    var _cars = db.person_cars.Where(x => x.person_id == personId).Select(x => x.car);
                    person.cars = _cars.ToList();
                }

                if (fields.Contains("currentLocation") || fields.Contains("@all"))
                {
                    var _row = db.addresses.
                        Join(db.person_current_locations, a => a.id, b => b.address_id, (a, b) => new { a, b }).
                        Where(x => x.b.person_id == personId).Select(x => x.a).SingleOrDefault();
                    if (_row != null)
                    {
                        if (string.IsNullOrEmpty(_row.unstructured_address))
                        {
                            _row.unstructured_address = (_row.street_address + " " + _row.region + " " + _row.country).Trim();
                        }
                        var _addres = new Address(_row.unstructured_address);
                        _addres.country = _row.country;
                        _addres.latitude = _row.latitude;
                        _addres.longitude = _row.longitude;
                        _addres.locality = _row.locality;
                        _addres.postalCode = _row.postal_code;
                        _addres.region = _row.region;
                        _addres.streetAddress = _row.street_address;
                        _addres.type = _row.address_type;
                        person.currentLocation = _addres;
                    }
                }

                if (fields.Contains("emails") || fields.Contains("@all"))
                {
                    var _emails = db.person_emails.Where(x => x.person_id == personId);
                    List<ListField> _emailList = new List<ListField>();
                    foreach (person_email _email in _emails)
                    {
                        _emailList.Add(new ListField(_email.email_type, _email.address)); // TODO: better email canonicalization; remove dups
                    }
                    person.emails = _emailList;
                }

                if (fields.Contains("food") || fields.Contains("@all"))
                {
                    var _foods = db.person_foods.Where(x => x.person_id == personId).Select(x => x.food);
                    person.food = _foods.ToList();
                }

                if (fields.Contains("heroes") || fields.Contains("@all"))
                {
                    var _strings = db.person_heroes.Where(x => x.person_id == personId).Select(x => x.hero);
                    person.heroes = _strings.ToList();
                }

                if (fields.Contains("interests") || fields.Contains("@all"))
                {
                    var _strings = db.person_interests.Where(x => x.person_id == personId).Select(x => x.interest);
                    person.interests = _strings.ToList();
                }
                List<Organization> _organizations = new List<Organization>();
                bool _fetchedOrg = false;
                if (fields.Contains("jobs") || fields.Contains("@all"))
                {
                    var _org = db.organizations.
                        Join(db.person_jobs, a => a.id, b => b.organization_id, (a, b) => new { a, b }).
                        Where(x => x.b.person_id == personId).
                        Select(x => x.a);
                    foreach (var _row in _org)
                    {
                        var _organization = new Organization();
                        _organization.description = _row.description;
                        if (_row.end_date.HasValue)
                            _organization.endDate = UnixTime.ToDateTime(_row.end_date.Value);
                        _organization.field = _row.field;
                        _organization.name = _row.name;
                        _organization.salary = _row.salary;
                        if (_row.start_date.HasValue)
                            _organization.startDate = UnixTime.ToDateTime(_row.start_date.Value);
                        _organization.subField = _row.sub_field;
                        _organization.title = _row.title;
                        _organization.webpage = _row.webpage;
                        _organization.type = "job";
                        if (_row.address_id.HasValue)
                        {
                            int addressid = _row.address_id.Value;
                            var _res3 = db.addresses.Where(x => x.id == addressid).Single();
                            if (string.IsNullOrEmpty(_res3.unstructured_address))
                            {
                                _res3.unstructured_address = (_res3.street_address + " " + _res3.region + " " + _res3.country).Trim();
                            }
                            var _addres = new Address(_res3.unstructured_address);
                            _addres.country = _res3.country;
                            _addres.latitude = _res3.latitude;
                            _addres.longitude = _res3.longitude;
                            _addres.locality = _res3.locality;
                            _addres.postalCode = _res3.postal_code;
                            _addres.region = _res3.region;
                            _addres.streetAddress = _res3.street_address;
                            _addres.type = _res3.address_type;
                            _organization.address = _addres;
                        }
                        _organizations.Add(_organization);
                    }
                    _fetchedOrg = true;
                }

                if (fields.Contains("schools") || fields.Contains("@all"))
                {
                    var _res2 = db.organizations.
                        Join(db.person_schools, a => a.id, b => b.organization_id, (a, b) => new { a, b }).
                        Where(x => x.b.person_id == personId).
                        Select(x => x.a);
                    foreach (var _row in _res2)
                    {
                        var _organization = new Organization();
                        _organization.description = _row.description;
                        if (_row.end_date.HasValue)
                            _organization.endDate = UnixTime.ToDateTime(_row.end_date.Value);
                        _organization.field = _row.field;
                        _organization.name = _row.name;
                        _organization.salary = _row.salary;
                        if (_row.start_date.HasValue)
                            _organization.startDate = UnixTime.ToDateTime(_row.start_date.Value);
                        _organization.subField = _row.sub_field;
                        _organization.title = _row.title;
                        _organization.webpage = _row.webpage;
                        _organization.type = "school";
                        if (_row.address_id.HasValue)
                        {
                            int addressid = _row.address_id.Value;
                            var _res3 = db.addresses.Where(x => x.id == addressid).Single();
                            if (string.IsNullOrEmpty(_res3.unstructured_address))
                            {
                                _res3.unstructured_address = (_res3.street_address + " " + _res3.region + " " + _res3.country).Trim();
                            }
                            var _addres = new Address(_res3.unstructured_address);
                            _addres.country = _res3.country;
                            _addres.latitude = _res3.latitude;
                            _addres.longitude = _res3.longitude;
                            _addres.locality = _res3.locality;
                            _addres.postalCode = _res3.postal_code;
                            _addres.region = _res3.region;
                            _addres.streetAddress = _res3.street_address;
                            _addres.type = _res3.address_type;
                            _organization.address = _addres;
                        }
                        _organizations.Add(_organization);
                    }
                    _fetchedOrg = true;
                }
                if (_fetchedOrg)
                {
                    person.organizations = _organizations;
                }
                //TODO languagesSpoken, currently missing the languages / countries tables so can"t do this yet

                if (fields.Contains("movies") || fields.Contains("@all"))
                {
                    var _strings = db.person_movies.Where(x => x.person_id == personId).Select(x => x.movie);
                    person.movies = _strings.ToList();
                }
                if (fields.Contains("music") || fields.Contains("@all"))
                {
                    var _strings = db.person_musics.Where(x => x.person_id == personId).Select(x => x.music);
                    person.music = _strings.ToList();
                }
                if (fields.Contains("phoneNumbers") || fields.Contains("@all"))
                {
                    List<ListField> numList = new List<ListField>();
                    var _numbers = db.person_phone_numbers.Where(x => x.person_id == personId);
                    foreach (var _number in _numbers)
                    {
                        numList.Add(new ListField(_number.number_type, _number.number));
                    }
                    person.phoneNumbers = numList;
                }
                /*
                if (_fields.Contains("ims") || _fields.Contains("@all")) 
                {
                    var _ims = array();
                    _res2 = mysqli_query(this._db, "select value, value_type from person_ims where person_id = " + _person_id);
                    while (list(_value, _type) = @mysqli_fetch_row(_res2)) 
                    {
                    _ims[] = new Im(_value, _type);
                    }
                    _person.Ims = _ims;
                }
                if (_fields.Contains("accounts") || _fields.Contains("@all")) {
                _accounts = array();
                _res2 = mysqli_query(this._db, "select domain, userid, username from person_accounts where person_id = " + _person_id);
                while (list(_domain, _userid, _username) = @mysqli_fetch_row(_res2)) {
                _accounts[] = new Account(_domain, _userid, _username);
                }
                _person.Accounts = _accounts;
                }*/
                if (fields.Contains("quotes") || fields.Contains("@all"))
                {
                    var _strings = db.person_quotes.Where(x => x.person_id == personId).Select(x => x.quote);
                    person.quotes = _strings.ToList();
                }
                if (fields.Contains("sports") || fields.Contains("@all"))
                {
                    var _strings = db.person_sports.Where(x => x.person_id == personId).Select(x => x.sport);
                    person.sports = _strings.ToList();
                }
                if (fields.Contains("tags") || fields.Contains("@all"))
                {
                    var _strings = db.person_tags.Where(x => x.person_id == personId).Select(x => x.tag);
                    person.tags = _strings.ToList();
                }

                if (fields.Contains("turnOns") || fields.Contains("@all"))
                {
                    var _strings = db.person_turn_ons.Where(x => x.person_id == personId).Select(x => x.turn_on);
                    person.turnOns = _strings.ToList();
                }
                if (fields.Contains("turnOffs") || fields.Contains("@all"))
                {
                    var _strings = db.person_turn_offs.Where(x => x.person_id == personId).Select(x => x.turn_off);
                    person.turnOffs = _strings.ToList();
                }
                
                if (fields.Contains("urls") || fields.Contains("@all"))
                {
                    var _strings = db.person_urls.Where(x => x.person_id == personId).Select(x => x.url);
                    List<ListField> urllist = new List<ListField>();
                    foreach (string s in _strings)
                    {
                        var url = new Url(s, null, null);
                        urllist.Add(url);
                    }
                    //urllist.Add(new Url(urlPrefix + "/profile/" + personId, null, "profile"));
                    person.urls = urllist;
                }
                 
                result.Add(personId.ToString(), person);
            } // foreach

            return result;  
        }
Beispiel #8
0
        public List<Activity> GetActivities(HashSet<string> ids, string appId, HashSet<String> fields, CollectionOptions options) 
        {
            var activities = db.activities
                .OrderByDescending(x => x.id)
                .Where(x => ids.AsEnumerable().Contains(x.person_id.ToString()) && (string.IsNullOrEmpty(appId)?true:x.app_id.ToString() == appId));

            int first = options.getFirst();
            int max = options.getMax();
            if (first != 0)
            {
                activities = activities.Skip(first);
            }
            if (max != 0)
            {
                activities = activities.Take(max);
            }
            List<Activity> actList = new List<Activity>();
            foreach (var row in activities)
            {
                var act = new Activity(row.id.ToString(), row.person_id.ToString());
                act.streamTitle = "activities";
                act.title = row.title;
                act.body = row.body;
                act.postedTime = row.created;
                act.mediaItems = GetMediaItems(row.id.ToString());
                actList.Add(act);
            }
            return actList;
        }
Beispiel #9
0
 /**
  * Returns a list of people that correspond to the passed in person ids.
  *
  * @param userIds A set of users
  * @param groupId The group
  * @param collectionOptions How to filter, sort and paginate the collection being fetched
  * @param fields The profile details to fetch. Empty set implies all
  * @param token The gadget token @return a list of people.
  */
 abstract public RestfulCollection <Person> getPeople(HashSet <UserId> userIds, GroupId groupId,
                                                      CollectionOptions collectionOptions, HashSet <String> fields, ISecurityToken token);
Beispiel #10
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; 
        }