jacquayj / GoRODS

Golang binding for iRODS C API: An iRODS client library written in Golang + C
https://godoc.org/github.com/jjacquay712/GoRODS
BSD 3-Clause "New" or "Revised" License
17 stars 5 forks source link

Problem creating new metadata for data objects #14

Closed simont closed 8 years ago

simont commented 8 years ago

I'm having some issues with creating new metadata using either dataObject.AddMeta() or mc.Add(). It seems that regardless of how I fill out the Attribute/Value/Units I get an error suggesting that I don't have the Attribute and Value (they are there), or that the attribute already exists (it doesn't, at least not in iRODS)

Snippet of relevant code, the attribute comes from the triple (which is a[]string) and in this particular example I am deliberately specifying the value and units so I know that they exist (ignoring the values of triple[1] and triple[2] for debugging purposes).

info("New metadata, Creating ", triple)
_, err := theThing.AddMeta(gorods.Meta{
  Attribute: triple[0],
  Value:     "test",
  Units:     "data",
})
if err != nil {
  warning("Problem creating metadata: ", triple, ", error: ", err)
}

the relevant log messages when I pass in a three element array containing the AVU, essentially trying to add a new A:V:U of Organism:test:data (though triple itself is ["Organism","Mouse, ""] )

New metadata, Creating  [Organism Mouse ]
WARNING 2016/07/13 13:17:24 utils.go:122: Problem creating metadata:  [Organism Mouse ] , error:  2016-07-13 13:17:24.664335411 +0000 UTC: Fatal - iRods Add Meta Failed: Please specify Attribute and Value fields or the attribute already exists

triple[0] = 'Organism' and the value and units are provided as strings so are specified, if I look in iRODS using imeta there is no 'Organism' metadata AVU triple that already exists for this object.

Any suggestions for what I might be missing? I haven't tried to see if this creation of new metadata objects work in a more isolated example, i.e. to see if there is something odd/unique about my code or environment as a whole that is the issue.

On the flips side, editing metadata triples that are already in iRODS (added via imeta) using the following approach is working fine, its just the creation of new metadata triples that appears to be causing the issue.

meta := dataObj.Attribute(attribute_name)
meta.SetValue(val)
meta.SetUnits(units)
jjacquay712 commented 8 years ago

Looks like my logic to check for existing meta attributes was flipped:

// Add creates a new meta AVU triple, returns pointer to the created Meta struct
func (mc *MetaCollection) Add(m Meta) (*Meta, error) {
    if er := mc.init(); er != nil {
        return nil, er
    }

    _, er := mc.Get(m.Attribute)

    if m.Attribute != "" && m.Value != "" && er != nil {

This has been fixed, thanks for the bug report!

jjacquay712 commented 8 years ago

Need to separate errors for preexisting attributes and empty Attribute, Value fields