How to get the value of Owned by attribute using HTTP Client Query method(Custom Java implementation)?
Hi,
We are trying to get a custom workitem type named Release Schedule and it's attributes details using HTTP Client Query method and the headers are "Content-Type", "application/Json", "OSLC-Core-Version", "2.0", "Accept", "application/Json".
The application version is 6.0.6.1 with iFix027.
We are writing a HTTP Client Query to fetch field Ownedby by using dcterms:contributor.
Query:
String workitemUrl = cnfprop.getWebContextUrl() + "/oslc/contexts/_JSWgwaSqEeqGIaAO2lNttQ/workitems?"
+"oslc.where=rtc_cm:type=%22com.ibm.team.workitem.workItemType.p6%22&oslc.select=dcterms:contributor,rtc_cm:filedAgainst";
+"oslc.where=rtc_cm:type=%22com.ibm.team.workitem.workItemType.p6%22&oslc.select=dcterms:contributor,rtc_cm:filedAgainst";
But while fetching we are getting this parser exception, but for other attribute like filedagainst we are getting output but for owned by we are unable to get the output.
We are getting this Parser Exception
org.apache.wink.json4j.JSONException: Expecting '{' on line 1, column 6 instead, obtained token: 'Token: String - 'Error''
at org.apache.wink.json4j.internal.Parser.parseObject(Parser.java:193)
at org.apache.wink.json4j.internal.Parser.parse(Parser.java:130)
at org.apache.wink.json4j.internal.Parser.parse(Parser.java:95)
at org.apache.wink.json4j.JSONObject.<init>(JSONObject.java:138)
at com.test.Query.getfiledAgainst(Query.java:740)
at com.test.Query.main(Query.java:162)
Could you Please help on this how to get ownedby attribute value.
Thanks.
Thanks.
Accepted answer
It looks like
rtc_cm:ownedBy
is not defined as property.
Have you checked the resource shape for resources of that type in that project area to see what properties are defined?
Or looked at the RDF of an example work item from that project area to see how owner is represented?
If I look at work items on jazz.net I do not see a
rtc_cm:ownedBy
propery. Instead, the owner is represented by
dcterms:contributor
as per the OSLC Change Management specification - see https://docs.oasis-open-projects.org/oslc-op/cm/v3.0/os/change-mgt-shapes.html#changerequest.
If I look at the resource shape, I see it contains:
<https://jazz.net/jazz/oslc/shapes/workitems/_yOoaIKY7Ee2RrPFw5xrdAg/property/owner>
a oslc:Property ;
oslc:allowedValues <https://jazz.net/jazz/oslc/shapes/workitems/_yOoaIKY7Ee2RrPFw5xrdAg/property/owner/allowedValues> ;
oslc:defaultValue <https://jazz.net/jts/users/unassigned> ;
oslc:name "contributor"^^<http://www.w3.org/2001/XMLSchema#string> ;
oslc:occurs oslc:Zero-or-one ;
oslc:propertyDefinition
dcterms:contributor ;
oslc:range <http://xmlns.com/foaf/0.1/Person> ;
oslc:readOnly "false"^^<http://www.w3.org/2001/XMLSchema#boolean> ;
oslc:representation oslc:Either ;
oslc:valueType oslc:Resource ;
dcterms:title "Owned By"^^rdf:XMLLiteral .
Which tells me that
dcterms:contributor
is the property for owner.
2 other answers
If you are using OSLC related REST services, such as OSLC query, you should use a supported RDF media type. OSLC and Linked Lifecycle data is about RDF. Data is interchanged using RDF serialization formats such a RDF/XML or Turtle. Commonly supported RDF media types include
application/rdf+xml
,
application/turtle
,
test/turtle
.See section 4.1.3 of https://docs.oasis-open-projects.org/oslc-op/core/v3.0/os/oslc-core.html#resourceShapes.
Note that
application/json
is not an RDF media type. While some ELM application REST services might support it, the JSON representation is not defined by OSLC. Clients doing so are likely to become dependent on proprietary and undocumented JSON representations. You can represent RDF as json using
JSON-LD
for which the media type is
application/ld+json
. However, few, if any, ELM REST services currently support that media type.
One thing I notice is that your code example is manually constructing the requiest URI. This is bad practice. Instead, you should be using OSLC discovery to find the query base URI of the OSLC query capability you want to use. See https://docs.oasis-open-projects.org/oslc-op/core/v3.0/os/discovery.html.In that way, if an OSLC server changes the endpoint URIs in a later release, then clients should not be impacted. If you hard code assumptions about the paths, your OSLC client code will be more fragile and likely to break if such changes happen.
Lastly, 6.0.6.1 went end of service on 2022-10-31 and will no longer be remediated against security vulnerabilities. I highly recommend you upgrade to 7.0.2.
Lastly, 6.0.6.1 went end of service on 2022-10-31 and will no longer be remediated against security vulnerabilities. I highly recommend you upgrade to 7.0.2.