Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Lyo » Issues with creating a specific resource request body in OSLC4J(API requires a specific RDF/XML to be sent which I can not generate.)
Issues with creating a specific resource request body in OSLC4J [message #1799796] Thu, 13 December 2018 15:43 Go to next message
Ralph Schoon is currently offline Ralph SchoonFriend
Messages: 9
Registered: November 2018
Junior Member
Hi,

I am working on some automation using OSLC4J (2.3 and 2.4).
I have created a class representing the resource shape. The class also has the code to POST to the factory URL. The class represents a Changeset which has
a Component URI, a Stream URI, a description and a title.

Using
response = client.createResource(changeSetCreationFactory, this, OslcMediaType.APPLICATION_RDF_XML,
OslcMediaType.APPLICATION_XML);

this generates:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:oslc="http://open-services.net/ns/core#"
xmlns:j.0="http://open-services.net/ns/config#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<j.0:Changeset>
<j.0:stream rdf:resource="https://clm.example.com:9443/rm/cm/stream/_8HxiUPoZEei1heqPanuHaQ"/>
<dcterms:description>Created for automation.</dcterms:description>
<dcterms:title rdf:parseType="Literal">Import-Type-System-CS-2018/12/13 16:27:01 MEZ</dcterms:title>
<j.0:component rdf:resource="https://clm.example.com:9443/rm/cm/component/_qQIn0PoYEei1heqPanuHaQ"/>
</j.0:Changeset>
</rdf:RDF>


The API requires an additional

<rdf:type rdf:resource="http://open-services.net/ns/config#Configuration"/>

to be sent. I have not been reliably able to do that.

I have tried to use org.eclipse.lyo.oslc4j.core.model.AbstractResource.addType(URI) or
org.eclipse.lyo.oslc4j.core.model.AbstractResource.setTypes(Collection<URI>)

to add this information, but this does not work.

I also tried to specify a new type property on the change set class.
A common result of all these attempts is that the request changes to request a Configuration instead of a change set like this:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:oslc="http://open-services.net/ns/core#"
xmlns:j.0="http://open-services.net/ns/config#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<j.0:Configuration>
<j.0:component rdf:resource="https://clm.example.com:9443/rm/cm/component/_qQIn0PoYEei1heqPanuHaQ"/>
<j.0:stream rdf:resource="https://clm.example.com:9443/rm/cm/stream/_8HxiUPoZEei1heqPanuHaQ"/>
<dcterms:description>Created for automation.</dcterms:description>
<dcterms:title rdf:parseType="Literal">Import-Type-System-CS-2018/12/12 11:16:16 MEZ</dcterms:title>
<rdf:type rdf:resource="http://open-services.net/ns/config#Changeset"/>
</j.0:Configuration>
</rdf:RDF>

The result is quite the opposite of what I wanted to achieve.

For a short time I got what I wanted with using addType , but just refactoring come code in the class caused this to no longer work.

Does anyone have an idea what I should do to get the RDF generated that I need?
Another question is that I got several issues with the code generation for the annotations that I could not understand and that came and went away. I was wondering if this is due to the methods I have defined on the resource classes that do the creation etc. . Some problems I got was that the code generator had 204 errors complaining about illegal annotations unless I replaced the constants with strings.

Is it advised not to put any self created methods and code into the resource classes?

See the source code attached.

Any hints are greatly appreciated.

Ralph
Re: Issues with creating a specific resource request body in OSLC4J [message #1799806 is a reply to message #1799796] Thu, 13 December 2018 22:10 Go to previous messageGo to next message
Jad El-khoury is currently offline Jad El-khouryFriend
Messages: 37
Registered: August 2015
Member
Hi Ralph


1.
I am looking at your annotation: @OslcResourceShape(title = "Changeset", describes = "http://open-services.net/ns/config#" + "Changeset")

The "describes" is telling OSLC4J marsheller that the rdf:type is "http://open-services.net/ns/config#Changeset". So, you should change that value, if you expect <rdf:type rdf:resource="http://open-services.net/ns/config#Configuration"/>

2.
Don't think this is really the source of problems, but I am looking at your
response = client.createResource(changeSetCreationFactory, this, OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML);

Is there a reason contentType (APPLICATION_RDF_XML) is different from the accept type (APPLICATION_XML)?
Do you know what you server is expecting?

3.
I think you should avoid setting the rdf:type property through the getters in the class, as you tried to do in the commented-out code.


Finally, can you give more details about the issues you have with the code generation?
If you can start a new thread on that, I can try to help out.

[Updated on: Thu, 13 December 2018 22:15]

Report message to a moderator

Re: Issues with creating a specific resource request body in OSLC4J [message #1799824 is a reply to message #1799806] Fri, 14 December 2018 09:38 Go to previous messageGo to next message
Ralph Schoon is currently offline Ralph SchoonFriend
Messages: 9
Registered: November 2018
Junior Member
Hi Jad,

I know it is kind of against intuition, but the inventor of this API has decided they want a Changeset to be created. So the outer part is supposed to be Changeset. However the inner type must be Configuration. Here the important pieces:

<rdf:RDF
xmlns:j.0="http://open-services.net/ns/config#"
<j.0:Changeset>
<rdf:type rdf:resource="http://open-services.net/ns/config#Configuration"/>
</j.0:Changeset>
</rdf:RDF>

So the outer (I don't know the language here) type has to be "ChangeSet", hence the

@OslcNamespace("http://open-services.net/ns/config#")
@OslcResourceShape(title = "Changeset", describes = "http://open-services.net/ns/config#" + "Changeset")

and the class is also "Changeset".

But the designer of the API also requires the inner type to be "Configuration".

<rdf:type rdf:resource="http://open-services.net/ns/config#Configuration"/>

Note, this is not supposed to be "Changeset". I seem to be unable to get this to be generated.

What I get generated is

<rdf:RDF
.....
<j.0:Changeset>
<j.0:stream rdf:resource="https://clm.example.com:9443/rm/cm/stream/_8HxiUPoZEei1heqPanuHaQ"/>
<j.0:component rdf:resource="https://clm.example.com:9443/rm/cm/component/_qQIn0PoYEei1heqPanuHaQ"/>
<dcterms:title rdf:parseType="Literal">Import-Type-System-CS-2018/12/14 10:15:46 MEZ</dcterms:title>
<dcterms:description>Created for automation.</dcterms:description>
</j.0:Changeset>
</rdf:RDF>

Which is fine. But I need also
<rdf:type rdf:resource="http://open-services.net/ns/config#Configuration"/>
to be generated. As soon as I try to do that with setting the type or adding a property as described above things start to go wrong.
What typically happens is that the generated body looks like

<rdf:RDF
.....
<j.0:Configuration>
.....
<rdf:type rdf:resource="http://open-services.net/ns/config#Changeset"/>
</j.0:Configuration>
</rdf:RDF>

So the other way round.

BTW, I changed the factory call to

response = client.createResource(changeSetCreationFactory, (Changeset)this, OslcMediaType.APPLICATION_RDF_XML, OSLCConstants.CT_RDF);

The result is the same. This is not the issue. I have accidentally been able to generate the correct body and then everything worked.
I was able to achieve that by using
// This is a work around.
this.addType(new URI("http://open-services.net/ns/config#Configuration"));

but for some reason unknown to me, this does not work anymore. If I do that, this is the result (only the important bits)

<rdf:RDF
...
<j.0:Configuration>
...
<rdf:type rdf:resource="http://open-services.net/ns/config#Changeset"/>
</j.0:Configuration>
</rdf:RDF>

and this is exactly the opposite of what I need. I am also concerned that it was working once and somehow it does not any more. How can I trust my code if some random stuff happens?

I hope I have explained this in enough details. As it stands I should probably duplicate the class, call it Configuration and use the trick in reverse. But I don't understand why the change from

<rdf:RDF
...
<j.0:Changeset>
...
</j.0:Changeset>
</rdf:RDF>

to

<rdf:RDF
...
<j.0:Configuration>
...
<rdf:type rdf:resource="http://open-services.net/ns/config#Changeset"/>
</j.0:Configuration>
</rdf:RDF>

actually happens and if this would change some time in the future for a random reason.

Any ideas you have are most welcome!
Re: Issues with creating a specific resource request body in OSLC4J [message #1799828 is a reply to message #1799824] Fri, 14 December 2018 10:02 Go to previous messageGo to next message
Ralph Schoon is currently offline Ralph SchoonFriend
Messages: 9
Registered: November 2018
Junior Member
Please note: I changed the annotation of my class to

@OslcNamespace("http://open-services.net/ns/config#")
@OslcResourceShape(title = "Configuration", describes = "http://open-services.net/ns/config#" + "Configuration")

just out of desperation. However, the message the server receives is still "Changeset"

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:oslc="http://open-services.net/ns/core#"
xmlns:j.0="http://open-services.net/ns/config#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<j.0:Changeset>
<j.0:component rdf:resource="https://clm.example.com:9443/rm/cm/component/_qQIn0PoYEei1heqPanuHaQ"/>
<dcterms:description>Created for automation.</dcterms:description>
<j.0:stream rdf:resource="https://clm.example.com:9443/rm/cm/stream/_8HxiUPoZEei1heqPanuHaQ"/>
<dcterms:title rdf:parseType="Literal">Import-Type-System-CS-2018/12/14 10:56:02 MEZ</dcterms:title>
</j.0:Changeset>
</rdf:RDF>

So I don't understand what s happening.
Re: Issues with creating a specific resource request body in OSLC4J [message #1799835 is a reply to message #1799828] Fri, 14 December 2018 13:39 Go to previous messageGo to next message
Ralph Schoon is currently offline Ralph SchoonFriend
Messages: 9
Registered: November 2018
Junior Member
An update...... What I explained about what I see about the generated code is still true. But actually, what I see in the debug string on the server might not be what I am sending.

It would be nice if it would be possible to get access to the body of the createResource(). so far I have not been able to find out if that is possible.

However, the errors I was seeing on the server have, as it turns out, a completely different reason. The reason is that the API on the server does not tolerate a missing about,

<rdf:RDF
....
<j.0:Changeset>
...
</j.0:Changeset>
</rdf:RDF>

Fails

But
<rdf:RDF
....
<j.0:Changeset about="">
...
</j.0:Changeset>
</rdf:RDF>

works. If I try to send new URI("") the OSLC client runs into an error in the serialization,

I have to send a valid URL so I use new URI("http://open-services.net/ns/config#Changeset").
I use

setType(new URI("http://open-services.net/ns/config#Configuration"));

to send the resource type information. So it seems to be working.

If you have an idea how to see the POST body before it is POSTed that would be nice. Otherwise I think I have it working now.
Re: Issues with creating a specific resource request body in OSLC4J [message #1799844 is a reply to message #1799835] Fri, 14 December 2018 15:50 Go to previous messageGo to next message
Andrii BerezovskyiFriend
Messages: 23
Registered: May 2016
Junior Member
Ralph,

Quote:
the inventor of this API has decided they want a Changeset to be created. So the outer part is supposed to be Changeset. However the inner type must be Configuration


In RDF, all types are equal and strictly speaking, you have no control over which type is picked as an XML tag. Seems like you got this fixed for you, here is how you can manipulate the serialisation at the low level: https://stackoverflow.com/questions/43599490/jena-owl-rdf-functionalproperty/43607424#43607424

The rdf:about URI set the RDF subject on a Changeset you are POSTing. Thus, you can generate any valid URI there if the resource does not exist yet.


Best regards,
Andrew
Eclipse Lyo project lead & OSLC Core TC voting member
Re: Issues with creating a specific resource request body in OSLC4J [message #1799847 is a reply to message #1799844] Fri, 14 December 2018 18:20 Go to previous messageGo to next message
Jad El-khoury is currently offline Jad El-khouryFriend
Messages: 37
Registered: August 2015
Member
Now I see, so you need a Configuration within a ChangeSet. '
Sounds like the Configuration resource should be inlined Or a localResource of a ChangeSet.

So, how do you know what the "inventor" wants? I am no longer sure which of hte above xml is the expected results. Just to be sure, can you share an example of the expected result? Even better, do you know the Resoure Shape that defines ChangeSet and/or Configuration?

Re: Issues with creating a specific resource request body in OSLC4J [message #1799848 is a reply to message #1799847] Fri, 14 December 2018 18:32 Go to previous message
Jad El-khoury is currently offline Jad El-khouryFriend
Messages: 37
Registered: August 2015
Member
So, I'm first answering my own questions above. Assuming the "inventor" is following the latest oslc specs, the expected shape of ChangeSet is https://tools.oasis-open.org/version-control/browse/wsvn/oslc-core/trunk/specs/config/config-resources.html#shape-changeset

But according to that shape, there is no such property called configuration. I see an "overrides" property that is expected to be of type Configuration.

So just to know how to proceed, can you confirm what is expected from the inventor? Are we looking at the right version of the shape?



Previous Topic:OSLC source code
Next Topic:What I'd like to have in Lyo
Goto Forum:
  


Current Time: Sun Sep 22 16:22:25 GMT 2019

Powered by FUDForum. Page generated in 0.02292 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top