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

hs.createHydroShareResource does not return resource_id #122

Open
dtarb opened this issue May 9, 2018 · 1 comment
Open

hs.createHydroShareResource does not return resource_id #122

dtarb opened this issue May 9, 2018 · 1 comment
Assignees
Labels

Comments

@dtarb
Copy link
Member

dtarb commented May 9, 2018

The calling statement for creating a resource in the current welcome notebook is

# create the new resource
resource_id = hs.createHydroShareResource(abstract,
title,
keywords=keywords,
resource_type=rtype,
content_files=files,
public=False)

However print(resource_id) following this returns "None"

I am not sure if the design intention was for this function to return resource_id, but either the function hs.createHydroShareResource should be fixed to return this id, or we should not use a statement like the above to illustrate functionality in the welcome notebook.

In discussing this with @sblack-usu there is a question as to why we are using a wrapper (hydrology.py) for the REST client which is already a wrapper for the REST API. Should we not be directly using REST client functions in our example notebooks.

@Castronova
Copy link
Member

I'll take a look at the return value for createHydroShareResource...this sounds like a bug.

@dtarb @sblack-usu
The reason for the wrapper is to make resource creation easier from within a notebook, but it's not required which is why it's included as a utility library (utilities.hydroshare). Users are encouraged to use whatever method they want to interact with HydroShare, but the following code is the minimum required to accomplish the same task as the above (without threading or error messaging) using the hs_restclient.

    # query the hydroshare resource types and make sure that
    # resource_type is valid
    restypes = {r.lower(): r for r in hs.getResourceTypes()}
    res_type = restypes[resource_type]

    # get the 'derived resource' metadata
    if derivedFromId is not None:
       science_meta = hs.getScienceMetadata(resid)
       system_meta = hs.getSystemMetadata(resid)

       # you would need to write a function to handle metadata
       meta = MY_FUNCTION_TO_PARSE_METADATA(system_meta, science_meta)
      
       abstract = meta.abstract \
                + '\n\n[Modified in JupyterHub on %s]\n%s' \
                % (dt.now(), abstract)
       keywords = set(keywords + meta.keywords)


    f = None if len(content_files) == 0 else content_files[0]

    # create the hs resource (1 content file allowed)
    resid = hs.createResource(resource_type=res_type,
                              title=title,
                              abstract=abstract,
                              resource_file=f,
                              keywords=keywords)

    # add the remaining content files to the hs resource
        if len(content_files) > 1:
             for f in content_files:
                 self.hs.addResourceFile(resid, f)

@Castronova Castronova added the bug label May 9, 2018
@Castronova Castronova self-assigned this May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants