It's all about the answers!

Ask a question

Example working code for adding requirements to a module via OSLC?

Andy Dennis (119) | asked Nov 16 '20, 7:57 a.m.

 I've been reading the various documentation, as listed below, in order to meet my requirements.

I can successfully create a module, create folders, add artifacts to the new folder and modify the name of the module.  However, if I add artifacts to the module or remove artifacts (after adding them manually) by manipulating the oscl_rm:uses tags I get a bad request error.

The workshop is a great resource to cover OSLC functions, but it doesn't unfortunately, have an example that does this task.  
Does anyone have some example code that they could post for this?

I've used the following article:

Also tried this following in place of using the above for module structure changes:


2 answers

permanent link
Ian Barnard (1.9k613) | answered Nov 16 '20, 1:58 p.m.

 AFAICT the documentation for using the Module Structure API is correct apart from two conflicting statements about the headers on the PUT: the correct statement says to use If-Match with the etag header from the GET response. The incorrect statement says to use an etag header on the PUT.

NOTE it is only possible to modify the structure from 6.0.6 onwards.

The headers you use are critical - use exactly what the docs say exactly (these are case-sensitive!) and it works.

This links to:
2. Three scenarios for usage: 
a. Discover a module and its associated structure

So the sequence might look like:

  1. Find the module URI -e.g. by OSLC Query, or by manually finding the module an dselecting Sahre Link To Artifact., e.g.
    1. The module URL is the first part of this up to ? - i.e.
  2. GET from this url with only headers:
  3. Accept: application/rdf+xml
  4. DOORS-RP-Request-Type: public 2.0
    NOTE yes that's "public" with a lower case p - P won't work!
  5. This returns the RDF with an entry like this (prefix j.1 is
    NOTE if what you get has any <oslc_rm:uses ...> tags you haven't done the above right - no point in proceeding beyond here until you see the structure tag
  6. The structure URL is e.g.
  7. GET from this URL with headers same as the previous request
    The structure starts like this:
        <j.0:childBindings rdf:parseType="Collection">
            <j.0:isHeading rdf:datatype=""
            <oslc_config:component rdf:resource=""/>
            <j.0:boundArtifact rdf:resource=""/>
            <j.0:childBindings rdf:parseType="Collection">
  8. Modify the structure, e.g. removing an artifact etc. as per and

  9. PUT the structure with the same headers as previous, plus:
    If-Match: (copy the complete etag header from the response to the GET, don't decode it or remove " or modify it in any way - NOTE the documentation says submit using the etag header on the put but this is wrong - you must use If-Match, as it says here
  10. You'll get a 202 Accepted response - use the Location header in the response to get the task tracker URL
  11. Poll the task tracker URL until you get 200 response with   oslc_auto:state  property NOT set to  oslc_auto:inProgress  and the  oslc_auto:verdict  property NOT set to  oslc_auto:unavailable
  12. The final task tracker response indicating no longer in progress and with a verdict available, the response has dcterms:references with a URL of the status.

    I suggest you test this out using a browser REST client.


Andy Dennis commented Nov 18 '20, 5:44 a.m. | edited Nov 18 '20, 5:44 a.m.

 Thanks for the detail Ian.  I don't think I'm doing anything different other than  I'm not doing a get on the module and just adding "/structure" to the module reference to get to it.  I get the structure back ok.  I use the etag value from the structure GET for the If-Match header for the PUT.  Do I need to use the etag from a module GET instead?

I've now have a REST client so will experiment with that.


Ian Barnard commented Nov 18 '20, 7:48 a.m. | edited Nov 18 '20, 7:48 a.m.

The etag is a version identifier, so you PUT back with the etag from the corresponding GET, but if the server can't match the If-Match in the PUT with the current etag of the resource then it won't update the resource because another user has updated it since the GET you did; each update changes the etag.

permanent link
Ian Barnard (1.9k613) | answered Nov 16 '20, 9:26 a.m.
edited Nov 16 '20, 9:27 a.m.

The Module Structure API is the way to modify module structure. - Note this is only provided on >=6.0.5

I don't have example code - GET/PUT should be used to first retrieve the structure then update it.

Andy Dennis commented Nov 16 '20, 11:33 a.m. | edited Nov 16 '20, 12:02 p.m.


I've been exploring that API aswell, but yet to make it successful.
Can you say which tags are required for adding an new binding?
I've pulled the below xml from a requirement manually added to a module.
Clearly Binding @about can't be added because that's the value added by the server when successful.
Do you need to all all the others as I would think all but the boundArtifact would be implied?

<j.0:Binding rdf:about="...">;
   <oslc_config:component rdf:resource="..."/>;
   <j.0:boundArtifact rdf:resource="..."/>;
   <j.0:module rdf:resource="..."/>;

Ian Barnard commented Nov 16 '20, 1:17 p.m.

Which version are you using? Are you using configuration management?

Ian Barnard commented Nov 16 '20, 1:59 p.m. | edited Nov 16 '20, 1:59 p.m.

 The top-level rdf:about is already in the GET - don't modify that.

Andy Dennis commented Nov 17 '20, 4:04 a.m.

I'm on and not using configuration management at the moment.

I just added the boundArtifact element in my last test.  It accepted but returned an unknown exception in the response to the tracker call.

Andy Dennis commented Nov 17 '20, 5:16 a.m.
    <dcterms:title rdf:datatype="">Update Structure Task</dcterms:title>
        <oslc:message>Unexpected exception while executing task</oslc:message>

Andy Dennis commented Nov 17 '20, 5:16 a.m.

     <j.0:childBindings rdf:parseType="Collection">;

<oslc_config:component rdf:resource="/rm/cm/component/_TThLUGIdEeq8D41kBsw16A" />

<j.0:boundArtifact rdf:resource="/rm/resources/_6R9zgSi7Eeu9Cbv8kQ-y-Q" />
<oslc_config:component rdf:resource="/rm/cm/component/_TThLUGIdEeq8D41kBsw16A" />
<j.0:boundArtifact rdf:resource="/rm/resources/_8H7PkSi7Eeu9Cbv8kQ-y-Q" />

Andy Dennis commented Nov 17 '20, 5:17 a.m.

 I've removed the server details in the resource attributes...

Lewis Tsao commented Nov 18 '20, 8:16 a.m.

 Andy, you may want to have a look at Lyo examples in

The 2 samples that are probable most useful are and

Note that there are also API calls to traverse a folder tree structure (6.0.6 onwards) and you can create artefacts at the required level.

Andy Dennis commented Nov 18 '20, 11:42 a.m. | edited Nov 18 '20, 11:42 a.m.

Thanks Lewis.  I'm looked at that code and the old Workshop code.  I can successfully read the folder structure, create new folders, requirements and modules.  It's just adding the new requirements to the new module that I'm getting a problem with.

I'm confident that I'm setting the correct headers and passing the etag from the structure GET. ok, so I'm not sure what is wrong.  The Server accepts the structure update, but then the task response has status 0 with an unexpected exception in the response

showing 5 of 9 show 4 more comments

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.