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

Iterate over contributor list which is a custom attribute

I am writing java plugin to retrieve the below usecase. There's a custom attribute created of type contributor list . How do I iterate over this attribute to retrieve all the users added in the contributor list ?  Any inputs or pointers are appreciated

0 votes


Accepted answer

Permanent link

 // provided that you have already retrieved these data...
IProgressMonitor monitor = ...;
IAuditableCommon auditableCommon = ...;
IWorkItem workItem = ...;
IAttribute contributorsCustomAttribute =  ...;
List<?> contributors = (List<?>) contributorsCustomAttribute.getValue(auditableCommon, workItem, monitor);
for (Object contributorObj : contributors) {
IContributor contributor = (IContributor) contributorObj;
}

AMEYA KALE selected this answer as the correct answer

0 votes

Comments

Thanks for a quick response. But IContributor contributor = (IContributor) contributorObj is throwing the below exception .

com.ibm.team.repository.common.model.impl.ContributorHandleImpl incompatible with com.ibm.team.repository.common.IContributor. 

Is there any other way to convert the object into IContributor?

What you got from the getValue method is likely a list of IContributorHandle objects.

Try this way:

AbstractService pluginAbstractService = (AbstractService) this;
IRepositoryItemService repositoryItemService = pluginAbstractService.getService(IRepositoryItemService.class);

for (Object contributorObj : contributors) {
IContributorHandle contributorHandle = (IContributorHandle) contributorObj;
IContributor contributor = (IContributor) repositoryItemService.fetchItem(contributorHandle, IRepositoryItemService.COMPLETE);
}


One other answer

Permanent link

I gave it a try and its working perfectly.


Thanks Luca 

0 votes

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

Question asked: Mar 02 '20, 4:02 a.m.

Question was seen: 607 times

Last updated: Mar 03 '20, 5:59 a.m.

Confirmation Cancel Confirm