Hi ,
I have a scripted field and I am getting an error on
"Attributes attrs = results[0].getAttributes("");".
Line no. 33 in below code
The code runs properly and gives the correct result but I want to remove the error from the line.
That's not a compilation error... it's a "static type checking" error.
They are generally safe to ignore. It just means that the editor is not able to confirm that results[0] yield an object that has a "getAttributes()" method.
So to fix that (not that I would bother... this is groovy code, not java), you would have to look up the javadoc for the classes you are using to get the SearchResult.
Guessing at what the might be since you didn't show the import, I'm thinking this might be in the ballpark:
https://docs.oracle.com/javase/7/docs/api/javax/naming/directory/SearchResult.html#getAttributes()
If that's correct, then try:
Attributes attrs = results[0].getAttributes();
(no empty quotes inside getAtrributes() since no arguments are requested for that method)
Hi @PD Sheehan ,
Thank you for your reply. Yes it is a static type error.
I have already tried :
But it is not giving expected results. It returns null.
Can you share the full code (just remove/hide passwords or other binding/private information)?
What you seem to be telling me is that getAttributes("") works, returns the values you expect, but you don't like the static code checking error in the editor.
But when you remove the doubleQuotes, the static code checking errors go away, but the method returns null instead of the data you want.
My advice, in this case, would be to just ignore the static type errors.
But if you share the rest of the code, I can run a couple of tests in my environment and see what I get.
I don't want to ignore the static type errors. So I am finding the replacement methods.
Here is the full code.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issue;import com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolder/////////////////////@GrabResolver(name='apache-snapshot', root='http://repository.apache.org/snapshots/')@Grab(group='org.apache.directory', module='groovyldap', version='0.1-SNAPSHOT')import javax.naming.Context;import javax.naming.NameNotFoundException;import javax.naming.NamingEnumeration;import javax.naming.NamingException;import javax.naming.directory.Attribute;import javax.naming.directory.Attributes;import javax.naming.directory.BasicAttribute;import javax.naming.directory.BasicAttributes;import javax.naming.directory.ModificationItem;import javax.naming.directory.SearchControls;import javax.naming.directory.SearchResult;import javax.naming.ldap.InitialLdapContext;import javax.naming.ldap.LdapContext;import javax.naming.ldap.LdapName;simport java.text.MessageFormat;import java.util.ArrayList;import java.util.Collection;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.logging.Level;import java.util.logging.Logger;import org.apache.directory.groovyldap.*////////////////////////////////////////def userManager = ComponentAccessor.getUserManager()def customFieldManager = ComponentAccessor.getCustomFieldManager();def cFieldError=customFieldManager.getCustomFieldObject("customfield_18010")//def cFieldErrorOld = customFieldManager.getCustomFieldObject("customfield_18010")//String cFieldErrorOldValue = issue.getCustomFieldValue(cFieldErrorOld)
String sAMAccountNameString displayError = null;if (issue.reporter){sAMAccountName = issue.reporter.name;}else {displayError = "Reporter: Anonymous";cFieldError.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cFieldError), displayError), new DefaultIssueChangeHolder())return null}
def ldap = LDAP.newInstance('ldap://ldap.akad.kaercher.com:389/OU=KAERCHER,OU=ACCOUNTS,DC=AKAD,DC=KAERCHER,DC=COM','user','pw')
//get the direct manager and employee type of reporterdef attributesList = readAttributesFromPerson(ldap, sAMAccountName);String cnManager = attributesList.get(0)String employeeType = attributesList.get(1)int numEmployeeTypeString sAMAccountNameManagerString tempEmployeeType
if (employeeType == null && cnManager == null) {displayError = "Employee Type Reporter (" + sAMAccountName + ") and Reporter Manager: null value from AD";cFieldError.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cFieldError), displayError), new DefaultIssueChangeHolder())return null}else if (employeeType == null) {displayError = "Employee Type Reporter (" + sAMAccountName + "): null value from AD";cFieldError.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cFieldError), displayError), new DefaultIssueChangeHolder())return null}else if (cnManager == null) {displayError = "Reporter Manager (" + sAMAccountName + "): null value from AD";cFieldError.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cFieldError), displayError), new DefaultIssueChangeHolder())return null}else {numEmployeeType = employeeType as Integerif (numEmployeeType >= 4){/*if (cFieldErrorOldValue != null && cFieldErrorOldValue.length() > 0) {displayError = cFieldErrorOldValue + ", " + "There is no business unit manager";}else {displayError = "There is no business unit manager";}*///displayError = "There is no business unit manager";//cFieldError.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cFieldError), displayError), new DefaultIssueChangeHolder())return null}else{String tempManager = cnManager;int numTempEmployeeType = numEmployeeType//repeat this loop till get a direct manager with employee type = 4while(numTempEmployeeType < 4) {sAMAccountNameManager = tempManager;if (sAMAccountNameManager !=null) {def attributesListManager = readAttributesFromPerson(ldap, sAMAccountNameManager);tempManager = attributesListManager.get(0)tempEmployeeType = attributesListManager.get(1)if (tempEmployeeType != null && tempEmployeeType.length() > 0) {numTempEmployeeType = tempEmployeeType as Integer}else {displayError = sAMAccountNameManager + "'s Employee Type: null value from AD";break;}if (tempManager == null) {displayError = sAMAccountNameManager + "'s Manager: null value from AD";break;}}else {break;}}if (numTempEmployeeType ==4) {def userBusinessUnitManager = userManager.getUserByName(sAMAccountNameManager)return userBusinessUnitManager}else {/*if (cFieldErrorOldValue != null && cFieldErrorOldValue.length() > 0) {displayError = cFieldErrorOldValue + ", " + "There is no business unit manager";}else {displayError = "There is no business unit manager";}*///displayError = "There is no business unit manager";//cFieldError.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cFieldError), displayError), new DefaultIssueChangeHolder())return null}}}/////////////////////////////////////////////////////read attributes from LDAP in Jira using GroovyList readAttributesFromPerson (LDAP ad, String sAMAccountName) {def results = ad.search('(&(objectClass=person)(objectClass=user)(sAMAccountName='+sAMAccountName+'))', '', SearchScope.SUB )String cnManager = null;String employeeType = null;if (results[0]){Attributes attrs = results[0].getAttributes("");String managerValueAttribute = attrs.get('manager');String employeeTypeAttribute = attrs.get('employeeType');
if (managerValueAttribute != null && managerValueAttribute.length() > 0) {String managerValue = managerValueAttribute.substring(9);def listManagerValue = managerValue.split(',').collect{it as String}cnManager = listManagerValue.get(0).substring(3)}if (employeeTypeAttribute != null && employeeTypeAttribute.length() > 0) {employeeType = employeeTypeAttribute.substring(14);}}List attributesList = [cnManager, employeeType]return attributesList;}
I try also tried with:
Instead of this:
def results = ad.search('(&(objectClass=person)(objectClass=user)(sAMAccountName='+sAMAccountName+'))', '', SearchScope.SUB )
I did:
ArrayList<SearchResult > results =(ArrayList<SearchResult>) ldap.search('(&(objectClass=person)(objectClass=user)(sAMAccountName='+sAMAccountNameManager+'))', '', SearchScope.SUB ) ;
But still the same error.
Your help will be appreciated.
It looks like you're new here. Sign in or register to get started.