Hi everyone, !
I’m currently trying to store in a Hashmap object the value and key of the ldapAttributeList returned by my ldap connector using the the output operation window.
Here is a piece of code doing this thing :
import org.bonitasoft.connectors.ldap.LdapAttribute;
def temp_list = [:]
ldapAttributeList[0].each {
temp_list.put((it.getName()), (it.getValue()))
}
return new HashMap(temp_list)
So to resume, I'm getting every attribute form the output of my ldap connector, storing them in a hasmap object and returning it.
When I test this piece of code in a test connector it return that :
So correct me if I’m wrong but this piece of code is actually working.
Now when I’m trying to use the same connector but with filled-by-variables fields such as a login and password field the connector fails.
Key elements :
– I’m currently using the Bonita Community pack (version 6.2.6), in a windows Seven professional 64 bits.
– The problem is not linked with a bad credentials.
– My code works when I only try to invoke the ldapAttribute.getName() like this :
import org.bonitasoft.connectors.ldap.LdapAttribute;
def temp_list = [:]
ldapAttributeList[0].each {
temp_list.put((it.getName()), (it.getName()))
}
return new HashMap(temp_list)
– But when I try to use the piece of code in the top of the question, the connector fails.
– I tried to get the exception thrown by the ldapAttribute.getValue() methods, here is what I get :
java.lang.NullPointerException: Cannot invoke method getAt() on null objectdescription= <>
So it is confirmed that the getValue() method throw the exception, I’ve checked the source code and i don’t know what’s wrong.
– I even tried to clone the ldapAttribute in order not to use the getValue() method, but it doesn’t work as it seems that the clone() method has not been implemented, so I’m completely stucked and i look forward to hear you suggestions.
Thank you for all !
It seems that some values are null and it creates a problem. You can try to test for null values on your object something like this:
if (it.getValue() != null){temp_list.put((it.getName()), (it.getValue()))}
or this
if (it != null){temp_list.put((it.getName()), (it.getValue()))}
Hi ! I’ve added your condition and several other things in a new piece code, here I am :
import org.bonitasoft.connectors.ldap.LdapAttribute;
def temp_hashmap = [:]
ldapAttributeList[0].each {
try{
if (it.getValue() != null && it != null){
temp_hashmap.put((it.getName()), (it.getValue()))
}
else{
temp_hashmap.put(“NULL”, “NULL”)
}
}
catch (e){
temp_hashmap.put(e.toString(), e.getStackTrace())
}
}
return temp_hashmap.toString()
To sum up, this piece of code is doing exactly what I want (creating a hashmap/dictionnary of ldap attributes with [key:value]) except the fact that it return the .toString() of the hashmap.
It works perfectly ! I can get the toString of a good-shaped hashmap, and I checked and I didn’t find any occurences of “NULL” value.
So :
– No null value
– The connector fails when I try to save the ouput as an hashmap,
The problem is : I can’t get any other things than a string in the output operation window !
For your information, when I try to store the hashmap (not the toString) the only thing who change compared to the code at the beginning is the return method :
return temp_hashmap
– I set the return type as and hashmap in the script’s window
– Here is what i have in the output operation window of my ldap connector :
Do you have any suggestion ?
I’ve read a lot of topic about storing such data but even if I return an hashmap and try to store it in my java object it doesn’t works
If anyone have a better solution to store user attributes from the ldap connector i’m interested as well !
Hello, I have tried your initial groovy script code and it worked fine for me.
This is what I did:
In the connector config:
Base DN: ou=People,dc=example,dc=com
Filter: (objectClass=person)
Attributes: *
Scope: Subtree
Then I create variable to a java.util.Map and assign it connector output.
I use your groovy script for the ‘ldapAttributeList’, important, changing the return type to : java.util.Map (the same as the defined variable)
Then I use this Map in a form and I have checked that I have access to All user attributes.
I would suggest to double check the LDAP query parameters, delete you java_object variable and create a new one of java.util.Map type and use it with your groovy script.
Regards,
Jordi
Hmm, I did not think about this, I’ll try it !
On your output operation screenshot, what is the class of your “java_object”? It is a variable of the java type, I guess, but did you choose java.util.Map as a class?
The problem might be coming from the fact that you declared your variable temp_hashmap in Groovy, and it cannot be casted to java map when you map the output. You could try to declare it the following way instead:
HashMap<String,Object> temp_hashmap = new HashMap<String,Object>();
Otherwise, it would be helpful to get log for the latest connector failure.
I don’t know how to get the log of the failure when a connector doesn’t works.
I’m trying right now to store into a java.util.map object and changing my code.
the java_object variable is of type java.lang.object by the way.