It's all about the answers!

Ask a question

Add workitem owner to project members RTC extension


Marcin Blacha (146214) | asked Apr 13 '17, 4:30 a.m.
edited Apr 13 '17, 4:41 a.m.

Hi,

I'm trying to create operation participant which check, is owner of workitem member of project area. I have code like this:

WorkItem workItem = (IWorkItem)auditable;
IWorkItemServer workItemServer = (IWorkItemServer)getService(IWorkItemServer.class);
IWorkItem workItemCopy = (IWorkItem)((IWorkItem)workItemServer.getAuditableCommon().resolveAuditable(workItem, IWorkItem.FULL_PROFILE, monitor)).getWorkingCopy();
IProcessArea proc = operation.getProcessArea();
IProcessServerService pss = getService(IProcessServerService.class);
IServerProcess servProc = pss.getServerProcess(proc);
IRole[] processRoles = servProc.getRoles(proc);
IRole[] defaultRole = new IRole[1]; for (IRole processRole : processRoles) {
if (processRole.getId().equals("user"))
defaultRole[0] = processRole;
} if (!proc.hasMember(workItemCopy.getOwner())) { proc.addMember(workItemCopy.getOwner()); proc.addRoleAssignments(workItemCopy.getOwner(), defaultRole); }


But I'm getting ImmutablePropertyException in line proc.AddMember(workItemCopy.getOwner()).

What is the problem? How can I properly add members to project area?

2 answers



permanent link
Ralph Schoon (63.1k33646) | answered Apr 13 '17, 5:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Apr 13 '17, 5:34 a.m.

 See https://rsjazz.wordpress.com/2013/09/18/deploying-templates-and-creating-projects-using-the-plain-java-clients-library/ 


As explained in https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ you need a working copy to change most objects. 
In this example it would look similar to 

private IProjectArea addUsersAndRoles(ITeamRepository teamRepository,
        IProjectArea area, IProgressMonitor monitor)
        throws TeamRepositoryException {

IProcessItemService service = (IProcessItemService) teamRepository
            .getClientLibrary(IProcessItemService.class);
area = (IProjectArea) service.getMutableCopy(area);

For the server API it should look similar to
    IProcessItemService service = (IProcessItemService) getService(IProcessItemService.class);
    area = (IProjectArea) service.getMutableCopy(area);

You also have to save the change later. e.g. below. Please note the different call to get a working copy. 
    /*
     * Adds a user as a member with a specific role to a process area
     * 
     * @param user
     * @param role
     * @param processArea
     * @param itemService
     * @param monitor
     * @throws TeamRepositoryException
     /
    public static void addMemberToProcessArea(IContributor user, IRole role,
            IProcessArea processArea, IProcessItemService itemService,
            IProgressMonitor monitor) throws TeamRepositoryException {
        IProcessAreaWorkingCopy areaWc = (IProcessAreaWorkingCopy) itemService
                .getWorkingCopyManager().createPrivateWorkingCopy(
                        processArea);
        areaWc.getTeam().addContributorsSettingRoleCast(
                new IContributor[] { user }, new IRole[] { role });
        areaWc.save(monitor);
    }


Comments
Ralph Schoon commented Apr 13 '17, 5:19 a.m. | edited Apr 13 '17, 5:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 In general, I think you can overshoot with automation. I am not a friend of automating administrative duties in a follow up action/participant.


Please also note that the participant is run in the context of the user that performs the work item save. If this user is not a member of the project area and does not have permission to alter and save the project area process (which is usually an administrator or project owner role privilege) the operation to add the owner will fail.

No, there is no way to elevate your role to an administrator in a participant, if you are not already an administrator. 


Marcin Blacha commented Apr 13 '17, 6:10 a.m.

The main problem why I'm trying to create such participant is that access to project areas is restricted, but people are adding tasks and assign them to guys who are not members of project area, and they don't get mail notifications about this tasks. Do you have idea how to workaround this problem?


permanent link
Marcin Blacha (146214) | answered Apr 13 '17, 6:07 a.m.
edited Apr 13 '17, 6:12 a.m.

Hi Ralph,

I've get it to work with this code:

IWorkItem workItem = (IWorkItem)auditable;
IWorkItemServer workItemServer = (IWorkItemServer)getService(IWorkItemServer.class);
IWorkItem workItemCopy = (IWorkItem)((IWorkItem)workItemServer.getAuditableCommon().resolveAuditable(workItem, IWorkItem.FULL_PROFILE, monitor)).getWorkingCopy();
IProcessArea proc = operation.getProcessArea();
IProcessServerService pss = getService(IProcessServerService.class);
IServerProcess servProc = pss.getServerProcess(proc);

IProcessArea processAreaCopy = (IProcessArea)proc.getWorkingCopy();

IRole[] processRoles = servProc.getRoles(proc);
IRole[] defaultRole = new IRole[1];

for (IRole processRole : processRoles)
{
     if (processRole.getId().equals("user"))
            defaultRole[0] = processRole;
}

if (!processAreaCopy.hasMember(workItemCopy.getOwner()))
{
   processAreaCopy.addMember(workItemCopy.getOwner());
   processAreaCopy.addRoleAssignments(workItemCopy.getOwner(), defaultRole)
}

pss.saveProcessItem(processAreaCopy);


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.