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

How to link workItem in one project area to workitem in other project area using participant plugin

 Hello, 

I am quite new in plugin development for RTC. I am writing a Participant plugin. My requirment :

1. Creating a new workItem(Implementation task-customize) in Project Area B from a workItem (Defect) in Project Area A,

2. link created new work Item ,from Step 1,  in project area B as a child to workItem in project Area A.

I've completed 1st part , and need some help or code snipped for part 2 (create parent child WorkItem link in Project Area A and B)

Please guide me to the correct information if already available. I already check https://jazz.net/wiki/bin/view/Main/ProgrammaticLinkCreation link but couldnt understand as ILinkManager is not available.

0 votes


Accepted answer

Permanent link
You can find some information in the link API here: http://rsjazz.wordpress.com/2012/09/20/the-rtc-workitem-server-link-api-linking-to-work-items-and-other-elements/

I haven't tried that yet, but IWorkItemServer provides a way to create a work item in the server API. You probably need to work with the WorkingCopy as described here http://rsjazz.wordpress.com/2012/11/27/resolve-parent-if-all-children-are-resolved-participant/ and here http://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ .
Nikhil Bharti selected this answer as the correct answer

1 vote

Comments

 Thank you Ralph thats what I am looking for.


I've another requirement. I've created 'Implementation Task' (WorkItem) on project area B, I was able to copy the value of attributes Summary and Description from workItem in Project A , using wi.setHTMLSummary and description method , however , I've requirement to set the mandatory attributes 'Filed Against' (type category) and 'Owned By'(type contributor) attributes.  I tried finding these attributes using workItemServer.findAttributes method using ID but couldn't get any success.

Appreciate if I get some sample code to set 'Filed Against' and 'Owned By' value to the new workItem in project area B.


2 other answers

Permanent link
Hi Nikhil,

this is how the code for creating and linking a work item would look like.
How you would find the owner would depend on your scenario and can get quite complex. I am about to blog about a participant to create an approval but won't be able to make it next week. The code below is the simple scenario where you know the owner ID.
	private IWorkItem createWorkItem(String projectAreaName, String workItemType,
			String categoryName, String summary, String owner, IProgressMonitor monitor)
			throws TeamRepositoryException {
		URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));
		IProcessArea processArea = fAuditableCommon.findProcessAreaByURI(uri, null, monitor);
		IProjectAreaHandle projectArea=processArea.getProjectArea();
		IWorkItemType type = fWorkItemCommon.findWorkItemType(projectArea, workItemType, monitor);

		List path = Arrays.asList(categoryName.split("/"));

		IWorkItem newWorkItem = fWorkItemServer.createWorkItem2(type);
		ICategoryHandle category = fWorkItemCommon.findCategoryByNamePath(projectArea, path, monitor);
		newWorkItem.setCategory(category);
		newWorkItem.setHTMLSummary(XMLString.createFromPlainText(summary));
		newWorkItem.setOwner(getContributorByID(owner));
		IStatus status = fWorkItemServer.saveWorkItem2(newWorkItem, null, null);
		if (!status.isOK()) {
			return null;
		}
		return newWorkItem;	
	}
	
	private IContributorHandle getContributorByID(
			String approverId) throws TeamRepositoryException {
		/**
		 * Get Approver Handle by searching some external system Replace this
		 * with some code to query the external system.
		 */
		IContributorService contributorService = getService(IContributorService.class);
		IContributorHandle approver = contributorService
				.fetchContributorByUserId(approverId);
		return approver;
	}

	
	/**
	 * Link two work items as blocking
	 * 
	 * @param blockingWorkItem
	 * @param blockedWorkItem
	 * @throws TeamRepositoryException
	 */
	private void linkBlockingWorkItems(IItemHandle blockingWorkItem,
			IItemHandle blockedWorkItem) throws TeamRepositoryException {
		/**
		 * Creating Links on the Server.
		 * 
		 * @see: 
		 *       https://jazz.net/forum/questions/82384/serverside-create-link-from
		 *       -a-workitem-to-a-changeset
		 * @see: 
		 *       https://jazz.net/forum/questions/80731/how-do-i-create-an-included
		 *       -in-build-link-from-java-api/80781
		 */

		IReferenceFactory refFactory = IReferenceFactory.INSTANCE;
		IReference source = refFactory.createReferenceToItem(blockingWorkItem);
		IReference target = refFactory.createReferenceToItem(blockedWorkItem);
		ILinkService linkService = getService(ILinkService.class);
		ILinkServiceLibrary linkServiceLibrary = (ILinkServiceLibrary) linkService
				.getServiceLibrary(ILinkServiceLibrary.class);

		ILink link = linkServiceLibrary.createLink(
				WorkItemLinkTypes.BLOCKS_WORK_ITEM, source, target);
		linkServiceLibrary.saveLink(link);
	}



0 votes

Comments

And this code calls it


            fAuditableCommon = getService(IAuditableCommon.class);
            fWorkItemCommon = getService(IWorkItemCommon.class);

        String projectAreaName="DevProject";
        String categoryName = "Dev1";
        String workItemType = "defect";
        String summary = "Test";
        String owner = "TestJazzGuest1";

        IWorkItem newWorkItem = createWorkItem(projectAreaName, workItemType, categoryName, summary, owner,
                monitor);
        if(newWorkItem!=null){
            linkBlockingWorkItems(newWorkItem, newState);
            return;
        }
        String description = "Failed to create and link work item.";
        IReportInfo info = collector.createInfo(
                "Unable to update Parent state.", description);
        info.setSeverity(IProcessReport.ERROR);
        collector.addInfo(info);

Thank you Ralph. Much appreciated 


Permanent link
Decided to get the approval participant posted right away. Maybe an inspiration for you how to find the owner for the work item.

0 votes

Comments

Thank you Ralph. Much appreciated 

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,939
× 1,700

Question asked: Nov 30 '12, 7:31 a.m.

Question was seen: 4,964 times

Last updated: Dec 03 '12, 5:06 a.m.

Confirmation Cancel Confirm