eclipse / lyo

Eclipse Lyo, a Java SDK for OSLC-based tool integration

Home Page:https://oslc.github.io/developing-oslc-applications/eclipse_lyo/eclipse-lyo.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getResource() in LyoStore does not handle inlined properties

jadelkhoury opened this issue · comments

Consider a ResourceShape ObjectType that has an inlined property "targets", as examplified below.
Creating such an insstance (with inlined resources) works fine with LyoStore.
However, when calling getResource() on the uri http://localhost:8080/oslc-server1/oslc/pm/ObjectType/12, the properties of the inlined AnotherObjectType resources are not returned as part of the request.
That is, getResource() does not consider the resourceShape properties of ObjectType in its query.
This an be easily seen in the code of getResource() which is too simple to deal with this scenario.

<rdf:RDF
    <pref:ObjectType rdf:about="http://localhost:8080/oslc-server1/oslc/pm/ObjectType/12">
        <dcterms:identifier>12</dcterms:identifier>
        <pref:targets>
            <pref:AnotherObjectType rdf:about="http://localhost:8080/oslc-server1/oslc/pm/AnotherObjectType/1">
                <dcterms:identifier>1</dcterms:identifier>
            </pref:AnotherObjectType>
        </pref:targets>
        <pref:targets>
            <pref:AnotherObjectType rdf:about="http://localhost:8080/oslc-server1/oslc/pm/AnotherObjectType/2">
                <dcterms:identifier>2</dcterms:identifier>
            </pref:AnotherObjectType>
        </pref:targets>
    </pref:ObjectType>
</rdf:RDF>

A very simple workaround is to do another getResource() call on the set of target properties, to construct the complete instance.

        //Individually get the set of inlined resources the aResource points to.
        Set<AnotherObjectType> inlinedTargets = new HashSet<>();
		for (AnotherObjectType obj : aResource.getTargets()) {
			AnotherObjectType r = store.getResource(...., obj.getAbout(), AnotherObjectType.class);
			inlinedTargets.add(r);
		}
        aResource.setTargets(inlinedTargets);