precondition: restrict assigning roles for team members
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
Accepted answer
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
in a participant (too far after the fact).. the getSaveditems()[0] has the new data. while getItems()[0] has the old data
Object objData = operation;
if (operation instanceof ProjectAreaSaveOperation)
{
ProjectAreaSaveOperation data = (ProjectAreaSaveOperation) objData;
List<String> actions = Arrays.asList(data.getActions());
if (actions.contains(ProjectAreaSaveOperation.ACTION_MODIFY_MEMBERS))
{
if(fcontributorService==null)
{
IContributorService fcontributorService= getService(IContributorService.class);
fItemService = getService(IRepositoryItemService.class);
}
System.out.println("in modify members");
IProjectArea pa = (IProjectArea) data.getItems()[0];
IContributorHandle members[] = pa.getMembers();
for(IContributorHandle member: members)
{
IContributor user = (IContributor) fItemService.fetchItem(member, (new String[]{IContributor.NAME_PROPERTY,IContributor.DETAILS_PROPERTY}));
System.out.println("user name="+user.getName());
String[] roles = RolePersistence.getRoleIds(RolePersistence.getPersistentRoleData(pa.getTeamData(), user));
for(String role:roles)
{
System.out.println("\t role="+role);
}
}
Comments
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
in a participant (too far after the fact).. the getSaveditems()[0] has the new data. while getItems()[0] has the old data
but data.getSavedItems()[0]; returns a
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
there are two different solutions..
in an Advisor, you get the NEW data, and have to LOAD the old data for the project area to compare against
in a Participant, you get BOTH the old and the new, least I do.
1 vote
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
Many thanks Sam for your support. Now it work's.
IProcessArea oldProcess = (IProcessArea) repositoryService.fetchItem( newProcess.getItemHandle(), null);
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
had to post another 'answer' to hold the full sample. see my comment there about using the itemhandle
2 other answers
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
Comments
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
get the contributor service ( add it as a pre-req to the plugin.xml)
private static IContributorService fcontributorService = null;
fcontributorService = getService(IContributorService.class);
then the extension is running in the context of the user making the change
on the AbstractService class the extension is part of
getAuthenticatedContributor()
will get u the users handle, then use the service..
![](http://jazz.net/_images/myphoto/e5e63d5878217b64611c1df9401b7cd3.jpg)
Some examples of the roles API also on my blog. E.g. https://rsjazz.wordpress.com/2013/06/26/attribute-customization-java-based-value-providers-conditions-and-validators/
Once you have the above, you could go deeper into the roles.
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
Sorry, I write my question unclear. I did not need the working copy of the user - I need the working copy of the project area that the authenticated user has changed. (and exactly the working copy that contains the changes of the authenticated user)
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
ah.. because you are in a pre-condition no changes have been made yet.
but you should be able ot get the list of users in the teamarea/project area,
and get their role data
RolePersistence.getPersistentRoleData(teamarea_area.getTeamData(), user_handle);
my guess is that the old/new process data will point to different data.
I haven't done this is a plugin.
but you will have to loop thru each user, get their role data on both old/new process areas and compare lists.
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
Right, and this works perfect for the operation saveTeamArea.
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
don't you get a teamarea save for the project area, when you don't change the process config?
I don't see the save project area extension point in the default list.
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
Unfortunately it is a saveProjectArea operation if you change the members of the project area.
In Web the editor you dont see this operation for precondition but there is an operation for it (see https://jazz.net/wiki/bin/view/Main/CustomPreconditionsLandingSite)
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
I don't see that operation listed except in the 'data passed' table.
"The following table gives the data types of the operation data"
you should not get the processarea (working copy), as you should HAVE the process area already.
and as u are not changing it (pre-conditions don't change), the other apis against it would work ok.
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
And that's the problem. I don't have the the process area that contains the changes. For the operation saveTeamArea I get the process area that CONTAINS the changed by calling
operation.getProcessArea();
But if I try the same with the operation saveProjectArea I receive the process area WITHOUT the changes. Therefore I can't check if the changes are correct.
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
ok, sorry, without debugging this myself, I don't have any other answer..
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
can u show me how you configured you advisor?
(cut/paste the xml from eclipse project source view)
as I don't see it.
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
![](http://jazz.net/_images/myphoto/d0f7b0b7bfc90721959d790b8a9bf79f.jpg)
thanks.. one more thing.. I am getting ''Save Project Area' failed. Preconditions have not been met: The advisor com.sd.tools.SaveProjectArea.advisor is not valid for the operation com.ibm.team.process.server.saveProjectArea.'
and my class def is
public class ProjectAreaSaveAdvisor extends AbstractService implements IOperationAdvisor
running on a 4.0.3 server. compiled against the 4.0.3 sdk.
![](http://jazz.net/_images/myphoto/d9cab087e0286be8236b0e0286dd0849.jpg)
which holds the data you seek, but there is no method to get it.
I was concerned with using the projectArea handle provided in the advisor to load the pre-change data, as it was provided by the advisor..
so I did this
URI srcuri = URI.create(pa.getName().replaceAll(" ", "%20"));
IProcessArea projectArea = fProcessServerService.findProcessArea(srcuri.toString(), null);
full sample
package com.sd.tools;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.process.common.IDevelopmentLine;
import com.ibm.team.process.common.IProcessArea;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;
import com.ibm.team.process.common.advice.runtime.IOperationParticipant;
import com.ibm.team.process.common.advice.runtime.IParticipantInfoCollector;
import com.ibm.team.process.internal.common.RolePersistence;
import com.ibm.team.process.internal.service.ProjectAreaSaveOperation;
import com.ibm.team.process.service.IProcessServerService;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.common.service.IContributorService;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.repository.service.IRepositoryItemService;
public class ProjectAreaSaveAdvisor extends AbstractService implements IOperationAdvisor
{
IContributorService fcontributorService = null;
IRepositoryItemService fItemService = null;
IProcessServerService fProcessServerService = null;
public ProjectAreaSaveAdvisor()
{
System.out.println("in project save constructor");
}
@SuppressWarnings("restriction")
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IAdvisorInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException
{
Object objData = operation;
if (operation instanceof ProjectAreaSaveOperation)
{
ProjectAreaSaveOperation data = (ProjectAreaSaveOperation) objData;
List<String> actions = Arrays.asList(data.getActions());
if (actions.contains(ProjectAreaSaveOperation.ACTION_MODIFY_MEMBERS))
{
if(fcontributorService==null)
{
IContributorService fcontributorService= getService(IContributorService.class);
fItemService = getService(IRepositoryItemService.class);
fProcessServerService = getService(IProcessServerService.class);
}
System.out.println("in modify members");
//
IProjectArea pa = (IProjectArea) data.getItems()[0];
IContributorHandle members[] = pa.getMembers();
for(IContributorHandle member: members)
{
IContributor user = (IContributor) fItemService.fetchItem(member, (new String[]{IContributor.NAME_PROPERTY,IContributor.DETAILS_PROPERTY}));
System.out.println("user name="+user.getName());
String[] roles = RolePersistence.getRoleIds(RolePersistence.getPersistentRoleData(pa.getTeamData(), user));
for(String role:roles)
{
System.out.println("\t role="+role);
}
}
// use this if in an Advisor
// get the old data
URI srcuri = URI.create(pa.getName().replaceAll(" ", "%20"));
IProcessArea projectArea = fProcessServerService.findProcessArea(srcuri.toString(), null);
// use this if in a participant
// gets the new data (post save)
// projectArea = (IProjectArea) data.getSavedItems()[0];
// get the list of members
members = projectArea.getMembers();
System.out.println(" old info");
for(IContributorHandle member: members)
{
IContributor user = (IContributor) fItemService.fetchItem(member, (new String[]{IContributor.NAME_PROPERTY,IContributor.DETAILS_PROPERTY}));
System.out.println("user name="+user.getName());
String[] roles = RolePersistence.getRoleIds(RolePersistence.getPersistentRoleData(projectArea.getTeamData(), user));
for(String role:roles)
{
System.out.println("\t role="+role);
}
}
}
}
}
}
Comments
sam detweiler
Jun 24 '14, 10:32 a.m.I don't believe there is history for team area changes.
I'm not aware of any before/after capabilty on anything other than workitems
altho the getprocessarea/getsecondaryprocessarea might be how to get it.
what does operation.getSecondaryActions(operation.getProcessArea()) return.
1 vote
Martin Wassermann
Jun 30 '14, 2:59 a.m.Unfortunately "operation.getSecondaryActions(operation.getProcessArea())" returns an empty String array.
sam detweiler
Jun 30 '14, 8:45 a.m.I do not know any more about this. I have never seen any history or change info team areas or project areas other than the process config source.