Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [lyo-dev] preserving the order of properties in JenaModelHelper

Hi, Marius. As you've found, arrays are modeled as multi-valued properties in RDF by Lyo, which doesn't guarantee ordering.

You're on the right track with OslcRdfCollectionType, but Link is not currently supported. I believe it's just a point-in-time limitation and could be implemented later on. Do you need the Link class or is URI sufficient? Link is there so you can give the URI a label, usually for when you want to display it in a UI.

For List and Seq, have a look at the RDF primer section on collections:

http://www.w3.org/2007/02/turtle/primer/#L2986

The primary difference is that List says these are all the members and there can be no others. Seq is an ordered group, but not necessarily all-inclusive.

--
Samuel Padgett | IBM Rational | spadgett@xxxxxxxxxx
Eclipse Lyo: Enabling tool integration with OSLC


Inactive hide details for Marius Mikucionis ---10/18/2013 11:41:29 AM---Hello, I am new in webservice business and I have a proMarius Mikucionis ---10/18/2013 11:41:29 AM---Hello, I am new in webservice business and I have a problem with restoring the


    From:

Marius Mikucionis <mmikucionis@xxxxxxxxx>

    To:

lyo-dev@xxxxxxxxxxx

    Date:

10/18/2013 11:41 AM

    Subject:

[lyo-dev] preserving the order of properties in JenaModelHelper

    Sent by:

lyo-dev-bounces@xxxxxxxxxxx




Hello,

I am new in webservice business and I have a problem with restoring the property order from Jena model, I would appreciate your advice.

Consider the following annotated property of a resource:

@OslcDescription("Links to the requirement parts of this collection.")
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "hasPart")
@OslcName("hasPart")
@OslcTitle("Has a Part")
@OslcValueType(ValueType.Resource)
@OslcRange(RequirementConstants.TYPE_REQUIREMENT)
public Link[] getHasParts() { return hasParts.toArray(new Link[hasParts.size()]); }


I save the resources like this:

resources = getAllResources();
Model jenamodel = JenaModelHelper.createJenaModel(resources);
if (jenamodel != null) {
       final RDFWriter writer = jenamodel.getWriter(FileUtils.langXMLAbbrev);
       writer.setProperty("showXmlDeclaration", "true");
       writer.write(jenamodel, new FileOutputStream(dbFile), null);
}

And then restore like that:

final Model jenamodel = ModelFactory.createDefaultModel();
jenamodel.read(new FileInputStream(dbFile), null, FileUtils.langXMLAbbrev);
Object[] objects = JenaModelHelper.fromJenaModel(jenamodel, resourceType);


Then the order is messed up in unpredictable ways every time I go through store-load cycle, but I need to preserve the order.

After looking around, I noticed OslcRdfCollectionType annotation, so I got creative and added the following annotation to my hasParts property:

@OslcRdfCollectionType(collectionType="List")

which seems to be default setting anyway (right?) but then it breaks with types like Link.
Here is a stacktrace:

java.lang.NullPointerException
at org.eclipse.lyo.oslc4j.core.exception.OslcCoreInvalidPropertyDefinitionException.<init>(OslcCoreInvalidPropertyDefinitionException.java:35)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.handleLocalResource(JenaModelHelper.java:1856)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.buildAttributeResource(JenaModelHelper.java:1611)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.buildResource(JenaModelHelper.java:1222)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.handleSingleResource(JenaModelHelper.java:313)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.createJenaModel(JenaModelHelper.java:228)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.createJenaModel(JenaModelHelper.java:155)


whereas OslcCoreInvalidPropertyDefinitionException.java:35 contains this:

super(MESSAGE_KEY, new Object[] {resourceClass.getName(), method.getName(), oslcPropertyDefinition.value()});


which is called from JenaModelHelper:1856 like this:

if (nestedNode != null)
{
  if (rdfNodeContainer != null)
  {
     if (reifiedResource != null)
     {
     // Reified resource is not supported for rdf collection resources
      throw new OslcCoreInvalidPropertyDefinitionException(resourceClass, method, null);
      }


Notice the null parameter which breaks the construction of the exception -- that must be a bug, either in the constructor, or this call.
But then there is this comment saying that "reified resource is not supported".

Is this current implementation limitation or is this somehow wrong and will never be supported? or perhaps I can configure it differently?
Or perhaps I should get a more sophisticated database than just RDF dump?

By the way, what is a difference between "List" and "Seq" collection types?

Best regards,
--
Marius_______________________________________________
lyo-dev mailing list
lyo-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/lyo-dev


GIF image

GIF image


Back to the top