It's all about the answers!

Ask a question

creating a Project Association programmatically does not create link back


Miguel Tomico (5001423) | asked Dec 01 '14, 11:45 a.m.
edited Dec 01 '14, 12:30 p.m.
In RTC, when creating Project Associations programmatically using the Java client API, it does not create the link back.
The Association is successfully created in RTC, but the correspondent Association is not created in the other system. In this case, RQM. The funny thing is, deleting the project association in RTC will display a error: 'Failure to delete back links'
If we create the association manually, the link back is created. And no error will be displayed when deleting it.
My thoughts:
I expected the same behaviour in the API than in the RTC client. To a strict observer, it may look like we can corrupt RTC by using the API.
- I guess we need to create the corresponding link back in RQM to set up the association successfully. I was wondering if somebody can point me to an example or a section in the RQM OSLC API.
Thank you.

Comments
sam detweiler commented Dec 01 '14, 5:40 p.m. | edited Dec 24 '16, 5:07 p.m.

>I expected the same behaviour in the API than in the RTC client.

but you don't know what the RTC client actually did when you requested this action. it might have called 50 apis.
you could find and read the source code to know exactly. all the source is in the SDK download for each release.

Accepted answer


permanent link
Miguel Tomico (5001423) | answered Dec 10 '14, 12:07 p.m.
Your comments gave me some ideas, and I managed to get it working.
The solution uses internal classes, and it still has a tweak I need investigate, but in case it can be useful for anybody,
The following code creates the link successfully in RTC, but it does not create the backlink:

IProjectLink prjLink; 
prj = (IProjectArea) prj.getWorkingCopy();
IWorkItemCommon workItemCommon = (IWorkItemCommon)repo.getClientLibrary(IWorkItemCommon.class);
prjLink = (IProjectLink) workItemCommon.getAuditableCommon().createAuditable(IProjectLink.ITEM_TYPE);
prjLink = (IProjectLink) prjLink.getWorkingCopy();
prjLink.setProjectArea(prj);
prjLink.setLinkType(strLinkType);
prjLink.setLabel(strRQMProjectAreaName);
prjLink.setTargetConsumerRegistryUrl(strTargetConsumerRegistryUrl);
prjLink.setTargetServicesUrl(strTargetServicesUrl);
prjLink.setTargetUrl(strTargetUrl);

IProcessItemService processItemService = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
prj.addProjectLink(prjLink);
processItemService.save(new IProcessItem[] { prj, prjLink }, null);


If we replace the last three lines with the following ones, it will prompt for the RQM credentials and will create the backlink:

IProcessItemService service =(IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
service.getWorkingCopyManager().connect(prj);
ProjectAreaWorkingCopy prjWC = (ProjectAreaWorkingCopy) service.getWorkingCopyManager().getWorkingCopy(prj);
prjWC.getLinks().addLinks(new IProjectLinkHandle[] {prjLink});
prjWC.save(null);

This solution is meant to be run from the Eclipse client.

I guess any Jazz developer will recommend not to mess with internal classes,
but the level of automation required by my organization worths the risk.
Ralph Schoon selected this answer as the correct answer

Comments
sam detweiler commented Dec 10 '14, 2:07 p.m.

thanks for showing how you would address this.

Internal classes.. You will need them for most of the advanced things we want to do, so don't listen to the noise..


Ralph Schoon commented Dec 11 '14, 3:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As I am a fan of automation, all I can suggest is to express your demand for these internal API's to be made externally available by submitting enhancement requests.


Daniel Chirillo commented Dec 16 '16, 1:51 p.m.

How did you get the 4 strings (used in your snippet) needed to create the project area associations?

strLinkType
strTargetConsumerRegistryUrl
strTargetServicesUrl
strTargetUrl

3 other answers



permanent link
Don Yang (7.7k21114139) | answered Dec 01 '14, 11:46 p.m.
edited Dec 01 '14, 11:47 p.m.
I don't have experience in using Java API but OSLC API to add a link won't create a back link automatically and you will need to create a back link manually or using OSLC API as well. There are some good reference in this blog for RQM API:
http://sleroyblog.wordpress.com/2013/04/09/querying-rqm-40-through-oslc-and-rest-api/

Comments
Miguel Tomico commented Dec 02 '14, 5:45 a.m. | edited Dec 24 '16, 5:09 p.m.

Thank you all for your responses,

but Ralph, Don, I'm afraid that is not what I was asking about.
We are not trying to automate the creation of links between artifacts, but to automate the creation of the Project Associations themselves (Project Area setup).
I have been looking for this in the RQM OSLC and REST APIs without luck.
I guess the only option is, as Sam says, to read the source code. But I guess that can be a daunting task.
In any case, thank you all for your help. I understand this was a tricky question.


1
Ralph Schoon commented Dec 02 '14, 5:51 a.m. | edited Dec 02 '14, 5:52 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

My naive assumption is that the same restrictions apply to creation of these references. Especially because I have seen the same issue with deleting links in the past and it happened to be a link that was created the wrong way (with the wrong location information) which resulted in a URL that was equivalent to the other in the UI, but apparently not for the application.

I would try to first analyze the data and find out how the link data looks like and then start from there. Please be aware that not all source code ships with the SDK. There s code with intellectual capital that does not ship. Some classes thus don't show code. However I very rarely run into those classes. The main API's come with code.

I would first look into the unit tests that ship with the SDK.


permanent link
Ralph Schoon (63.5k33646) | answered Dec 02 '14, 4:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please also refer to this post: https://rsjazz.wordpress.com/2013/11/06/creating-clm-links-with-back-link/ this is about work item CLM links.

If you use the RTC Java API, you need to understand that there are also various ways how to create the links e.g. for work items. Different link types require different information to allow linking. If the links are of a wrong format you will experience problems with links not showing up on one end or with errors when trying to delete the links. It is important to figure out which format the links on both ends have and to recreate that format when creating them with the API.

permanent link
Miguel Tomico (5001423) | answered Dec 19 '16, 3:42 a.m.

@danchirillo, please have a look at below code.

Feels like ages since I did this.

In the end, I created the backlink using also the RTC Java API to avoid using dodgy internal code. See below:

    //Create the backlink RQM -> RTC
    String strRTCUUID = prj.getItemId().getUuidValue();
    prjRQM = (IProjectArea) repoRQM.itemManager().fetchCompleteItem(prjRQM, IItemManager.REFRESH, null);
    prjRQM = (IProjectArea) prjRQM.getWorkingCopy();
    IWorkItemCommon workItemCommon = (IWorkItemCommon)repoRQM.getClientLibrary(IWorkItemCommon.class);
    IProjectLink prjLink = (IProjectLink) workItemCommon.getAuditableCommon().createAuditable(IProjectLink.ITEM_TYPE);
    prjLink = (IProjectLink) prjLink.getWorkingCopy();
    prjLink.setProjectArea(prjRQM);
    prjLink.setLinkType(strInternalLinkTypeBackLink);
    prjLink.setLabel(prj.getName());
    prjLink.setTargetConsumerRegistryUrl(repo.getRepositoryURI() + "process/project-areas/" + strRTCUUID + "/links");
    prjLink.setTargetServicesUrl(repo.getRepositoryURI() + "oslc/contexts/" + strRTCUUID + "/workitems/services.xml");
    prjLink.setTargetUrl(repo.getRepositoryURI() + "process/project-areas/" + strRTCUUID);
    prjRQM.addProjectLink(prjLink);
    //Save RQM
    IProcessItemService processItemService = (IProcessItemService) repoRQM.getClientLibrary(IProcessItemService.class);
    processItemService.save(new IProcessItem[] { prjRQM, prjLink }, null);

    //Create the link RTC -> RQM
    String strRQMUUID = prjRQM.getItemId().getUuidValue();
    prj = (IProjectArea) prj.getWorkingCopy();
    workItemCommon = (IWorkItemCommon)repo.getClientLibrary(IWorkItemCommon.class);
    prjLink = (IProjectLink) workItemCommon.getAuditableCommon().createAuditable(IProjectLink.ITEM_TYPE);
    prjLink = (IProjectLink) prjLink.getWorkingCopy();
    prjLink.setProjectArea(prj);
    prjLink.setLinkType(strInternalLinkType);
    prjLink.setLabel(strArtifactContainer);
    prjLink.setTargetConsumerRegistryUrl(repoRQM.getRepositoryURI() + "process/project-areas/" + strRQMUUID + "/links");
    prjLink.setTargetServicesUrl(repoRQM.getRepositoryURI() + "oslc_qm/contexts/" + strRQMUUID + "/services.xml");
    prjLink.setTargetUrl(repoRQM.getRepositoryURI() + "process/project-areas/" + strRQMUUID); 
    prj.addProjectLink(prjLink);
    //Save RTC
    processItemService = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
    processItemService.save(new IProcessItem[] { prj, prjLink }, null);


Comments
Daniel Chirillo commented Dec 23 '16, 10:00 a.m.

thank you, @miguel.tomico

Your answer


Register or 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.