Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionResource RDF not supported: requesting CollectionResource causes Could not find schema Exception #25

Open
aaraney opened this issue Sep 22, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@aaraney
Copy link
Member

aaraney commented Sep 22, 2021

Having done a little digging, this seems to be an issue propagating from hsmodels. That being said, it may be more appropriate to move this issue to that projects issue tracker and ref it here.

It appears that hsclient does not support parsing CollectionResourceRDF's (i.e. Web App Resource ). See below.

Resource used in reproducible example: https://hydroshare.org/resource/d139b42c4de545d78706e4c0b0bf0172

from hsclient import HydroShare

session = HydroShare()
session.sign_in()
res = session.resource("d139b42c4de545d78706e4c0b0bf0172")

>>> ../venv/lib/python3.8/site-packages/hsclient/hydroshare.py:910: in resource
    res.metadata
../venv/lib/python3.8/site-packages/hsclient/hydroshare.py:188: in metadata
    return self._metadata
../venv/lib/python3.8/site-packages/hsclient/hydroshare.py:95: in _metadata
    self._retrieved_metadata = self._retrieve_and_parse(self.metadata_path)
../venv/lib/python3.8/site-packages/hsclient/hydroshare.py:152: in _retrieve_and_parse
    instance = load_rdf(file_str)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

rdf_str = '<?xml version="1.0" encoding="utf-8"?>\n<rdf:RDF\n  xmlns:dc="http://purl.org/dc/elements/1.1/"\n  xmlns:hsterms="htt...er.</dcterms:abstract>\n      </rdf:Description>\n    </dc:description>\n  </hsterms:CollectionResource>\n</rdf:RDF>\n'
file_format = 'xml'

    def load_rdf(rdf_str, file_format='xml'):
    
        g = Graph().parse(data=rdf_str, format=file_format)
        for target_class, schema in rdf_schemas.items():
            subject = g.value(predicate=RDF.type, object=target_class)
            if subject:
                if target_class == ResourceMap:
                    return _parse(schema, g)
                else:
                    rdf_metadata = _parse(schema, g)
                    if schema in user_schemas.keys():
                        return user_schemas[schema](**rdf_metadata.dict())
                    return rdf_metadata
>       raise Exception("Could not find schema for \n{}".format(rdf_str))
E       Exception: Could not find schema for 
E       <?xml version="1.0" encoding="utf-8"?>
E       <rdf:RDF
E         xmlns:dc="http://purl.org/dc/elements/1.1/"
E         xmlns:hsterms="https://www.hydroshare.org/terms/"
E         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
E         xmlns:dcterms="http://purl.org/dc/terms/"
E         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
E       >
E         <hsterms:CollectionResource rdf:about="http://www.hydroshare.org/resource/d139b42c4de545d78706e4c0b0bf0172">
E           <dc:identifier>
E             <rdf:Description>
E               <hsterms:hydroShareIdentifier rdf:resource="http://www.hydroshare.org/resource/d139b42c4de545d78706e4c0b0bf0172"/>
E             </rdf:Description>
E           </dc:identifier>
E           <dc:date>
E             <dcterms:created>
E               <rdf:value>2020-02-07T15:25:24.758812+00:00</rdf:value>
E             </dcterms:created>
E           </dc:date>
E           <dc:subject>examples</dc:subject>
E           <dc:relation>
E             <rdf:Description>
E               <hsterms:hasPart>http://www.hydroshare.org/resource/866ce585737d4894b8b5536f2e275de9/</hsterms:hasPart>
E             </rdf:Description>
E           </dc:relation>
E           <dc:creator>
E             <rdf:Description>
E               <hsterms:phone>3399334127</hsterms:phone>
E               <hsterms:name>Castronova, Anthony Michael</hsterms:name>
E               <hsterms:organization>CUAHSI</hsterms:organization>
E               <hsterms:creatorOrder rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">1</hsterms:creatorOrder>
E               <hsterms:ResearchGateID rdf:resource="https://www.researchgate.net/profile/Anthony_Castronova"/>
E               <hsterms:description>/user/11/</hsterms:description>
E               <hsterms:ORCID rdf:resource="https://orcid.org/0000-0002-1341-5681"/>
E               <hsterms:GoogleScholarID rdf:resource="https://scholar.google.com/citations?user=ScWTFoQAAAAJ&amp;hl=en"/>
E               <hsterms:email>castronova.anthony@gmail.com</hsterms:email>
E             </rdf:Description>
E           </dc:creator>
E           <dc:language>eng</dc:language>
E           <dcterms:bibliographicCitation>Castronova, A. M. (2020). Binder Examples, HydroShare, http://www.hydroshare.org/resource/d139b42c4de545d78706e4c0b0bf0172</dcterms:bibliographicCitation>
E           <dc:rights>
E             <rdf:Description>
E               <hsterms:URL rdf:resource="http://creativecommons.org/licenses/by/4.0/"/>
E               <hsterms:rightsStatement>This resource is shared under the Creative Commons Attribution CC BY.</hsterms:rightsStatement>
E             </rdf:Description>
E           </dc:rights>
E           <dc:type>
E             <rdf:Description rdf:about="http://www.hydroshare.org/terms/CollectionResource">
E               <rdfs:label>Collection Resource</rdfs:label>
E               <rdfs:isDefinedBy rdf:resource="https://www.hydroshare.org/terms/"/>
E             </rdf:Description>
E           </dc:type>
E           <dc:relation>
E             <rdf:Description>
E               <hsterms:hasPart>http://www.hydroshare.org/resource/93f12f2607a64e4aad7dc9ff7f3ec5e1/</hsterms:hasPart>
E             </rdf:Description>
E           </dc:relation>
E           <dc:relation>
E             <rdf:Description>
E               <hsterms:hasPart>http://www.hydroshare.org/resource/51188b5303514b20b1b092a24c6620e9/</hsterms:hasPart>
@sblack-usu
Copy link
Collaborator

You are correct, a collection resource is not yet supported. The WebApp Resource is also not supported. For now, I think we should just handle this exception and raise a not-implemented exception. We will eventually support Collection and WebApp resources in hsmodels.

@aaraney
Copy link
Member Author

aaraney commented Sep 22, 2021

Thanks for elaborating on this @sblack-usu. I can get a PR in adding your suggestion by the end of the week or early next.

@aaraney aaraney self-assigned this Sep 22, 2021
@aaraney aaraney added the bug Something isn't working label Sep 22, 2021
@sblack-usu
Copy link
Collaborator

Thanks @aaraney! I'm having trouble keeping up with you. You've got a few merges that I haven't released yet.

@rreinecke
Copy link

Is there a timeline on supporting Collections?

@aaraney
Copy link
Member Author

aaraney commented Feb 8, 2022

any update on this @sblack-usu? In a quick glance, I did not see any related issues in the hsmodels repo.

@sblack-usu
Copy link
Collaborator

I have not prioritized this work yet. @rreinecke - do you have a need for Collections support in hsclient? The action on this issue up until now was to just handle exception feedback to communicate to users that collections are not yet supported. If the community has a need for Collections, we can start prioritizing this work.

@SteveCoss
Copy link

Just wanted to add that I am VERY interested in being able to use collections in the API. My intended data flow is to have users update thier own personal resources that are all contained under the collection umbrella which I maintain control over.

@sblack-usu
Copy link
Collaborator

An update here, I have some more tests to write but I do have a working implementation of a collection resource with hsclient with this pr in hsmodels hydroshare/hsmodels#42

We should be able to get a release out that supports collections once I get the tests written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants