It's all about the answers!

Ask a question

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


0
1
Andy Dennis (118) | 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:


Thanks,
Andy.

2 answers



permanent link
Ian Barnard (1.9k613) | 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
Andy Dennis commented Nov 16 '20, 11:33 a.m. | edited Nov 16 '20, 12:02 p.m.

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:Binding> 


Ian Barnard commented Nov 16 '20, 1:17 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


Andy Dennis commented Nov 17 '20, 5:16 a.m.
    <dcterms:title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Update Structure Task</dcterms:title>
    <dcterms:references>
      <oslc:Error>
        <oslc:statusCode>0</oslc:statusCode>
        <oslc:message>Unexpected exception while executing task</oslc:message>
      </oslc:Error>
    </dcterms:references>
  </dng_task:Task>
</rdf:RDF>


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

     <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>


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

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


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

 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.


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

permanent link
Ian Barnard (1.9k613) | 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.

This links to:
2. Three scenarios for usage: 
a. Discover a module and its associated structure https://jazz.net/wiki/bin/view/Main/DNGModuleAPI


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.  https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w?oslc_config.context=https%3A%2F%2Fjazz.ibm.com%3A9443%2Frm%2Fcm%2Fstream%2F_NMu5RtcLEeqXpuBdEolY7w
    1. The module URL is the first part of this up to ? - i.e.  https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w
  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 http://jazz.net/ns/rm/dng/module#
    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. https://jazz.ibm.com:9443/rm/resources/_OAAJRdcLEeqXpuBdEolY7w/structure
  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="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:childBindings rdf:parseType="Collection">
            ...
  8. 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

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

    HTH
    Ian


Comments
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.

Andy.


Ian Barnard commented Nov 18 '20, 7:48 a.m. | edited Nov 18 '20, 7:48 a.m.
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.

Your answer


Register or to post your answer.