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.
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:
Thanks,
Andy.
|
2 answers
![]()
Ian Barnard (1.5k●6●13)
| answered Nov 16 '20, 1:58 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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.
The overview is here: https://jazz.net/wiki/bin/view/Main/DNGModuleApiOverview
This links to:
1. The 'specification' https://jazz.net/wiki/bin/view/Main/DNGModuleAPI
2. Three scenarios for usage:
a. Discover a module and its associated structure https://jazz.net/wiki/bin/view/Main/DNGModuleAPI
b. Add a new / existing Artifact to a Module. https://jazz.net/wiki/bin/view/Main/DNGModuleApiScenario2
c. Manipulation of Module structure (remove, re-order, re-parent). https://jazz.net/wiki/bin/view/Main/DNGModuleApiScenario3
So the sequence might look like:
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?
I've now have a REST client so will experiment with that.
Andy.
![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. |
![]()
Ian Barnard (1.5k●6●13)
| answered Nov 16 '20, 9:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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.
Comments Thanks,
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="..."/>
<j.0:childBindings rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</j.0:Binding>
Which version are you using? Are you using configuration management? ![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
I just added the boundArtifact element in my last test. It accepted but returned an unknown exception in the response to the tracker call.
<dcterms:title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Update Structure Task</dcterms:title>
<oslc_auto:state rdf:resource="http://open-services.net/ns/auto#complete"/>
<dcterms:references>
<oslc:Error>
<oslc:statusCode>0</oslc:statusCode>
<oslc:message>Unexpected exception while executing task</oslc:message>
</oslc:Error>
</dcterms:references>
<oslc_auto:verdict rdf:resource="http://open-services.net/ns/auto#error"/>
</dng_task:Task>
</rdf:RDF>
<j.0:childBindings rdf:parseType="Collection">
<j.0:Binding>
<oslc_config:component rdf:resource="/rm/cm/component/_TThLUGIdEeq8D41kBsw16A" />
<j.0:boundArtifact rdf:resource="/rm/resources/_6R9zgSi7Eeu9Cbv8kQ-y-Q" />
</j.0:Binding>
<j.0:Binding>
<oslc_config:component rdf:resource="/rm/cm/component/_TThLUGIdEeq8D41kBsw16A" />
<j.0:boundArtifact rdf:resource="/rm/resources/_8H7PkSi7Eeu9Cbv8kQ-y-Q" />
</j.0:Binding>
</j.0:childBindings>
I've removed the server details in the resource attributes... 1
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.
The 2 samples that are probable most useful are RMSample.java and ERMSample.java.
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.
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
|