Skip to content

getResource() in LyoStore does not handle inlined properties #363

@jadelkhoury

Description

@jadelkhoury

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions