Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Add workitem owner to project members RTC extension

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?

1 vote



2 answers

Permanent link

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);


1 vote


Permanent link

 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);
    }

0 votes

Comments

 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. 

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?

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,954

Question asked: Apr 13 '17, 4:30 a.m.

Question was seen: 1,758 times

Last updated: Apr 13 '17, 6:12 a.m.

Confirmation Cancel Confirm