Trying to Create Requirements using OSLC in 4.0.1
I am trying to create requirement using OSLC. The artifacts are not getting created if they have Primary Text.
The XML I am trying to post is
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:oslc_rm="http://open-services.net/ns/rm#"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:oslc="http://open-services.net/ns/core#"
xmlns:rm_property="https://ch2dlfi047.in.ibm.com:9450/rm/types/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<oslc_rm:Requirement
rdf:about="">
<dc:title>My Document for Rich Text 2</dc:title>
<dc:description>This is a test document created</dc:description>
<oslc:instanceShape rdf:resource="https://ch2dlfi047.in.ibm.com:9450/rm/types/_ZxxE8loiEeKdy44Rd03Qsw"/>
<jazz_rm:PrimaryText rdf:parseType="Literal"><div xmlns="http://www.w3.org/1999/xhtml" > <p id="_1359530511630"> <br/> Test123</p> </div></jazz_rm:PrimaryText>
</oslc_rm:Requirement>
</rdf:RDF>
and the error is Forbidden although the moment I remove the Primary Text part it works fine.
This is from the OSLC workshop and worked fine in 4.0.1 M3 however fails in 4.0.1 thats mainly because of the property URI for Primary Text which is different in 4.0.1 and coming as - http://jazz.net/ns/rm#PrimaryText
I am using the following method to get the Property URI:
protected String findPropertyByTitle(Document doc, String title) throws Exception {
// based on last Resource shapes changes we need to use dcterms:title to get the property name
String propertyDefinition = null;
propertyDefinition = "//oslc:Property[dcterms:title=\"" + title +"\"]/oslc:propertyDefinition/@rdf:resource";
XPath xpathNamespace = getXpathNamespace();
Node node = (Node) xpathNamespace.evaluate(propertyDefinition, doc, XPathConstants.NODE);
if(node != null){
return node.getTextContent();
}
return null;
}
Is there any suggestion as to how to work on this?
The XML I am trying to post is
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:oslc_rm="http://open-services.net/ns/rm#"
xmlns:dc="http://purl.org/dc/terms/"
xmlns:oslc="http://open-services.net/ns/core#"
xmlns:rm_property="https://ch2dlfi047.in.ibm.com:9450/rm/types/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<oslc_rm:Requirement
rdf:about="">
<dc:title>My Document for Rich Text 2</dc:title>
<dc:description>This is a test document created</dc:description>
<oslc:instanceShape rdf:resource="https://ch2dlfi047.in.ibm.com:9450/rm/types/_ZxxE8loiEeKdy44Rd03Qsw"/>
<jazz_rm:PrimaryText rdf:parseType="Literal"><div xmlns="http://www.w3.org/1999/xhtml" > <p id="_1359530511630"> <br/> Test123</p> </div></jazz_rm:PrimaryText>
</oslc_rm:Requirement>
</rdf:RDF>
and the error is Forbidden although the moment I remove the Primary Text part it works fine.
This is from the OSLC workshop and worked fine in 4.0.1 M3 however fails in 4.0.1 thats mainly because of the property URI for Primary Text which is different in 4.0.1 and coming as - http://jazz.net/ns/rm#PrimaryText
I am using the following method to get the Property URI:
protected String findPropertyByTitle(Document doc, String title) throws Exception {
// based on last Resource shapes changes we need to use dcterms:title to get the property name
String propertyDefinition = null;
propertyDefinition = "//oslc:Property[dcterms:title=\"" + title +"\"]/oslc:propertyDefinition/@rdf:resource";
XPath xpathNamespace = getXpathNamespace();
Node node = (Node) xpathNamespace.evaluate(propertyDefinition, doc, XPathConstants.NODE);
if(node != null){
return node.getTextContent();
}
return null;
}
Is there any suggestion as to how to work on this?
One answer
Hi,
To support the new way primaryText is exposed following method should be changed on the workshop code :
Add following to the Requirement request class :
static final String RM_JAZZ = "rm_jazz"; // Vocabulary Support
and modify following method ( look for Vocabulary support comment )
public void writeXML(Writer out) throws IOException {
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.append("<rdf:RDF\n");
out.append("\t\txmlns:oslc_rm=\"http://open-services.net/ns/rm#\"\n");
out.append("\t\txmlns:dc=\"http://purl.org/dc/terms/\"\n");
out.append("\t\txmlns:oslc=\"http://open-services.net/ns/core#\"\n");
out.append("\t\txmlns:nav=\"http://jazz.net/ns/rm/navigation#\"\n");
out.append("\t\txmlns:rm_jazz=\"http://jazz.net/ns/rm#\"\n"); // Vocabulary Support
out.append("\t\txmlns:rm_property=\"" + rmPropertyURI + "\"\n");
out.append("\t\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n");
out.append("\t<oslc_rm:Requirement\n");
if (uri != null) {
out.append("\t\trdf:about=\""+uri+"\">\n");
} else {
out.append(">\n");
}
//Always need to have a title
appendXMLAttribute(out, RM_TITLE, dcTitle);
appendXMLAttribute(out, RM_DESCRIPTION, dcDescription);
appendXMLAttribute(out, RM_IDENTIFIER, dcIdentifier);
appendXMLAttribute(out, RM_CREATOR, dcCreator);
//Always need to specify the shape uri
out.append("\t<" + INSTANCE_SHAPE + " rdf:resource=\"" + shapeURI + "\"/>\n");
// Append the parent Folder
if ( this.parentFolder != null) {
out.append("\t<" + RM_PARENT + " rdf:resource=\"" + this.parentFolder + "\"/>\n");
}
if(dcModified != null){
appendXMLAttribute(out, RM_MODIFIED, RFC3339Format.format(dcModified));
}
//Add internal properties
for (Iterator<String> iterator = rmLiteralProperties.keySet().iterator(); iterator.hasNext();) {
String type = iterator.next();
if ( type == null) // gruelas
continue;
// Vocabulary Support
String xmlTag = null;
if ( type.equals("http://jazz.net/ns/rm#PrimaryText")) {
xmlTag = RM_JAZZ + ":" + type.substring(type.lastIndexOf("#") + 1 );
} else {
xmlTag = RM_PROPERTY + ":" + type.substring(rmPropertyURI.length());
}
out.append("\t<" + xmlTag + " rdf:parseType=\"Literal\">" + rmLiteralProperties.get(type)+ "</" + xmlTag + ">\n");
}
for (Iterator<String> iterator = rmResourceProperties.keySet().iterator(); iterator.hasNext();) {
String type = iterator.next();
String xmlTag = RM_PROPERTY + ":" + type.substring(rmPropertyURI.length());
out.append("\t<" + xmlTag + " rdf:resource=\"" + rmResourceProperties.get(type) + "\"/>\n");
}
out.append("\t</oslc_rm:Requirement>\n");
out.append("</rdf:RDF>\n");
out.flush();
}
To support the new way primaryText is exposed following method should be changed on the workshop code :
Add following to the Requirement request class :
static final String RM_JAZZ = "rm_jazz"; // Vocabulary Support
and modify following method ( look for Vocabulary support comment )
public void writeXML(Writer out) throws IOException {
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
out.append("<rdf:RDF\n");
out.append("\t\txmlns:oslc_rm=\"http://open-services.net/ns/rm#\"\n");
out.append("\t\txmlns:dc=\"http://purl.org/dc/terms/\"\n");
out.append("\t\txmlns:oslc=\"http://open-services.net/ns/core#\"\n");
out.append("\t\txmlns:nav=\"http://jazz.net/ns/rm/navigation#\"\n");
out.append("\t\txmlns:rm_jazz=\"http://jazz.net/ns/rm#\"\n"); // Vocabulary Support
out.append("\t\txmlns:rm_property=\"" + rmPropertyURI + "\"\n");
out.append("\t\txmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n");
out.append("\t<oslc_rm:Requirement\n");
if (uri != null) {
out.append("\t\trdf:about=\""+uri+"\">\n");
} else {
out.append(">\n");
}
//Always need to have a title
appendXMLAttribute(out, RM_TITLE, dcTitle);
appendXMLAttribute(out, RM_DESCRIPTION, dcDescription);
appendXMLAttribute(out, RM_IDENTIFIER, dcIdentifier);
appendXMLAttribute(out, RM_CREATOR, dcCreator);
//Always need to specify the shape uri
out.append("\t<" + INSTANCE_SHAPE + " rdf:resource=\"" + shapeURI + "\"/>\n");
// Append the parent Folder
if ( this.parentFolder != null) {
out.append("\t<" + RM_PARENT + " rdf:resource=\"" + this.parentFolder + "\"/>\n");
}
if(dcModified != null){
appendXMLAttribute(out, RM_MODIFIED, RFC3339Format.format(dcModified));
}
//Add internal properties
for (Iterator<String> iterator = rmLiteralProperties.keySet().iterator(); iterator.hasNext();) {
String type = iterator.next();
if ( type == null) // gruelas
continue;
// Vocabulary Support
String xmlTag = null;
if ( type.equals("http://jazz.net/ns/rm#PrimaryText")) {
xmlTag = RM_JAZZ + ":" + type.substring(type.lastIndexOf("#") + 1 );
} else {
xmlTag = RM_PROPERTY + ":" + type.substring(rmPropertyURI.length());
}
out.append("\t<" + xmlTag + " rdf:parseType=\"Literal\">" + rmLiteralProperties.get(type)+ "</" + xmlTag + ">\n");
}
for (Iterator<String> iterator = rmResourceProperties.keySet().iterator(); iterator.hasNext();) {
String type = iterator.next();
String xmlTag = RM_PROPERTY + ":" + type.substring(rmPropertyURI.length());
out.append("\t<" + xmlTag + " rdf:resource=\"" + rmResourceProperties.get(type) + "\"/>\n");
}
out.append("\t</oslc_rm:Requirement>\n");
out.append("</rdf:RDF>\n");
out.flush();
}