OSLC ValidatedBy bidirectional link
I created OSLC ValidatedBy link Requirement to TestCase using function below from Example04.java but link is unidirectional how can i make it bidirectional. Link shows in RRC but not in RQM 'Validates Requirements'.
private void updateRequirement(String requirementURL, String testcaseURL) throws Exception {
//Get the document
HttpGet query = new HttpGet(requirementURL);
query.addHeader("Accept", "application/xml");
query.addHeader("OSLC-Core-Version", "2.0");
HttpResponse response = HttpUtils.sendGetForSecureDocument(RM_server,
query, login, password, httpclient, RM_JTS_Server);
if (response.getStatusLine().getStatusCode() != 200) {
response.getEntity().consumeContent();
throw new HttpResponseException(response.getStatusLine()
.getStatusCode(), response.getStatusLine()
.getReasonPhrase());
}
// Retrieve the designated Service Provider
InputSource source = new InputSource(response.getEntity().getContent());
Document doc = parse(source);
response.getEntity().consumeContent();
Header etag = response.getLastHeader("etag");
//Add a link, with DOM
NodeList elementsByTagName = doc.getDocumentElement().getElementsByTagName("oslc_rm:Requirement");
if (elementsByTagName.getLength() == 1){
Element req = (Element)elementsByTagName.item(0);
//Note: You can only add links for OSLC link types,
//Check the OSLC RM V2 specification for a list of available types
// http://open-services.net/bin/view/Main/RmSpecificationV2?sortcol=table;table=up#Resource_Requirement
Element validatedBy = doc.createElement("oslc_rm:validatedBy");
validatedBy.setAttribute("rdf:resource", testcaseURL); //Any valid url can be added
req.appendChild(validatedBy);
}
//Write out our content then do a PUT
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "no"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
StreamResult result = new StreamResult(new StringWriter());
transformer.transform(new DOMSource(doc), result);
String newContent = result.getWriter().toString();
System.out.println("Modified Requirement Content ->>\n" + newContent);
//Do the PUT
HttpPut put = new HttpPut(requirementURL);
put.addHeader("Accept", "application/xml");
put.addHeader("Content-Type", "application/xml");
put.addHeader("OSLC-Core-Version", "2.0");
if ( etag != null) {
put.addHeader("If-Match", etag.getValue());
}
put.setEntity(new StringEntity(newContent, HTTP.UTF_8));
response = HttpUtils.sendPutForSecureDocument(RM_server, put, login, password, httpclient, RM_JTS_Server);
response.getEntity().consumeContent();
if (response.getStatusLine().getStatusCode() != 200) {
throw new HttpResponseException(response.getStatusLine()
.getStatusCode(), response.getStatusLine()
.getReasonPhrase());
}
//If we get here then our PUT succeeded and the requirement should have our link now
}
private void updateRequirement(String requirementURL, String testcaseURL) throws Exception {
//Get the document
HttpGet query = new HttpGet(requirementURL);
query.addHeader("Accept", "application/xml");
query.addHeader("OSLC-Core-Version", "2.0");
HttpResponse response = HttpUtils.sendGetForSecureDocument(RM_server,
query, login, password, httpclient, RM_JTS_Server);
if (response.getStatusLine().getStatusCode() != 200) {
response.getEntity().consumeContent();
throw new HttpResponseException(response.getStatusLine()
.getStatusCode(), response.getStatusLine()
.getReasonPhrase());
}
// Retrieve the designated Service Provider
InputSource source = new InputSource(response.getEntity().getContent());
Document doc = parse(source);
response.getEntity().consumeContent();
Header etag = response.getLastHeader("etag");
//Add a link, with DOM
NodeList elementsByTagName = doc.getDocumentElement().getElementsByTagName("oslc_rm:Requirement");
if (elementsByTagName.getLength() == 1){
Element req = (Element)elementsByTagName.item(0);
//Note: You can only add links for OSLC link types,
//Check the OSLC RM V2 specification for a list of available types
// http://open-services.net/bin/view/Main/RmSpecificationV2?sortcol=table;table=up#Resource_Requirement
Element validatedBy = doc.createElement("oslc_rm:validatedBy");
validatedBy.setAttribute("rdf:resource", testcaseURL); //Any valid url can be added
req.appendChild(validatedBy);
}
//Write out our content then do a PUT
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "no"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
StreamResult result = new StreamResult(new StringWriter());
transformer.transform(new DOMSource(doc), result);
String newContent = result.getWriter().toString();
System.out.println("Modified Requirement Content ->>\n" + newContent);
//Do the PUT
HttpPut put = new HttpPut(requirementURL);
put.addHeader("Accept", "application/xml");
put.addHeader("Content-Type", "application/xml");
put.addHeader("OSLC-Core-Version", "2.0");
if ( etag != null) {
put.addHeader("If-Match", etag.getValue());
}
put.setEntity(new StringEntity(newContent, HTTP.UTF_8));
response = HttpUtils.sendPutForSecureDocument(RM_server, put, login, password, httpclient, RM_JTS_Server);
response.getEntity().consumeContent();
if (response.getStatusLine().getStatusCode() != 200) {
throw new HttpResponseException(response.getStatusLine()
.getStatusCode(), response.getStatusLine()
.getReasonPhrase());
}
//If we get here then our PUT succeeded and the requirement should have our link now
}