<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<div class="moz-forward-container"><br>
<br>
-------- Forwarded Message --------
<table class="moz-email-headers-table" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">Subject: </th>
<td>Re: [ome-devel] get annotations java code</td>
</tr>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">Date: </th>
<td>Tue, 5 Jun 2018 09:36:06 +1000</td>
</tr>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">From: </th>
<td>Thomas Boudier <a class="moz-txt-link-rfc2396E" href="mailto:boudier.t@wehi.edu.au">
<boudier.t@wehi.edu.au></a></td>
</tr>
<tr>
<th valign="BASELINE" align="RIGHT" nowrap="nowrap">To: </th>
<td>Dominik Lindner (Staff) <a class="moz-txt-link-rfc2396E" href="mailto:d.lindner@dundee.ac.uk">
<d.lindner@dundee.ac.uk></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<p>Hi Dominik,</p>
<p>Thanks, I was a bit confused I guess between Facility classes. Maybe in the future you may  want to also have some
<i>setAnnotations</i> methods ;-) .</p>
<p>Here my code for information :</p>
<pre>Map<String, String> map = new HashMap<>();
        MetadataFacility metadataFacility = gateway.getFacility(MetadataFacility.class);
        List<AnnotationData> list = metadataFacility.getAnnotations(ctx, image);
        for (AnnotationData annotationData : list) {
            //IJ.log("" + annotationData.getClass().getName() + " " + annotationData.getLastModified());
            if (annotationData instanceof MapAnnotationData) {
                MapAnnotationData mapAnnotationData = (MapAnnotationData) annotationData;
                //IJ.log("FOUND PAIR " + mapAnnotationData.getContentAsString());
                String[] data = mapAnnotationData.getContentAsString().split("=");
                map.put(data[0], data[1]);
            }
        }
</pre>
<p>Many thanks.</p>
<p>Best,</p>
<p>Thomas<br>
</p>
<br>
<div class="moz-cite-prefix">On 04/06/18 20:56, Dominik Lindner (Staff) wrote:<br>
</div>
<blockquote type="cite" cite="mid:73D8B260-7498-4B29-8F4F-0B45528AF671@dundee.ac.uk">
Hi Thomas,
<div class=""><br class="">
</div>
<div class="">it looks like you're using the java gateway. In that case you can use the "MetadataFacility" to load </div>
<div class="">the MapAnnotations. Here's a github gist with an example: </div>
<div class=""><br class="">
</div>
<div class=""><a href="https://gist.github.com/dominikl/b16bc46f702dbc1cdea1b8ffeb0421c9" class="" moz-do-not-send="true">https://gist.github.com/dominikl/b16bc46f702dbc1cdea1b8ffeb0421c9</a></div>
<div class=""><br class="">
</div>
<div class="">Kind Regards,</div>
<div class="">Dominik</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On 1 Jun 2018, at 01:00, Thomas Boudier <<a href="mailto:boudier.t@wehi.edu.au" class="" moz-do-not-send="true">boudier.t@wehi.edu.au</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div text="#000000" bgcolor="#FFFFFF" class="">
<p class="">Dear Omero devs,</p>
<p class="">I would like to access key value pairs assocaited to an image but created by other users. It seems, thanks to the code provided on the omero website, to extract all annotations from me, but I do not know how to get only annotatins assocaited to
 a specific image.</p>
<p class="">here the code I wrote with "image" being an imageData object.<br class="">
</p>
<pre style="background-color: rgb(255, 255, 255); font-family: 'DejaVu Sans Mono'; font-size: 10pt;" class=""><span style="color:#000080;font-weight:bold;" class="">long </span>userId = <span style="color:#660e7a;font-weight:bold;" class="">gateway</span>.getLoggedInUser().getId();
List<String> nsToInclude = <span style="color:#000080;font-weight:bold;" class="">new </span>ArrayList<>();
<span style="color:#808080;font-style:italic;" class="">//nsToInclude.add(MapAnnotationData.NS_CLIENT_CREATED);
</span>List<String> nsToExclude = <span style="color:#000080;font-weight:bold;" class="">new </span>ArrayList<>();
ParametersI param = <span style="color:#000080;font-weight:bold;" class="">new </span>ParametersI();
<span style="color:#808080;font-style:italic;" class="">//param.exp(omero.rtypes.rlong(userId)); // user
</span>param.exp(omero.rtypes.<span style="font-style:italic;" class="">rlong</span>(image.getId())); <span style="color:#808080;font-style:italic;" class="">// image ??
</span>IMetadataPrx proxy = <span style="color:#660e7a;font-weight:bold;" class="">gateway</span>.getMetadataService(<span style="color:#660e7a;font-weight:bold;" class="">ctx</span>);
<span style="color:#000080;font-weight:bold;" class="">try </span>{
    List<Annotation> annotations = proxy.loadSpecifiedAnnotations(MapAnnotation.<span style="color:#000080;font-weight:bold;" class="">class</span>.getName(), nsToInclude, nsToExclude, param);
    IJ.<span style="font-style:italic;" class="">log</span>(annotations.size() + <span style="color:#008000;font-weight:bold;" class="">"  annotations found"</span>);
    <span style="color:#000080;font-weight:bold;" class="">for </span>(Annotation annotation : annotations) {
        IJ.<span style="font-style:italic;" class="">log</span>(<span style="color:#008000;font-weight:bold;" class="">" "</span>+annotation.getClass()+<span style="color:#008000;font-weight:bold;" class="">" "</span>+annotation.getId());
        MapAnnotation mapAnnotation = (MapAnnotation) annotation;
        List<NamedValue> list = mapAnnotation.getMapValue();
        <span style="color:#000080;font-weight:bold;" class="">for </span>(NamedValue namedValue : list)
            IJ.<span style="font-style:italic;" class="">log</span>(namedValue.<span style="color:#660e7a;font-weight:bold;" class="">name </span>+ <span style="color:#008000;font-weight:bold;" class="">"  " </span>+ namedValue.<span style="color:#660e7a;font-weight:bold;" class="">value</span>);
    }
} <span style="color:#000080;font-weight:bold;" class="">catch </span>(ServerError serverError) {
    IJ.<span style="font-style:italic;" class="">log</span>(<span style="color:#008000;font-weight:bold;" class="">"Pb reading annotation " </span>+ serverError.<span style="color:#660e7a;font-weight:bold;" class="">message</span>);
    serverError.printStackTrace();
}

</pre>
<p class="">Thanks for any help.</p>
<p class=""><br class="">
best</p>
<p class=""><br class="">
Thomas</p>
<pre class="moz-signature" cols="72">-- 
/***************************************************************/
      Thomas Boudier, Senior Research Officer,
      BioImage Analyst, Dynamic Imaging Centre,
      Walter and Eliza Hall Institute (WEHI), Australia.
/**************************************************************/  
</pre>
<div class="">
<p style="font-size:8pt; line-height:10pt;
                      font-family: 'Arial','Arial',serif;" class="">
_______________________________________________ <br class="">
<br class="">
The information in this email is confidential and intended solely for the addressee.<br class="">
You must not disclose, forward, print or use it without the permission of the sender.<br class="">
<br class="">
The Walter and Eliza Hall Institute acknowledges the Wurundjeri people of the Kulin
<br class="">
Nation as the traditional owners of the land where our campuses are located and <br class="">
the continuing connection to country and community.<br class="">
_______________________________________________ </p>
</div>
</div>
_______________________________________________<br class="">
ome-devel mailing list<br class="">
<a href="mailto:ome-devel@lists.openmicroscopy.org.uk" class="" moz-do-not-send="true">ome-devel@lists.openmicroscopy.org.uk</a><br class="">
<a class="moz-txt-link-freetext" href="http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel" moz-do-not-send="true">http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
<br>
<span style="font-size:10pt;">The University of Dundee is a registered Scottish Charity, No: SC015096</span><!--'"-->
<br>
<fieldset class="mimeAttachmentHeader"></fieldset> <br>
<pre wrap="">_______________________________________________
ome-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:ome-devel@lists.openmicroscopy.org.uk" moz-do-not-send="true">ome-devel@lists.openmicroscopy.org.uk</a>
<a class="moz-txt-link-freetext" href="http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel" moz-do-not-send="true">http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
/***************************************************************/
      Thomas Boudier, Senior Research Officer,
      BioImage Analyst, Dynamic Imaging Centre,
      Walter and Eliza Hall Institute (WEHI), Australia.
/**************************************************************/  
</pre>
</div>
<div>
<p style="font-size:8pt; line-height:10pt; font-family: 'Arial','Arial',serif;">_______________________________________________
<br>
<br>
The information in this email is confidential and intended solely for the addressee.<br>
You must not disclose, forward, print or use it without the permission of the sender.<br>
<br>
The Walter and Eliza Hall Institute acknowledges the Wurundjeri people of the Kulin
<br>
Nation as the traditional owners of the land where our campuses are located and <br>
the continuing connection to country and community.<br>
_______________________________________________ </p>
</div>
</body>
</html>