Announcement Announcement Module
Collapse
No announcement yet.
Update in LDAP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Update in LDAP

    Update is a real pain in the ass overhere, so I hope that this is the last bug i'm encountering :-).

    We use Spring-LDAP 1.2-RC1 in our project. We have to use this, because we had a problem with case sensitivity and on this board someone stated that the issue was resolved in this build (which was btw, so thanks).

    Now the problem is as follows:

    We have an employee who can have multiple values for one field. So there are multiple occurences of one attribute in the LDAP with a value. Let's say that an employee can be member of several departments in the company. So you have multiple occurences of "memberOfDepartment" with each a departmentCode.

    The problem is, we also have an option that an employee is not a member of any departments, so if you modify a profile, all the attributes "memberOfDepartment" should be erased if the user selected None on the JSP. For some reason, a modification as such isn't interpreted like that by Spring-LDAP. It states that the modificationItems is empty.

    In our domain object we have an ArrayList<Department> which contains all (or none) departments of which the employee is a member.

    When the user presses the submit button, the code iterates over the selectbox and enters all the departments in an ArrayList. If a user selected None, the arraylist is empty.

    To perform an update on the LDAP, this is the code:
    Code:
    DirContextAdapter contextAdapter = (DirContextAdapter) ldapTemplate.lookup(currentDn);
    
    EmployeeToAttributesMapper employeeToAttributesMapper = new EmployeeToAttributesMapper(contextAdapter);
    
    employeeToAttributesMapper.mapToAttributes(employee);
    
    ModificationItem[] modificationItems = contextAdapter.getModificationItems();
    
    ldapTemplate.modifyAttributes(currentDn, modificationItems);
    For some reason, if the ArrayList in the Employee object contains no items, Spring-LDAP doesn't detect that this should be changed (thus, all the attributes should be removed). So modificationItems is empty.

    However, if I select other departments, or I select additional departments, no problems occur. But for some reason, if the list is empty, it doesn't detect whether anything has been changed.

    Mapper:
    Code:
    ArrayList<String> departments = new ArrayList<String>();
    
    for(Department department: employee.getDepartments())
    {
        departments.add(department.getDepartmentCode());
    }
    
    setTextAttributeList("memberOfDepartments", departments);
    I'm rather desperate atm :-).

  • #2
    So what you're saying is that if you have some values set for memberOfDepartment and try doing
    Code:
    dirContextAdapter.setAttributeValues("memberOfDepartment", new String[0]);
    ModificationItem[] mods = dirContextAdapter.getModificationItems();
    that will produce an empty array of modification items?

    I think that should work, but I'm not absolutely positive - I'll need to check it out. As a workaround in the meantime you could try setting the attribute to null if there are no values:
    Code:
    if(departmentArray.length == 0){
      dirContextAdapter.setAttributeValues("memberOfDepartment", null);
    }else{
      dirContextAdapter.setAttributeValues("memberOfDepartment", departmentArray);
    }
    It's not all that pretty, but it should work.

    Comment


    • #3
      When there are no departments selected, you actually do:

      Code:
          contextAdapter.setAttributeValue("departments", new ArrayList<String>);
      Maybe it's the arraylist that seems to cause the problem, i don't know :-/

      Comment


      • #4
        Ouch, I don't think that will work. You'll need to work with arrays and use setAttributeValues() instead:
        Code:
        contextAdapter.setAttributeValues("departments", departmentCodeList.toArray());

        Comment

        Working...
        X