Page 1 of 1

Retrieve NamedValue from MapAnnotation

PostPosted: Wed May 16, 2018 1:12 pm
by derekeh
Hi,
I've got the CommentAnnotations and the TagAnnotations returning from my Java app but I can't seem to get the key/value pairs for the MapAnnotation.
Using OMERO 5.4.0 on Linux Centos 7.
In the following code I've split out each assign to separate lines and used the get(i) function instead of an iterator at present.
The NamedValue: nv_0.getClass.getName() returns omero.model.NamedValue@16c069df
but nv_0.getValue() is not a valid function.
How do I get the value of the current NamedValue, nv_0 ?
Thanks in advance
Derek

Code: Select all
List mapTypes = new ArrayList();
mapTypes.add("ome.model.annotations.MapAnnotation");
Map <Long,Set<Annotation>> mapSetMap = proxy.loadAnnotations("Image", imageIds, mapTypes, annotatorIds, param);
            Iterator mit = mapSetMap.entrySet().iterator();
            while (mit.hasNext()) {
                Map.Entry pair = (Map.Entry)mit.next();
                ArrayList ret = (ArrayList)pair.getValue();
                MapAnnotation mapannot = (MapAnnotation)ret.get(0);
                List<NamedValue> nv = mapannot.getMapValue();
                NamedValue nv_0 = (NamedValue)nv.get(0);

                System.out.println("Named Value type: " + nv_0.getClass().getName());
                System.out.println("Named Value Value: " + nv_0);

                mit.remove();
            }



Re: Retrieve NamedValue from MapAnnotation

PostPosted: Wed May 16, 2018 1:27 pm
by mtbc
Dear Derek,

You should find that nv_0.name and nv_0.value are simple strings containing what you need.

Cheers,
Mark

Re: Retrieve NamedValue from MapAnnotation

PostPosted: Wed May 16, 2018 1:42 pm
by derekeh
Mark,
Thanks for that.
I spent way too much time trying to find that simple answer !

Still, why does the getValue() method not return the same as the API suggests.
What am I missing?

Anyway, thanks to your reply I now have the data back that I want.

Cheers
Derek

Re: Retrieve NamedValue from MapAnnotation

PostPosted: Wed May 16, 2018 2:27 pm
by mtbc
Dear Derek,

I am glad that that works for you now. You might want to try out different IDEs for developing in Java as some make it easy to see what various object classes offer.

I suspect that the class that you read about offering getValue() is not in the package of the class that you are actually using. :) Many of the classes from the omero.model package appear not to be in any published documentation that I see online. I've made a note that we should look at including them.

Cheers,
Mark