Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unimplemented Operation on BoardAdminServer.update

Derek Fields Community Leader Apr 14, 2020

I wrote the following script to add "jira-administrators" group as a board administrator. This runs in the ScriptRunner console but fails with a

java.lang.UnsupportedOperationException: Not implemented at com.atlassian.greenhopper.service.rapid.view.BoardAdminAOMapper.update(BoardAdminAOMapper.java:73)

error on the last line - here is the code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.greenhopper.model.rapid.RapidView;;
import com.atlassian.greenhopper.manager.rapidview.RapidViewManager;
import com.atlassian.greenhopper.service.rapid.view.RapidViewService;
import com.atlassian.greenhopper.model.rapid.BoardAdmin;
import com.atlassian.greenhopper.service.rapid.view.BoardAdminService;
import com.atlassian.greenhopper.model.rapid.BoardAdmin.Type;

import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.pyxis.greenhopper.jira")
// We need a user to retrieve and update the board. this should probably be a service account
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// This gets all of the boards available to the current user
// We are going to randomly pick the first one, just for testing purposes
// In a Listener, the event should provide the board and we won't have to look it up
// Note that a Board is called a RapidView
RapidViewService rapidViewService = PluginModuleCompilationCustomiser.getGreenHopperBean(RapidViewService);
List<RapidView> boards = rapidViewService.getRapidViews(currentUser).get();
RapidView ourBoard = boards[0]

// Now we construct a new list of BoardAdmins using the current BoardAdmin list as our base
BoardAdminService boardAdminService = PluginModuleCompilationCustomiser.getGreenHopperBean(BoardAdminService);
List<BoardAdmin> boardAdmins = boardAdminService.getBoardAdmins(ourBoard).collect {it};

// Add the new admin to the boardAdmins list.
// This line constructs a new BoardAdmin
def group = ComponentAccessor.getGroupManager().getGroup("jira-administrators");
BoardAdmin newAdmin = BoardAdmin.builder().key(group.getName()).type(BoardAdmin.Type.GROUP).build();
boardAdmins.add(newAdmin);

// Update the board admins
boardAdminService.updateBoardAdmins(ourBoard, currentUser, boardAdmins);

the last line fails with the error above. 

If I change the last line to 

// Update the board admins
boardAdminService.updateBoardAdmins(ourBoard, currentUser, [newAdmin]);

it works. I don't see any difference between the two versions. Both are java.util.ArrayList classes. Both contain valid BoardAdmin objects. I don't understand why the first one fails and the second one runs. Any ideas are greatly appreciated.

1 answer

1 accepted

0 votes
Answer accepted

Hi there.

This is a useful script, and a tricky question.
I think the problem is wether related to the List, nor to the ObjectType of the Element.
The problem seems to be in the data you fetch to get the board admins. The elements contain an id. But if you want to insert a new admin, the id needs to be empty.

See:

for (f in boardAdminService.getBoardAdmins(ourBoard))
{ log.warn(f) }

BoardAdmin newAdmin = BoardAdmin.builder().key(group.getName()).type(BoardAdmin.Type.GROUP).build();
log.warn(newAdmin)

admin.png

Conclusion: I think you'll need to convert the existing admins to users and re-build an admin object, so that the id gets deleted.

Hope this works
Cheers Leonard

Derek Fields Community Leader Apr 17, 2020

Your response was spot on. I modified the script to create a new list of admins using the original list as input and it works as expected. I appreciate the help.

For anyone who wants to see the correct solution

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.greenhopper.model.rapid.RapidView;;
import com.atlassian.greenhopper.manager.rapidview.RapidViewManager;
import com.atlassian.greenhopper.service.rapid.view.RapidViewService;
import com.atlassian.greenhopper.model.rapid.BoardAdmin;
import com.atlassian.greenhopper.service.rapid.view.BoardAdminService;
import com.atlassian.greenhopper.model.rapid.BoardAdmin.Type;

import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.pyxis.greenhopper.jira")
// We need a user to retrieve and update the board. this should probably be a service account
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// This gets all of the boards available to the current user
// We are going to randomly pick the first one, just for testing purposes
// In a Listener, the event should provide the board and we won't have to look it up
// Note that a Board is called a RapidView
RapidViewService rapidViewService = PluginModuleCompilationCustomiser.getGreenHopperBean(RapidViewService);
List<RapidView> boards = rapidViewService.getRapidViews(currentUser).get();
RapidView ourBoard = boards[0]

// Now we construct a new list of BoardAdmins using the current BoardAdmin list as our base
BoardAdminService boardAdminService = PluginModuleCompilationCustomiser.getGreenHopperBean(BoardAdminService);
List<BoardAdmin> boardAdmins = boardAdminService.getBoardAdmins(ourBoard).collect {
BoardAdmin.builder().key(it.getKey()).type(it.getType()).build();
};

// Add the new admin to the boardAdmins list.
// This line constructs a new BoardAdmin
def group = ComponentAccessor.getGroupManager().getGroup("jira-administrators");
BoardAdmin newAdmin = BoardAdmin.builder().key(group.getName()).type(BoardAdmin.Type.GROUP).build();
boardAdmins.add(newAdmin);

// Update the board admins
boardAdminService.updateBoardAdmins(ourBoard, currentUser, boardAdmins);
Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Learn how to request and manage app requests in the Marketplace

G’day everyone! Super exciting news coming from the Marketplace. We have now fully rolled out the ability for end-users to submit app requests to admins directly from within the product! No longer ...

62 views 1 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you