Example working code for adding requirements to a module via OSLC?
I've been reading the various documentation, as listed below, in order to meet my requirements.
2 answers
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.
-
Find the module URI -e.g. by OSLC Query, or by manually finding the module an dselecting Sahre Link To Artifact., e.g. https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w?oslc_config.context=https%3A%2F%2Fjazz.ibm.com%3A9443%2Frm%2Fcm%2Fstream%2F_NMu5RtcLEeqXpuBdEolY7w
- The module URL is the first part of this up to ? - i.e. https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w
-
GET from this url with only headers:
-
Accept: application/rdf+xml
-
DOORS-RP-Request-Type: public 2.0
NOTE yes that's "public" with a lower case p - P won't work!
-
This returns the RDF with an entry like this (prefix j.1 is http://jazz.net/ns/rm/dng/module#
<j.1:structure rdf:resource="https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w/structure"/>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
-
The structure URL is e.g. https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w/structure
-
GET from this URL with headers same as the previous request
The structure starts like this:<j.0:Binding rdf:about="https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w/structure"><j.0:childBindings rdf:parseType="Collection"><j.0:Binding rdf:about="https://jazz.ibm.com:9443/rm/resources/_OAvwIdcLEeqXpuBdEolY7w"><j.0:isHeading rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isHeading><oslc_config:component rdf:resource="https://jazz.ibm.com:9443/rm/cm/component/_NMJDYNcLEeqXpuBdEolY7w"/><j.0:boundArtifact rdf:resource="https://jazz.ibm.com:9443/rm/resources/_OCh41tcLEeqXpuBdEolY7w"/><j.0:module rdf:resource="https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w"/><j.0:childBindings rdf:parseType="Collection"><j.0:Binding rdf:about="https://jazz.ibm.com:9443/rm/resources/_OAvwItcLEeqXpuBdEolY7w">...
-
Modify the structure, e.g. removing an artifact etc. as per https://jazz.net/wiki/bin/view/Main/DNGModuleApiScenario2 and https://jazz.net/wiki/bin/view/Main/DNGModuleApiScenario3
-
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 https://jazz.net/wiki/bin/view/Main/DNGModuleApiOverview#IfMatch says submit using the etag header on the put but this is wrong - you must use If-Match, as it says here https://jazz.net/wiki/bin/view/Main/DNGModuleApiScenario2
-
You'll get a 202 Accepted response - use the Location header in the response to get the task tracker URL
-
Poll the task tracker URL until you get 200 response with
oslc_auto:state
property NOT set tooslc_auto:inProgress
and theoslc_auto:verdict
property NOT set tooslc_auto:unavailable
-
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.
HTHIan
Comments
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?
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.
The Module Structure API is the way to modify module structure. - Note this is only provided on >=6.0.5
Comments
Thanks,
Which version are you using? Are you using configuration management?
The top-level rdf:about is already in the GET - don't modify that.
I'm on 6.0.6.1 and not using configuration management at the moment.
<j.0:childBindings rdf:parseType="Collection">
I've removed the server details in the resource attributes...
Andy, you may want to have a look at Lyo examples in https://github.com/OSLC/lyo-samples/tree/master/oslc4j-client-samples/src/main/java/org/eclipse/lyo/oslc4j/client/samples.
1 vote
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.