sbmlteam / libCombine

a C++ library for working with the COMBINE Archive format
BSD 2-Clause "Simplified" License
8 stars 5 forks source link

Multiple metafiles created when writing multiple descriptions #23

Closed matthiaskoenig closed 5 years ago

matthiaskoenig commented 7 years ago

Somehow I get multiple metafiles in the archive when writing descriptions for multiple entries named

metadata.xml
metadata_1.xml
metadata_2.xml
...

See for instance this example L1V3_repressilator.zip

I am using the code below to write the description.

...
    time_now = libcombine.OmexDescription.getCurrentDateAndTime()
    archive = libcombine.CombineArchive()

    for entry in json_entries:
        location = entry['location']
        path = os.path.join(folder, location)
        format = entry['format']
        master = entry.get('master', False)
        # add file
        archive.addFile(path, location, format, master)

        # read json metadata
        description = entry.get("description", None)
        creators = entry.get("creators", None)
        if description or creators:
            omex_d = libcombine.OmexDescription()
            omex_d.setAbout(location)
            omex_d.setCreated(time_now)

            if description:
                omex_d.setDescription(description)
                print("Setting description:", description)

            if creators:
                for c in creators:
                    creator = libcombine.VCard()
                    creator.setFamilyName(c.get("familyName", ""))
                    creator.setGivenName(c.get("givenName", ""))
                    creator.setEmail(c.get("email", ""))
                    creator.setOrganization(c.get("organisation"))
                    omex_d.addCreator(creator)

            archive.addMetadata(location, omex_d)

    archive.writeToFile(omex_file)
    archive.cleanUp()

Could you upload a pip package with the latest fixes, so I can test if these are already fixing this issue.

Thanks a lot for all your help. M

fbergmann commented 7 years ago

This is exactly how I intended it to work ... each call to addMetadata creates a new document with meta information. That is perfectly fine according to the omex spec. While I added support for reading multiple ones from multiple files that is not something i see really sustainable ... i will try and create an update for the pip package later today

matthiaskoenig commented 7 years ago

So I am doing something wrong. How can I get all the descriptions for the different locations in one metadata file?

fbergmann commented 7 years ago

there is currently no convenience method for that. I could add one if needed .. it would be something like:

descriptions = []
for location in archive.getAllLocations(): 
    current = archive.getMetadataForLocation(location)
    if current.isEmpty(): 
       continue
    descriptions.append(current)
matthiaskoenig commented 7 years ago

Just to clarify: Currently with the library I can only store one description per metadata file. If I want multiple descriptions I have to add multiple metadata files.

I am still not sure if I am just doing something wrong and not getting multiple descriptions in one metafile.

fbergmann commented 7 years ago

The functions that are currently there are written so that they would create multiple files, rather than only one. However, if you generate all the meta information yourself, you could create one huge file containing multiple metadata descriptions, and just add it to the archive.