How to get User preferences?

Hi,

From my plug-in code, I want to access the User preferences for "Own Changes:" filed. Here is my code

Preferences userPrefs = ComponentManager.getInstance().getUserPreferencesManager().getPreferences(currentUser);

String userOwnChanges = userPrefs.getString(PreferenceKeys.USER_NOTIFY_OWN_CHANGES);

I am getting the following exception

com.opensymphony.module.propertyset.InvalidPropertyTypeException: Tried to retrieve PropertySet key 'user.notify.own.changes' as a String, but it is the wrong type.
at com.atlassian.jira.propertyset.PropertySetCache.getString(PropertySetCache.java:256)
at com.atlassian.jira.propertyset.JiraCachingPropertySet.getString(JiraCachingPropertySet.java:629)
at com.atlassian.jira.user.preferences.JiraUserPreferences.getString(JiraUserPreferences.java:94)
at com.teradata.engtools.jiraplugins.issueoperations.AddDetailedComment.isUserNotified(AddDetailedComment.java:567)
at com.teradata.engtools.jiraplugins.issueoperations.AddDetailedComment.notifySpecificComment(AddDetailedComment.java:349)
at com.teradata.engtools.jiraplugins.issueoperations.AddDetailedComment.addComment(AddDetailedComment.java:218)
at com.teradata.engtools.jiraplugins.issueoperations.AddDetailedComment.doAdd(AddDetailedComment.java:717)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at webwork.util.InjectionUtils$DefaultInjectionImpl.invoke(InjectionUtils.java:70)
at webwork.util.InjectionUtils.invoke(InjectionUtils.java:56)
at webwork.action.ActionSupport.invokeCommand(ActionSupport.java:433)
at webwork.action.ActionSupport.execute(ActionSupport.java:157)
at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:54)
at webwork.dispatcher.GenericDispatcher.executeAction(GenericDispatcher.java:139)
at com.atlassian.jira.web.dispatcher.JiraWebworkActionDispatcher.service(JiraWebworkActionDispatcher.java:168)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.atlassian.jira.web.filters.JiraLastFilter.doFilter(JiraLastFilter.java:69)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

Is there any other way to achive this?

Thanks in advance!!

Raju

4 answers

Sorry, when I use getBoolean, it works.

Hi,

iam searching for a solution to read and update user preferences of a gadget in mein Rest service? How can I access the portlet instance preferences? The following does only return the global JIRA preferences:

ComponentAccessor.getInstance().getUserPreferencesManager().getPreferences(currentUser);

Regards

Martin

For getting user preferences from a gadget instance (portlet) programatically in java, you can find a good article here:

https://confluence.atlassian.com/display/~aatkins/Atlassian+Intern+Adventures%3A+from+Portlet+to+Gadget

According to https://confluence.atlassian.com/display/GADGETS010/Gadget+Object+API. To get preference you must call gadget.getPref("your_pref_name"); in gadget.xml file. Than you can pass it parametr to your rest source (via params) to make backend logic and return correct response.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

122 views 6 8
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you