From MR-Mencel at wiu.edu Fri Aug 15 15:58:01 2008 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Fri, 15 Aug 2008 14:58:01 -0500 (CDT) Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <163116767.135611218829852276.JavaMail.root@zcs8.wiu.edu> Message-ID: <115088884.136551218830281352.JavaMail.root@zcs8.wiu.edu> Not sure if I'm doing to much work here and something in ActiveLDAP would be more efficient, but I need to have an indexed list of LDAP objects once they have been retrieved as I will eventually be dealing with several thousand entries. So I am putting the data into a Hash. def course_list_search(course_filter) puts "Course Search:" Course.search( :base => 'ou=courses,dc=wiu,dc=edu', :filter => course_filter, :scope => :sub, :attributes => ['cn','wiuCourseDays','wiuCourseEndDate','wiuCourseInstructor','wiuCourseLocation','wiuCourseNumber','wiuCourseSection','wiuCourseStartDate','wiuCourseTime','wiuCourseTitle','wiuStarNumber'] ) end courses = course_list_search('wiuStarNumber=3167*') course_hash = Hash.new courses.each do |course| course_hash[course[0]] = course[1] end puts course_hash.size course_hash.each do |val| puts val.inspect puts val[1]["cn"] exit end So I'm getting a Hash now with the object DN as the index and all the attribute values I am returning as a Hash of attributes => values. >>>OUTPUT OF ABOVE Course Search: 7 ["wiuStarNumber=31673,ou=Courses,dc=wiu,dc=edu", {"cn"=>["ELED470"], "wiuCourseNumber"=>["470"], "wiuCourseStartDate"=>["20080825"], "wiuCourseTime"=>["08-00-12-00"], "wiuCourseLocation"=>["ARR"], "wiuCourseEndDate"=>["20081031"], "wiuCourseTitle"=>["SENIOR FIELD"], "wiuCourseSection"=>["003"], "wiuStarNumber"=>["31673"], "wiuCourseDays"=>["' MTWTF '"]}] ELED470 <<<< But maybe I'm doing too much work and the data I get back from LDAP in the "courses" object is already an indexed Hash? I've compared the output of courses[0].inspect with the output in the loop where I do the 'puts val.inspect' and it looks identical. However...when I get the output of courses.class and then course_hash.class, the first is type Array, not Hash as the second one is. So am I doing too much work...or is this what I should be doing? Thanks, Matt From kou at cozmixng.org Sat Aug 16 00:48:43 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 16 Aug 2008 13:48:43 +0900 (JST) Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <115088884.136551218830281352.JavaMail.root@zcs8.wiu.edu> References: <163116767.135611218829852276.JavaMail.root@zcs8.wiu.edu> <115088884.136551218830281352.JavaMail.root@zcs8.wiu.edu> Message-ID: <20080816.134843.722554765817566062.kou@cozmixng.org> Hi, In <115088884.136551218830281352.JavaMail.root at zcs8.wiu.edu> "[Ruby-activeldap-discuss] Putting the LDAP records into a Hash?" on Fri, 15 Aug 2008 14:58:01 -0500 (CDT), Matt Mencel wrote: > Not sure if I'm doing to much work here and something in ActiveLDAP would be more efficient, but I need to have an indexed list of LDAP objects once they have been retrieved as I will eventually be dealing with several thousand entries. So I am putting the data into a Hash. > > > > def course_list_search(course_filter) > puts "Course Search:" > Course.search( > :base => 'ou=courses,dc=wiu,dc=edu', :filter => course_filter, > :scope => :sub, > :attributes => ['cn','wiuCourseDays','wiuCourseEndDate','wiuCourseInstructor','wiuCourseLocation','wiuCourseNumber','wiuCourseSection','wiuCourseStartDate','wiuCourseTime','wiuCourseTitle','wiuStarNumber'] > ) > end > > > courses = course_list_search('wiuStarNumber=3167*') > course_hash = Hash.new > courses.each do |course| > course_hash[course[0]] = course[1] > end > puts course_hash.size > > course_hash.each do |val| > puts val.inspect > puts val[1]["cn"] > exit > end > > > > So I'm getting a Hash now with the object DN as the index and all the attribute values I am returning as a Hash of attributes => values. > > > >>>OUTPUT OF ABOVE > Course Search: > 7 > ["wiuStarNumber=31673,ou=Courses,dc=wiu,dc=edu", {"cn"=>["ELED470"], "wiuCourseNumber"=>["470"], "wiuCourseStartDate"=>["20080825"], "wiuCourseTime"=>["08-00-12-00"], "wiuCourseLocation"=>["ARR"], "wiuCourseEndDate"=>["20081031"], "wiuCourseTitle"=>["SENIOR FIELD"], "wiuCourseSection"=>["003"], "wiuStarNumber"=>["31673"], "wiuCourseDays"=>["' MTWTF '"]}] > ELED470 > <<<< > > But maybe I'm doing too much work and the data I get back from LDAP in the "courses" object is already an indexed Hash? I've compared the output of courses[0].inspect with the output in the loop where I do the 'puts val.inspect' and it looks identical. However...when I get the output of courses.class and then course_hash.class, the first is type Array, not Hash as the second one is. So am I doing too much work...or is this what I should be doing? I'm sorry but I can't understand what you want to expect. What is your expected result? Should courses be a Hash? Thanks, -- kou From MR-Mencel at wiu.edu Mon Aug 18 13:00:02 2008 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Mon, 18 Aug 2008 12:00:02 -0500 (CDT) Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <20080816.134843.722554765817566062.kou@cozmixng.org> Message-ID: <680762316.245561219078802557.JavaMail.root@zcs8.wiu.edu> ----- "Kouhei Sutou" wrote: > > I'm sorry but I can't understand what you want to expect. > What is your expected result? > Should courses be a Hash? > > Thanks, > -- > kou I'm needing the LDAP query which returns a list of objects....that query is returned to "courses"...I need that to be a Hash with the indexes being the object DNs and the values being arrays of object attributes. The way I have it in my code, converting the "courses" object to "course_hash" seems to be working. I just didn't know if ActiveLdap already did that and whether I was overcomplicating it. Unless you suggest a better solution, what I have seems to be working. Thanks, Matt From kou at cozmixng.org Mon Aug 18 17:06:14 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 19 Aug 2008 06:06:14 +0900 Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <680762316.245561219078802557.JavaMail.root@zcs8.wiu.edu> References: <20080816.134843.722554765817566062.kou@cozmixng.org> <680762316.245561219078802557.JavaMail.root@zcs8.wiu.edu> Message-ID: Hi, 2008/8/19 Matt Mencel : > I'm needing the LDAP query which returns a list of objects....that query is returned to "courses"...I need that to be a Hash with the indexes being the object DNs and the values being arrays of object attributes. Did you try ActiveLdap::Base.find? courses = Course.find(:all, :base => 'ou=courses,dc=wiu,dc=edu', :filter => course_filter, :scope => :sub, ) courses.each do |course| p course.dn p course.cn p course.wiu_course_days end Thanks, -- kou From MR-Mencel at wiu.edu Tue Aug 19 22:17:13 2008 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Tue, 19 Aug 2008 21:17:13 -0500 (CDT) Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <1727472485.407511219198034323.JavaMail.root@zcs8.wiu.edu> Message-ID: <1473133184.407901219198633920.JavaMail.root@zcs8.wiu.edu> ----- "Kouhei Sutou" wrote: > Hi, > > 2008/8/19 Matt Mencel : > > > I'm needing the LDAP query which returns a list of objects....that > query is returned to "courses"...I need that to be a Hash with the > indexes being the object DNs and the values being arrays of object > attributes. > > Did you try ActiveLdap::Base.find? > > courses = Course.find(:all, > :base => 'ou=courses,dc=wiu,dc=edu', > :filter => course_filter, > :scope => :sub, > ) > courses.each do |course| > p course.dn > p course.cn > p course.wiu_course_days > end > I have no problems iterating through the list of objects....but I need to be able to reach into the list with the specific DN that I am looking for... find_dn = 'cn=111111,ou=courses,dc=wiu,dc=edu' course_I_want = courses.fetch(find_dn) #fetch this indexed item from the Hash So 'courses' has to be a Hash. So if ActiveLdap won't naturally return a Hash I have to convert what it is returning to a Hash (which I have been able to do). If I'm doing it wrong let me know, but what I've coded seems to be working. Thanks, Matt From kou at cozmixng.org Tue Aug 19 22:41:17 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Wed, 20 Aug 2008 11:41:17 +0900 Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <1473133184.407901219198633920.JavaMail.root@zcs8.wiu.edu> References: <1727472485.407511219198034323.JavaMail.root@zcs8.wiu.edu> <1473133184.407901219198633920.JavaMail.root@zcs8.wiu.edu> Message-ID: Hi, 2008/8/20 Matt Mencel : > > ----- "Kouhei Sutou" wrote: > >> Hi, >> >> 2008/8/19 Matt Mencel : >> >> > I'm needing the LDAP query which returns a list of objects....that >> query is returned to "courses"...I need that to be a Hash with the >> indexes being the object DNs and the values being arrays of object >> attributes. >> >> Did you try ActiveLdap::Base.find? >> >> courses = Course.find(:all, >> :base => 'ou=courses,dc=wiu,dc=edu', >> :filter => course_filter, >> :scope => :sub, >> ) >> courses.each do |course| >> p course.dn >> p course.cn >> p course.wiu_course_days >> end >> > > I have no problems iterating through the list of objects....but I need to be able to reach into the list with the specific DN that I am looking for... > > > find_dn = 'cn=111111,ou=courses,dc=wiu,dc=edu' > course_I_want = courses.fetch(find_dn) #fetch this indexed item from the Hash > > > So 'courses' has to be a Hash. So if ActiveLdap won't naturally return a Hash I have to convert what it is returning to a Hash (which I have been able to do). > > If I'm doing it wrong let me know, but what I've coded seems to be working. What about this? course_you_want = Course.find(find_dn, :base => 'ou=courses,dc=wiu,dc=edu', :filter => course_filter, :scope => :sub, ) Do you need a course list too? Thanks, -- kou From MR-Mencel at wiu.edu Tue Aug 19 23:14:45 2008 From: MR-Mencel at wiu.edu (Matt Mencel) Date: Tue, 19 Aug 2008 22:14:45 -0500 (CDT) Subject: [Ruby-activeldap-discuss] Putting the LDAP records into a Hash? In-Reply-To: <1946807894.409531219202077733.JavaMail.root@zcs8.wiu.edu> Message-ID: <968503924.409551219202085521.JavaMail.root@zcs8.wiu.edu> ----- "Kouhei Sutou" wrote: > Hi, > > 2008/8/20 Matt Mencel : > > > > ----- "Kouhei Sutou" wrote: > > > >> Hi, > >> > >> 2008/8/19 Matt Mencel : > >> > >> > I'm needing the LDAP query which returns a list of > objects....that > >> query is returned to "courses"...I need that to be a Hash with the > >> indexes being the object DNs and the values being arrays of object > >> attributes. > >> > >> Did you try ActiveLdap::Base.find? > >> > >> courses = Course.find(:all, > >> :base => 'ou=courses,dc=wiu,dc=edu', > >> :filter => course_filter, > >> :scope => :sub, > >> ) > >> courses.each do |course| > >> p course.dn > >> p course.cn > >> p course.wiu_course_days > >> end > >> > > > > I have no problems iterating through the list of objects....but I > need to be able to reach into the list with the specific DN that I am > looking for... > > > > > > find_dn = 'cn=111111,ou=courses,dc=wiu,dc=edu' > > course_I_want = courses.fetch(find_dn) #fetch this indexed item from > the Hash > > > > > > So 'courses' has to be a Hash. So if ActiveLdap won't naturally > return a Hash I have to convert what it is returning to a Hash (which > I have been able to do). > > > > If I'm doing it wrong let me know, but what I've coded seems to be > working. > > What about this? > > course_you_want = Course.find(find_dn, > :base => 'ou=courses,dc=wiu,dc=edu', > :filter => course_filter, > :scope => :sub, > ) > > Do you need a course list too? > > I thought about doing it that way except that when this application goes live I'll be searching multiple times for each course (once for every student who is enrolled) and there's 6000+ courses. So I could be slamming the LDAP server with 10s or 100s of thousands of these single object queries. That's why I thought I'd just run one big query >>>pseudocode Course.find(ALL_COURSES_FOR_FALL_2008) ....grab all the courses with their attributes and put the data into a Hash....then I just have to fetch from the Hash each time I need to retrieve info for a course. Except for the initial query for ALL the courses and then putting that data into a Hash...I'm thinking this will be much faster plus the load on the LDAP server will only be for a short period of time while it finishes that one big query(in my testing it takes about 10 minutes). The program will run early in the morning so impact on the users should be negligent....I just am trying to go easy on the LDAP server. :) Thanks, matt From tlepich at verizon.net Fri Aug 29 20:02:24 2008 From: tlepich at verizon.net (Ted Lepich) Date: Fri, 29 Aug 2008 20:02:24 -0400 Subject: [Ruby-activeldap-discuss] Integer attribute where nil should be valid Message-ID: <48B88E10.5050509@verizon.net> First of all thanks for all the hard work on this gem. I'm in the final stages of converting my rails sqlite based app over to open ldap (75+ models) and the activeldap gem has been working great! I'll probably be shooting off a few emails with questions on some challenges I'm having and some work around that I've done. Here's the first one: One item that I have run in to is validation on integer fields. I have a number of integer attributes in my schema where nil is a valid condition, for example a user could set x=5 and then go back and un-set it. When these attributes are submitted through the rails app to active-ldap they fail the validation for valid integer. To get around this issue I've modified the validate_normalized_value method in the Integer class found in syntaxes.rb to treat blank as valid. This seems to be working as expected - when nil is sent to openldap for an integer attribute the attribute is removed from the entry, which is perfect for me. I'd appreciate any feedback on this approach and also like to know what others are doing for cases like this? NOTE: I haven't checked all other types, but char and DN seem to work fine with nil thanks, ted From kou at cozmixng.org Fri Aug 29 23:03:56 2008 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 30 Aug 2008 12:03:56 +0900 (JST) Subject: [Ruby-activeldap-discuss] Integer attribute where nil should be valid In-Reply-To: <48B88E10.5050509@verizon.net> References: <48B88E10.5050509@verizon.net> Message-ID: <20080830.120356.787670930858395286.kou@cozmixng.org> Hi, In <48B88E10.5050509 at verizon.net> "[Ruby-activeldap-discuss] Integer attribute where nil should be valid" on Fri, 29 Aug 2008 20:02:24 -0400, Ted Lepich wrote: > One item that I have run in to is validation on integer fields. I have > a number of integer attributes in my schema where nil is a valid > condition, for example a user could set x=5 and then go back and un-set > it. When these attributes are submitted through the rails app to > active-ldap they fail the validation for valid integer. > > To get around this issue I've modified the validate_normalized_value > method in the Integer class found in syntaxes.rb to treat blank as > valid. This seems to be working as expected - when nil is sent to > openldap for an integer attribute the attribute is removed from the > entry, which is perfect for me. I'd appreciate any feedback on this > approach and also like to know what others are doing for cases like this? I couldn't reproduce the problem. (I used sambaPwdLastSet attribute in samba.schema.) It seems that nil value is not validated by classes in lib/active_ldap/schema/syntaxes.rb because ActiveLdap::Validations#validate_ldap_values in lib/active_ldap/validations.rb skips nil value. Thanks, -- kou From tlepich at verizon.net Sat Aug 30 12:01:08 2008 From: tlepich at verizon.net (Ted Lepich) Date: Sat, 30 Aug 2008 12:01:08 -0400 Subject: [Ruby-activeldap-discuss] Integer attribute where nil should be valid In-Reply-To: <20080830.120356.787670930858395286.kou@cozmixng.org> References: <48B88E10.5050509@verizon.net> <20080830.120356.787670930858395286.kou@cozmixng.org> Message-ID: <48B96EC4.7090202@verizon.net> An HTML attachment was scrubbed... URL: