lib/ldap/ldap_facade.rb in dm-ldap-adapter-0.3.0 vs lib/ldap/ldap_facade.rb in dm-ldap-adapter-0.3.1

- old
+ new

@@ -19,29 +19,32 @@ else @ldap = config end end - # @param dn_prefix String the prefix of the dn - # @param treebase the treebase of the dn or any search - # @param key_field field which carries the integer unique id of the entity - # @param props Hash of the ldap attributes of the new ldap object - # @return nil in case of an error or the new id of the created object - def create_object(dn_prefix, treebase, key_field, props, silence = false) + def retrieve_next_id(treebase, key_field) base = "#{treebase},#{@ldap.base}" id_sym = key_field.downcase.to_sym max = 0 @ldap.search( :base => base, :attributes => [key_field], :return_result => false ) do |entry| n = entry[id_sym].first.to_i max = n if max < n end - id = max + 1 - props[id_sym] = "#{id}" + max + 1 + end + + # @param dn_prefix String the prefix of the dn + # @param treebase the treebase of the dn or any search + # @param key_field field which carries the integer unique id of the entity + # @param props Hash of the ldap attributes of the new ldap object + # @return nil in case of an error or the new id of the created object + def create_object(dn_prefix, treebase, key_field, props, silence = false) + base = "#{treebase},#{@ldap.base}" if @ldap.add( :dn => dn(dn_prefix, treebase), :attributes => props) and @ldap.get_operation_result.code.to_s == "0" - id + props[key_field.downcase.to_sym] else unless silence msg = ldap_error("create", dn(dn_prefix, treebase)) + "\n\t#{props.inspect}" # TODO maybe raise always an error