It's all about the answers!

Ask a question

OSLC API/Rest API to Programmatically link Testcase with Requirement or vice versa with GC Enabled


jyoti mishra (45138) | asked Sep 01 '21, 3:59 a.m.

 Hello Everyone,


I would like to know the  OSLC API or reportable rest API to fetch link validity summary(ex-suspect) and link attached to test cases and requirements, from the project Area ,where GC Enabled .I would also like to know, how we can automatically link requirement with Testcase and vice-versa. I am able to link programmatically Requirement with Test case from the project Areas, where GC has not enabled, but when I am trying to link Requirement with Testcase, from the project area, where GC has enabled,is throwing forbidden Exception.

Error:- org.apache.http.client.HttpResponseException: Forbidden

Kindly help at the earliest.

Thanks and Regards,
Jyoti


Comments
David Honey commented Sep 01 '21, 4:20 a.m. | edited Sep 01 '21, 4:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please supply more specific information. For example:
  • Which resource are you trying to modify - a test case, or a requirement?
  • Which link (e.g. link type or RDF predicate URI) are you trying to add?
  • Details of the REST request (URI, headers, body) being made?
  • Details of the REST response (status, headers, body) you are getting back?
Note that in some cases, requests to DOORS Next might require an Oslc-Version=2.0 header. .

Regarding getting link validity information about a relationship between two versioned artifacts. This data is not a property of either the source resource or the target resource. Its meta data about the relationship itself and is stored in JTS rather than the application that owns the source or target resource. I'm not aware of any public REST API for this. My understanding is that this is currently regarded as a private API.

jyoti mishra commented Sep 01 '21, 5:16 a.m. | edited Sep 01 '21, 5:19 a.m.

I am trying to link Requirement with Testcase,by using below code-

Example:-
HttpGet query = new HttpGet(requirementURL);
query.addHeader("Accept", "application/xml");query.addHeader("OSLC-Core-Version", "2.0");
InputSource source = new InputSource(response.getEntity().getContent());
Document doc = parse(source);
response.getEntity().consumeContent();
Header etag = response.getLastHeader("etag");
Element validatedBy = doc.createElement("oslc_rm:validatedBy");
req.appendChild(validatedBy ); 
Using put command to requirementURL for updating link.

2 answers



permanent link
Steven Wallace (336) | answered Sep 02 '21, 1:53 p.m.

I do the following:


GET
URL = server_url>/rm/resources/<requirement_externalId>
HEADER = {"Content-Type": "application/rdf+xml", "OSLC-CORE-Version": "2.0"}

Add a validatedBy element to the xml returned
<oslc_rm:validatedBy rdf:resouce="<oslc url to testcase>"

POST
URL = server_url>/rm/resources/<requirement_externalId>
HEADER = {"Content-Type": "application/rdf+xml", "OSLC-CORE-Version": "2.0", If-Match": "<eTag from GET>"}


permanent link
David Honey (1.8k17) | answered Sep 02 '21, 2:12 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A better method is not to directly changed serialized RDF (RDF/XML or Turtle) but use Jena to do the serialization/deserialization and then make changes to a Jena Model object. That way the code works with a variety of supported RDF media types and is likely to be more robust. Something like....

    HttpResponse response; // The response from executing the GET
    Model model = ModelFactory.createDefaultModel();
    model.read(httpResponse.getEntity().getContent(), null, "RDF/XML");
    Resource subject = model.createResource(uriOfResource);
    model.add(subject, model.createProperty(), model.createResource());
    RdfJsonEntity entity = new RdfJsonEntity(model, null, contentType, null);
    HttpPut put = new HttpPut(uriOfResource);
    put.addHeader(HttpConstants.CONTENT_TYPE, "application/rdf+xml");
    put.setEntity(entity);
The above can be made more general and support multiple RDF media types. For example, accept either RDF/XML or Turtle types.

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.