Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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";

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.

0 votes


Accepted answer

Permanent link
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.
Ralph Schoon selected this answer as the correct answer

0 votes


2 other answers

Permanent link

 We had a similar question recently. The answer was to use application/rdf-xml as content type and accept and not JSON.

0 votes


Permanent link

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.

0 votes

Comments

I would like to point out that we have gotten another question from this user, about the same or similar topics (OSLC, JSON, JAVA API) and answered pretty much already. The parser error is the same as before. You have also pointed out the issues already in your answer David.  

 Hi Ralph,

The Parser issue is already resolved. For other attributes like Planned for, filed against, we are getting the expected output but for only Owned by attribute it is giving this issue. But other attributes are working fine.
In the HTTP Client Query if I used dcterms:contributor  as id in the query it is showing the above parser issue. But other attributes are working fine.

But if I am try to use rtc_cm:ownedBy as id it is showing an error like
The Key [rtc_cm:ownedby] was not  in the Map. 

Cloud you please help on this one.

Thanks. 

How? You seem to ignore the answers.


As David has already stated in his answer and in https://jazz.net/forum/questions/282584/how-to-return-data-in-json-format-in-eclipse-while-using-http-client-query-method JSON is not a supported media type.


Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936
× 7,494
× 1,324

Question asked: Feb 08 '23, 6:16 a.m.

Question was seen: 1,277 times

Last updated: Feb 09 '23, 4:38 a.m.

Confirmation Cancel Confirm