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

Unimplemented Operation on BoardAdminServer.update

C_ Derek Fields
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 15, 2020

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

C_ Derek Fields
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 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
Jeremy Jedlicka July 11, 2022

@C_ Derek Fields

This is exactly what I've been trying to write.  Thanks for this.  Question though, I can't figure out how to use the list "boards" to add the admin across all boards.  I've tried to accomplish this through iterating though "boards", but it keeps erroring out.

Can you provide the modification to the above code that uses "boards" instead of "ourBoard" to update the admins?

C_ Derek Fields
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2022

@Jeremy Jedlicka - This is simply a matter of iterating through the different boards in the list. Here is the modified 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();

// This iterates over each board updating the admins
boards.each { ourBoard ->
  // 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);
}

TAGS
AUG Leaders

Atlassian Community Events