It's all about the answers!

Ask a question

OSLC ValidatedBy bidirectional link


Munjal Patel (111) | asked Jan 06 '14, 6:47 p.m.
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
    }

One answer



permanent link
Paul Slauenwhite (8.4k12) | answered Jan 07 '14, 7:59 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
Both forward and back links must be added separately.  That is, repeat the same steps for the QM resource.

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.