It's all about the answers!

Ask a question

Linking RTC files to RQM


Jitesh Saha (131) | asked Nov 26 '20, 1:21 a.m.
We have a java application which needs to create links between files in RTC with RQM test artifacts (Test cases ).

We can currently find existing file links using

public RelatedArtifactsDTO[] getRelatedArtifacts(IVersionableHandle[] itemStateHandles,
            String gcURL, String[] options,
            IRepositoryProgressMonitorHandle monitor)

but this won't work to create new links. Is there a java API ( or any other viable way) that can create new links between files and artifacts ?

Comments
Michael Valenta commented Nov 30 '20, 9:00 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Jitesh,

Before I can answer your question, I need a bit more information.What type of link are you trying to create? That is, what is the OSLC type to be associated with the link? Also, is the RQM application in configuration mode (or opt-in) mode?

Michael


Jitesh Saha commented Nov 30 '20, 11:28 p.m.
I want to my file to Rreference Test Case. Similar to how we do it in our eclipse client with " Related Artifact "  . The RQM project area is in Global Configuration enabled.


3 answers



permanent link
Subhajit Bhuiya (5992) | answered Dec 01 '20, 2:55 a.m.
JAZZ DEVELOPER

 The API mentioned above is internal API. Please use public API - Reportable Rest API or OSLC API. For more details check https://jazz.net/wiki/bin/view/Main/RqmApi


permanent link
Michael Valenta (3.6k3) | answered Dec 01 '20, 7:48 a.m.
FORUM MODERATOR / JAZZ DEVELOPER

Creating links programmatically is possible but it is a bit complicated. Also, one of the DTOs that you need to use is in an internal package. I don't know if this was intentional or a mistake on the part of the developers who implemented the feature.

The first thing you will need to do is pick a specific link type. The out-of-the-box link types for SCM to RQM links are defined in the plugin.xml of the com.ibm.team.filesystem.common bundle.

"com.ibm.team.scm.service.file.implements.testscript.link"
"com.ibm.team.scm.service.file.references.testcase.link"
"com.ibm.team.scm.service.file.references.testcase.result.link"
"com.ibm.team.scm.service.file.references.testsuite.result.link"

It sounds like you want the References Test Case type

String linkTypeId = "com.ibm.team.scm.service.file.references.testcase.link";

Next, you will need a handle to the component that contains the file

IComponentHandle component

Along with either a workspace or a stream handle.

IWorkspaceHandle workspaceHandle
IWorkspaceHandle streamHandle

You will also need to use the SCM service

IScmService scm

The below code shows how to create the link in a workspace, which is the usual SCM flow

    // Create a change set on the workspace
    IChangeSetHandle cs = (IChangeSetHandle) scm.createChangeSet(workspaceHandle, component, "", false, null, null, null).getItem();

    // Create the link description
    ILinkType linkType = ILinkTypeRegistry.INSTANCE.getLinkType(linkTypeId);
    ExternalLinkEntry entry = ScmDtoFactory.eINSTANCE.createExternalLinkEntry();
    entry.setType(linkType.toLinkServiceId());
    entry.setTypeInstanceId(linkType.getInstanceId());
    final String resourceUri = "http://www.example.com/qm/" + ?;
    entry.setToLink(resourceUri);

    // Create a commit parameter    
    ICommitParameter parm = ICommitParameter.FACTORY.create(cs);        
    parm.addItemToSave(item, links);

    // Commit the link addition to the change set and close the change set
    scm.batchCommit(workspaceHandle, new ICommitParameter[] {parm}, IScmService.DELTA_PER_INVOCATION, null, null);
    scm.closeChangeSets(workspaceHandle, new IChangeSetHandle[] {cs}, true, null, null, null);

    // Deliver the change set to the stream
    scm.deliverCombined(null, null, streamHandle, new IBaselineHandle[0], new IChangeSetHandle[]{cs}, null, null, null, null);

As an alternative, you could create the change set directly on the stream using the following API.

    IChangeSetHandle cs = scm.createChangeSetForStream(streamHandle, component, "comment", commitParameter, null, null);

Hope that helps,
Michael


Comments
Jitesh Saha commented Dec 02 '20, 1:04 a.m.
Thank you for the detailed answer Micheal. . It helps me understand the whole workflow very well.

But  the methods toLinkServiceId() and getInstanceId() are undefined for object of ILinkType.
Although I saw that they're present for the type ExternalLink.

Am I understanding something incorrectly here ?

Thank you.

Jitesh Saha commented Dec 02 '20, 1:49 a.m.
Also ,
in the following snippet

 // Create a commit parameter 
  ICommitParameter parm = ICommitParameter.FACTORY.create(cs);       
    parm.addItemToSave(item, links);

the method addItemToSave() takes the secnd parameter as ExternalLinkEntry.

Do we need to create externalLinks from ExternalLinkEntry somehow ? if so any tips for that.

Thank you.




Jitesh Saha commented Dec 02 '20, 4:32 a.m.
Sorry, I am unable to edit my last comment.

I meant to ask if i need to add external links to ExternalLinkEntry entry and pass that as the second parameter in parm.addItemToSave(item, links);

Because the links parameter is of type Collection<? extends ExternalLinkEntry>



permanent link
Julian Hemm (54212) | answered Dec 03 '20, 2:00 a.m.
edited Dec 03 '20, 6:08 a.m.
UPDATE
----
It seems that this code is working fine, I think I was just using a wrong URL format of the QM Testcase
It should be something like:
https://server:port/qm/oslc_qm/contexts/_XYZ/resources/com.ibm.rqm.planning.VersionedTestCase/_ABC
------

 Hello Michael,

unfortunately this doesn't seem to work for me as well, I miss at least a part where the External Link is set to the Versionable.
I found another way to create such links, but while it actually creates the link and produces a changeset, after delivery this link is visible on the file but on in QM even though it looks the very same is one created via UI (which becomes visible immediately)

 operation = IOperationFactory.instance.getChangePropertiesOperation(null);
 linkType = ILinkTypeRegistry.INSTANCE.getLinkType("com.ibm.team.scm.service.file.references.testcase.link");
operation.addExternalLink(shareable, LinkTypeIdentifier.create(linkType), uri);
operation.run(null);

Is this one valid to use and do I have to trigger any LinkIndex action or something like this additionally to make the link visible in QM.

Thanks a lot

Your answer


Register or to post your answer.