Impossible to update AnyResource?

To avoid the ClassCastExceptions that I started to receive after the update to Lyo 4.1 I followed the advice in ClassCastException with Lyo 4.1 - #7 by estepper. I.e., I changed our entire application to use AnyResource instead of Requirement. That worked very well for reading requirements.

But today I have to realize that apparently it’s impossible to update an AnyResource on the server, i.e., modify the object locally and PUT it on the server via OslcClient.updateResource().

At the end of OslcRdfXmlProvider.isWriteable() there’s this code:

         return ProviderHelper.isSingleResourceType(actualType);

And in ProviderHelper.isSingleResourceType() I see this:

        if (hasShapeAnnotation(type)) {
            return true;
        } 

       return false;

I interpret that as “only annotated beans can be written back”. And the whole purpose of AnyResource is that it’s fully dynamic, which implies it has no annotations.

I really don’t get this, especially if you consider that the dynamic (extended) properties are inherited from AbstractResource, which is the super class of both Requirement and AnyResource. I.e., even an annotated Requirement has these dynamic properties that must be written back somehow. So the needed mechanism must be somewhere already.

Am I missing something?

Out of desperation I copied all the Jena-Provider sources and changed the above “if” statement to the following:

       if (type == AnyResource.class || hasShapeAnnotation(type))

And now it all works as expected, even in updates. Go figure…

2 Likes

This looks both simple and harmless from the compatibility PoV! Glad to accept a PR for this. Thank you for posting the solution, Eike!

thanks for the awesome information.