Associating Work Items with Change Sets in RTC: A Java API Approach
To associate a work item with a change set using the Java Plain API in IBM Rational Team Concert (RTC), you can follow these steps based on the provided search results. Here's a concise guide to help you achieve this:
Steps to Associate a Work Item with a Change Set
- Set Up Your RTC Environment: Ensure that you have the RTC SDK set up in your Java environment. You will need access to the necessary libraries and classes.
-
Obtain References: You will need to get references to the relevant services, including the
ILinkManager
andIWorkItemServer
. -
Create a Link Between Change Set and Work Item:
-
Use the
ILinkManager
to create a link between your change set and the work item. - You can create a reference to the work item using its handle.
-
Use the
-
Code Example:
Here’s a simple code snippet demonstrating how to associate a work item with a change set:javaimport com.ibm.team.repository.common.TeamRepositoryException; import com.ibm.team.scm.common.IChangeSetHandle; import com.ibm.team.scm.common.IChangeSet; import com.ibm.team.scm.client.IChangeSetClient; import com.ibm.team.workitem.common.model.IWorkItemHandle; import com.ibm.team.workitem.common.model.IWorkItem; // Assuming 'repository' is your connected repository and 'changeSetHandle' is your change set IChangeSetClient changeSetClient = (IChangeSetClient) repository.getClientLibrary(IChangeSetClient.class); IWorkItemServer workItemServer = (IWorkItemServer) repository.getClientLibrary(IWorkItemServer.class); try { // Fetch the change set IChangeSet changeSet = changeSetClient.resolve(changeSetHandle, null);
<button aria-label="Copy Code" class="sc-blHHSb fdjstX" style="border-width: 0px; border-style: solid; border-color: rgb(229, 231, 235); scrollbar-color: auto; scrollbar-width: auto; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgba(59,130,246,.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; font-family: inherit; font-feature-settings: inherit; font-variation-settings: inherit; font-size: 14px; font-weight: inherit; line-height: inherit; letter-spacing: inherit; margin: 0.15rem 0px 0px; padding: 0.25rem; appearance: button; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; cursor: pointer; position: absolute; top: 0.5em; right: 0.75em; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; border-radius: 0.25rem; max-height: 2rem; max-width: 2rem;" type="button"><svg class="icon" fill="#4d4d4c" height="16pt" viewbox="0 0 384 512" width="16pt"><path d="M280 240H168c-4.4 0-8 3.6-8 8v16c0 4.4 3.6 8 8 8h112c4.4 0 8-3.6 8-8v-16c0-4.4-3.6-8-8-8zm0 96H168c-4.4 0-8 3.6-8 8v16c0 4.4 3.6 8 8 8h112c4.4 0 8-3.6 8-8v-16c0-4.4-3.6-8-8-8zM112 232c-13.3 0-24 10.7-24 24s10.7 24 24 24 24-10.7 24-24-10.7-24-24-24zm0 96c-13.3 0-24 10.7-24 24s10.7 24 24 24 24-10.7 24-24-10.7-24-24-24zM336 64h-80c0-35.3-28.7-64-64-64s-64 28.7-64 64H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V112c0-26.5-21.5-48-48-48zM192 48c8.8 0 16 7.2 16 16s-7.2 16-16 16-16-7.2-16-16 7.2-16 16-16zm144 408c0 4.4-3.6 8-8 8H56c-4.4 0-8-3.6-8-8V120c0-4.4 3.6-8 8-8h40v32c0 8.8 7.2 16 16 16h160c8.8 0 16-7.2 16-16v-32h40c4.4 0 8 3.6 8 8v336z"></path></svg></button>
// Create a reference to the work item IWorkItemHandle workItemHandle = workItemServer.findWorkItemById(workItemId, null);
// Associate the work item with the change set changeSetClient.linkChangeSetToWorkItem(changeSet, workItemHandle);
System.out.println("Successfully associated change set with work item."); } catch (TeamRepositoryException e) { e.printStackTrace(); System.out.println("Failed to associate change set with work item: " + e.getMessage()); }</pre> </div> </span><span style="--tw-backdrop-blur:; --tw-backdrop-brightness:; --tw-backdrop-contrast:; --tw-backdrop-grayscale:; --tw-backdrop-hue-rotate:; --tw-backdrop-invert:; --tw-backdrop-opacity:; --tw-backdrop-saturate:; --tw-backdrop-sepia:; --tw-blur:; --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-brightness:; --tw-contain-layout:; --tw-contain-paint:; --tw-contain-size:; --tw-contain-style:; --tw-contrast:; --tw-drop-shadow:; --tw-gradient-from-position:; --tw-gradient-to-position:; --tw-gradient-via-position:; --tw-grayscale:; --tw-hue-rotate:; --tw-invert:; --tw-numeric-figure:; --tw-numeric-fraction:; --tw-numeric-spacing:; --tw-ordinal:; --tw-pan-x:; --tw-pan-y:; --tw-pinch-zoom:; --tw-ring-color: rgba(59,130,246,.5); --tw-ring-inset:; --tw-ring-offset-color: #fff; --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-offset-width: 0px; --tw-ring-shadow: 0 0 #0000; --tw-rotate: 0; --tw-saturate:; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-sepia:; --tw-shadow-colored: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-skew-x: 0; --tw-skew-y: 0; --tw-slashed-zero:; --tw-translate-x: 0; --tw-translate-y: 0; border: 0px solid rgb(229, 231, 235); box-sizing: border-box; scrollbar-color: auto; scrollbar-width: auto;"></span> </li>
Important Notes
- Error Handling: Always implement error handling to manage exceptions that may arise during API calls.
- Permissions: Ensure you have the necessary permissions to modify change sets and work items in your RTC environment.
- Documentation: Refer to the official RTC API documentation for more details on methods and classes available for use.
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Sep 23 '24, 3:03 a.m.If you want to do this correctly, I would suggest to