Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

New UniversalResourceSingleProvider to support more RDF formats #76

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

berezovskyi
Copy link
Member

@berezovskyi berezovskyi commented Feb 15, 2019

2nd try, #9 has too many merge conflicts

TODO

  • clean up AbstractRdfProvider
  • add a handler for collections and arrays
  • fix a query-related exception

2nd try, #9 has too many
merge conflicts

Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
@berezovskyi
Copy link
Member Author

I just applied the changes from #9 but a collection-based test now fails:

java.lang.IllegalArgumentException: Query Result resources have to be constructed before marshalling

	at org.eclipse.lyo.oslc4j.provider.jena.AbstractRdfProvider.writeTo(AbstractRdfProvider.java:51)
	at org.eclipse.lyo.oslc4j.provider.jena.OslcRdfXmlArrayProvider.writeTo(OslcRdfXmlArrayProvider.java:92)
	at org.eclipse.lyo.oslc4j.provider.jena.test.JsonLdTest.testWriteArray(JsonLdTest.java:82)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

*
* @since 4.0.0
*/
public class AbstractRdfProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be an abstract class.

OslcMediaType.N_TRIPLES_MIME, OslcMediaType.RDF_JSON_MIME, OslcMediaType.RDF_THRIFT_MIME})
@Consumes({OslcMediaType.APPLICATION_JSON_LD, OslcMediaType.TEXT_TURTLE,
OslcMediaType.N_TRIPLES_MIME, OslcMediaType.RDF_JSON_MIME, OslcMediaType.RDF_THRIFT_MIME})
public class UniversalResourceSingleProvider extends AbstractRdfProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle rdf/xml as well.

OslcMediaType.N_TRIPLES_MIME, OslcMediaType.RDF_JSON_MIME, OslcMediaType.RDF_THRIFT_MIME})
@Consumes({OslcMediaType.APPLICATION_JSON_LD, OslcMediaType.TEXT_TURTLE,
OslcMediaType.N_TRIPLES_MIME, OslcMediaType.RDF_JSON_MIME, OslcMediaType.RDF_THRIFT_MIME})
public class UniversalResourceSingleProvider extends AbstractRdfProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name suggestion: OslcResourceProvider

@Consumes({OslcMediaType.APPLICATION_JSON_LD, OslcMediaType.TEXT_TURTLE,
OslcMediaType.N_TRIPLES_MIME, OslcMediaType.RDF_JSON_MIME, OslcMediaType.RDF_THRIFT_MIME})
public class UniversalResourceSingleProvider extends AbstractRdfProvider
implements MessageBodyReader<IResource>, MessageBodyWriter<IResource> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can one also add?
implements MessageBodyReader<Collection<? extends IResource>>, MessageBodyWriter<Collection<? extends IResource>>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, unfortunately this does not work due to type erasure in Java. See https://softwareengineering.stackexchange.com/questions/219427/implementing-multiple-generic-interfaces-in-java for the background.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. We simply need to provide other Providers for collection.
Don’t even remember why we said we can do it all in 1 class.

# Conflicts:
#	oslc4j-jena-provider/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java
#	oslc4j-jena-provider/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/JsonLdTest.java
@berezovskyi
Copy link
Member Author

@jadelkhoury you were right, this does not include a Jena Model writer.

@jadelkhoury
Copy link
Contributor

@jadelkhoury you were right, this does not include a Jena Model writer.

I have one somewhere I can contribute. I'm sure you will want to make changes to that :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants