From d830832c9633482200d784b601814e3186e8056e Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 11:26:56 +0100 Subject: [PATCH 01/14] Fix distinct() and PlateAcquisitionWrapper, and return distinct ROIs in ImageWrapper and FolderWrapper --- .github/workflows/maven.yml | 3 +- .omeroci/test-data | 4 + pom.xml | 2 +- src/main/java/fr/igred/omero/Client.java | 4 +- .../java/fr/igred/omero/GatewayWrapper.java | 2 + .../fr/igred/omero/GenericObjectWrapper.java | 12 +-- .../annotations/FileAnnotationWrapper.java | 4 +- .../annotations/GenericAnnotationWrapper.java | 10 +- .../annotations/MapAnnotationWrapper.java | 4 +- .../igred/omero/annotations/TableWrapper.java | 6 +- .../annotations/TagAnnotationWrapper.java | 4 +- .../igred/omero/annotations/package-info.java | 4 +- .../omero/exception/AccessException.java | 2 + .../omero/exception/ExceptionHandler.java | 4 +- .../omero/exception/OMEROServerError.java | 2 + .../omero/exception/ServiceException.java | 2 + .../igred/omero/exception/package-info.java | 4 +- .../igred/omero/meta/ExperimenterWrapper.java | 4 +- .../fr/igred/omero/meta/GroupWrapper.java | 4 +- .../fr/igred/omero/meta/PlaneInfoWrapper.java | 4 +- .../fr/igred/omero/meta/package-info.java | 4 +- .../java/fr/igred/omero/package-info.java | 4 +- .../omero/repository/ChannelWrapper.java | 4 +- .../omero/repository/DatasetWrapper.java | 4 +- .../igred/omero/repository/FolderWrapper.java | 24 ++--- .../GenericRepositoryObjectWrapper.java | 8 +- .../igred/omero/repository/ImageWrapper.java | 101 +++++++++--------- .../igred/omero/repository/PixelsWrapper.java | 4 +- .../repository/PlateAcquisitionWrapper.java | 7 +- .../igred/omero/repository/PlateWrapper.java | 4 +- .../omero/repository/ProjectWrapper.java | 24 ++--- .../igred/omero/repository/ScreenWrapper.java | 4 +- .../omero/repository/WellSampleWrapper.java | 4 +- .../igred/omero/repository/WellWrapper.java | 2 + .../igred/omero/repository/package-info.java | 4 +- .../fr/igred/omero/roi/EllipseWrapper.java | 4 +- .../igred/omero/roi/GenericShapeWrapper.java | 8 +- .../java/fr/igred/omero/roi/LineWrapper.java | 4 +- .../java/fr/igred/omero/roi/MaskWrapper.java | 4 +- .../java/fr/igred/omero/roi/PointWrapper.java | 4 +- .../fr/igred/omero/roi/PolygonWrapper.java | 4 +- .../fr/igred/omero/roi/PolylineWrapper.java | 4 +- .../java/fr/igred/omero/roi/ROIWrapper.java | 2 + .../fr/igred/omero/roi/RectangleWrapper.java | 4 +- .../java/fr/igred/omero/roi/ShapeList.java | 4 +- .../java/fr/igred/omero/roi/TextWrapper.java | 4 +- .../java/fr/igred/omero/roi/package-info.java | 4 +- .../fr/igred/omero/util/LibraryChecker.java | 4 +- .../fr/igred/omero/util/package-info.java | 4 +- .../fr/igred/omero/AccessExceptionTest.java | 2 + src/test/java/fr/igred/omero/BasicTest.java | 2 + src/test/java/fr/igred/omero/ClientTest.java | 4 +- .../java/fr/igred/omero/ConnectionTest.java | 2 + .../java/fr/igred/omero/ExceptionTest.java | 2 + .../java/fr/igred/omero/LoggingExtension.java | 2 + src/test/java/fr/igred/omero/RootTest.java | 2 + src/test/java/fr/igred/omero/SudoTest.java | 2 + src/test/java/fr/igred/omero/TestObject.java | 2 + src/test/java/fr/igred/omero/UserTest.java | 2 + .../omero/annotations/ImageJTableTest.java | 2 + .../fr/igred/omero/annotations/TableTest.java | 2 + .../fr/igred/omero/annotations/TagTest.java | 2 + .../fr/igred/omero/meta/ExperimenterTest.java | 2 + .../java/fr/igred/omero/meta/GroupTest.java | 2 + .../omero/meta/PlaneInfoWrapperTest.java | 2 + .../igred/omero/repository/DatasetTest.java | 2 + .../fr/igred/omero/repository/FolderTest.java | 2 + .../omero/repository/ImageImportTest.java | 2 + .../fr/igred/omero/repository/ImageTest.java | 2 + .../fr/igred/omero/repository/PixelsTest.java | 2 + .../repository/PlateAcquisitionTest.java | 2 + .../fr/igred/omero/repository/PlateTest.java | 2 + .../igred/omero/repository/ProjectTest.java | 4 +- .../fr/igred/omero/repository/ScreenTest.java | 2 + .../omero/repository/WellSampleTest.java | 2 + .../fr/igred/omero/repository/WellTest.java | 2 + .../fr/igred/omero/roi/ROI2ImageJTest.java | 2 + src/test/java/fr/igred/omero/roi/ROITest.java | 2 + .../fr/igred/omero/roi/ShapeErrorTest.java | 4 +- .../java/fr/igred/omero/roi/ShapeTest.java | 2 + .../igred/omero/util/LibraryCheckerTest.java | 4 +- 81 files changed, 249 insertions(+), 168 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 7c3823e9..aaae1cc4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -78,8 +78,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - name: Upload to codecov after successful tests - if: ${{ success() }} - run: bash <(curl -s https://codecov.io/bash) + uses: codecov/codecov-action@v3 - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.omeroci/test-data b/.omeroci/test-data index 92269c3a..c61cf720 100755 --- a/.omeroci/test-data +++ b/.omeroci/test-data @@ -98,16 +98,20 @@ PROJECT2=$(omero obj new Project name=TestProject2) DATASET1=$(omero obj new Dataset name=TestDataset description=description) DATASET2=$(omero obj new Dataset name=TestDatasetImport) DATASET3=$(omero obj new Dataset name=TestDataset) +DATASET4=$(omero obj new Dataset name=TestDataset4) omero obj new ProjectDatasetLink parent="$PROJECT1" child="$DATASET1" omero obj new ProjectDatasetLink parent="$PROJECT1" child="$DATASET2" omero obj new ProjectDatasetLink parent="$PROJECT2" child="$DATASET3" +omero obj new ProjectDatasetLink parent="$PROJECT1" child="$DATASET4" IMAGE1=$(omero import --output=ids "$WORKDIR/image1.fake" -T "$DATASET1") IMAGE2=$(omero import --output=ids "$WORKDIR/image1.fake" -T "$DATASET1") IMAGE3=$(omero import --output=ids "$WORKDIR/image2.fake" -T "$DATASET1") IMAGE4=$(omero import --output=ids "$WORKDIR/image1.fake" -T "$DATASET3") +omero obj new DatasetImageLink parent="$DATASET4" child="$IMAGE1" + # import screens SCREEN1=$(omero obj new Screen name=TestScreen description=description) SCREEN2=$(omero obj new Screen name=TestScreen2) diff --git a/pom.xml b/pom.xml index 6514dc3c..41c3f39c 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ fr.igred simple-omero-client - 5.10.0 + 5.10.1 jar Simple OMERO Client diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index 5663d1b6..ce6d3e32 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/GatewayWrapper.java b/src/main/java/fr/igred/omero/GatewayWrapper.java index c648e0fa..6b9b90e4 100644 --- a/src/main/java/fr/igred/omero/GatewayWrapper.java +++ b/src/main/java/fr/igred/omero/GatewayWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/GenericObjectWrapper.java b/src/main/java/fr/igred/omero/GenericObjectWrapper.java index 3e485abe..b5d3a17a 100644 --- a/src/main/java/fr/igred/omero/GenericObjectWrapper.java +++ b/src/main/java/fr/igred/omero/GenericObjectWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -52,10 +52,10 @@ public abstract class GenericObjectWrapper { /** * Constructor of the class GenericObjectWrapper. * - * @param object The object contained in the GenericObjectWrapper. + * @param o The object contained in the GenericObjectWrapper. */ - protected GenericObjectWrapper(T object) { - this.data = object; + protected GenericObjectWrapper(T o) { + this.data = o; } @@ -124,7 +124,7 @@ protected static void delete(Client client, IObject object) */ public static > List distinct(Collection objects) { return objects.stream() - .collect(Collectors.toMap(T::getId, o -> o)) + .collect(Collectors.toMap(T::getId, o -> o, (o1, o2) -> o1)) .values() .stream() .sorted(Comparator.comparing(T::getId)) diff --git a/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java index 56403dfc..bb4efb2c 100644 --- a/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/FileAnnotationWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java index fcaf0902..b9568a32 100644 --- a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -49,10 +49,10 @@ public abstract class GenericAnnotationWrapper extends /** * Constructor of the GenericAnnotationWrapper class. * - * @param object Annotation to be contained. + * @param a Annotation to be contained. */ - protected GenericAnnotationWrapper(T object) { - super(object); + protected GenericAnnotationWrapper(T a) { + super(a); } diff --git a/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java index 7483e6de..497f642b 100644 --- a/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/MapAnnotationWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/annotations/TableWrapper.java b/src/main/java/fr/igred/omero/annotations/TableWrapper.java index 027f2383..3998dcb6 100644 --- a/src/main/java/fr/igred/omero/annotations/TableWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TableWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -325,7 +325,7 @@ private static ROIData[] columnToROIColumn(Variable[] roiCol, *

If neither column is present, it will check the {@value LABEL} column for the ROI names inside. * * @param results An ImageJ results table. - * @param rois A list of OMERO ROIs. + * @param rois A list of OMERO ROIs (each ID should be present only once). * @param ijRois A list of ImageJ Rois. * @param roiProperty The Roi property storing the local ROI IDs. * diff --git a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java index 4057ce25..0bccebe0 100644 --- a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/annotations/package-info.java b/src/main/java/fr/igred/omero/annotations/package-info.java index 03bbd9cc..ce942350 100644 --- a/src/main/java/fr/igred/omero/annotations/package-info.java +++ b/src/main/java/fr/igred/omero/annotations/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/exception/AccessException.java b/src/main/java/fr/igred/omero/exception/AccessException.java index 65357a87..7f1ca0ee 100644 --- a/src/main/java/fr/igred/omero/exception/AccessException.java +++ b/src/main/java/fr/igred/omero/exception/AccessException.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java index 6937f8d1..f51beceb 100644 --- a/src/main/java/fr/igred/omero/exception/ExceptionHandler.java +++ b/src/main/java/fr/igred/omero/exception/ExceptionHandler.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/exception/OMEROServerError.java b/src/main/java/fr/igred/omero/exception/OMEROServerError.java index 66e7663a..8e4a4b07 100644 --- a/src/main/java/fr/igred/omero/exception/OMEROServerError.java +++ b/src/main/java/fr/igred/omero/exception/OMEROServerError.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/exception/ServiceException.java b/src/main/java/fr/igred/omero/exception/ServiceException.java index 739b970c..507d038d 100644 --- a/src/main/java/fr/igred/omero/exception/ServiceException.java +++ b/src/main/java/fr/igred/omero/exception/ServiceException.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/exception/package-info.java b/src/main/java/fr/igred/omero/exception/package-info.java index e4523b8a..21a87a84 100644 --- a/src/main/java/fr/igred/omero/exception/package-info.java +++ b/src/main/java/fr/igred/omero/exception/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java b/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java index 0c412853..fb0c9d31 100644 --- a/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java +++ b/src/main/java/fr/igred/omero/meta/ExperimenterWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/meta/GroupWrapper.java b/src/main/java/fr/igred/omero/meta/GroupWrapper.java index 51aa61b9..e3e841a2 100644 --- a/src/main/java/fr/igred/omero/meta/GroupWrapper.java +++ b/src/main/java/fr/igred/omero/meta/GroupWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java b/src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java index aef2c7e4..89715a81 100644 --- a/src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java +++ b/src/main/java/fr/igred/omero/meta/PlaneInfoWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/meta/package-info.java b/src/main/java/fr/igred/omero/meta/package-info.java index 61b825f7..619f34a4 100644 --- a/src/main/java/fr/igred/omero/meta/package-info.java +++ b/src/main/java/fr/igred/omero/meta/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/package-info.java b/src/main/java/fr/igred/omero/package-info.java index dd4cbb1e..34ef8db5 100644 --- a/src/main/java/fr/igred/omero/package-info.java +++ b/src/main/java/fr/igred/omero/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/ChannelWrapper.java b/src/main/java/fr/igred/omero/repository/ChannelWrapper.java index 600bdb0b..cea54414 100644 --- a/src/main/java/fr/igred/omero/repository/ChannelWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ChannelWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index d1410832..fd09cf4b 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/FolderWrapper.java b/src/main/java/fr/igred/omero/repository/FolderWrapper.java index 942fb6d3..a98e1c7a 100644 --- a/src/main/java/fr/igred/omero/repository/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/repository/FolderWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -17,6 +19,7 @@ import fr.igred.omero.Client; +import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; @@ -26,7 +29,6 @@ import omero.gateway.exception.DSOutOfServiceException; import omero.gateway.facility.ROIFacility; import omero.gateway.model.FolderData; -import omero.gateway.model.ROIData; import omero.gateway.model.ROIResult; import omero.gateway.model.TagAnnotationData; import omero.model.Folder; @@ -37,8 +39,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; import static fr.igred.omero.exception.ExceptionHandler.handleServiceOrAccess; import static fr.igred.omero.exception.ExceptionHandler.handleServiceOrServer; @@ -251,18 +255,14 @@ public List getROIs(Client client) handleServiceOrAccess(e, "Cannot get ROIs from " + this); } - List roiWrappers = new ArrayList<>(roiResults.size()); - if (!roiResults.isEmpty()) { - ROIResult r = roiResults.iterator().next(); - - Collection rois = r.getROIs(); - for (ROIData roi : rois) { - ROIWrapper temp = new ROIWrapper(roi); - roiWrappers.add(temp); - } - } + List roiWrappers = roiResults.stream() + .map(ROIResult::getROIs) + .flatMap(Collection::stream) + .map(ROIWrapper::new) + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); - return roiWrappers; + return distinct(roiWrappers); } diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java index 3d1ff684..0232a39c 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -81,10 +83,10 @@ public abstract class GenericRepositoryObjectWrapper exten /** * Constructor of the class GenericRepositoryObjectWrapper. * - * @param object The object contained in the GenericRepositoryObjectWrapper. + * @param o The object contained in the GenericRepositoryObjectWrapper. */ - protected GenericRepositoryObjectWrapper(T object) { - super(object); + protected GenericRepositoryObjectWrapper(T o) { + super(o); } diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index a669a653..de8dcc16 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -17,6 +19,7 @@ import fr.igred.omero.Client; +import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; @@ -95,6 +98,47 @@ public ImageWrapper(ImageData image) { } + /** + * Sets the calibration. Planes information has to be loaded first. + * + * @param pixels The pixels. + * @param calibration The ImageJ calibration. + */ + private static void setCalibration(PixelsWrapper pixels, Calibration calibration) { + Length positionX = pixels.getPositionX(); + Length positionY = pixels.getPositionY(); + Length positionZ = pixels.getPositionZ(); + Length spacingX = pixels.getPixelSizeX(); + Length spacingY = pixels.getPixelSizeY(); + Length spacingZ = pixels.getPixelSizeZ(); + Time stepT = pixels.getTimeIncrement(); + + if (stepT == null) { + stepT = pixels.getMeanTimeInterval(); + } + + calibration.setXUnit(positionX.getSymbol()); + calibration.setYUnit(positionY.getSymbol()); + calibration.setZUnit(positionZ.getSymbol()); + calibration.xOrigin = positionX.getValue(); + calibration.yOrigin = positionY.getValue(); + calibration.zOrigin = positionZ.getValue(); + if (spacingX != null) { + calibration.pixelWidth = spacingX.getValue(); + } + if (spacingY != null) { + calibration.pixelHeight = spacingY.getValue(); + } + if (spacingZ != null) { + calibration.pixelDepth = spacingZ.getValue(); + } + if (!Double.isNaN(stepT.getValue())) { + calibration.setTimeUnit(stepT.getSymbol()); + calibration.frameInterval = stepT.getValue(); + } + } + + /** * Gets the ImageData name * @@ -170,47 +214,6 @@ protected String annotationLinkType() { } - /** - * Sets the calibration. Planes information has to be loaded first. - * - * @param pixels The pixels. - * @param calibration The ImageJ calibration. - */ - private static void setCalibration(PixelsWrapper pixels, Calibration calibration) { - Length positionX = pixels.getPositionX(); - Length positionY = pixels.getPositionY(); - Length positionZ = pixels.getPositionZ(); - Length spacingX = pixels.getPixelSizeX(); - Length spacingY = pixels.getPixelSizeY(); - Length spacingZ = pixels.getPixelSizeZ(); - Time stepT = pixels.getTimeIncrement(); - - if (stepT == null) { - stepT = pixels.getMeanTimeInterval(); - } - - calibration.setXUnit(positionX.getSymbol()); - calibration.setYUnit(positionY.getSymbol()); - calibration.setZUnit(positionZ.getSymbol()); - calibration.xOrigin = positionX.getValue(); - calibration.yOrigin = positionY.getValue(); - calibration.zOrigin = positionZ.getValue(); - if (spacingX != null) { - calibration.pixelWidth = spacingX.getValue(); - } - if (spacingY != null) { - calibration.pixelHeight = spacingY.getValue(); - } - if (spacingZ != null) { - calibration.pixelDepth = spacingZ.getValue(); - } - if (!Double.isNaN(stepT.getValue())) { - calibration.setTimeUnit(stepT.getSymbol()); - calibration.frameInterval = stepT.getValue(); - } - } - - /** * Retrieves the projects containing this image * @@ -436,17 +439,15 @@ public List getROIs(Client client) } catch (DSOutOfServiceException | DSAccessException e) { handleServiceOrAccess(e, "Cannot get ROIs from " + this); } - ROIResult r = roiResults.iterator().next(); - Collection rois = r.getROIs(); - - List roiWrappers = new ArrayList<>(rois.size()); - for (ROIData roi : rois) { - ROIWrapper temp = new ROIWrapper(roi); - roiWrappers.add(temp); - } + List roiWrappers = roiResults.stream() + .map(ROIResult::getROIs) + .flatMap(Collection::stream) + .map(ROIWrapper::new) + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); - return roiWrappers; + return distinct(roiWrappers); } diff --git a/src/main/java/fr/igred/omero/repository/PixelsWrapper.java b/src/main/java/fr/igred/omero/repository/PixelsWrapper.java index 3994686b..b7c44b9d 100644 --- a/src/main/java/fr/igred/omero/repository/PixelsWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PixelsWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java index 951d1859..ab134296 100644 --- a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -26,6 +26,7 @@ import omero.model.PlateAcquisition; import omero.model.PlateAcquisitionAnnotationLink; import omero.model.PlateAcquisitionAnnotationLinkI; +import omero.model._PlateAcquisitionOperationsNC; import java.sql.Timestamp; import java.util.concurrent.ExecutionException; @@ -48,6 +49,8 @@ public class PlateAcquisitionWrapper extends GenericRepositoryObjectWrapper getImages(Client client) throws ServiceException, AccessException, ExecutionException { - Collection datasets = getDatasets(); - - Collection> lists = new ArrayList<>(datasets.size()); - for (DatasetWrapper dataset : datasets) { - lists.add(dataset.getImages(client)); + Collection images = new ArrayList<>(0); + try { + images = client.getBrowseFacility() + .getImagesForProjects(client.getCtx(), + Collections.singletonList(data.getId())); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot get images from " + this); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); - - return distinct(images); + return distinct(wrap(images, ImageWrapper::new)); } diff --git a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java index 588f3f14..173723b8 100644 --- a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java index c94bc7ad..68e6686c 100644 --- a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/WellWrapper.java b/src/main/java/fr/igred/omero/repository/WellWrapper.java index f096ca7e..696c8923 100644 --- a/src/main/java/fr/igred/omero/repository/WellWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/repository/package-info.java b/src/main/java/fr/igred/omero/repository/package-info.java index 1ac70639..e565a013 100644 --- a/src/main/java/fr/igred/omero/repository/package-info.java +++ b/src/main/java/fr/igred/omero/repository/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/EllipseWrapper.java b/src/main/java/fr/igred/omero/roi/EllipseWrapper.java index 037c70da..6429010b 100644 --- a/src/main/java/fr/igred/omero/roi/EllipseWrapper.java +++ b/src/main/java/fr/igred/omero/roi/EllipseWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java b/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java index 9b6e77cd..b551fbc3 100644 --- a/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java +++ b/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -52,10 +54,10 @@ public abstract class GenericShapeWrapper extends GenericOb /** * Constructor of the GenericShapeWrapper class using a ShapeData. * - * @param object the shape + * @param s The shape. */ - protected GenericShapeWrapper(T object) { - super(object); + protected GenericShapeWrapper(T s) { + super(s); } diff --git a/src/main/java/fr/igred/omero/roi/LineWrapper.java b/src/main/java/fr/igred/omero/roi/LineWrapper.java index 5888ab40..700048ac 100644 --- a/src/main/java/fr/igred/omero/roi/LineWrapper.java +++ b/src/main/java/fr/igred/omero/roi/LineWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/MaskWrapper.java b/src/main/java/fr/igred/omero/roi/MaskWrapper.java index 6edb0020..6cbd2707 100644 --- a/src/main/java/fr/igred/omero/roi/MaskWrapper.java +++ b/src/main/java/fr/igred/omero/roi/MaskWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/PointWrapper.java b/src/main/java/fr/igred/omero/roi/PointWrapper.java index ae118a6d..b55de79a 100644 --- a/src/main/java/fr/igred/omero/roi/PointWrapper.java +++ b/src/main/java/fr/igred/omero/roi/PointWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/PolygonWrapper.java b/src/main/java/fr/igred/omero/roi/PolygonWrapper.java index ba64fdba..20ddb46d 100644 --- a/src/main/java/fr/igred/omero/roi/PolygonWrapper.java +++ b/src/main/java/fr/igred/omero/roi/PolygonWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/PolylineWrapper.java b/src/main/java/fr/igred/omero/roi/PolylineWrapper.java index 4a225e4d..f3d55535 100644 --- a/src/main/java/fr/igred/omero/roi/PolylineWrapper.java +++ b/src/main/java/fr/igred/omero/roi/PolylineWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index 3c57738d..fa379906 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/RectangleWrapper.java b/src/main/java/fr/igred/omero/roi/RectangleWrapper.java index c84699a8..d5882ec9 100644 --- a/src/main/java/fr/igred/omero/roi/RectangleWrapper.java +++ b/src/main/java/fr/igred/omero/roi/RectangleWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/ShapeList.java b/src/main/java/fr/igred/omero/roi/ShapeList.java index dbb25414..6b4483b9 100644 --- a/src/main/java/fr/igred/omero/roi/ShapeList.java +++ b/src/main/java/fr/igred/omero/roi/ShapeList.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/TextWrapper.java b/src/main/java/fr/igred/omero/roi/TextWrapper.java index d6cb749b..67e7242e 100644 --- a/src/main/java/fr/igred/omero/roi/TextWrapper.java +++ b/src/main/java/fr/igred/omero/roi/TextWrapper.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/roi/package-info.java b/src/main/java/fr/igred/omero/roi/package-info.java index 6bdfdec0..b2901e72 100644 --- a/src/main/java/fr/igred/omero/roi/package-info.java +++ b/src/main/java/fr/igred/omero/roi/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/util/LibraryChecker.java b/src/main/java/fr/igred/omero/util/LibraryChecker.java index 10bd02c8..013dda5b 100644 --- a/src/main/java/fr/igred/omero/util/LibraryChecker.java +++ b/src/main/java/fr/igred/omero/util/LibraryChecker.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/main/java/fr/igred/omero/util/package-info.java b/src/main/java/fr/igred/omero/util/package-info.java index 4b1b1d60..06c28503 100644 --- a/src/main/java/fr/igred/omero/util/package-info.java +++ b/src/main/java/fr/igred/omero/util/package-info.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/AccessExceptionTest.java b/src/test/java/fr/igred/omero/AccessExceptionTest.java index f8b2bc87..3de28525 100644 --- a/src/test/java/fr/igred/omero/AccessExceptionTest.java +++ b/src/test/java/fr/igred/omero/AccessExceptionTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/BasicTest.java b/src/test/java/fr/igred/omero/BasicTest.java index 12667a59..74ca4cfe 100644 --- a/src/test/java/fr/igred/omero/BasicTest.java +++ b/src/test/java/fr/igred/omero/BasicTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/ClientTest.java b/src/test/java/fr/igred/omero/ClientTest.java index af5466b1..cde1603e 100644 --- a/src/test/java/fr/igred/omero/ClientTest.java +++ b/src/test/java/fr/igred/omero/ClientTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -99,7 +101,7 @@ void testGetSingleDataset() throws Exception { @Test void testGetAllDatasets() throws Exception { Collection datasets = client.getDatasets(); - assertEquals(3, datasets.size()); + assertEquals(4, datasets.size()); } diff --git a/src/test/java/fr/igred/omero/ConnectionTest.java b/src/test/java/fr/igred/omero/ConnectionTest.java index 2f789f63..5dcdd6c5 100644 --- a/src/test/java/fr/igred/omero/ConnectionTest.java +++ b/src/test/java/fr/igred/omero/ConnectionTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/ExceptionTest.java b/src/test/java/fr/igred/omero/ExceptionTest.java index f8d1200b..6fd6c965 100644 --- a/src/test/java/fr/igred/omero/ExceptionTest.java +++ b/src/test/java/fr/igred/omero/ExceptionTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/LoggingExtension.java b/src/test/java/fr/igred/omero/LoggingExtension.java index 9c1da577..a32bdd80 100644 --- a/src/test/java/fr/igred/omero/LoggingExtension.java +++ b/src/test/java/fr/igred/omero/LoggingExtension.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/RootTest.java b/src/test/java/fr/igred/omero/RootTest.java index e703ee67..c2d5227b 100644 --- a/src/test/java/fr/igred/omero/RootTest.java +++ b/src/test/java/fr/igred/omero/RootTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/SudoTest.java b/src/test/java/fr/igred/omero/SudoTest.java index 28fe11e1..fa5786be 100644 --- a/src/test/java/fr/igred/omero/SudoTest.java +++ b/src/test/java/fr/igred/omero/SudoTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/TestObject.java b/src/test/java/fr/igred/omero/TestObject.java index 947a18d6..65ffb555 100644 --- a/src/test/java/fr/igred/omero/TestObject.java +++ b/src/test/java/fr/igred/omero/TestObject.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/UserTest.java b/src/test/java/fr/igred/omero/UserTest.java index b88946c5..52bfaa2d 100644 --- a/src/test/java/fr/igred/omero/UserTest.java +++ b/src/test/java/fr/igred/omero/UserTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java index caca2512..46a5fba2 100644 --- a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java +++ b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/annotations/TableTest.java b/src/test/java/fr/igred/omero/annotations/TableTest.java index fb8a8e2f..4265ec98 100644 --- a/src/test/java/fr/igred/omero/annotations/TableTest.java +++ b/src/test/java/fr/igred/omero/annotations/TableTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/annotations/TagTest.java b/src/test/java/fr/igred/omero/annotations/TagTest.java index 2dcb2841..730c6c4e 100644 --- a/src/test/java/fr/igred/omero/annotations/TagTest.java +++ b/src/test/java/fr/igred/omero/annotations/TagTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/meta/ExperimenterTest.java b/src/test/java/fr/igred/omero/meta/ExperimenterTest.java index 5939424a..8616703f 100644 --- a/src/test/java/fr/igred/omero/meta/ExperimenterTest.java +++ b/src/test/java/fr/igred/omero/meta/ExperimenterTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/meta/GroupTest.java b/src/test/java/fr/igred/omero/meta/GroupTest.java index c7e2d757..aa8b5b43 100644 --- a/src/test/java/fr/igred/omero/meta/GroupTest.java +++ b/src/test/java/fr/igred/omero/meta/GroupTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/meta/PlaneInfoWrapperTest.java b/src/test/java/fr/igred/omero/meta/PlaneInfoWrapperTest.java index 3e1dce86..a8a4a14c 100644 --- a/src/test/java/fr/igred/omero/meta/PlaneInfoWrapperTest.java +++ b/src/test/java/fr/igred/omero/meta/PlaneInfoWrapperTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/DatasetTest.java b/src/test/java/fr/igred/omero/repository/DatasetTest.java index cd7ebbaa..ba4ca425 100644 --- a/src/test/java/fr/igred/omero/repository/DatasetTest.java +++ b/src/test/java/fr/igred/omero/repository/DatasetTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/FolderTest.java b/src/test/java/fr/igred/omero/repository/FolderTest.java index ffc8ee2e..c7440045 100644 --- a/src/test/java/fr/igred/omero/repository/FolderTest.java +++ b/src/test/java/fr/igred/omero/repository/FolderTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/ImageImportTest.java b/src/test/java/fr/igred/omero/repository/ImageImportTest.java index cce29a91..22e165d9 100644 --- a/src/test/java/fr/igred/omero/repository/ImageImportTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageImportTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/ImageTest.java b/src/test/java/fr/igred/omero/repository/ImageTest.java index 302bdce9..fac49799 100644 --- a/src/test/java/fr/igred/omero/repository/ImageTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/PixelsTest.java b/src/test/java/fr/igred/omero/repository/PixelsTest.java index 956e508c..9fa634b1 100644 --- a/src/test/java/fr/igred/omero/repository/PixelsTest.java +++ b/src/test/java/fr/igred/omero/repository/PixelsTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java index 368e5b7a..a7d11ccf 100644 --- a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/PlateTest.java b/src/test/java/fr/igred/omero/repository/PlateTest.java index b46c8ac7..4e60673a 100644 --- a/src/test/java/fr/igred/omero/repository/PlateTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/ProjectTest.java b/src/test/java/fr/igred/omero/repository/ProjectTest.java index 463b3d42..a023d13b 100644 --- a/src/test/java/fr/igred/omero/repository/ProjectTest.java +++ b/src/test/java/fr/igred/omero/repository/ProjectTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -41,7 +43,7 @@ void testGetDatasetFromProject() throws Exception { List datasets = project.getDatasets(); - assertEquals(2, datasets.size()); + assertEquals(3, datasets.size()); } diff --git a/src/test/java/fr/igred/omero/repository/ScreenTest.java b/src/test/java/fr/igred/omero/repository/ScreenTest.java index 7a7e1540..c7c53aa8 100644 --- a/src/test/java/fr/igred/omero/repository/ScreenTest.java +++ b/src/test/java/fr/igred/omero/repository/ScreenTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/WellSampleTest.java b/src/test/java/fr/igred/omero/repository/WellSampleTest.java index 53f7401e..68c7e419 100644 --- a/src/test/java/fr/igred/omero/repository/WellSampleTest.java +++ b/src/test/java/fr/igred/omero/repository/WellSampleTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/repository/WellTest.java b/src/test/java/fr/igred/omero/repository/WellTest.java index bd67d019..27fc5da5 100644 --- a/src/test/java/fr/igred/omero/repository/WellTest.java +++ b/src/test/java/fr/igred/omero/repository/WellTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java index 380da616..63bbe0fb 100644 --- a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java +++ b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/roi/ROITest.java b/src/test/java/fr/igred/omero/roi/ROITest.java index 47c67ece..f0946f00 100644 --- a/src/test/java/fr/igred/omero/roi/ROITest.java +++ b/src/test/java/fr/igred/omero/roi/ROITest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/roi/ShapeErrorTest.java b/src/test/java/fr/igred/omero/roi/ShapeErrorTest.java index 7ffb1c29..51098da6 100644 --- a/src/test/java/fr/igred/omero/roi/ShapeErrorTest.java +++ b/src/test/java/fr/igred/omero/roi/ShapeErrorTest.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/roi/ShapeTest.java b/src/test/java/fr/igred/omero/roi/ShapeTest.java index d958143c..1c7c1be3 100644 --- a/src/test/java/fr/igred/omero/roi/ShapeTest.java +++ b/src/test/java/fr/igred/omero/roi/ShapeTest.java @@ -5,9 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java b/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java index d431ad04..b6c769c4 100644 --- a/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java +++ b/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java @@ -5,11 +5,11 @@ * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version. - + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin * Street, Fifth Floor, Boston, MA 02110-1301, USA. From c394800ca8f9732e86aa8b18faef148e9cb9177c Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 15:04:11 +0100 Subject: [PATCH 02/14] Bump version, improve readability from LibraryCheckerTest and remove useless constructor --- pom.xml | 2 +- src/main/java/fr/igred/omero/Client.java | 2 +- src/main/java/fr/igred/omero/GatewayWrapper.java | 10 ---------- src/test/java/fr/igred/omero/LoggingExtension.java | 8 ++++++++ .../java/fr/igred/omero/util/LibraryCheckerTest.java | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 41c3f39c..4a2be251 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ fr.igred simple-omero-client - 5.10.1 + 5.11.0 jar Simple OMERO Client diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index ce6d3e32..d6873dc8 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -79,7 +79,7 @@ public class Client extends GatewayWrapper { * Constructor of the Client class. Initializes the gateway. */ public Client() { - super(null); + this(null, null, null); } diff --git a/src/main/java/fr/igred/omero/GatewayWrapper.java b/src/main/java/fr/igred/omero/GatewayWrapper.java index 6b9b90e4..8883d3a9 100644 --- a/src/main/java/fr/igred/omero/GatewayWrapper.java +++ b/src/main/java/fr/igred/omero/GatewayWrapper.java @@ -68,16 +68,6 @@ public abstract class GatewayWrapper { private ExperimenterWrapper user; - /** - * Abstract constructor of the GatewayWrapper class. - * - * @param gateway The Gateway. - */ - protected GatewayWrapper(Gateway gateway) { - this(gateway, null, null); - } - - /** * Abstract constructor of the GatewayWrapper class. *

Null arguments will be replaced with default empty objects. diff --git a/src/test/java/fr/igred/omero/LoggingExtension.java b/src/test/java/fr/igred/omero/LoggingExtension.java index a32bdd80..96ecce10 100644 --- a/src/test/java/fr/igred/omero/LoggingExtension.java +++ b/src/test/java/fr/igred/omero/LoggingExtension.java @@ -202,4 +202,12 @@ private void hideOutputs() { System.setErr(logFile); } + + @Override + public String toString() { + return "LoggingExtension{" + + "start=" + start + + "}"; + } + } diff --git a/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java b/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java index b6c769c4..4f1ab800 100644 --- a/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java +++ b/src/test/java/fr/igred/omero/util/LibraryCheckerTest.java @@ -45,7 +45,7 @@ void checkAvailableLibraries() { } - @ParameterizedTest + @ParameterizedTest(name = "{0}") @ValueSource(strings = {"omero-gateway", "omero-model", "omero-blitz", From ad1f4f6b1536e5cf8cf2b2e20dbe8f13f21fd861 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 15:59:07 +0100 Subject: [PATCH 03/14] Change how ROI names are converted to/from ImageJ (using "ROI_NAME" property) --- README.md | 25 ++- .../igred/omero/annotations/TableWrapper.java | 177 +++++++++++------- .../java/fr/igred/omero/roi/ROIWrapper.java | 94 +++++++--- .../omero/annotations/ImageJTableTest.java | 2 +- .../fr/igred/omero/roi/ROI2ImageJTest.java | 13 +- 5 files changed, 208 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 58da3083..f3fb7920 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ List datasets = client.getDatasets(); These objects can then be used to retrieve their children: ```java -for(DatasetWrapper dataset:datasets){ +for (DatasetWrapper dataset:datasets) { List images = dataset.getImages(client); //... } @@ -108,12 +108,29 @@ List rois = image.getROIs(client); They can also be converted from or to ImageJ Rois: ```java -// The property is a string used to create 3D/4D ROIs in OMERO, by grouping shapes sharing the same value (used to name the ROI) -List omeroRois = ROIWrapper.fromImageJ(ijRois, property); - +// The property is a string used to create 3D/4D ROIs in OMERO, by grouping shapes sharing the same value (e.g. local index). +// The ROI name can be set/accessed using the property ROI.ijNameProperty(property). +// The OMERO IDs are available through the property ROI.ijIDProperty(property). +// The ijNameProperty() and ijIDProperty() methods append "_NAME" and "_ID" to the property (respectively). +// By default, the property is "ROI", and thus, the name property is "ROI_NAME" and the ID property, "ROI_ID". ROIWrapper roi = new ROIWrapper(); +roi.setName("ROI name"); roi.addShape(new RectangleWrapper(0, 0, 5, 5)); List imagejRois = roi.toImageJ(); +String name = imagejRois.get(0).getProperty(ROI.ijNameProperty(property)); +String ID = imagejRois.get(0).getProperty(ROI.ijIDProperty(property)); + +// Conversely ImageJ Rois can be converted to OMERO from ImageJ using "ROIWrapper::fromImageJ" +Roi ijRoi1 = new Roi(1.0, 2.0, 3.0, 4.0); +ijRoi1.setProperty(property, 0); +ijRoi1.setProperty(ROIWrapper.ijNameProperty(property), "Name 1"); +Roi ijRoi2 = new Roi(2.0, 3.0, 4.0, 5.0); +ijRoi2.setProperty(property, 1); +ijRoi2.setProperty(ROIWrapper.ijNameProperty(property), "Name 2"); +List ijRois = new ArrayList(2); +ijRois.add(ijRoi1); +ijRois.add(ijRoi2); +List rois = ROIWrapper.fromImageJ(ijRois); ``` ## License diff --git a/src/main/java/fr/igred/omero/annotations/TableWrapper.java b/src/main/java/fr/igred/omero/annotations/TableWrapper.java index 3998dcb6..4d76d580 100644 --- a/src/main/java/fr/igred/omero/annotations/TableWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TableWrapper.java @@ -38,14 +38,16 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.text.NumberFormat; +import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; +import java.util.function.BiFunction; + +import static java.util.stream.Collectors.toMap; /** @@ -267,52 +269,85 @@ private static void renameImageColumn(ResultsTable results) { *

    *
  • The ROI local IDs (indices, assumed by default)
  • *
  • The ROI OMERO IDs (if indices do not map)
  • + *
  • The ROI names (if IDs do not map or if the column contains Strings)
  • *
  • The ShapeData names (if the column contains Strings)
  • *
* * @param roiCol Variable column containing ROI info - * @param name2roi ROI names map + * @param index2roi ROI indices map * @param id2roi ROI IDs map + * @param name2roi ROI names map * @param shapeName2roi ROI shape names map * * @return A ROIData column. */ - private static ROIData[] columnToROIColumn(Variable[] roiCol, - Map name2roi, - Map id2roi, - Map shapeName2roi) { - ROIData[] roiColumn = EMPTY_ROI; + private static ROIData[] propertyColumnToROIColumn(Variable[] roiCol, + Map index2roi, + Map id2roi, + Map name2roi, + Map shapeName2roi) { + ROIData[] roiColumn; if (isColumnNumeric(roiCol)) { - List ids = Arrays.stream(roiCol) - .map(Variable::getValue) - .map(Double::longValue) - .collect(Collectors.toList()); - - List numericNames = Arrays.stream(roiCol) - .map(Variable::toString) - .collect(Collectors.toList()); - - name2roi.keySet().retainAll(numericNames); - id2roi.keySet().retainAll(ids); - boolean isIndices = name2roi.size() >= id2roi.size(); - if (isIndices) { - roiColumn = numericNames.stream().map(name2roi::get).toArray(ROIData[]::new); - if (Arrays.asList(roiColumn).contains(null)) isIndices = false; - } - if (!isIndices) { - roiColumn = ids.stream().map(id2roi::get).toArray(ROIData[]::new); - } + roiColumn = idColumnToROIColumn(roiCol, index2roi); + if (roiColumn.length == 0) roiColumn = idColumnToROIColumn(roiCol, id2roi); + if (roiColumn.length == 0) roiColumn = Arrays.stream(roiCol) + .map(Variable::toString) + .map(name2roi::get) + .toArray(ROIData[]::new); } else { + roiColumn = labelColumnToROIColumn(roiCol, name2roi, shapeName2roi, (m, s) -> s); + } + if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; + return roiColumn; + } + + + /** + * Creates a ROIData column from a Variable column containing the ROI OMERO IDs. + * + * @param roiCol Variable column containing ROI info + * @param id2roi ROI IDs map + * + * @return A ROIData column. + */ + private static ROIData[] idColumnToROIColumn(Variable[] roiCol, Map id2roi) { + ROIData[] roiColumn = Arrays.stream(roiCol) + .map(Variable::getValue) + .map(Double::longValue) + .map(id2roi::get).toArray(ROIData[]::new); + // If roiColumn contains null, we return an empty array + if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; + return roiColumn; + } + + + /** + * Creates a ROIData column from a Variable column containing the ROI OMERO IDs. + * + * @param roiCol Variable column containing ROI info + * @param name2roi ROI names map + * @param shapeName2roi ROI shape names map + * + * @return A ROIData column. + */ + private static ROIData[] labelColumnToROIColumn(Variable[] roiCol, + Map name2roi, + Map shapeName2roi, + BiFunction, ? super String, String> filter) { + ROIData[] roiColumn = Arrays.stream(roiCol) + .map(Variable::getString) + .map(s -> filter.apply(shapeName2roi, s)) + .map(shapeName2roi::get) + .toArray(ROIData[]::new); + if (Arrays.asList(roiColumn).contains(null)) { roiColumn = Arrays.stream(roiCol) - .map(v -> name2roi.get(v.getString())) + .map(Variable::getString) + .map(s -> filter.apply(name2roi, s)) + .map(name2roi::get) .toArray(ROIData[]::new); - // If the names don't all match ROIs, try with shape names - if (Arrays.asList(roiColumn).contains(null)) { - roiColumn = Arrays.stream(roiCol) - .map(v -> shapeName2roi.get(v.getString())) - .toArray(ROIData[]::new); - } } + // If roiColumn contains null, we return an empty array + if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; return roiColumn; } @@ -325,7 +360,7 @@ private static ROIData[] columnToROIColumn(Variable[] roiCol, *

If neither column is present, it will check the {@value LABEL} column for the ROI names inside. * * @param results An ImageJ results table. - * @param rois A list of OMERO ROIs (each ID should be present only once). + * @param rois A list of OMERO ROIs (each ROI (ID) should be present only once). * @param ijRois A list of ImageJ Rois. * @param roiProperty The Roi property storing the local ROI IDs. * @@ -339,46 +374,47 @@ private static ROIData[] createROIColumn(ResultsTable results, ROIData[] roiColumn = EMPTY_ROI; - Map id2roi = rois.stream().collect(Collectors.toMap(ROIWrapper::getId, ROIWrapper::asROIData)); - - Map name2roi = new HashMap<>(ijRois.size()); - Map shapeName2roi = new HashMap<>(ijRois.size()); - for (Roi ijRoi : ijRois) { - String name = ijRoi.getProperty(roiProperty); - Long id = safeParseLong(ijRoi.getProperty(roiIdProperty)); - if (id != null) { - ROIData roi = id2roi.get(id); - shapeName2roi.put(ijRoi.getName(), roi); - if (name != null) name2roi.putIfAbsent(name, roi); - } - } + Map id2roi = rois.stream().collect(toMap(ROIWrapper::getId, ROIWrapper::asROIData)); + Map name2roi = rois.stream() + .filter(r -> !r.getName().isEmpty()) + .collect(toMap(ROIWrapper::getName, ROIWrapper::asROIData)); + + Map index2roi = ijRois.stream() + .map(r -> new SimpleEntry<>(safeParseLong(r.getProperty(roiProperty)), + safeParseLong(r.getProperty(roiIdProperty)))) + .filter(p -> p.getKey() != null) + .filter(p -> p.getValue() != null) + .collect(toMap(SimpleEntry::getKey, + p -> id2roi.get(p.getValue()), + (x1, x2) -> x1)); + + Map shape2roi = ijRois.stream() + .map(r -> new SimpleEntry<>(r.getName(), + safeParseLong(r.getProperty(roiIdProperty)))) + .filter(p -> p.getKey() != null) + .filter(p -> p.getValue() != null) + .collect(toMap(SimpleEntry::getKey, + p -> id2roi.get(p.getValue()), + (x1, x2) -> x1)); String[] headings = results.getHeadings(); - if (results.columnExists(roiProperty)) { Variable[] roiCol = results.getColumnAsVariables(roiProperty); - roiColumn = columnToROIColumn(roiCol, name2roi, id2roi, shapeName2roi); - // If roiColumn contains null, we return an empty array - if (Arrays.asList(roiColumn).contains(null)) return EMPTY_ROI; - results.deleteColumn(roiProperty); - } else if (results.columnExists(roiIdProperty)) { + roiColumn = propertyColumnToROIColumn(roiCol, index2roi, id2roi, name2roi, shape2roi); + if (roiColumn.length != 0) results.deleteColumn(roiProperty); + } + if (roiColumn.length == 0 && results.columnExists(roiIdProperty)) { Variable[] roiCol = results.getColumnAsVariables(roiIdProperty); - List ids = Arrays.stream(roiCol) - .map(Variable::getValue) - .map(Double::longValue) - .collect(Collectors.toList()); - roiColumn = ids.stream().map(id2roi::get).toArray(ROIData[]::new); - // If roiColumn contains null, we return an empty array - if (Arrays.asList(roiColumn).contains(null)) return EMPTY_ROI; - results.deleteColumn(roiIdProperty); - } else if (Arrays.asList(headings).contains(LABEL)) { - String[] roiNames = Arrays.stream(results.getColumnAsVariables(LABEL)) - .map(Variable::getString) - .map(s -> shapeName2roi.keySet().stream().filter(s::contains) - .findFirst().orElse(null)) - .toArray(String[]::new); - roiColumn = Arrays.stream(roiNames).map(shapeName2roi::get).toArray(ROIData[]::new); - if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; + roiColumn = idColumnToROIColumn(roiCol, id2roi); + if (roiColumn.length != 0) results.deleteColumn(roiIdProperty); + } + if (roiColumn.length == 0 && Arrays.asList(headings).contains(LABEL)) { + Variable[] roiCol = results.getColumnAsVariables(LABEL); + roiColumn = labelColumnToROIColumn(roiCol, name2roi, shape2roi, (m, s) -> m.keySet() + .stream() + .filter(s::contains) + .findFirst() + .orElse(null)); } return roiColumn; @@ -730,6 +766,7 @@ public TableData createTable() { public void saveAs(String path, char delimiter) throws FileNotFoundException, UnsupportedEncodingException { NumberFormat formatter = NumberFormat.getInstance(); formatter.setMaximumFractionDigits(4); + formatter.setGroupingUsed(false); StringBuilder sb = new StringBuilder(10 * columnCount * rowCount); diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index fa379906..a81e344d 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -35,11 +35,15 @@ import omero.model._RoiOperationsNC; import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.regex.Pattern; import java.util.stream.Collectors; import static fr.igred.omero.exception.ExceptionHandler.handleServiceOrServer; @@ -116,6 +120,20 @@ public static String ijIDProperty(String property) { } + /** + * Returns the name property corresponding to input local ID property (appends "_NAME" to said property). + * + * @param property The property where the 4D ROI local ID is stored, defaults to {@value IJ_PROPERTY} if null or + * empty. + * + * @return See above. + */ + static String ijNameProperty(String property) { + property = checkProperty(property); + return property + "_NAME"; + } + + /** * Converts an ImageJ list of ROIs to a list of OMERO ROIs * @@ -132,32 +150,56 @@ public static List fromImageJ(List ijRois) { * Converts an ImageJ list of ROIs to a list of OMERO ROIs * * @param ijRois A list of ImageJ ROIs. - * @param property The property where 4D ROI local ID is stored. Defaults to {@value IJ_PROPERTY} if null or empty. + * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or empty. * * @return The converted list of OMERO ROIs. */ public static List fromImageJ(List ijRois, String property) { + return fromImageJ(ijRois, property, ROIWrapper::new, GenericShapeWrapper::fromImageJ); + } + + + /** + * Converts an ImageJ list of ROIs to a list of OMERO ROIs using the provided constructor and shape converter. + * + * @param ijRois A list of ImageJ ROIs. + * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or + * empty. + * @param constructor A constructor to create ROI instances. + * @param converter A function to convert an IJ Roi to a list of OMERO Shapes. + * + * @return The converted list of OMERO ROIs. + */ + private static List fromImageJ(List ijRois, + String property, + Supplier constructor, + Function>> converter) { property = checkProperty(property); - Map rois4D = new TreeMap<>(); + Pattern intPattern = Pattern.compile("-?\\d+"); + + Map rois4D = new TreeMap<>(); + Map names = new TreeMap<>(); Map shape2roi = new TreeMap<>(); for (int i = 0; i < ijRois.size(); i++) { String value = ijRois.get(i).getProperty(property); - if (value != null && !value.trim().isEmpty()) { - rois4D.computeIfAbsent(value, val -> new ROIWrapper()); - shape2roi.put(i, rois4D.get(value)); + String name = ijRois.get(i).getProperty(ijNameProperty(property)); + if (value != null && intPattern.matcher(value).matches()) { + long id = Long.parseLong(value); + rois4D.computeIfAbsent(id, v -> constructor.get()); + names.putIfAbsent(id, name); + shape2roi.put(i, rois4D.get(id)); } else { - shape2roi.put(i, new ROIWrapper()); + shape2roi.put(i, constructor.get()); } } - - rois4D.forEach((name, roi) -> roi.setName(name)); + rois4D.forEach((id, roi) -> roi.setName(names.get(id))); for (Map.Entry entry : shape2roi.entrySet()) { ij.gui.Roi ijRoi = ijRois.get(entry.getKey()); ROIWrapper roi = entry.getValue(); - roi.addShape(ijRoi); + roi.addShapes(converter.apply(ijRoi)); } return shape2roi.values().stream().distinct().collect(Collectors.toList()); } @@ -184,8 +226,23 @@ public static List toImageJ(List rois) { * @return The converted list of ImageJ ROIs. */ public static List toImageJ(List rois, String property) { + return toImageJ(rois, property, true); + } + + + /** + * Converts an OMERO list of ROIs to a list of ImageJ ROIs + * + * @param rois A list of OMERO ROIs. + * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or empty. + * @param groupRois Whether ImageJ Rois belonging to the same OMERO ROI should be grouped or not. + * + * @return The converted list of ImageJ ROIs. + */ + public static List toImageJ(Collection rois, String property, boolean groupRois) { property = checkProperty(property); final int maxGroups = 255; + groupRois = groupRois && rois.size() < maxGroups; int nShapes = rois.stream().map(ROIWrapper::asROIData).mapToInt(ROIData::getShapeCount).sum(); @@ -194,13 +251,12 @@ public static List toImageJ(List rois, String int index = 1; for (ROIWrapper roi : rois) { String name = roi.getName(); - if (name.trim().isEmpty()) { - name = "SOC_INDEX_" + index; - } + List shapes = roi.toImageJ(property); for (ij.gui.Roi r : shapes) { - r.setProperty(property, name); - if (rois.size() < maxGroups) { + r.setProperty(property, String.valueOf(index)); + r.setProperty(ijNameProperty(property), name); + if (groupRois) { r.setGroup(index); } } @@ -418,14 +474,4 @@ public List toImageJ(String property) { return rois; } - - /** - * Adds an ImageJ ROI to an OMERO ROI. - * - * @param ijRoi The ImageJ ROI. - */ - private void addShape(ij.gui.Roi ijRoi) { - addShapes(GenericShapeWrapper.fromImageJ(ijRoi)); - } - } \ No newline at end of file diff --git a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java index 46a5fba2..c62ab880 100644 --- a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java +++ b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java @@ -138,7 +138,7 @@ public void cleanUp() { @Test void testCreateTableWithROIsFromIJResults1() throws Exception { List rois = createAndSaveROI(client, image, "ROI_1"); - List ijRois = ROIWrapper.toImageJ(rois, null); + List ijRois = ROIWrapper.toImageJ(rois, null, false); String label = image.getName(); diff --git a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java index 63bbe0fb..e65a25af 100644 --- a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java +++ b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java @@ -63,13 +63,14 @@ void testROIsFromImageJ() { TextRoi textRoi = new TextRoi(3.0, 4.0, "Text"); textRoi.setName("text"); - textRoi.setProperty("ROI", "text"); + textRoi.setProperty("ROI", "24"); + textRoi.setProperty("ROI_NAME", "text"); rois.add(textRoi); OvalRoi ovalRoi = new OvalRoi(4.0, 5.0, 6.0, 7.0); ovalRoi.setName("oval"); ovalRoi.setPosition(1, 0, 3); - ovalRoi.setProperty("ROI", "24"); + ovalRoi.setProperty("ROI", " "); rois.add(ovalRoi); Arrow arrow = new Arrow(2.0, 3.0, 3.0, 4.0); @@ -87,11 +88,13 @@ void testROIsFromImageJ() { PolygonRoi polylineRoi = new PolygonRoi(x2, y2, Roi.POLYLINE); polylineRoi.setPosition(1, 1, 2); polylineRoi.setProperty("ROI", "23"); + polylineRoi.setProperty("ROI_NAME", "23"); rois.add(polylineRoi); PolygonRoi polygonRoi = new PolygonRoi(x2, y2, Roi.POLYGON); polygonRoi.setPosition(1, 1, 1); polygonRoi.setProperty("ROI", "23"); + polygonRoi.setProperty("ROI_NAME", "233"); rois.add(polygonRoi); EllipseRoi ellipseRoi = new EllipseRoi(0.0, 0.0, 5.0, 5.0, 0.5); @@ -109,6 +112,7 @@ void testROIsFromImageJ() { assertEquals(9, omeroROIs.size()); assertEquals(1, omeroROIs.stream().filter(r -> "text".equals(r.getName())).count()); assertEquals(1, omeroROIs.stream().filter(r -> "23".equals(r.getName())).count()); + assertEquals(0, omeroROIs.stream().filter(r -> "233".equals(r.getName())).count()); assertEquals(0, omeroROIs.stream().filter(r -> "invalid".equals(r.getName())).count()); } @@ -197,8 +201,9 @@ void testROItoImageJ() { List ijRois = ROIWrapper.toImageJ(rois); assertEquals(nRois, ijRois.size()); - assertEquals("2", ijRois.get(0).getProperty("ROI")); - assertEquals("SOC_INDEX_2", ijRois.get(nRois - 1).getProperty("ROI")); + assertEquals("2", ijRois.get(0).getProperty("ROI_NAME")); + assertEquals("2", ijRois.get(nRois - 1).getProperty("ROI")); + assertNull(ijRois.get(nRois - 1).getProperty("ROI_NAME")); } From caf1cfa59450cb706cbdba30d87a9e4bd9e9fe07 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 16:32:11 +0100 Subject: [PATCH 04/14] Add link methods to repository objects and asDataObject to ObjectWrapper --- src/main/java/fr/igred/omero/Client.java | 2 +- .../java/fr/igred/omero/GatewayWrapper.java | 8 +- .../fr/igred/omero/GenericObjectWrapper.java | 10 ++ .../annotations/FileAnnotationWrapper.java | 5 +- .../annotations/MapAnnotationWrapper.java | 5 +- .../igred/omero/annotations/TableWrapper.java | 9 +- .../annotations/TagAnnotationWrapper.java | 6 +- .../igred/omero/meta/ExperimenterWrapper.java | 5 +- .../fr/igred/omero/meta/GroupWrapper.java | 5 +- .../fr/igred/omero/meta/PlaneInfoWrapper.java | 5 +- .../omero/repository/ChannelWrapper.java | 7 +- .../omero/repository/DatasetWrapper.java | 7 +- .../igred/omero/repository/FolderWrapper.java | 21 +-- .../GenericRepositoryObjectWrapper.java | 166 +++++++++++------- .../igred/omero/repository/ImageWrapper.java | 13 +- .../repository/PlateAcquisitionWrapper.java | 21 +-- .../igred/omero/repository/PlateWrapper.java | 5 +- .../omero/repository/ProjectWrapper.java | 7 +- .../igred/omero/repository/ScreenWrapper.java | 5 +- .../omero/repository/WellSampleWrapper.java | 9 +- .../igred/omero/repository/WellWrapper.java | 7 +- .../igred/omero/roi/GenericShapeWrapper.java | 5 +- .../java/fr/igred/omero/roi/LineWrapper.java | 4 +- .../java/fr/igred/omero/roi/ROIWrapper.java | 13 +- .../fr/igred/omero/AccessExceptionTest.java | 2 +- src/test/java/fr/igred/omero/SudoTest.java | 2 +- .../fr/igred/omero/annotations/TableTest.java | 16 +- .../igred/omero/repository/DatasetTest.java | 6 +- .../fr/igred/omero/repository/FolderTest.java | 2 +- .../omero/repository/ImageImportTest.java | 16 +- .../fr/igred/omero/repository/ImageTest.java | 33 +++- .../repository/PlateAcquisitionTest.java | 2 +- .../fr/igred/omero/repository/PlateTest.java | 2 +- .../igred/omero/repository/ProjectTest.java | 10 +- .../fr/igred/omero/repository/ScreenTest.java | 2 +- .../fr/igred/omero/repository/WellTest.java | 2 +- .../fr/igred/omero/roi/ROI2ImageJTest.java | 10 +- 37 files changed, 272 insertions(+), 183 deletions(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index d6873dc8..658dc8cc 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -895,7 +895,7 @@ public Client sudoGetUser(String username) throws ServiceException, AccessExcept ExperimenterWrapper sudoUser = getUser(username); SecurityContext context = new SecurityContext(sudoUser.getDefaultGroup().getId()); - context.setExperimenter(sudoUser.asExperimenterData()); + context.setExperimenter(sudoUser.asDataObject()); context.sudo(); return new Client(this.getGateway(), context, sudoUser); diff --git a/src/main/java/fr/igred/omero/GatewayWrapper.java b/src/main/java/fr/igred/omero/GatewayWrapper.java index 8883d3a9..9d788362 100644 --- a/src/main/java/fr/igred/omero/GatewayWrapper.java +++ b/src/main/java/fr/igred/omero/GatewayWrapper.java @@ -143,7 +143,7 @@ public long getCurrentGroupId() { public String getSessionId() throws ServiceException { String sessionId; try { - sessionId = gateway.getSessionId(user.asExperimenterData()); + sessionId = gateway.getSessionId(user.asDataObject()); } catch (DSOutOfServiceException e) { throw new ServiceException("Could not retrieve session ID", e, e.getConnectionStatus()); } @@ -231,7 +231,7 @@ public void connect(LoginCredentials cred) throws ServiceException { throw new ServiceException(oos, oos.getConnectionStatus()); } this.ctx = new SecurityContext(user.getGroupId()); - this.ctx.setExperimenter(this.user.asExperimenterData()); + this.ctx.setExperimenter(this.user.asDataObject()); this.ctx.setServerInformation(cred.getServer()); } @@ -244,7 +244,7 @@ public void disconnect() { boolean sudo = ctx.isSudo(); user = new ExperimenterWrapper(new ExperimenterData()); ctx = new SecurityContext(-1); - ctx.setExperimenter(user.asExperimenterData()); + ctx.setExperimenter(user.asDataObject()); if (sudo) { gateway = new Gateway(gateway.getLogger()); } else { @@ -262,7 +262,7 @@ public void disconnect() { public void switchGroup(long groupId) { boolean sudo = ctx.isSudo(); ctx = new SecurityContext(groupId); - ctx.setExperimenter(user.asExperimenterData()); + ctx.setExperimenter(user.asDataObject()); if (sudo) ctx.sudo(); } diff --git a/src/main/java/fr/igred/omero/GenericObjectWrapper.java b/src/main/java/fr/igred/omero/GenericObjectWrapper.java index b5d3a17a..cf391dd4 100644 --- a/src/main/java/fr/igred/omero/GenericObjectWrapper.java +++ b/src/main/java/fr/igred/omero/GenericObjectWrapper.java @@ -132,6 +132,16 @@ public static > List distinct(Collection result) { /** - * Gets the MapAnnotationData contained. - * * @return the {@link MapAnnotationData} contained. + * + * @deprecated Gets the MapAnnotationData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public MapAnnotationData asMapAnnotationData() { return data; } diff --git a/src/main/java/fr/igred/omero/annotations/TableWrapper.java b/src/main/java/fr/igred/omero/annotations/TableWrapper.java index 4d76d580..feecd55e 100644 --- a/src/main/java/fr/igred/omero/annotations/TableWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TableWrapper.java @@ -19,6 +19,7 @@ import fr.igred.omero.Client; +import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.ImageWrapper; @@ -189,7 +190,7 @@ public TableWrapper(Client client, ResultsTable results, Long imageId, List 0) { createColumn(0, IMAGE, ImageData.class); data[0] = new ImageData[rowCount]; - Arrays.fill(data[0], image.asImageData()); + Arrays.fill(data[0], image.asDataObject()); } if (offset > 1) { createColumn(1, roiProperty, ROIData.class); @@ -374,10 +375,10 @@ private static ROIData[] createROIColumn(ResultsTable results, ROIData[] roiColumn = EMPTY_ROI; - Map id2roi = rois.stream().collect(toMap(ROIWrapper::getId, ROIWrapper::asROIData)); + Map id2roi = rois.stream().collect(toMap(ROIWrapper::getId, GenericObjectWrapper::asDataObject)); Map name2roi = rois.stream() .filter(r -> !r.getName().isEmpty()) - .collect(toMap(ROIWrapper::getName, ROIWrapper::asROIData)); + .collect(toMap(ROIWrapper::getName, GenericObjectWrapper::asDataObject)); Map index2roi = ijRois.stream() .map(r -> new SimpleEntry<>(safeParseLong(r.getProperty(roiProperty)), @@ -510,7 +511,7 @@ public void addRows(Client client, ResultsTable results, Long imageId, List 0) Arrays.fill(data[0], row, row + n, image.asImageData()); + if (offset > 0) Arrays.fill(data[0], row, row + n, image.asDataObject()); if (offset > 1) System.arraycopy(roiColumn, 0, data[1], row, n); for (int i = 0; i < nColumns; i++) { if (columns[offset + i].getType().equals(String.class)) { diff --git a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java index 0bccebe0..3a9e145f 100644 --- a/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TagAnnotationWrapper.java @@ -39,7 +39,6 @@ public class TagAnnotationWrapper extends GenericAnnotationWrapper plane /** - * Returns the PlaneInfoData contained. - * * @return See above. + * + * @deprecated Returns the PlaneInfoData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public PlaneInfoData asPlaneInfoData() { return data; } diff --git a/src/main/java/fr/igred/omero/repository/ChannelWrapper.java b/src/main/java/fr/igred/omero/repository/ChannelWrapper.java index cea54414..22649889 100644 --- a/src/main/java/fr/igred/omero/repository/ChannelWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ChannelWrapper.java @@ -42,10 +42,11 @@ public ChannelWrapper(ChannelData channel) { /** - * Returns the ChannelData contained. - * * @return See above. + * + * @deprecated Returns the ChannelData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public ChannelData asChannelData() { return data; } @@ -91,7 +92,7 @@ public String getChannelLabeling() { * @return See above. */ public String getName() { - return asChannelData().getName(); + return asDataObject().getName(); } diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index fd09cf4b..f737c3cb 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -107,10 +107,11 @@ public void setName(String name) { /** - * Returns the DatasetData contained. - * * @return See above. + * + * @deprecated Returns the DatasetData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public DatasetData asDatasetData() { return data; } @@ -393,7 +394,7 @@ public void addImages(Client client, List images) public void addImage(Client client, ImageWrapper image) throws ServiceException, AccessException, ExecutionException { DatasetImageLink link = new DatasetImageLinkI(); - link.setChild(image.asImageData().asImage()); + link.setChild(image.asDataObject().asImage()); link.setParent(new DatasetI(data.getId(), false)); client.save(link); diff --git a/src/main/java/fr/igred/omero/repository/FolderWrapper.java b/src/main/java/fr/igred/omero/repository/FolderWrapper.java index a98e1c7a..679018a0 100644 --- a/src/main/java/fr/igred/omero/repository/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/repository/FolderWrapper.java @@ -20,6 +20,7 @@ import fr.igred.omero.Client; import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.annotations.GenericAnnotationWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; @@ -30,11 +31,9 @@ import omero.gateway.facility.ROIFacility; import omero.gateway.model.FolderData; import omero.gateway.model.ROIResult; -import omero.gateway.model.TagAnnotationData; import omero.model.Folder; import omero.model.FolderAnnotationLink; import omero.model.FolderAnnotationLinkI; -import omero.model.FolderI; import java.util.ArrayList; import java.util.Collection; @@ -116,21 +115,22 @@ protected String annotationLinkType() { /** - * Private function. Adds a tag to the object in OMERO, if possible. + * Adds an annotation to the object in OMERO, if possible. * - * @param client The client handling the connection. - * @param tagData Tag to be added. + * @param client The client handling the connection. + * @param annotation Annotation to be added. + * @param The type of the annotation. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - protected void addTag(Client client, TagAnnotationData tagData) + public > void link(Client client, A annotation) throws ServiceException, AccessException, ExecutionException { FolderAnnotationLink link = new FolderAnnotationLinkI(); - link.setChild(tagData.asAnnotation()); - link.setParent(new FolderI(data.getId(), false)); + link.setChild(annotation.asDataObject().asAnnotation()); + link.setParent(data.asFolder()); client.save(link); } @@ -159,10 +159,11 @@ public void setName(String name) { /** - * Gets the folder contained in the FolderWrapper - * * @return the FolderData. + * + * @deprecated Gets the folder contained in the FolderWrapper. Use {@link #asDataObject()} instead. */ + @Deprecated public FolderData asFolderData() { return data; } diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java index 0232a39c..f0260cac 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java @@ -58,6 +58,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -218,62 +219,122 @@ protected static List importImage(GatewayWrapper client, DataObject target /** - * Adds a newly created tag to the object in OMERO, if possible. + * Checks if a specific annotation is linked to the object. * - * @param client The client handling the connection. - * @param name Tag Name. - * @param description Tag description. + * @param client The client handling the connection. + * @param annotation Annotation to be checked. + * @param The type of the annotation. + * + * @return True if the object is linked to the given annotation, false otherwise. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void addTag(Client client, String name, String description) + public > boolean isLinked(Client client, A annotation) throws ServiceException, AccessException, ExecutionException { - TagAnnotationData tagData = new TagAnnotationData(name); - tagData.setTagDescription(description); - addTag(client, tagData); + return getAnnotations(client).stream().anyMatch(a -> a.getId() == annotation.getId()); } /** - * Adds a tag to the object in OMERO, if possible. + * Adds an annotation to the object in OMERO, if possible. * - * @param client The client handling the connection. - * @param tag Tag to be added. + * @param client The client handling the connection. + * @param annotation Annotation to be added. + * @param The type of the annotation. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void addTag(Client client, TagAnnotationWrapper tag) + public > void link(Client client, A annotation) throws ServiceException, AccessException, ExecutionException { - addTag(client, tag.asTagAnnotationData()); + String error = String.format("Cannot add %s to %s", annotation, this); + try { + client.getDm().attachAnnotation(client.getCtx(), annotation.asDataObject(), data); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, error); + } } /** - * Protected function. Adds a tag to the object in OMERO, if possible. + * Adds multiple annotations to the object in OMERO, if possible. * - * @param client The client handling the connection. - * @param tagData Tag to be added. + * @param client The client handling the connection. + * @param annotations Annotations to add. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - protected void addTag(Client client, TagAnnotationData tagData) + public void link(Client client, GenericAnnotationWrapper... annotations) throws ServiceException, AccessException, ExecutionException { - try { - client.getDm().attachAnnotation(client.getCtx(), tagData, data); - } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot add tag " + tagData.getTagValue() + " to " + this); + for (GenericAnnotationWrapper annotation : annotations) { + link(client, annotation); } } /** - * Adds multiple tags to the object in OMERO, if possible. + * Adds multiple annotations to the object in OMERO if they are not already linked. + * + * @param client The client handling the connection. + * @param annotations Annotations to add. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void linkIfNotLinked(Client client, GenericAnnotationWrapper... annotations) + throws ServiceException, AccessException, ExecutionException { + List annotationIds = getAnnotations(client).stream() + .map(DataObject::getId) + .collect(Collectors.toList()); + link(client, Arrays.stream(annotations) + .filter(a -> !annotationIds.contains(a.getId())) + .toArray(GenericAnnotationWrapper[]::new)); + } + + + /** + * Adds a newly created tag to the object in OMERO, if possible. + * + * @param client The client handling the connection. + * @param name Tag Name. + * @param description Tag description. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void addTag(Client client, String name, String description) + throws ServiceException, AccessException, ExecutionException { + TagAnnotationWrapper tag = new TagAnnotationWrapper(new TagAnnotationData(name)); + tag.setDescription(description); + link(client, tag); + } + + + /** + * @param client The client handling the connection. + * @param tag Tag to be added. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Adds a tag to the object in OMERO, if possible. Use {@link #link} instead. + */ + @Deprecated + public void addTag(Client client, TagAnnotationWrapper tag) + throws ServiceException, AccessException, ExecutionException { + link(client, tag); + } + + + /** + * Adds a tag to the object in OMERO, if possible. * * @param client The client handling the connection. * @param id ID of the tag to add to the object. @@ -286,25 +347,24 @@ public void addTag(Client client, Long id) throws ServiceException, AccessException, ExecutionException { TagAnnotationI tag = new TagAnnotationI(id, false); TagAnnotationData tagData = new TagAnnotationData(tag); - addTag(client, tagData); + link(client, new TagAnnotationWrapper(tagData)); } /** - * Adds multiple tag to the object in OMERO, if possible. - * * @param client The client handling the connection. * @param tags Array of TagAnnotationWrapper to add. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Adds multiple tag to the object in OMERO, if possible. Use + * {@link #link(Client, GenericAnnotationWrapper[])} instead. */ + @Deprecated public void addTags(Client client, TagAnnotationWrapper... tags) throws ServiceException, AccessException, ExecutionException { - for (TagAnnotationWrapper tag : tags) { - addTag(client, tag.asTagAnnotationData()); - } + link(client, tags); } @@ -404,16 +464,16 @@ public void addPairKeyValue(Client client, String key, String value) List kv = Collections.singletonList(new NamedValue(key, value)); MapAnnotationWrapper pkv = new MapAnnotationWrapper(kv); pkv.setNameSpace(NSCLIENTMAPANNOTATION.value); - addMapAnnotation(client, pkv); + link(client, pkv); } /** - * Gets the List of NamedValue (Key-Value pair) associated to an object. + * Gets the List of key-value pairs associated to an object as a map (no duplicate key should exist). * * @param client The client handling the connection. * - * @return Collection of NamedValue. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -421,22 +481,10 @@ public void addPairKeyValue(Client client, String key, String value) */ public Map getKeyValuePairs(Client client) throws ServiceException, AccessException, ExecutionException { - List> types = Collections.singletonList(MapAnnotationData.class); - - List annotations = new ArrayList<>(0); - try { - annotations = client.getMetadata().getAnnotations(client.getCtx(), data, types, null); - } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot get key-value pairs for " + this); - } - - return annotations.stream() - .filter(MapAnnotationData.class::isInstance) - .map(MapAnnotationData.class::cast) - .map(MapAnnotationWrapper::new) - .map(MapAnnotationWrapper::getContent) - .flatMap(List::stream) - .collect(Collectors.toMap(nv -> nv.name, nv -> nv.value)); + return getMapAnnotations(client).stream() + .map(MapAnnotationWrapper::getContent) + .flatMap(List::stream) + .collect(Collectors.toMap(nv -> nv.name, nv -> nv.value)); } @@ -466,25 +514,19 @@ public String getValue(Client client, String key) /** - * Adds a List of Key-Value pair to the object. - *

The list is contained in the MapAnnotationWrapper. - * * @param client The client handling the connection. * @param mapAnnotation MapAnnotationWrapper containing a list of NamedValue. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Adds a List of Key-Value pair to the object. Use {@link #link} instead. + *

The list is contained in the MapAnnotationWrapper. */ + @Deprecated public void addMapAnnotation(Client client, MapAnnotationWrapper mapAnnotation) throws ServiceException, AccessException, ExecutionException { - try { - client.getDm().attachAnnotation(client.getCtx(), - mapAnnotation.asMapAnnotationData(), - this.data); - } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot add key-value pairs to " + this); - } + link(client, mapAnnotation); } @@ -719,22 +761,18 @@ public long addAndReplaceFile(Client client, File file) /** - * Links a file annotation to the object - * * @param client The client handling the connection. * @param annotation FileAnnotationWrapper to link. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Links a file annotation to the object. Use {@link #link} instead. */ + @Deprecated public void addFileAnnotation(Client client, FileAnnotationWrapper annotation) throws AccessException, ServiceException, ExecutionException { - try { - client.getDm().attachAnnotation(client.getCtx(), annotation.asFileAnnotationData(), this.data); - } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot link file annotation to " + this); - } + link(client, annotation); } diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index de8dcc16..7268d0f4 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -163,10 +163,11 @@ public void setName(String name) { /** - * Returns the ImageData contained. - * * @return See above. + * + * @deprecated Returns the ImageData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public ImageData asImageData() { return data; } @@ -270,7 +271,7 @@ public List getDatasets(Client client) * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public List getWells(Client client) throws AccessException, ServiceException, ExecutionException { - Long[] ids = this.asImageData() + Long[] ids = this.asDataObject() .asImage() .copyWellSamples() .stream() @@ -356,7 +357,7 @@ public List getFilesetImages(Client client) throws AccessException, ServiceException, ExecutionException, OMEROServerError { List related = new ArrayList<>(0); if (data.isFSImage()) { - long fsId = this.asImageData().getFilesetId(); + long fsId = this.asDataObject().getFilesetId(); List objects = client.findByQuery("select i from Image i where fileset=" + fsId); @@ -383,7 +384,9 @@ public List getFilesetImages(Client client) public List saveROIs(Client client, Collection rois) throws ServiceException, AccessException, ExecutionException { rois.forEach(r -> r.setImage(this)); - List roisData = rois.stream().map(ROIWrapper::asROIData).collect(Collectors.toList()); + List roisData = rois.stream() + .map(GenericObjectWrapper::asDataObject) + .collect(Collectors.toList()); Collection results = new ArrayList<>(0); try { results = client.getRoiFacility().saveROIs(client.getCtx(), data.getId(), roisData); diff --git a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java index ab134296..b97123b1 100644 --- a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java @@ -19,11 +19,10 @@ import fr.igred.omero.Client; +import fr.igred.omero.annotations.GenericAnnotationWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.PlateAcquisitionData; -import omero.gateway.model.TagAnnotationData; -import omero.model.PlateAcquisition; import omero.model.PlateAcquisitionAnnotationLink; import omero.model.PlateAcquisitionAnnotationLinkI; import omero.model._PlateAcquisitionOperationsNC; @@ -89,10 +88,11 @@ public void setName(String name) { /** - * Returns the PlateAcquisitionData contained. - * * @return See above. + * + * @deprecated Returns the PlateAcquisitionData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public PlateAcquisitionData asPlateAcquisitionData() { return data; } @@ -120,21 +120,22 @@ public void setDescription(String description) { /** - * Protected function. Adds a tag to the object in OMERO, if possible. + * Adds a tag to the object in OMERO, if possible. * - * @param client The client handling the connection. - * @param tagData Tag to be added. + * @param client The client handling the connection. + * @param annotation Tag to be added. + * @param The type of the annotation. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ @Override - protected void addTag(Client client, TagAnnotationData tagData) + public > void link(Client client, A annotation) throws ServiceException, AccessException, ExecutionException { PlateAcquisitionAnnotationLink link = new PlateAcquisitionAnnotationLinkI(); - link.setChild(tagData.asAnnotation()); - link.setParent((PlateAcquisition) data.asIObject()); + link.setChild(annotation.asDataObject().asAnnotation()); + link.setParent((omero.model.PlateAcquisition) data.asIObject()); client.save(link); } diff --git a/src/main/java/fr/igred/omero/repository/PlateWrapper.java b/src/main/java/fr/igred/omero/repository/PlateWrapper.java index bcb033e1..5080743a 100644 --- a/src/main/java/fr/igred/omero/repository/PlateWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateWrapper.java @@ -97,10 +97,11 @@ public void setName(String name) { /** - * Returns the PlateData contained. - * * @return See above. + * + * @deprecated Returns the PlateData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public PlateData asPlateData() { return data; } diff --git a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java b/src/main/java/fr/igred/omero/repository/ProjectWrapper.java index 4a8d308e..a8945a50 100644 --- a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ProjectWrapper.java @@ -106,10 +106,11 @@ public void setName(String name) { /** - * Returns the ProjectData contained. - * * @return See above. + * + * @deprecated Returns the ProjectData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public ProjectData asProjectData() { return data; } @@ -208,7 +209,7 @@ public DatasetWrapper addDataset(Client client, DatasetWrapper dataset) throws ServiceException, AccessException, ExecutionException { dataset.saveAndUpdate(client); ProjectDatasetLink link = new ProjectDatasetLinkI(); - link.setChild(dataset.asDatasetData().asDataset()); + link.setChild(dataset.asDataObject().asDataset()); link.setParent(data.asProject()); client.save(link); diff --git a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java index 173723b8..06ef38a5 100644 --- a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java @@ -110,10 +110,11 @@ public void setName(String name) { /** - * Returns the ScreenData contained. - * * @return See above. + * + * @deprecated Returns the ScreenData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public ScreenData asScreenData() { return data; } diff --git a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java index 68e6686c..ec98cf16 100644 --- a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java @@ -48,10 +48,11 @@ public WellSampleWrapper(WellSampleData wellSample) { /** - * Returns the WellSampleData contained. - * * @return See above. + * + * @deprecated Returns the WellSampleData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public WellSampleData asWellSampleData() { return data; } @@ -69,7 +70,7 @@ public WellSampleData asWellSampleData() { * @throws ExecutionException A Facility can't be retrieved or instantiated. */ public WellWrapper getWell(Client client) throws AccessException, ServiceException, ExecutionException { - return client.getWell(asWellSampleData().asWellSample().getWell().getId().getValue()); + return client.getWell(asDataObject().asWellSample().getWell().getId().getValue()); } @@ -89,7 +90,7 @@ public ImageWrapper getImage() { * @param image The image to set. */ public void setImage(ImageWrapper image) { - data.setImage(image.asImageData()); + data.setImage(image.asDataObject()); } diff --git a/src/main/java/fr/igred/omero/repository/WellWrapper.java b/src/main/java/fr/igred/omero/repository/WellWrapper.java index 696c8923..82037e41 100644 --- a/src/main/java/fr/igred/omero/repository/WellWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellWrapper.java @@ -98,10 +98,11 @@ public String getDescription() { /** - * Returns the WellData contained. - * * @return See above. + * + * @deprecated Returns the WellData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public WellData asWellData() { return data; } @@ -113,7 +114,7 @@ public WellData asWellData() { * @return See above. */ public List getWellSamples() { - return wrap(data.getWellSamples(), WellSampleWrapper::new, w -> w.getImage().asImageData().getSeries()); + return wrap(data.getWellSamples(), WellSampleWrapper::new, w -> w.getImage().asDataObject().getSeries()); } diff --git a/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java b/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java index b551fbc3..e3bc1ddc 100644 --- a/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java +++ b/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java @@ -157,10 +157,11 @@ protected void copyToIJRoi(ij.gui.Roi ijRoi) { /** - * Gets the ShapeData object contained. - * * @return the shape. + * + * @deprecated Gets the ShapeData object contained. */ + @Deprecated public T asShapeData() { return data; } diff --git a/src/main/java/fr/igred/omero/roi/LineWrapper.java b/src/main/java/fr/igred/omero/roi/LineWrapper.java index 700048ac..5d03cbbf 100644 --- a/src/main/java/fr/igred/omero/roi/LineWrapper.java +++ b/src/main/java/fr/igred/omero/roi/LineWrapper.java @@ -268,8 +268,8 @@ public Roi toImageJ() { java.awt.geom.Rectangle2D shape1 = p1.createTransformedAWTShape().getBounds2D(); java.awt.geom.Rectangle2D shape2 = p2.createTransformedAWTShape().getBounds2D(); - String start = asShapeData().getShapeSettings().getMarkerStart(); - String end = asShapeData().getShapeSettings().getMarkerEnd(); + String start = data.getShapeSettings().getMarkerStart(); + String end = data.getShapeSettings().getMarkerEnd(); double x1 = shape1.getX(); double x2 = shape2.getX(); diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index a81e344d..a7a40263 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -79,7 +79,7 @@ public ROIWrapper(Iterable> shapes) { super(new ROIData()); for (GenericShapeWrapper shape : shapes) { - data.addShapeData(shape.asShapeData()); + data.addShapeData(shape.asDataObject()); } } @@ -244,7 +244,7 @@ public static List toImageJ(Collection rois, S final int maxGroups = 255; groupRois = groupRois && rois.size() < maxGroups; - int nShapes = rois.stream().map(ROIWrapper::asROIData).mapToInt(ROIData::getShapeCount).sum(); + int nShapes = rois.stream().map(GenericObjectWrapper::asDataObject).mapToInt(ROIData::getShapeCount).sum(); List ijRois = new ArrayList<>(nShapes); @@ -314,7 +314,7 @@ public void addShapes(List> shapes) { * @param shape GenericShapeWrapper to add. */ public void addShape(GenericShapeWrapper shape) { - data.addShapeData(shape.asShapeData()); + data.addShapeData(shape.asDataObject()); } @@ -336,15 +336,16 @@ public ShapeList getShapes() { * @param image Image linked to the ROIData. */ public void setImage(ImageWrapper image) { - data.setImage(image.asImageData().asImage()); + data.setImage(image.asDataObject().asImage()); } /** - * Returns the ROIData contained. - * * @return the {@link ROIData} contained. + * + * @deprecated Returns the ROIData contained. Use {@link #asDataObject()} instead. */ + @Deprecated public ROIData asROIData() { return data; } diff --git a/src/test/java/fr/igred/omero/AccessExceptionTest.java b/src/test/java/fr/igred/omero/AccessExceptionTest.java index 3de28525..6a44d88e 100644 --- a/src/test/java/fr/igred/omero/AccessExceptionTest.java +++ b/src/test/java/fr/igred/omero/AccessExceptionTest.java @@ -99,7 +99,7 @@ void testAddTagToImageWrongUser() throws Exception { TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "image tag", "tag attached to an image"); try { - image.addTag(client, tag); + image.link(client, tag); } catch (AccessException e) { exception = true; } diff --git a/src/test/java/fr/igred/omero/SudoTest.java b/src/test/java/fr/igred/omero/SudoTest.java index fa5786be..7d9367ee 100644 --- a/src/test/java/fr/igred/omero/SudoTest.java +++ b/src/test/java/fr/igred/omero/SudoTest.java @@ -61,7 +61,7 @@ void testSudoTag() throws Exception { List images = dataset.getImages(test); for (ImageWrapper image : images) { - image.addTag(test, tag); + image.link(test, tag); } List tagged = dataset.getImagesTagged(test, tag); diff --git a/src/test/java/fr/igred/omero/annotations/TableTest.java b/src/test/java/fr/igred/omero/annotations/TableTest.java index 4265ec98..f25a00da 100644 --- a/src/test/java/fr/igred/omero/annotations/TableTest.java +++ b/src/test/java/fr/igred/omero/annotations/TableTest.java @@ -57,10 +57,10 @@ void testCreateTable() throws Exception { for (ImageWrapper image : images) { assertNotEquals(true, table.isComplete()); - table.addRow(image.asImageData(), image.getName()); + table.addRow(image.asDataObject(), image.getName()); } - assertEquals(images.get(0).asImageData(), table.getData(0, 0)); + assertEquals(images.get(0).asDataObject(), table.getData(0, 0)); assertEquals(images.get(1).getName(), table.getData(0, 1)); dataset.addTable(client, table); @@ -96,10 +96,10 @@ void testReplaceTable() throws Exception { for (ImageWrapper image : images) { assertNotEquals(true, table1.isComplete()); - table1.addRow(image.asImageData(), image.getName()); + table1.addRow(image.asDataObject(), image.getName()); } - assertEquals(images.get(0).asImageData(), table1.getData(0, 0)); + assertEquals(images.get(0).asDataObject(), table1.getData(0, 0)); assertEquals(images.get(1).getName(), table1.getData(0, 1)); dataset.addTable(client, table1); @@ -111,7 +111,7 @@ void testReplaceTable() throws Exception { table2.setRowCount(images.size()); for (ImageWrapper image : images) { assertNotEquals(true, table2.isComplete()); - table2.addRow(image.asImageData(), image.getDescription()); + table2.addRow(image.asDataObject(), image.getDescription()); } dataset.addTable(client, table2); long tableId2 = table2.getId(); @@ -122,7 +122,7 @@ void testReplaceTable() throws Exception { table3.setRowCount(images.size()); for (ImageWrapper image : images) { assertNotEquals(true, table3.isComplete()); - table3.addRow(image.asImageData(), "Test name"); + table3.addRow(image.asDataObject(), "Test name"); } dataset.addAndReplaceTable(client, table3); long tableId3 = table3.getId(); @@ -158,7 +158,7 @@ void testErrorTableFull() throws Exception { table.setRowCount(images.size() - 1); assertThrows(IndexOutOfBoundsException.class, - () -> images.forEach(img -> table.addRow(img.asImageData(), img.getName()))); + () -> images.forEach(img -> table.addRow(img.asDataObject(), img.getName()))); } @@ -181,7 +181,7 @@ void testErrorTableUninitialized() throws Exception { table.setColumn(0, "Image", ImageData.class); table.setColumn(1, "Name", String.class); assertThrows(IndexOutOfBoundsException.class, - () -> images.forEach(img -> table.addRow(img.asImageData(), img.getName()))); + () -> images.forEach(img -> table.addRow(img.asDataObject(), img.getName()))); } diff --git a/src/test/java/fr/igred/omero/repository/DatasetTest.java b/src/test/java/fr/igred/omero/repository/DatasetTest.java index ba4ca425..7e4db4f6 100644 --- a/src/test/java/fr/igred/omero/repository/DatasetTest.java +++ b/src/test/java/fr/igred/omero/repository/DatasetTest.java @@ -125,7 +125,7 @@ void testAddTagToDataset() throws Exception { TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Dataset tag", "tag attached to a dataset"); - dataset.addTag(client, tag); + dataset.link(client, tag); List tags = dataset.getTags(client); client.delete(tag); @@ -199,7 +199,7 @@ void testAddTagsToDataset2() throws Exception { TagAnnotationWrapper tag3 = new TagAnnotationWrapper(client, "Dataset tag", "tag attached to a dataset"); TagAnnotationWrapper tag4 = new TagAnnotationWrapper(client, "Dataset tag", "tag attached to a dataset"); - dataset.addTags(client, tag1, tag2, tag3, tag4); + dataset.linkIfNotLinked(client, tag1, tag2, tag3, tag4); List tags = dataset.getTags(client); client.delete(tag1); @@ -219,7 +219,7 @@ void testAddAndRemoveTagFromDataset() throws Exception { TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Dataset tag", "tag attached to a dataset"); - dataset.addTag(client, tag); + dataset.link(client, tag); List tags = dataset.getTags(client); dataset.unlink(client, tag); diff --git a/src/test/java/fr/igred/omero/repository/FolderTest.java b/src/test/java/fr/igred/omero/repository/FolderTest.java index c7440045..5e6f7b94 100644 --- a/src/test/java/fr/igred/omero/repository/FolderTest.java +++ b/src/test/java/fr/igred/omero/repository/FolderTest.java @@ -192,7 +192,7 @@ void testAddAndRemoveTagFromFolder() throws Exception { TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Dataset tag", "tag attached to a folder"); - folder.addTag(client, tag); + folder.link(client, tag); List tags = folder.getTags(client); assertEquals(1, tags.size()); diff --git a/src/test/java/fr/igred/omero/repository/ImageImportTest.java b/src/test/java/fr/igred/omero/repository/ImageImportTest.java index 22e165d9..670bb8a9 100644 --- a/src/test/java/fr/igred/omero/repository/ImageImportTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageImportTest.java @@ -80,7 +80,7 @@ void testReplaceAndDeleteImages() throws Exception { image1.saveAndUpdate(client); TagAnnotationWrapper tag1 = new TagAnnotationWrapper(client, "ReplaceTestTag1", "Copy annotations"); - image1.addTag(client, tag1); + image1.link(client, tag1); image1.addPairKeyValue(client, "Map", "ReplaceTest"); long fileId = image1.addFile(client, file); @@ -93,9 +93,9 @@ void testReplaceAndDeleteImages() throws Exception { image2.saveAndUpdate(client); TagAnnotationWrapper tag2 = new TagAnnotationWrapper(client, "ReplaceTestTag2", "Copy annotations"); - image2.addTag(client, tag2); - image2.addFileAnnotation(client, image1.getFileAnnotations(client).get(0)); - image2.addMapAnnotation(client, image1.getMapAnnotations(client).get(0)); + image2.link(client, tag2); + image2.link(client, image1.getFileAnnotations(client).get(0)); + image2.link(client, image1.getMapAnnotations(client).get(0)); RectangleWrapper rectangle = new RectangleWrapper(3, 3, 2, 2); ROIWrapper roi = new ROIWrapper(); @@ -164,7 +164,7 @@ void testReplaceAndUnlinkImages() throws Exception { ImageWrapper image1 = client.getImage(ids1.get(0)); TagAnnotationWrapper tag1 = new TagAnnotationWrapper(client, "ReplaceTestTag1", "Copy annotations"); - image1.addTag(client, tag1); + image1.link(client, tag1); image1.addPairKeyValue(client, "Map", "ReplaceTest"); long fileId = image1.addFile(client, file); @@ -177,9 +177,9 @@ void testReplaceAndUnlinkImages() throws Exception { image2.saveAndUpdate(client); TagAnnotationWrapper tag2 = new TagAnnotationWrapper(client, "ReplaceTestTag2", "Copy annotations"); - image2.addTag(client, tag2); - image2.addFileAnnotation(client, image1.getFileAnnotations(client).get(0)); - image2.addMapAnnotation(client, image1.getMapAnnotations(client).get(0)); + image2.link(client, tag2); + image2.link(client, image1.getFileAnnotations(client).get(0)); + image2.link(client, image1.getMapAnnotations(client).get(0)); RectangleWrapper rectangle = new RectangleWrapper(3, 3, 2, 2); ROIWrapper roi = new ROIWrapper(); diff --git a/src/test/java/fr/igred/omero/repository/ImageTest.java b/src/test/java/fr/igred/omero/repository/ImageTest.java index fac49799..72c2411f 100644 --- a/src/test/java/fr/igred/omero/repository/ImageTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageTest.java @@ -144,7 +144,7 @@ void testAddKeyValuePair1() throws Exception { values.add(new NamedValue(name2, value2)); MapAnnotationWrapper mapAnnotation = new MapAnnotationWrapper(values); - image.addMapAnnotation(client, mapAnnotation); + image.link(client, mapAnnotation); Map pairs = image.getKeyValuePairs(client); @@ -176,7 +176,7 @@ void testAddKeyValuePair2() throws Exception { mapData.setContent(values); MapAnnotationWrapper mapAnnotation = new MapAnnotationWrapper(mapData); - image.addMapAnnotation(client, mapAnnotation); + image.link(client, mapAnnotation); Map pairs = image.getKeyValuePairs(client); @@ -206,7 +206,7 @@ void testAddKeyValuePair3() throws Exception { MapAnnotationWrapper mapAnnotation = new MapAnnotationWrapper(); mapAnnotation.setContent(values); - image.addMapAnnotation(client, mapAnnotation); + image.link(client, mapAnnotation); List maps = image.getMapAnnotations(client); @@ -365,7 +365,7 @@ void testAddTagToImage() throws Exception { TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "image tag", "tag attached to an image"); - image.addTag(client, tag); + image.link(client, tag); List tags = image.getTags(client); client.delete(tag); @@ -439,7 +439,7 @@ void testAddTagsToImage2() throws Exception { TagAnnotationWrapper tag3 = new TagAnnotationWrapper(client, "Image tag 3", "tag attached to an image"); TagAnnotationWrapper tag4 = new TagAnnotationWrapper(client, "Image tag 4", "tag attached to an image"); - image.addTags(client, tag1, tag2, tag3, tag4); + image.linkIfNotLinked(client, tag1, tag2, tag3, tag4); List tags = image.getTags(client); client.delete(tag1); client.delete(tag2); @@ -452,13 +452,34 @@ void testAddTagsToImage2() throws Exception { } + @Test + void testAddNewTagsToImage() throws Exception { + ImageWrapper image = client.getImage(IMAGE1.id); + + TagAnnotationWrapper tag1 = client.getTag(TAG1.id); + TagAnnotationWrapper tag2 = client.getTag(TAG2.id); + TagAnnotationWrapper tag3 = new TagAnnotationWrapper(client, "Image tag 1", "tag attached to an image"); + TagAnnotationWrapper tag4 = new TagAnnotationWrapper(client, "Image tag 2", "tag attached to an image"); + + image.linkIfNotLinked(client, tag1, tag2, tag3, tag4); + List tags = image.getTags(client); + client.delete(tag3); + client.delete(tag4); + List endTags = image.getTags(client); + + assertTrue(image.isLinked(client, tag1)); + assertEquals(4, tags.size()); + assertEquals(2, endTags.size()); + } + + @Test void testAddAndRemoveTagFromImage() throws Exception { ImageWrapper image = client.getImage(IMAGE2.id); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Dataset tag", "tag attached to an image"); - image.addTag(client, tag); + image.link(client, tag); List tags = image.getTags(client); image.unlink(client, tag); diff --git a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java index a7d11ccf..094b7e62 100644 --- a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java @@ -37,7 +37,7 @@ void testAddTagToPlateAcquisition() throws Exception { PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Plate acq. tag", "tag attached to a plate acq."); - acq.addTag(client, tag); + acq.link(client, tag); List tags = acq.getTags(client); client.delete(tag); List checkTags = acq.getTags(client); diff --git a/src/test/java/fr/igred/omero/repository/PlateTest.java b/src/test/java/fr/igred/omero/repository/PlateTest.java index 4e60673a..34005df9 100644 --- a/src/test/java/fr/igred/omero/repository/PlateTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateTest.java @@ -63,7 +63,7 @@ void testAddTagToPlate() throws Exception { PlateWrapper plate = client.getPlate(PLATE2.id); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Plate tag", "tag attached to a plate"); - plate.addTag(client, tag); + plate.link(client, tag); List tags = plate.getTags(client); client.delete(tag); List checkTags = plate.getTags(client); diff --git a/src/test/java/fr/igred/omero/repository/ProjectTest.java b/src/test/java/fr/igred/omero/repository/ProjectTest.java index a023d13b..939fc614 100644 --- a/src/test/java/fr/igred/omero/repository/ProjectTest.java +++ b/src/test/java/fr/igred/omero/repository/ProjectTest.java @@ -176,7 +176,7 @@ void testAddAndRemoveTagFromProject() throws Exception { ProjectWrapper project = client.getProject(PROJECT1.id); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Project tag", "tag attached to a project"); - project.addTag(client, tag); + project.link(client, tag); List tags = project.getTags(client); project.unlink(client, tag); List removedTags = project.getTags(client); @@ -303,7 +303,7 @@ void testCopyAnnotations() throws Exception { assertNotEquals(0L, fileId); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "CopyTestTag", "Copy annotations"); - project1.addTag(client, tag); + project1.link(client, tag); project1.addPairKeyValue(client, "CopyTest", "Annotation"); TableWrapper table = new TableWrapper(1, "CopyTest"); @@ -371,7 +371,7 @@ void testReplaceAndUnlinkFile() throws Exception { long fileId1 = project1.addFile(client, file); assertEquals(1, project1.getFileAnnotations(client).size()); - project2.addFileAnnotation(client, project1.getFileAnnotations(client).get(0)); + project2.link(client, project1.getFileAnnotations(client).get(0)); long fileId2 = project1.addAndReplaceFile(client, file); assertEquals(1, project1.getFileAnnotations(client).size()); assertEquals(1, project2.getFileAnnotations(client).size()); @@ -394,7 +394,7 @@ void testReplaceAndDeleteFile() throws Exception { long fileId1 = project1.addFile(client, file); assertEquals(1, project1.getFileAnnotations(client).size()); - project2.addFileAnnotation(client, project1.getFileAnnotations(client).get(0)); + project2.link(client, project1.getFileAnnotations(client).get(0)); long fileId2 = project1.addAndReplaceFile(client, file, DELETE); assertEquals(1, project1.getFileAnnotations(client).size()); assertEquals(0, project2.getFileAnnotations(client).size()); @@ -416,7 +416,7 @@ void testReplaceAndDeleteOrphanedFile1() throws Exception { long fileId1 = project1.addFile(client, file); assertEquals(1, project1.getFileAnnotations(client).size()); - project2.addFileAnnotation(client, project1.getFileAnnotations(client).get(0)); + project2.link(client, project1.getFileAnnotations(client).get(0)); long fileId2 = project1.addAndReplaceFile(client, file, DELETE_ORPHANED); assertEquals(1, project1.getFileAnnotations(client).size()); assertEquals(1, project2.getFileAnnotations(client).size()); diff --git a/src/test/java/fr/igred/omero/repository/ScreenTest.java b/src/test/java/fr/igred/omero/repository/ScreenTest.java index c7c53aa8..1ad9fa3a 100644 --- a/src/test/java/fr/igred/omero/repository/ScreenTest.java +++ b/src/test/java/fr/igred/omero/repository/ScreenTest.java @@ -54,7 +54,7 @@ void testAddTagToScreen() throws Exception { ScreenWrapper screen = client.getScreen(SCREEN2.id); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Screen tag", "tag attached to a screen"); - screen.addTag(client, tag); + screen.link(client, tag); List tags = screen.getTags(client); client.delete(tag); List checkTags = screen.getTags(client); diff --git a/src/test/java/fr/igred/omero/repository/WellTest.java b/src/test/java/fr/igred/omero/repository/WellTest.java index 27fc5da5..f19c8587 100644 --- a/src/test/java/fr/igred/omero/repository/WellTest.java +++ b/src/test/java/fr/igred/omero/repository/WellTest.java @@ -35,7 +35,7 @@ void testAddTagToWell() throws Exception { WellWrapper well = client.getWell(2L); TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Well tag", "tag attached to a well"); - well.addTag(client, tag); + well.link(client, tag); List tags = well.getTags(client); client.delete(tag); List checkTags = well.getTags(client); diff --git a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java index e65a25af..2235f9c8 100644 --- a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java +++ b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java @@ -151,7 +151,7 @@ void testROItoImageJ() { LineWrapper line = new LineWrapper(0, 0, 10, 10); line.setCZT(1, 0, 3); - line.asShapeData().getShapeSettings().setMarkerStart(LineWrapper.ARROW); + line.asDataObject().getShapeSettings().setMarkerStart(LineWrapper.ARROW); LineWrapper line2 = new LineWrapper(0, 0, 10, 10); line2.setCZT(1, 0, 4); @@ -159,8 +159,8 @@ void testROItoImageJ() { LineWrapper line3 = new LineWrapper(2, 2, 3, 4); line3.setCZT(1, 0, 5); - line3.asShapeData().getShapeSettings().setMarkerStart(LineWrapper.ARROW); - line3.asShapeData().getShapeSettings().setMarkerEnd(LineWrapper.ARROW); + line3.asDataObject().getShapeSettings().setMarkerStart(LineWrapper.ARROW); + line3.asDataObject().getShapeSettings().setMarkerEnd(LineWrapper.ARROW); List points2D = new ArrayList<>(3); @@ -283,8 +283,8 @@ void convertArrow() { assertEquals(arrow.getC(), newArrow.getC()); assertEquals(arrow.getZ(), newArrow.getZ()); assertEquals(arrow.getT(), newArrow.getT()); - assertEquals(arrow.asShapeData().getShapeSettings().getMarkerStart(), - newArrow.asShapeData().getShapeSettings().getMarkerEnd()); + assertEquals(arrow.asDataObject().getShapeSettings().getMarkerStart(), + newArrow.asDataObject().getShapeSettings().getMarkerEnd()); } From d379f621a3145150fa31cc27dcce8ca726f72336 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 17:37:45 +0100 Subject: [PATCH 05/14] Add Wrapper class to dynamically wrap objects, and AnnotationList --- .../omero/annotations/AnnotationList.java | 88 +++++++ .../igred/omero/roi/GenericShapeWrapper.java | 2 +- .../java/fr/igred/omero/roi/ROIWrapper.java | 3 +- .../java/fr/igred/omero/roi/ShapeList.java | 55 ++-- .../java/fr/igred/omero/util/Wrapper.java | 224 +++++++++++++++++ .../java/fr/igred/omero/util/WrapperTest.java | 237 ++++++++++++++++++ 6 files changed, 574 insertions(+), 35 deletions(-) create mode 100644 src/main/java/fr/igred/omero/annotations/AnnotationList.java create mode 100644 src/main/java/fr/igred/omero/util/Wrapper.java create mode 100644 src/test/java/fr/igred/omero/util/WrapperTest.java diff --git a/src/main/java/fr/igred/omero/annotations/AnnotationList.java b/src/main/java/fr/igred/omero/annotations/AnnotationList.java new file mode 100644 index 00000000..7f18f5d8 --- /dev/null +++ b/src/main/java/fr/igred/omero/annotations/AnnotationList.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package fr.igred.omero.annotations; + + +import fr.igred.omero.util.Wrapper; +import omero.gateway.model.AnnotationData; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + + +/** List of GenericShapeWrapper objects */ +public class AnnotationList extends ArrayList> { + + + private static final long serialVersionUID = 8792604507462788823L; + + + /** + * Constructs an empty list with an initial capacity of ten. + */ + public AnnotationList() { + } + + + /** + * Constructs an empty list with the specified initial capacity. + * + * @param initialCapacity the initial capacity of the list + * + * @throws IllegalArgumentException if the specified initial capacity is negative + */ + public AnnotationList(int initialCapacity) { + super(initialCapacity); + } + + + /** + * Gets a list of elements from this list whose class is specified. + * + * @param clazz Class of the wanted elements. + * @param Subclass of GenericShapeWrapper. + * + * @return See above. + */ + public > List getElementsOf(Class clazz) { + return stream().filter(clazz::isInstance).map(clazz::cast).collect(Collectors.toList()); + } + + + /** + * Wraps the specified AnnotationData object and add it to the end of this list. + * + * @param shape element to be wrapped and appended to this list + * + * @return {@code true} (as specified by {@link ArrayList#add(Object)}) + */ + public boolean add(AnnotationData shape) { + boolean added; + + try { + GenericAnnotationWrapper wrapper = Wrapper.wrap(shape); + added = add(wrapper); + } catch (IllegalArgumentException e) { + added = false; + } + + return added; + } + +} diff --git a/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java b/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java index e3bc1ddc..c3723e31 100644 --- a/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java +++ b/src/main/java/fr/igred/omero/roi/GenericShapeWrapper.java @@ -148,7 +148,7 @@ protected void copyToIJRoi(ij.gui.Roi ijRoi) { ijRoi.setName(getText()); ijRoi.setStrokeColor(getStroke()); Color fill = getFill(); - if(!TRANSPARENT.equals(fill)) ijRoi.setFillColor(getFill()); + if (!TRANSPARENT.equals(fill)) ijRoi.setFillColor(getFill()); int c = Math.max(0, getC() + 1); int z = Math.max(0, getZ() + 1); int t = Math.max(0, getT() + 1); diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index a7a40263..3baf9f3b 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -324,7 +324,8 @@ public void addShape(GenericShapeWrapper shape) { * @return list of shape contained in the ROIData. */ public ShapeList getShapes() { - ShapeList shapes = new ShapeList(); + List shapeData = data.getShapes(); + ShapeList shapes = new ShapeList(shapeData.size()); data.getShapes().stream().sorted(Comparator.comparing(ShapeData::getId)).forEach(shapes::add); return shapes; } diff --git a/src/main/java/fr/igred/omero/roi/ShapeList.java b/src/main/java/fr/igred/omero/roi/ShapeList.java index 6b4483b9..cce1f3fc 100644 --- a/src/main/java/fr/igred/omero/roi/ShapeList.java +++ b/src/main/java/fr/igred/omero/roi/ShapeList.java @@ -18,19 +18,11 @@ package fr.igred.omero.roi; -import omero.gateway.model.EllipseData; -import omero.gateway.model.LineData; -import omero.gateway.model.MaskData; -import omero.gateway.model.PointData; -import omero.gateway.model.PolygonData; -import omero.gateway.model.PolylineData; -import omero.gateway.model.RectangleData; +import fr.igred.omero.util.Wrapper; import omero.gateway.model.ShapeData; -import omero.gateway.model.TextData; import java.util.ArrayList; import java.util.List; -import java.util.function.Function; import java.util.stream.Collectors; @@ -38,24 +30,25 @@ public class ShapeList extends ArrayList> { - private static final long serialVersionUID = 9076633148525603098L; + private static final long serialVersionUID = -5942132062803749727L; /** - * Tries to convert a ShapeData object to a GenericShapeWrapper object. + * Constructs an empty list with an initial capacity of ten. + */ + public ShapeList() { + } + + + /** + * Constructs an empty list with the specified initial capacity. * - * @param object The shape. - * @param klass The suspected class of the shape. - * @param mapper The method used to wrap the object. - * @param The type of ShapeData. - * @param The type of GenericObjectWrapper. + * @param initialCapacity the initial capacity of the list * - * @return A GenericObjectWrapper. + * @throws IllegalArgumentException if the specified initial capacity is negative */ - private static > - U tryConvert(ShapeData object, Class klass, Function mapper) { - if (klass.isInstance(object)) return mapper.apply(klass.cast(object)); - else return null; + public ShapeList(int initialCapacity) { + super(initialCapacity); } @@ -80,18 +73,14 @@ public > List getElementsOf(Class wrapper = tryConvert(shape, PointData.class, PointWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, TextData.class, TextWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, RectangleData.class, RectangleWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, MaskData.class, MaskWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, EllipseData.class, EllipseWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, LineData.class, LineWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, PolylineData.class, PolylineWrapper::new); - if (wrapper == null) wrapper = tryConvert(shape, PolygonData.class, PolygonWrapper::new); - - if (wrapper != null) added = add(wrapper); + boolean added; + + try { + GenericShapeWrapper wrapper = Wrapper.wrap(shape); + added = add(wrapper); + } catch (IllegalArgumentException e) { + added = false; + } return added; } diff --git a/src/main/java/fr/igred/omero/util/Wrapper.java b/src/main/java/fr/igred/omero/util/Wrapper.java new file mode 100644 index 00000000..ceea991f --- /dev/null +++ b/src/main/java/fr/igred/omero/util/Wrapper.java @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package fr.igred.omero.util; + + +import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.annotations.FileAnnotationWrapper; +import fr.igred.omero.annotations.GenericAnnotationWrapper; +import fr.igred.omero.annotations.MapAnnotationWrapper; +import fr.igred.omero.annotations.RatingAnnotationWrapper; +import fr.igred.omero.annotations.TagAnnotationWrapper; +import fr.igred.omero.meta.ExperimenterWrapper; +import fr.igred.omero.meta.GroupWrapper; +import fr.igred.omero.meta.PlaneInfoWrapper; +import fr.igred.omero.repository.ChannelWrapper; +import fr.igred.omero.repository.DatasetWrapper; +import fr.igred.omero.repository.FolderWrapper; +import fr.igred.omero.repository.GenericRepositoryObjectWrapper; +import fr.igred.omero.repository.ImageWrapper; +import fr.igred.omero.repository.PixelsWrapper; +import fr.igred.omero.repository.PlateAcquisitionWrapper; +import fr.igred.omero.repository.PlateWrapper; +import fr.igred.omero.repository.ProjectWrapper; +import fr.igred.omero.repository.ScreenWrapper; +import fr.igred.omero.repository.WellSampleWrapper; +import fr.igred.omero.repository.WellWrapper; +import fr.igred.omero.roi.EllipseWrapper; +import fr.igred.omero.roi.GenericShapeWrapper; +import fr.igred.omero.roi.LineWrapper; +import fr.igred.omero.roi.MaskWrapper; +import fr.igred.omero.roi.PointWrapper; +import fr.igred.omero.roi.PolygonWrapper; +import fr.igred.omero.roi.PolylineWrapper; +import fr.igred.omero.roi.ROIWrapper; +import fr.igred.omero.roi.RectangleWrapper; +import fr.igred.omero.roi.TextWrapper; +import omero.gateway.model.AnnotationData; +import omero.gateway.model.ChannelData; +import omero.gateway.model.DataObject; +import omero.gateway.model.DatasetData; +import omero.gateway.model.EllipseData; +import omero.gateway.model.ExperimenterData; +import omero.gateway.model.FileAnnotationData; +import omero.gateway.model.FolderData; +import omero.gateway.model.GroupData; +import omero.gateway.model.ImageData; +import omero.gateway.model.LineData; +import omero.gateway.model.MapAnnotationData; +import omero.gateway.model.MaskData; +import omero.gateway.model.PixelsData; +import omero.gateway.model.PlaneInfoData; +import omero.gateway.model.PlateAcquisitionData; +import omero.gateway.model.PlateData; +import omero.gateway.model.PointData; +import omero.gateway.model.PolygonData; +import omero.gateway.model.PolylineData; +import omero.gateway.model.ProjectData; +import omero.gateway.model.ROIData; +import omero.gateway.model.RectangleData; +import omero.gateway.model.ScreenData; +import omero.gateway.model.ShapeData; +import omero.gateway.model.TagAnnotationData; +import omero.gateway.model.TextData; +import omero.gateway.model.WellData; +import omero.gateway.model.WellSampleData; + + +@SuppressWarnings({"OverlyCoupledClass", "unchecked", "IfStatementWithTooManyBranches"}) +public final class Wrapper { + + private static final String UNKNOWN_TYPE = "Unknown type: %s"; + + + private Wrapper() { + } + + + /** + * Converts (wraps) a ShapeData object to a Shape object. + * + * @param object The object to convert + * @param The ShapeData type. + * @param The Shape type. + * + * @return See above. + */ + public static > U wrap(T object) { + U converted; + + if (object instanceof RectangleData) { + converted = (U) new RectangleWrapper((RectangleData) object); + } else if (object instanceof PolygonData) { + converted = (U) new PolygonWrapper((PolygonData) object); + } else if (object instanceof PolylineData) { + converted = (U) new PolylineWrapper((PolylineData) object); + } else if (object instanceof EllipseData) { + converted = (U) new EllipseWrapper((EllipseData) object); + } else if (object instanceof PointData) { + converted = (U) new PointWrapper((PointData) object); + } else if (object instanceof LineData) { + converted = (U) new LineWrapper((LineData) object); + } else if (object instanceof TextData) { + converted = (U) new TextWrapper((TextData) object); + } else if (object instanceof MaskData) { + converted = (U) new MaskWrapper((MaskData) object); + } else { + throw new IllegalArgumentException(String.format(UNKNOWN_TYPE, object.getClass().getName())); + } + return converted; + } + + + /** + * Converts (wraps) an AnnotationData object to an Annotation object. + * + * @param object The object to convert + * @param The AnnotationData type. + * @param The Annotation type. + * + * @return See above. + */ + public static > U wrap(T object) { + U converted; + + if (object instanceof FileAnnotationData) { + converted = (U) new FileAnnotationWrapper((FileAnnotationData) object); + } else if (object instanceof MapAnnotationData) { + converted = (U) new MapAnnotationWrapper((MapAnnotationData) object); + } else if (object instanceof TagAnnotationData) { + converted = (U) new TagAnnotationWrapper((TagAnnotationData) object); + } else { + throw new IllegalArgumentException(String.format(UNKNOWN_TYPE, object.getClass().getName())); + } + return converted; + } + + + /** + * Converts (wraps) a DataObject object to a Repository object. + * + * @param object The object to convert + * @param The DataObject type. + * @param The RepositoryObject type. + * + * @return See above. + */ + public static > + U wrapRepositoryObject(T object) { + U converted; + + if (object instanceof ProjectData) { + converted = (U) new ProjectWrapper((ProjectData) object); + } else if (object instanceof DatasetData) { + converted = (U) new DatasetWrapper((DatasetData) object); + } else if (object instanceof ImageData) { + converted = (U) new ImageWrapper((ImageData) object); + } else if (object instanceof ScreenData) { + converted = (U) new ScreenWrapper((ScreenData) object); + } else if (object instanceof PlateData) { + converted = (U) new PlateWrapper((PlateData) object); + } else if (object instanceof PlateAcquisitionData) { + converted = (U) new PlateAcquisitionWrapper((PlateAcquisitionData) object); + } else if (object instanceof WellData) { + converted = (U) new WellWrapper((WellData) object); + } else if (object instanceof FolderData) { + converted = (U) new FolderWrapper((FolderData) object); + } else { + throw new IllegalArgumentException(String.format(UNKNOWN_TYPE, object.getClass().getName())); + } + return converted; + } + + + /** + * Converts (wraps) a DataObject to a GenericObjectWrapper. + * + * @param object The object to convert + * @param The DataObject type. + * @param The RemoteObject type. + * + * @return See above. + */ + public static > U wrap(T object) { + U converted; + if (object instanceof ShapeData) { + converted = (U) wrap((ShapeData) object); + } else if (object instanceof AnnotationData) { + converted = (U) wrap((AnnotationData) object); + } else if (object instanceof PixelsData) { + converted = (U) new PixelsWrapper((PixelsData) object); + } else if (object instanceof ROIData) { + converted = (U) new ROIWrapper((ROIData) object); + } else if (object instanceof PlaneInfoData) { + converted = (U) new PlaneInfoWrapper((PlaneInfoData) object); + } else if (object instanceof WellSampleData) { + converted = (U) new WellSampleWrapper((WellSampleData) object); + } else if (object instanceof ExperimenterData) { + converted = (U) new ExperimenterWrapper((ExperimenterData) object); + } else if (object instanceof GroupData) { + converted = (U) new GroupWrapper((GroupData) object); + } else if (object instanceof ChannelData) { + converted = (U) new ChannelWrapper((ChannelData) object); + } else { + converted = (U) wrapRepositoryObject(object); + } + return converted; + } + +} diff --git a/src/test/java/fr/igred/omero/util/WrapperTest.java b/src/test/java/fr/igred/omero/util/WrapperTest.java new file mode 100644 index 00000000..04bbb063 --- /dev/null +++ b/src/test/java/fr/igred/omero/util/WrapperTest.java @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package fr.igred.omero.util; + + +import fr.igred.omero.BasicTest; +import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.annotations.AnnotationList; +import fr.igred.omero.annotations.FileAnnotationWrapper; +import fr.igred.omero.annotations.MapAnnotationWrapper; +import fr.igred.omero.annotations.TagAnnotationWrapper; +import fr.igred.omero.meta.ExperimenterWrapper; +import fr.igred.omero.meta.GroupWrapper; +import fr.igred.omero.meta.PlaneInfoWrapper; +import fr.igred.omero.repository.ChannelWrapper; +import fr.igred.omero.repository.DatasetWrapper; +import fr.igred.omero.repository.FolderWrapper; +import fr.igred.omero.repository.ImageWrapper; +import fr.igred.omero.repository.PixelsWrapper; +import fr.igred.omero.repository.PlateAcquisitionWrapper; +import fr.igred.omero.repository.PlateWrapper; +import fr.igred.omero.repository.ProjectWrapper; +import fr.igred.omero.repository.ScreenWrapper; +import fr.igred.omero.repository.WellSampleWrapper; +import fr.igred.omero.repository.WellWrapper; +import fr.igred.omero.roi.EllipseWrapper; +import fr.igred.omero.roi.LineWrapper; +import fr.igred.omero.roi.MaskWrapper; +import fr.igred.omero.roi.PointWrapper; +import fr.igred.omero.roi.PolygonWrapper; +import fr.igred.omero.roi.PolylineWrapper; +import fr.igred.omero.roi.ROIWrapper; +import fr.igred.omero.roi.RectangleWrapper; +import fr.igred.omero.roi.TextWrapper; +import omero.gateway.model.AnnotationData; +import omero.gateway.model.ChannelData; +import omero.gateway.model.DataObject; +import omero.gateway.model.DatasetData; +import omero.gateway.model.EllipseData; +import omero.gateway.model.ExperimenterData; +import omero.gateway.model.FileAnnotationData; +import omero.gateway.model.FolderData; +import omero.gateway.model.GroupData; +import omero.gateway.model.ImageData; +import omero.gateway.model.LineData; +import omero.gateway.model.MapAnnotationData; +import omero.gateway.model.MaskData; +import omero.gateway.model.PixelsData; +import omero.gateway.model.PlaneInfoData; +import omero.gateway.model.PlateAcquisitionData; +import omero.gateway.model.PlateData; +import omero.gateway.model.PointData; +import omero.gateway.model.PolygonData; +import omero.gateway.model.PolylineData; +import omero.gateway.model.ProjectData; +import omero.gateway.model.ROIData; +import omero.gateway.model.RectangleData; +import omero.gateway.model.ScreenData; +import omero.gateway.model.ShapeData; +import omero.gateway.model.TagAnnotationData; +import omero.gateway.model.TextData; +import omero.gateway.model.WellData; +import omero.gateway.model.WellSampleData; +import omero.model.FileAnnotationI; +import omero.model.RectangleI; +import omero.model.TagAnnotationI; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Named.named; +import static org.junit.jupiter.params.provider.Arguments.arguments; + + +@SuppressWarnings({"OverlyCoupledMethod", "OverlyCoupledClass"}) +class WrapperTest extends BasicTest { + + private static Stream classes() { + return Stream.of( + /* These first classes do not have a default constructor. */ + //arguments(named("ChannelData", ChannelData.class, ChannelWrapper.class), + //arguments(named("FileAnnotationData", FileAnnotationData.class, FileAnnotationWrapper.class), + //arguments(named("TagAnnotationData", TagAnnotationData.class, TagAnnotationWrapper.class), + arguments(named("MapAnnotationData", MapAnnotationData.class), MapAnnotationWrapper.class), + arguments(named("ProjectData", ProjectData.class), ProjectWrapper.class), + arguments(named("DatasetData", DatasetData.class), DatasetWrapper.class), + arguments(named("ImageData", ImageData.class), ImageWrapper.class), + arguments(named("ScreenData", ScreenData.class), ScreenWrapper.class), + arguments(named("PlateData", PlateData.class), PlateWrapper.class), + arguments(named("PlateAcquisitionData", PlateAcquisitionData.class), PlateAcquisitionWrapper.class), + arguments(named("WellData", WellData.class), WellWrapper.class), + arguments(named("FolderData", FolderData.class), FolderWrapper.class), + arguments(named("RectangleData", RectangleData.class), RectangleWrapper.class), + arguments(named("PolygonData", PolygonData.class), PolygonWrapper.class), + arguments(named("PolylineData", PolylineData.class), PolylineWrapper.class), + arguments(named("EllipseData", EllipseData.class), EllipseWrapper.class), + arguments(named("PointData", PointData.class), PointWrapper.class), + arguments(named("LineData", LineData.class), LineWrapper.class), + arguments(named("TextData", TextData.class), TextWrapper.class), + arguments(named("MaskData", MaskData.class), MaskWrapper.class), + arguments(named("PixelsData", PixelsData.class), PixelsWrapper.class), + arguments(named("ROIData", ROIData.class), ROIWrapper.class), + arguments(named("PlaneInfoData", PlaneInfoData.class), PlaneInfoWrapper.class), + arguments(named("WellSampleData", WellSampleData.class), WellSampleWrapper.class), + arguments(named("ExperimenterData", ExperimenterData.class), ExperimenterWrapper.class), + arguments(named("GroupData", GroupData.class), GroupWrapper.class) + ); + } + + + @ParameterizedTest(name = "{0}") + @MethodSource("classes") + > void testWrap(Class input, Class output) + throws Exception { + T object = input.getConstructor().newInstance(); + U result = Wrapper.wrap(object); + assertSame(output, result.getClass()); + } + + + @Test + void testWrapChannelData() { + ChannelData object = new ChannelData(0); + assertSame(ChannelWrapper.class, Wrapper.wrap(object).getClass()); + } + + + @Test + void testWrapFileAnnotationData() { + FileAnnotationData object = new FileAnnotationData(new FileAnnotationI()); + assertSame(FileAnnotationWrapper.class, Wrapper.wrap(object).getClass()); + } + + + @Test + void testWrapTagAnnotationData() { + TagAnnotationData object = new TagAnnotationData(new TagAnnotationI()); + assertSame(TagAnnotationWrapper.class, Wrapper.wrap(object).getClass()); + } + + + @Test + void testWrapWrongDataObject() { + DataObject object = new WrongDataObject(); + assertThrows(IllegalArgumentException.class, () -> Wrapper.wrap(object)); + } + + + @Test + void testWrapWrongShapeData() { + ShapeData object = new WrongShapeData(); + assertThrows(IllegalArgumentException.class, () -> Wrapper.wrap(object)); + } + + + @Test + void testWrapWrongAnnotationData() { + AnnotationData object = new WrongAnnotationData(); + assertThrows(IllegalArgumentException.class, () -> Wrapper.wrap(object)); + } + + + @Test + void testAddWrongAnnotationDataToAnnotationList() { + AnnotationList annotations = new AnnotationList(); + + boolean added = annotations.add(new WrongAnnotationData()); + assertFalse(added); + assertEquals(0, annotations.size()); + } + + + private static class WrongDataObject extends DataObject { + + WrongDataObject() { + } + + } + + + private static class WrongShapeData extends ShapeData { + + WrongShapeData() { + super(new RectangleI()); + } + + } + + + private static class WrongAnnotationData extends AnnotationData { + + WrongAnnotationData() { + super(new TagAnnotationI()); + } + + + @Override + public Object getContent() { + return "null"; + } + + + @Override + public void setContent(Object content) { + } + + + @Override + public String getContentAsString() { + return "null"; + } + + } + +} From c24c606b0f2fbb87a1ae99a57b529e22acf77b11 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 17:49:43 +0100 Subject: [PATCH 06/14] Add method to get Annotations from repository object --- .../GenericRepositoryObjectWrapper.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java index f0260cac..38d9b55d 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java @@ -21,6 +21,7 @@ import fr.igred.omero.Client; import fr.igred.omero.GatewayWrapper; import fr.igred.omero.GenericObjectWrapper; +import fr.igred.omero.annotations.AnnotationList; import fr.igred.omero.annotations.FileAnnotationWrapper; import fr.igred.omero.annotations.GenericAnnotationWrapper; import fr.igred.omero.annotations.MapAnnotationWrapper; @@ -289,9 +290,9 @@ public void link(Client client, GenericAnnotationWrapper... annotations) */ public void linkIfNotLinked(Client client, GenericAnnotationWrapper... annotations) throws ServiceException, AccessException, ExecutionException { - List annotationIds = getAnnotations(client).stream() - .map(DataObject::getId) - .collect(Collectors.toList()); + List annotationIds = getAnnotationData(client).stream() + .map(DataObject::getId) + .collect(Collectors.toList()); link(client, Arrays.stream(annotations) .filter(a -> !annotationIds.contains(a.getId())) .toArray(GenericAnnotationWrapper[]::new)); @@ -858,7 +859,7 @@ protected void removeLink(Client client, String linkType, long childId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - private List getAnnotations(Client client) + private List getAnnotationData(Client client) throws AccessException, ServiceException, ExecutionException { List annotations = new ArrayList<>(0); try { @@ -870,6 +871,26 @@ private List getAnnotations(Client client) } + /** + * Retrieves annotations linked to the object (of known types). + * + * @param client The client handling the connection. + * + * @return A list of annotations. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public AnnotationList getAnnotations(Client client) + throws AccessException, ServiceException, ExecutionException { + List annotationData = getAnnotationData(client); + AnnotationList annotations = new AnnotationList(annotationData.size()); + annotationData.forEach(annotations::add); + return annotations; + } + + /** * Copies annotation links from some other object to this one * @@ -882,8 +903,8 @@ private List getAnnotations(Client client) */ public void copyAnnotationLinks(Client client, GenericRepositoryObjectWrapper object) throws AccessException, ServiceException, ExecutionException { - List newAnnotations = object.getAnnotations(client); - List oldAnnotations = this.getAnnotations(client); + List newAnnotations = object.getAnnotationData(client); + List oldAnnotations = this.getAnnotationData(client); for (AnnotationData annotation : oldAnnotations) { newAnnotations.removeIf(a -> a.getId() == annotation.getId()); } From a7bf25ad4c3e4426d5c02d15503d8da3cb7a8ff1 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 17:56:43 +0100 Subject: [PATCH 07/14] Add RatingAnnotationWrapper --- .../annotations/RatingAnnotationWrapper.java | 88 +++++++++++++++++ .../GenericRepositoryObjectWrapper.java | 91 +++++++++++++++++ .../java/fr/igred/omero/util/Wrapper.java | 2 + .../annotations/RatingAnnotationTest.java | 98 +++++++++++++++++++ .../java/fr/igred/omero/util/WrapperTest.java | 6 ++ 5 files changed, 285 insertions(+) create mode 100644 src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java create mode 100644 src/test/java/fr/igred/omero/annotations/RatingAnnotationTest.java diff --git a/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java new file mode 100644 index 00000000..97d8cf2f --- /dev/null +++ b/src/main/java/fr/igred/omero/annotations/RatingAnnotationWrapper.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package fr.igred.omero.annotations; + + +import omero.gateway.model.RatingAnnotationData; + + +/** + * Class containing a RatingAnnotationData object. + *

Wraps function calls to the RatingAnnotationData contained. + */ +public class RatingAnnotationWrapper extends GenericAnnotationWrapper { + + /** Indicates the object is not rated. */ + public static final int LEVEL_ZERO = RatingAnnotationData.LEVEL_ZERO; + + /** Indicates the object is rated with one star. */ + public static final int LEVEL_ONE = RatingAnnotationData.LEVEL_ONE; + + /** Indicates the object is rated with two stars. */ + public static final int LEVEL_TWO = RatingAnnotationData.LEVEL_TWO; + + /** Indicates the object is rated with three stars. */ + public static final int LEVEL_THREE = RatingAnnotationData.LEVEL_THREE; + + /** Indicates the object is rated with four stars. */ + public static final int LEVEL_FOUR = RatingAnnotationData.LEVEL_FOUR; + + /** Indicates the object is rated with five stars. */ + public static final int LEVEL_FIVE = RatingAnnotationData.LEVEL_FIVE; + + + /** + * Constructor of the RatingAnnotationWrapper class. + * + * @param object Rating Annotation to be contained. + */ + public RatingAnnotationWrapper(RatingAnnotationData object) { + super(object); + } + + + /** + * Creates a new Textual Annotation with the provided text. + * + * @param value The rating value. One of the constants defined by this class. + */ + public RatingAnnotationWrapper(int value) { + super(new RatingAnnotationData(value)); + } + + + /** + * Returns the rating value. + * + * @return See above. + */ + public int getRating() { + return data.getRating(); + } + + + /** + * Sets the rating value. + * + * @param value The value to set. Must be one of the constants defined by this class. + */ + public void setRating(int value) { + data.setRating(value); + } + +} diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java index 38d9b55d..ac3cbdf5 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java @@ -25,6 +25,7 @@ import fr.igred.omero.annotations.FileAnnotationWrapper; import fr.igred.omero.annotations.GenericAnnotationWrapper; import fr.igred.omero.annotations.MapAnnotationWrapper; +import fr.igred.omero.annotations.RatingAnnotationWrapper; import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.exception.AccessException; @@ -48,6 +49,7 @@ import omero.gateway.model.DataObject; import omero.gateway.model.FileAnnotationData; import omero.gateway.model.MapAnnotationData; +import omero.gateway.model.RatingAnnotationData; import omero.gateway.model.TableData; import omero.gateway.model.TagAnnotationData; import omero.gateway.util.PojoMapper; @@ -514,6 +516,95 @@ public String getValue(Client client, String key) } + /** + * Rates the object (using a rating annotation). + * + * @param client The client handling the connection. + * @param rating The rating. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws OMEROServerError Server error. + * @throws InterruptedException The thread was interrupted. + */ + public void rate(Client client, int rating) + throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { + String error = "Cannot retrieve rating annotations from " + this; + + List> types = Collections.singletonList(RatingAnnotationData.class); + List userIds = Collections.singletonList(client.getCtx().getExperimenter()); + + List anns = new ArrayList<>(0); + try { + anns = client.getMetadata().getAnnotations(client.getCtx(), data, types, userIds); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, error); + } + List myRatings = anns.stream() + .filter(RatingAnnotationData.class::isInstance) + .map(RatingAnnotationData.class::cast) + .map(RatingAnnotationWrapper::new) + .sorted(Comparator.comparing(RatingAnnotationWrapper::getId)) + .collect(Collectors.toList()); + + if (myRatings.isEmpty()) { + RatingAnnotationWrapper rate = new RatingAnnotationWrapper(rating); + try { + client.getDm().attachAnnotation(client.getCtx(), + rate.asDataObject(), + this.data); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot add rating to " + this); + } + } else { + int n = myRatings.size(); + if (n > 1) client.delete(myRatings.subList(1, n)); + RatingAnnotationWrapper rate = myRatings.get(0); + rate.setRating(rating); + rate.saveAndUpdate(client); + } + } + + + /** + * Returns the user rating for this object (averaged if multiple ratings are linked). + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public int getMyRating(Client client) + throws ServiceException, AccessException, ExecutionException { + String error = "Cannot retrieve rating annotations from " + this; + + List> types = Collections.singletonList(RatingAnnotationData.class); + List userIds = Collections.singletonList(client.getCtx().getExperimenter()); + + List anns = new ArrayList<>(0); + try { + anns = client.getMetadata().getAnnotations(client.getCtx(), data, types, userIds); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, error); + } + List myRatings = anns.stream() + .filter(RatingAnnotationData.class::isInstance) + .map(RatingAnnotationData.class::cast) + .map(RatingAnnotationWrapper::new) + .sorted(Comparator.comparing(RatingAnnotationWrapper::getId)) + .collect(Collectors.toList()); + int score = 0; + for (RatingAnnotationWrapper rate : myRatings) { + score += rate.getRating(); + } + return score / Math.max(1, myRatings.size()); + } + + /** * @param client The client handling the connection. * @param mapAnnotation MapAnnotationWrapper containing a list of NamedValue. diff --git a/src/main/java/fr/igred/omero/util/Wrapper.java b/src/main/java/fr/igred/omero/util/Wrapper.java index ceea991f..43371613 100644 --- a/src/main/java/fr/igred/omero/util/Wrapper.java +++ b/src/main/java/fr/igred/omero/util/Wrapper.java @@ -143,6 +143,8 @@ public static ratings = image.getAnnotations(client) + .getElementsOf(RatingAnnotationWrapper.class); + client.delete(ratings); + + assertEquals(1, ratings.size()); + assertEquals(score, ratings.get(0).getRating()); + } + + + @Test + void testRate1() throws Exception { + ImageWrapper image = client.getImage(IMAGE1.id); + int score1 = 4; + int score2 = 3; + + image.rate(client, score1); + int rating1 = image.getMyRating(client); + image.rate(client, score2); + int rating2 = image.getMyRating(client); + + List ratings = image.getAnnotations(client) + .getElementsOf(RatingAnnotationWrapper.class); + client.delete(ratings); + + assertEquals(1, ratings.size()); + assertEquals(score1, rating1); + assertEquals(score2, rating2); + } + + + @Test + void testRate2() throws Exception { + ImageWrapper image = client.getImage(IMAGE1.id); + int score0 = 1; + int score1 = 2; + int score2 = 3; + + RatingAnnotationWrapper rating1 = new RatingAnnotationWrapper(new RatingAnnotationData()); + rating1.setRating(score0); + RatingAnnotationWrapper rating2 = new RatingAnnotationWrapper(new RatingAnnotationData()); + rating1.setRating(score1); + image.link(client, rating1); + image.link(client, rating2); + int myRating1 = image.getMyRating(client); + image.rate(client, score2); + int myRating2 = image.getMyRating(client); + + List ratings = image.getAnnotations(client) + .getElementsOf(RatingAnnotationWrapper.class); + client.delete(ratings); + + assertEquals(1, ratings.size()); + assertEquals((score0 + score1) / 2, myRating1); + assertEquals(score2, myRating2); + } + +} diff --git a/src/test/java/fr/igred/omero/util/WrapperTest.java b/src/test/java/fr/igred/omero/util/WrapperTest.java index 04bbb063..8fb54394 100644 --- a/src/test/java/fr/igred/omero/util/WrapperTest.java +++ b/src/test/java/fr/igred/omero/util/WrapperTest.java @@ -23,6 +23,7 @@ import fr.igred.omero.annotations.AnnotationList; import fr.igred.omero.annotations.FileAnnotationWrapper; import fr.igred.omero.annotations.MapAnnotationWrapper; +import fr.igred.omero.annotations.RatingAnnotationWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.meta.GroupWrapper; @@ -69,13 +70,16 @@ import omero.gateway.model.PolylineData; import omero.gateway.model.ProjectData; import omero.gateway.model.ROIData; +import omero.gateway.model.RatingAnnotationData; import omero.gateway.model.RectangleData; import omero.gateway.model.ScreenData; import omero.gateway.model.ShapeData; import omero.gateway.model.TagAnnotationData; import omero.gateway.model.TextData; +import omero.gateway.model.TextualAnnotationData; import omero.gateway.model.WellData; import omero.gateway.model.WellSampleData; +import omero.model.CommentAnnotationI; import omero.model.FileAnnotationI; import omero.model.RectangleI; import omero.model.TagAnnotationI; @@ -103,6 +107,8 @@ private static Stream classes() { //arguments(named("ChannelData", ChannelData.class, ChannelWrapper.class), //arguments(named("FileAnnotationData", FileAnnotationData.class, FileAnnotationWrapper.class), //arguments(named("TagAnnotationData", TagAnnotationData.class, TagAnnotationWrapper.class), + //arguments(named("TextualAnnotationData", TextualAnnotationData.class), TextualAnnotationWrapper.class), + arguments(named("RatingAnnotationData", RatingAnnotationData.class), RatingAnnotationWrapper.class), arguments(named("MapAnnotationData", MapAnnotationData.class), MapAnnotationWrapper.class), arguments(named("ProjectData", ProjectData.class), ProjectWrapper.class), arguments(named("DatasetData", DatasetData.class), DatasetWrapper.class), From ca291c70e0dbd02c95191ad126cbe61676a22dd6 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 21 Feb 2023 18:28:20 +0100 Subject: [PATCH 08/14] Add TextualAnnotationWrapper --- .../annotations/TextualAnnotationWrapper.java | 69 ++++++++++++++++++ .../java/fr/igred/omero/util/Wrapper.java | 5 ++ .../annotations/TextualAnnotationTest.java | 70 +++++++++++++++++++ .../java/fr/igred/omero/util/WrapperTest.java | 8 +++ 4 files changed, 152 insertions(+) create mode 100644 src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java create mode 100644 src/test/java/fr/igred/omero/annotations/TextualAnnotationTest.java diff --git a/src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java new file mode 100644 index 00000000..1382e0ae --- /dev/null +++ b/src/main/java/fr/igred/omero/annotations/TextualAnnotationWrapper.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package fr.igred.omero.annotations; + + +import omero.gateway.model.TextualAnnotationData; + + +/** + * Class containing a TextualAnnotationData object. + *

Wraps function calls to the TextualAnnotationData contained. + */ +public class TextualAnnotationWrapper extends GenericAnnotationWrapper { + + /** + * Constructor of the TextualAnnotationWrapper class. + * + * @param object Textual Annotation to be contained. + */ + public TextualAnnotationWrapper(TextualAnnotationData object) { + super(object); + } + + + /** + * Creates a new Textual Annotation with the provided text. + * + * @param text Textual Annotation to be contained. + */ + public TextualAnnotationWrapper(String text) { + super(new TextualAnnotationData(text)); + } + + + /** + * Returns the text of this annotation. + * + * @return See above. + */ + public String getText() { + return data.getText(); + } + + + /** + * Sets the text. + * + * @param text The value to set. + */ + public void setText(String text) { + data.setText(text); + } + +} diff --git a/src/main/java/fr/igred/omero/util/Wrapper.java b/src/main/java/fr/igred/omero/util/Wrapper.java index 43371613..802fdaa0 100644 --- a/src/main/java/fr/igred/omero/util/Wrapper.java +++ b/src/main/java/fr/igred/omero/util/Wrapper.java @@ -24,6 +24,7 @@ import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.RatingAnnotationWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; +import fr.igred.omero.annotations.TextualAnnotationWrapper; import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.meta.GroupWrapper; import fr.igred.omero.meta.PlaneInfoWrapper; @@ -71,11 +72,13 @@ import omero.gateway.model.PolylineData; import omero.gateway.model.ProjectData; import omero.gateway.model.ROIData; +import omero.gateway.model.RatingAnnotationData; import omero.gateway.model.RectangleData; import omero.gateway.model.ScreenData; import omero.gateway.model.ShapeData; import omero.gateway.model.TagAnnotationData; import omero.gateway.model.TextData; +import omero.gateway.model.TextualAnnotationData; import omero.gateway.model.WellData; import omero.gateway.model.WellSampleData; @@ -145,6 +148,8 @@ public static texts = annotations.getElementsOf(TextualAnnotationWrapper.class); + client.delete(texts); + + assertEquals(1, texts.size()); + assertEquals(test, texts.get(0).getText()); + } + + + @Test + void testAddTextualAnnotation2() throws Exception { + ImageWrapper image = client.getImage(IMAGE1.id); + + String test = "Test !"; + + TextualAnnotationWrapper text = new TextualAnnotationWrapper("New"); + text.setText(test); + image.link(client, text); + AnnotationList annotations = image.getAnnotations(client); + + List texts = annotations.getElementsOf(TextualAnnotationWrapper.class); + client.delete(texts); + + assertEquals(1, texts.size()); + assertEquals(test, texts.get(0).getText()); + } + +} diff --git a/src/test/java/fr/igred/omero/util/WrapperTest.java b/src/test/java/fr/igred/omero/util/WrapperTest.java index 8fb54394..54b0a5c2 100644 --- a/src/test/java/fr/igred/omero/util/WrapperTest.java +++ b/src/test/java/fr/igred/omero/util/WrapperTest.java @@ -25,6 +25,7 @@ import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.RatingAnnotationWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; +import fr.igred.omero.annotations.TextualAnnotationWrapper; import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.meta.GroupWrapper; import fr.igred.omero.meta.PlaneInfoWrapper; @@ -167,6 +168,13 @@ void testWrapTagAnnotationData() { } + @Test + void testWrapTextualAnnotationData() { + TextualAnnotationData object = new TextualAnnotationData(new CommentAnnotationI()); + assertSame(TextualAnnotationWrapper.class, Wrapper.wrap(object).getClass()); + } + + @Test void testWrapWrongDataObject() { DataObject object = new WrongDataObject(); From 24cea5842de16c7684e8bedeca9f3169813a3b06 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 22 Feb 2023 01:15:14 +0100 Subject: [PATCH 09/14] Add methods to Client to retrieve objects for a given user --- src/main/java/fr/igred/omero/Client.java | 118 ++++++++++++++++++- src/test/java/fr/igred/omero/ClientTest.java | 92 +++++++++++++++ 2 files changed, 209 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index 658dc8cc..46930084 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -159,6 +159,29 @@ public List getProjects() throws ServiceException, AccessExcepti } + /** + * Gets all projects available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getProjects(ExperimenterWrapper experimenter) + throws ServiceException, AccessException, ExecutionException { + Collection projects = new ArrayList<>(0); + try { + projects = getBrowseFacility().getProjects(getCtx(), experimenter.getId()); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot get projects for user " + experimenter); + } + return wrap(projects, ProjectWrapper::new); + } + + /** * Gets all projects with a certain name from OMERO. * @@ -226,6 +249,30 @@ public List getDatasets(Long... ids) } + /** + * Gets all datasets available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws OMEROServerError Server error. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getDatasets(ExperimenterWrapper experimenter) + throws ServiceException, AccessException, OMEROServerError, ExecutionException { + String query = String.format("select d from Dataset d where d.details.owner.id=%d", experimenter.getId()); + Long[] ids = this.findByQuery(query) + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getDatasets(ids); + } + + /** * Gets all datasets available from OMERO. * @@ -563,6 +610,29 @@ public List getScreens() throws ServiceException, AccessException } + /** + * Gets all screens available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getScreens(ExperimenterWrapper experimenter) + throws ServiceException, AccessException, ExecutionException { + Collection screens = new ArrayList<>(0); + try { + screens = getBrowseFacility().getScreens(getCtx(), experimenter.getId()); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot get screens for user " + experimenter); + } + return wrap(screens, ScreenWrapper::new); + } + + /** * Gets the plate with the specified id from OMERO. * @@ -627,6 +697,29 @@ public List getPlates() throws ServiceException, AccessException, } + /** + * Gets all plates available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlates(ExperimenterWrapper experimenter) + throws ServiceException, AccessException, ExecutionException { + Collection plates = new ArrayList<>(0); + try { + plates = getBrowseFacility().getPlates(getCtx(), experimenter.getId()); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot get plates for user " + experimenter); + } + return wrap(plates, PlateWrapper::new); + } + + /** * Gets the well with the specified id from OMERO. * @@ -693,6 +786,30 @@ public List getWells() } + /** + * Gets all wells available from OMERO owned by a given user. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws OMEROServerError Server error. + */ + public List getWells(ExperimenterWrapper experimenter) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + String query = String.format("select w from Well w where w.details.owner.id=%d", experimenter.getId()); + Long[] ids = this.findByQuery(query) + .stream() + .map(IObject::getId) + .map(RLong::getValue) + .toArray(Long[]::new); + return getWells(ids); + } + + /** * Gets the list of TagAnnotationWrapper available to the user * @@ -902,4 +1019,3 @@ public Client sudoGetUser(String username) throws ServiceException, AccessExcept } } - diff --git a/src/test/java/fr/igred/omero/ClientTest.java b/src/test/java/fr/igred/omero/ClientTest.java index cde1603e..fe6142b3 100644 --- a/src/test/java/fr/igred/omero/ClientTest.java +++ b/src/test/java/fr/igred/omero/ClientTest.java @@ -18,6 +18,7 @@ package fr.igred.omero; +import fr.igred.omero.meta.ExperimenterWrapper; import fr.igred.omero.repository.DatasetWrapper; import fr.igred.omero.repository.ImageWrapper; import fr.igred.omero.repository.PlateWrapper; @@ -276,4 +277,95 @@ void testGetSingleWell() throws Exception { assertEquals(PLATE1.name, plateName); } + + @Test + void testGetAllProjectsForUser1() throws Exception { + ExperimenterWrapper user = client.getUser("testUser"); + + Collection projects = client.getProjects(user); + assertEquals(2, projects.size()); + } + + + @Test + void testGetAllProjectsForUser2() throws Exception { + ExperimenterWrapper user = client.getUser("testUser2"); + + Collection projects = client.getProjects(user); + assertEquals(0, projects.size()); + } + + + @Test + void testGetAllDatasetsForUser1() throws Exception { + ExperimenterWrapper user = client.getUser("testUser"); + + Collection datasets = client.getDatasets(user); + assertEquals(4, datasets.size()); + } + + + @Test + void testGetAllDatasetsForUser2() throws Exception { + ExperimenterWrapper user = client.getUser("testUser2"); + + Collection datasets = client.getDatasets(user); + assertEquals(0, datasets.size()); + } + + + @Test + void testGetAllScreensForUser1() throws Exception { + ExperimenterWrapper user = client.getUser("testUser"); + + Collection screens = client.getScreens(user); + assertEquals(2, screens.size()); + } + + + @Test + void testGetAllScreensForUser2() throws Exception { + ExperimenterWrapper user = client.getUser("testUser2"); + + Collection screens = client.getScreens(user); + assertEquals(0, screens.size()); + } + + + @Test + void testGetAllPlatesForUser1() throws Exception { + ExperimenterWrapper user = client.getUser("testUser"); + + Collection plates = client.getPlates(user); + assertEquals(3, plates.size()); + } + + + @Test + void testGetAllPlatesForUser2() throws Exception { + ExperimenterWrapper user = client.getUser("testUser2"); + + Collection plates = client.getPlates(user); + assertEquals(0, plates.size()); + } + + + @Test + void testGetAllWellsForUser1() throws Exception { + ExperimenterWrapper user = client.getUser("testUser"); + final int nWells = 17; + + Collection wells = client.getWells(user); + assertEquals(nWells, wells.size()); + } + + + @Test + void testGetAllWellsForUser2() throws Exception { + ExperimenterWrapper user = client.getUser("testUser2"); + + Collection wells = client.getWells(user); + assertEquals(0, wells.size()); + } + } From c5b89ae115c551a63e715165a2802347cf3bccc8 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 22 Feb 2023 01:18:46 +0100 Subject: [PATCH 10/14] Add saveROIs vararg method to ImageWrapper --- .../igred/omero/repository/ImageWrapper.java | 42 ++++++++++++------- .../java/fr/igred/omero/roi/ROIWrapper.java | 9 ++-- .../omero/annotations/ImageJTableTest.java | 8 ++-- .../omero/repository/ImageImportTest.java | 4 +- src/test/java/fr/igred/omero/roi/ROITest.java | 6 +-- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index 7268d0f4..49c807ee 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -62,8 +62,8 @@ import java.io.IOException; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; @@ -384,10 +384,10 @@ public List getFilesetImages(Client client) public List saveROIs(Client client, Collection rois) throws ServiceException, AccessException, ExecutionException { rois.forEach(r -> r.setImage(this)); - List roisData = rois.stream() - .map(GenericObjectWrapper::asDataObject) - .collect(Collectors.toList()); - Collection results = new ArrayList<>(0); + List roisData = rois.stream() + .map(GenericObjectWrapper::asDataObject) + .collect(Collectors.toList()); + Collection results = new ArrayList<>(0); try { results = client.getRoiFacility().saveROIs(client.getCtx(), data.getId(), roisData); } catch (DSOutOfServiceException | DSAccessException e) { @@ -398,28 +398,38 @@ public List saveROIs(Client client, Collection /** - * Links a ROI to the image in OMERO + * Links ROIs to the image in OMERO. *

DO NOT USE IT IF A SHAPE WAS DELETED !!! * + * @param client The data manager. + * @param rois ROIs to be added. + * + * @return The updated list of ROIs. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List saveROIs(Client client, ROIWrapper... rois) + throws ServiceException, AccessException, ExecutionException { + return saveROIs(client, Arrays.asList(rois)); + } + + + /** * @param client The client handling the connection. * @param roi ROI to be added. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Links a ROI to the image in OMERO + *

DO NOT USE IT IF A SHAPE WAS DELETED !!! */ + @Deprecated public void saveROI(Client client, ROIWrapper roi) throws ServiceException, AccessException, ExecutionException { - try { - ROIData roiData = client.getRoiFacility() - .saveROIs(client.getCtx(), - data.getId(), - Collections.singletonList(roi.asROIData())) - .iterator().next(); - roi.setData(roiData); - } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot link ROI to " + this); - } + roi.setData(saveROIs(client, roi).iterator().next().asDataObject()); } diff --git a/src/main/java/fr/igred/omero/roi/ROIWrapper.java b/src/main/java/fr/igred/omero/roi/ROIWrapper.java index 3baf9f3b..5ba4f318 100644 --- a/src/main/java/fr/igred/omero/roi/ROIWrapper.java +++ b/src/main/java/fr/igred/omero/roi/ROIWrapper.java @@ -289,10 +289,11 @@ public void setName(String name) { /** - * Changes the wrapped data. - * * @param data The ROI data. + * + * @deprecated Changes the wrapped data. */ + @Deprecated public void setData(ROIData data) { this.data = data; } @@ -319,14 +320,14 @@ public void addShape(GenericShapeWrapper shape) { /** - * Returns the list of shapes contained in the ROIData + * Returns the list of shapes contained in the ROIData. * * @return list of shape contained in the ROIData. */ public ShapeList getShapes() { List shapeData = data.getShapes(); ShapeList shapes = new ShapeList(shapeData.size()); - data.getShapes().stream().sorted(Comparator.comparing(ShapeData::getId)).forEach(shapes::add); + shapeData.stream().sorted(Comparator.comparing(ShapeData::getId)).forEach(shapes::add); return shapes; } diff --git a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java index c62ab880..babeb40b 100644 --- a/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java +++ b/src/test/java/fr/igred/omero/annotations/ImageJTableTest.java @@ -74,7 +74,7 @@ private static List createAndSaveROI(Client client, ImageWrapper ima roi.addShape(rectangle); } if (name != null && !name.trim().isEmpty()) roi.setName(name); - image.saveROI(client, roi); + image.saveROIs(client, roi); return image.getROIs(client); } @@ -138,7 +138,7 @@ public void cleanUp() { @Test void testCreateTableWithROIsFromIJResults1() throws Exception { List rois = createAndSaveROI(client, image, "ROI_1"); - List ijRois = ROIWrapper.toImageJ(rois, null, false); + List ijRois = ROIWrapper.toImageJ(rois, null, false); String label = image.getName(); @@ -515,8 +515,8 @@ void testCreateTableWithROINamesFromIJResults2() throws Exception { else roi2.addShape(rectangle); } - image.saveROI(client, roi1); - image.saveROI(client, roi2); + image.saveROIs(client, roi1); + image.saveROIs(client, roi2); List rois = image.getROIs(client); List ijRois = ROIWrapper.toImageJ(rois); diff --git a/src/test/java/fr/igred/omero/repository/ImageImportTest.java b/src/test/java/fr/igred/omero/repository/ImageImportTest.java index 670bb8a9..19ddfe62 100644 --- a/src/test/java/fr/igred/omero/repository/ImageImportTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageImportTest.java @@ -101,7 +101,7 @@ void testReplaceAndDeleteImages() throws Exception { ROIWrapper roi = new ROIWrapper(); roi.setImage(image2); roi.addShape(rectangle); - image2.saveROI(client, roi); + roi = image2.saveROIs(client, roi).get(0); FolderWrapper folder = new FolderWrapper(client, "ReplaceTestFolder"); folder.setImage(image2); @@ -185,7 +185,7 @@ void testReplaceAndUnlinkImages() throws Exception { ROIWrapper roi = new ROIWrapper(); roi.setImage(image2); roi.addShape(rectangle); - image2.saveROI(client, roi); + roi = image2.saveROIs(client, roi).get(0); FolderWrapper folder = new FolderWrapper(client, "ReplaceTestFolder"); folder.setImage(image2); diff --git a/src/test/java/fr/igred/omero/roi/ROITest.java b/src/test/java/fr/igred/omero/roi/ROITest.java index f0946f00..fa8ab9e0 100644 --- a/src/test/java/fr/igred/omero/roi/ROITest.java +++ b/src/test/java/fr/igred/omero/roi/ROITest.java @@ -83,7 +83,7 @@ void testROI2() throws Exception { ROIWrapper roiWrapper = new ROIWrapper(shapes); roiWrapper.setImage(image); - image.saveROI(client, roiWrapper); + image.saveROIs(client, roiWrapper); List rois = image.getROIs(client); @@ -116,7 +116,7 @@ void testRoiAddShapeAndDeleteIt() throws Exception { ROIWrapper roi = new ROIWrapper(); roi.addShapes(shapes); roi.setImage(image); - image.saveROI(client, roi); + image.saveROIs(client, roi); List rois = image.getROIs(client); @@ -203,7 +203,7 @@ void testROIAllShapes() throws Exception { roiWrapper.addShape(line); roiWrapper.addShape(polyline); roiWrapper.addShape(polygon); - image.saveROI(client, roiWrapper); + image.saveROIs(client, roiWrapper); List rois = image.getROIs(client); ShapeList shapes = rois.get(0).getShapes(); From da62bb18a01576995882788334430f92bdb3b233 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 22 Feb 2023 12:26:10 +0100 Subject: [PATCH 11/14] Refactor FolderWrapper --- src/main/java/fr/igred/omero/Client.java | 98 +++++- .../annotations/GenericAnnotationWrapper.java | 21 ++ .../omero/repository/DatasetWrapper.java | 7 +- .../igred/omero/repository/FolderWrapper.java | 326 ++++++++++++++++-- .../igred/omero/repository/ImageWrapper.java | 29 +- .../fr/igred/omero/AccessExceptionTest.java | 3 +- .../fr/igred/omero/repository/FolderTest.java | 107 +++++- .../omero/repository/ImageImportTest.java | 16 +- 8 files changed, 544 insertions(+), 63 deletions(-) diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index 46930084..cbd060ac 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -40,6 +40,7 @@ import omero.gateway.exception.DSOutOfServiceException; import omero.gateway.model.DatasetData; import omero.gateway.model.ExperimenterData; +import omero.gateway.model.FolderData; import omero.gateway.model.GroupData; import omero.gateway.model.ImageData; import omero.gateway.model.PlateData; @@ -810,6 +811,99 @@ public List getWells(ExperimenterWrapper experimenter) } + /** + * Gets the folder with the specified ID from OMERO, fully loaded. + * + * @param id ID of the folder. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws NoSuchElementException No element with such id. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public FolderWrapper getFolder(long id) + throws ServiceException, AccessException, ExecutionException { + List folders = loadFolders(id); + if (folders.isEmpty()) { + throw new NoSuchElementException(String.format("Folder %d doesn't exist in this context", id)); + } + return folders.iterator().next(); + } + + + /** + * Gets all folders available from OMERO. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getFolders() + throws ExecutionException, AccessException, ServiceException { + Collection folders = new ArrayList<>(0); + try { + folders = getBrowseFacility().getFolders(getCtx()); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot get folders"); + } + return wrap(folders, FolderWrapper::new); + } + + + /** + * Gets all the folders owned by a given user from OMERO. + * + * @param experimenter The user. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getFolders(ExperimenterWrapper experimenter) + throws ExecutionException, AccessException, ServiceException { + String error = String.format("Cannot get folders for user %s", experimenter); + + Collection folders = new ArrayList<>(0); + try { + folders = getBrowseFacility().getFolders(getCtx(), experimenter.getId()); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, error); + } + return wrap(folders, FolderWrapper::new); + } + + + /** + * Gets the folders with the specified IDs from OMERO (fully loaded). + * + * @param ids Project IDs + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List loadFolders(Long... ids) + throws ServiceException, AccessException, ExecutionException { + String error = "Cannot get folders with IDs: " + Arrays.toString(ids); + + Collection folders = new ArrayList<>(0); + try { + folders = getBrowseFacility().loadFolders(getCtx(), Arrays.asList(ids)); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, error); + } + return wrap(folders, FolderWrapper::new); + } + + /** * Gets the list of TagAnnotationWrapper available to the user * @@ -892,7 +986,7 @@ public void delete(Collection> objects) throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { for (GenericObjectWrapper object : objects) { if (object instanceof FolderWrapper) { - ((FolderWrapper) object).unlinkAllROI(this); + ((FolderWrapper) object).unlinkAllROIs(this); } } if (!objects.isEmpty()) { @@ -915,7 +1009,7 @@ public void delete(Collection> objects) public void delete(GenericObjectWrapper object) throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException { if (object instanceof FolderWrapper) { - ((FolderWrapper) object).unlinkAllROI(this); + ((FolderWrapper) object).unlinkAllROIs(this); } delete(object.asIObject()); } diff --git a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java index b9568a32..80286415 100644 --- a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java @@ -24,6 +24,7 @@ import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import fr.igred.omero.repository.DatasetWrapper; +import fr.igred.omero.repository.FolderWrapper; import fr.igred.omero.repository.ImageWrapper; import fr.igred.omero.repository.PlateWrapper; import fr.igred.omero.repository.ProjectWrapper; @@ -243,6 +244,26 @@ public List getWells(Client client) } + /** + * Gets all folders with this annotation from OMERO. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws OMEROServerError Server error. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getFolders(Client client) + throws ServiceException, AccessException, OMEROServerError, ExecutionException { + List os = getLinks(client, FolderWrapper.ANNOTATION_LINK); + Long[] ids = os.stream().map(IObject::getId).map(RLong::getValue).sorted().toArray(Long[]::new); + return client.loadFolders(ids); + } + + /** * Retrieves all links of the given type. * diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index f737c3cb..a4c79b19 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -490,10 +490,9 @@ public List replaceImages(Client client, descriptions.add(oldImage.getDescription()); newImage.copyAnnotationLinks(client, oldImage); List rois = oldImage.getROIs(client); - for (ROIWrapper roi : rois) { - roi.setImage(newImage); - newImage.saveROI(client, roi); - } + newImage.saveROIs(client, rois); + List folders = oldImage.getFolders(client); + for (FolderWrapper folder : folders) folder.addImages(client, newImage); this.removeImage(client, oldImage); if (oldImage.isOrphaned(client)) { orphaned.add(oldImage); diff --git a/src/main/java/fr/igred/omero/repository/FolderWrapper.java b/src/main/java/fr/igred/omero/repository/FolderWrapper.java index 679018a0..b4c18e22 100644 --- a/src/main/java/fr/igred/omero/repository/FolderWrapper.java +++ b/src/main/java/fr/igred/omero/repository/FolderWrapper.java @@ -29,13 +29,19 @@ import omero.gateway.exception.DSAccessException; import omero.gateway.exception.DSOutOfServiceException; import omero.gateway.facility.ROIFacility; +import omero.gateway.model.DataObject; import omero.gateway.model.FolderData; +import omero.gateway.model.ROIData; import omero.gateway.model.ROIResult; import omero.model.Folder; import omero.model.FolderAnnotationLink; import omero.model.FolderAnnotationLinkI; +import omero.model.FolderImageLink; +import omero.model.FolderImageLinkI; +import omero.model.IObject; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -56,8 +62,11 @@ public class FolderWrapper extends GenericRepositoryObjectWrapper { /** Annotation link name for this type of object */ public static final String ANNOTATION_LINK = "FolderAnnotationLink"; + /** Empty ROI array for fast list conversion */ + private static final ROIWrapper[] EMPTY_ROI_ARRAY = new ROIWrapper[0]; + /** ID of the associated image */ - private long imageId = -1L; + private long imageID = -1L; /** @@ -191,52 +200,215 @@ public void setDescription(String description) { /** - * Sets the image associated to the folder + * Reloads the folder from OMERO, to update all links. + * + * @param client The client handling the connection. + * + * @throws AccessException Cannot access data. + * @throws ServiceException Cannot connect to OMERO. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void reload(Client client) + throws AccessException, ServiceException, ExecutionException { + data = client.getFolder(getId()).asDataObject(); + } + + + /** + * Retrieves the parent folders for this folder. + * + * @return See above + */ + public FolderWrapper getParent() { + return new FolderWrapper(data.getParentFolder()); + } + + + /** + * Sets the parent folder for this folder. + * + * @param folder The new parent folder. + */ + public void setParent(FolderWrapper folder) { + data.setParentFolder(folder.asDataObject().asFolder()); + } + + + /** + * Adds a child folder to this folder. + * + * @param folder The new child folder. + */ + public void addChild(FolderWrapper folder) { + data.asFolder().addChildFolders(folder.asDataObject().asFolder()); + } + + + /** + * Adds children folders to this folder. + * + * @param folders The new children folders. + */ + public void addChildren(Collection folders) { + data.asFolder().addAllChildFoldersSet(folders.stream() + .map(GenericObjectWrapper::asDataObject) + .map(DataObject::asFolder) + .collect(Collectors.toList())); + } + + + /** + * Retrieves the children folders for this folder. + * + * @return See above + */ + public List getChildren() { + return wrap(data.copyChildFolders(), FolderWrapper::new); + } + + + /** + * Links images to the folder in OMERO. + * + * @param client The client handling the connection. + * @param images Images to add. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void addImages(Client client, ImageWrapper... images) + throws ServiceException, AccessException, ExecutionException { + List links = new ArrayList<>(images.length); + List linkedIds = getImages().stream().map(GenericObjectWrapper::getId).collect(Collectors.toList()); + for (ImageWrapper image : images) { + if (!linkedIds.contains(image.getId())) { + FolderImageLink link = new FolderImageLinkI(); + link.setChild(image.asDataObject().asImage()); + link.setParent(data.asFolder()); + links.add(link); + } + } + try { + client.getDm().saveAndReturnObject(client.getCtx(), links, null, null); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot save links."); + } + } + + + /** + * Retrieves the images contained in this folder. * + * @return See above + */ + public List getImages() { + return wrap(data.copyImageLinks(), ImageWrapper::new); + } + + + /** + * Retrieves the images contained in this folder. + * + * @param client The client handling the connection. + * + * @return See above + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImages(Client client) throws AccessException, ServiceException, ExecutionException { + reload(client); + return getImages(); + } + + + /** * @param id ID of the image to associate. + * + * @deprecated Sets the image associated to the folder */ + @Deprecated public void setImage(long id) { - imageId = id; + imageID = id; } /** - * Sets the image associated to the folder - * * @param image Image to associate. + * + * @deprecated Sets the image associated to the folder */ + @Deprecated public void setImage(ImageWrapper image) { - imageId = image.getId(); + imageID = image.getId(); } /** - * Add an ROI to the folder and associate it to the image id set(an image need to be associated) - * * @param client The client handling the connection. * @param roi ROI to add. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. + * @deprecated Adds an ROI to the folder and associate it to the image id set(an image need to be associated) */ + @Deprecated public void addROI(Client client, ROIWrapper roi) throws ServiceException, AccessException, ExecutionException { + addROIs(client, imageID, roi); + } + + + /** + * Adds ROIs to the folder and associate them to the provided image ID. + * + * @param client The client handling the connection. + * @param imageId The image ID. + * @param rois ROIs to add. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. + */ + public void addROIs(Client client, long imageId, ROIWrapper... rois) + throws ServiceException, AccessException, ExecutionException { + List roiData = Arrays.stream(rois) + .map(GenericObjectWrapper::asDataObject) + .collect(Collectors.toList()); + ROIFacility roiFac = client.getRoiFacility(); try { roiFac.addRoisToFolders(client.getCtx(), imageId, - Collections.singletonList(roi.asROIData()), + roiData, Collections.singletonList(data)); } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot add ROI to " + this); + handleServiceOrAccess(e, "Cannot add ROIs to " + this); } } /** - * Gets the ROI contained in the folder associated with the image id set (an image need to be associated) + * Adds ROIs to the folder and associate them to the provided image. * + * @param client The client handling the connection. + * @param image The image. + * @param rois ROIs to add. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException If the ROIFacility can't be retrieved or instantiated. + */ + public void addROIs(Client client, ImageWrapper image, ROIWrapper... rois) + throws ServiceException, AccessException, ExecutionException { + addROIs(client, image.getId(), rois); + } + + + /** * @param client The client handling the connection. * * @return List of ROIWrapper containing the ROI. @@ -244,8 +416,29 @@ public void addROI(Client client, ROIWrapper roi) * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets the ROI contained in the folder associated with the image id set (an image need to be + * associated) */ + @Deprecated public List getROIs(Client client) + throws ServiceException, AccessException, ExecutionException { + return getROIs(client, imageID); + } + + + /** + * Gets the ROIs contained in the folder associated with the provided image ID. + * + * @param client The client handling the connection. + * @param imageId The image. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getROIs(Client client, long imageId) throws ServiceException, AccessException, ExecutionException { ROIFacility roiFac = client.getRoiFacility(); @@ -268,45 +461,126 @@ public List getROIs(Client client) /** - * Unlink all ROI, associated to the image set, in the folder. ROIs are now linked to the image directly + * Gets the ROIs contained in the folder associated with the provided image. * * @param client The client handling the connection. + * @param image The image. + * + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ + public List getROIs(Client client, ImageWrapper image) + throws ServiceException, AccessException, ExecutionException { + return getROIs(client, image.getId()); + } + + + /** + * @param client The client handling the connection. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Unlink all ROI, associated to the image set, in the folder. ROIs are now linked to the image directly + */ + @Deprecated public void unlinkAllROI(Client client) throws ServiceException, AccessException, ExecutionException { - try { - List rois = getROIs(client); - for (ROIWrapper roi : rois) { - client.getRoiFacility().removeRoisFromFolders(client.getCtx(), - this.imageId, - Collections.singletonList(roi.asROIData()), - Collections.singletonList(data)); - } - } catch (DSOutOfServiceException | DSAccessException e) { - handleServiceOrAccess(e, "Cannot unlink ROIs from " + this); - } + unlinkAllROIs(client); } /** - * Unlink an ROI, associated to the image set, in the folder. the ROI is now linked to the image directly + * Unlink all ROIs associated to the provided image ID from the folder. + *

ROIs are now linked to the image directly. + * + * @param client The client handling the connection. + * @param imageId The image ID. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void unlinkAllROIs(Client client, long imageId) + throws ServiceException, AccessException, ExecutionException { + unlinkROIs(client, getROIs(client, imageId).toArray(EMPTY_ROI_ARRAY)); + } + + + /** + * Unlink all ROIs associated to the provided image from the folder. + *

ROIs are now linked to the image directly. + * + * @param client The client handling the connection. + * @param image The image. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void unlinkAllROIs(Client client, ImageWrapper image) + throws ServiceException, AccessException, ExecutionException { + unlinkAllROIs(client, image.getId()); + } + + + /** + * Unlink all ROIs associated to this folder. + *

The folder must be loaded beforehand.

+ *

ROIs are now linked to their images directly.

* + * @param client The client handling the connection. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void unlinkAllROIs(Client client) + throws ServiceException, AccessException, ExecutionException { + Collection rois = wrap(data.copyROILinks(), ROIWrapper::new); + unlinkROIs(client, rois.toArray(EMPTY_ROI_ARRAY)); + } + + + /** * @param client The client handling the connection. * @param roi ROI to unlink. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Unlink an ROI, associated to the image set, in the folder. The ROI is now linked to the image + * directly. */ + @Deprecated public void unlinkROI(Client client, ROIWrapper roi) throws ServiceException, AccessException, ExecutionException { + unlinkROIs(client, roi); + } + + + /** + * Unlink ROIs from the folder. + *

The ROIs are now linked to the image directly. + * + * @param client The data manager. + * @param rois ROI to unlink. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void unlinkROIs(Client client, ROIWrapper... rois) + throws ServiceException, AccessException, ExecutionException { + List roiData = Arrays.stream(rois) + .map(GenericObjectWrapper::asDataObject) + .collect(Collectors.toList()); try { client.getRoiFacility().removeRoisFromFolders(client.getCtx(), - this.imageId, - Collections.singletonList(roi.asROIData()), + this.imageID, + roiData, Collections.singletonList(data)); } catch (DSOutOfServiceException | DSAccessException e) { handleServiceOrAccess(e, "Cannot unlink ROI from " + this); diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index 49c807ee..e2e96cee 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -465,17 +465,17 @@ public List getROIs(Client client) /** - * Gets the list of Folder linked to the image Associate the folder to the image + * Gets the list of folders linked to the ROIs in this image. * * @param client The client handling the connection. * - * @return List of FolderWrapper containing the folder. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public List getFolders(Client client) + public List getROIFolders(Client client) throws ServiceException, AccessException, ExecutionException { ROIFacility roiFacility = client.getRoiFacility(); @@ -489,7 +489,6 @@ public List getFolders(Client client) List roiFolders = new ArrayList<>(folders.size()); for (FolderData folder : folders) { FolderWrapper roiFolder = new FolderWrapper(folder); - roiFolder.setImage(this.data.getId()); roiFolders.add(roiFolder); } @@ -498,8 +497,26 @@ public List getFolders(Client client) /** - * Gets the folder with the specified id on OMERO. + * Gets the list of folders linked to this image. * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws OMEROServerError Server error. + */ + public List getFolders(Client client) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + String query = String.format("select link.parent from FolderImageLink as link where link.child.id=%d", getId()); + Long[] ids = client.findByQuery(query).stream().map(o -> o.getId().getValue()).toArray(Long[]::new); + return client.loadFolders(ids); + } + + + /** * @param client The client handling the connection. * @param folderId ID of the folder. * @@ -508,7 +525,9 @@ public List getFolders(Client client) * @throws ServiceException Cannot connect to OMERO. * @throws OMEROServerError Server error. * @throws NoSuchElementException Folder does not exist. + * @deprecated Gets the folder with the specified id on OMERO. */ + @Deprecated public FolderWrapper getFolder(Client client, Long folderId) throws ServiceException, OMEROServerError { List os = client.findByQuery("select f " + "from Folder as f " + diff --git a/src/test/java/fr/igred/omero/AccessExceptionTest.java b/src/test/java/fr/igred/omero/AccessExceptionTest.java index 6a44d88e..d66fd6ce 100644 --- a/src/test/java/fr/igred/omero/AccessExceptionTest.java +++ b/src/test/java/fr/igred/omero/AccessExceptionTest.java @@ -120,7 +120,8 @@ void testFolderAddROIWithoutImage() throws Exception { roi.addShape(rectangle); roi.saveROI(client); - assertThrows(AccessException.class, () -> folder.addROI(client, roi)); + assertThrows(AccessException.class, () -> folder.addROIs(client, -1L, roi)); + client.delete(folder); } diff --git a/src/test/java/fr/igred/omero/repository/FolderTest.java b/src/test/java/fr/igred/omero/repository/FolderTest.java index 5e6f7b94..b17c0c7a 100644 --- a/src/test/java/fr/igred/omero/repository/FolderTest.java +++ b/src/test/java/fr/igred/omero/repository/FolderTest.java @@ -24,6 +24,7 @@ import fr.igred.omero.roi.RectangleWrapper; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; @@ -35,13 +36,81 @@ class FolderTest extends UserTest { @Test - void testGetDeletedFolder() throws Exception { - ImageWrapper image = client.getImage(IMAGE2.id); + void testImageFolderLinks() throws Exception { + FolderWrapper parent = new FolderWrapper(client, "Parent"); + parent.addImages(client, client.getImage(IMAGE1.id), client.getImage(IMAGE2.id)); + parent.reload(client); + parent.addImages(client, client.getImage(IMAGE1.id), client.getImage(IMAGE2.id)); + parent.reload(client); + + ImageWrapper image = client.getImage(IMAGE2.id); + List folders = image.getFolders(client); + List images = parent.getImages(client); + + client.delete(folders); + assertEquals(2, images.size()); + assertEquals(IMAGE1.id, images.get(0).getId()); + assertEquals(1, folders.size()); + assertEquals(parent.getId(), folders.get(0).getId()); + } + + + @Test + void testHierarchyFolders() throws Exception { + FolderWrapper parent = new FolderWrapper(client, "Parent"); + FolderWrapper child1 = new FolderWrapper(client, "Child 1"); + FolderWrapper child2 = new FolderWrapper(client, "Child 2"); + parent.addChild(child1); + parent.saveAndUpdate(client); + child2.setParent(parent); + child2.addChildren(Collections.singletonList(child1)); + child2.saveAndUpdate(client); + + parent.reload(client); + List children = parent.getChildren(); + List children2 = child2.getChildren(); + + client.delete(parent); + client.delete(child1); + client.delete(child2); + + assertEquals(2, children.size()); + assertEquals(child2.getId(), children.get(1).getId()); + assertEquals(parent.getId(), children.get(1).getParent().getId()); + assertEquals(1, children2.size()); + assertEquals(child1.getId(), children.get(0).getId()); + } + + + @Test + void testTagFolder() throws Exception { + FolderWrapper folder = new FolderWrapper(client, "Test"); + TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Folder test", "Folder tag"); + folder.link(client, tag); + + List folders = tag.getFolders(client); + List tags = folder.getTags(client); + + client.delete(tag); + client.delete(folder); + + assertEquals(1, folders.size()); + assertEquals(folders.get(0).getId(), folder.getId()); + assertEquals(1, tags.size()); + assertEquals(tags.get(0).getId(), tag.getId()); + } + + + @Test + void testGetDeletedFolder() throws Exception { FolderWrapper folder = new FolderWrapper(client, "Test"); - long id = folder.getId(); + assertEquals(1, client.getFolders().size()); + assertEquals(1, client.getFolders(client.getUser()).size()); + + long id = folder.getId(); client.delete(folder); - assertThrows(NoSuchElementException.class, () -> image.getFolder(client, id)); + assertThrows(NoSuchElementException.class, () -> client.getFolder(id)); } @@ -50,7 +119,6 @@ void testFolder1() throws Exception { ImageWrapper image = client.getImage(IMAGE2.id); FolderWrapper folder = new FolderWrapper(client, "Test"); - folder.setImage(image); for (int i = 0; i < 8; i++) { ROIWrapper roi = new ROIWrapper(); @@ -64,20 +132,24 @@ void testFolder1() throws Exception { roi.addShape(rectangle); roi.saveROI(client); - folder.addROI(client, roi); + folder.addROIs(client, image, roi); } - folder = image.getFolder(client, folder.getId()); - List rois = folder.getROIs(client); + folder = client.getFolder(folder.getId()); + List rois = folder.getROIs(client, image); assertEquals(8, rois.size()); assertEquals("Test", folder.getName()); assertEquals(8, image.getROIs(client).size()); - for (ROIWrapper roi : rois) { - client.delete(roi); - } + folder.unlinkAllROIs(client, image); + int nImgROIs = image.getROIs(client).size(); + int nFolderROIs = folder.getROIs(client, image).size(); - assertEquals(0, folder.getROIs(client).size()); + client.delete(rois); + + assertEquals(8, nImgROIs); + assertEquals(0, nFolderROIs); + assertEquals(0, folder.getROIs(client, image).size()); assertEquals(0, image.getROIs(client).size()); client.delete(folder); @@ -130,7 +202,6 @@ void testFolder3() throws Exception { folder1.saveAndUpdate(client); assertEquals("Test1", folder1.getName()); assertEquals("Test 1", folder1.getDescription()); - folder1.setImage(image); for (int i = 0; i < 8; i++) { ROIWrapper roi = new ROIWrapper(); @@ -144,14 +215,13 @@ void testFolder3() throws Exception { roi.addShape(rectangle); roi.saveROI(client); - folder1.addROI(client, roi); + folder1.addROIs(client, image, roi); } FolderWrapper folder2 = new FolderWrapper(client, "Test"); folder2.setName("Test2"); folder2.saveAndUpdate(client); assertEquals("Test2", folder2.getName()); - folder2.setImage(image); for (int i = 0; i < 8; i++) { ROIWrapper roi = new ROIWrapper(); @@ -165,16 +235,17 @@ void testFolder3() throws Exception { roi.addShape(rectangle); roi.saveROI(client); - folder2.addROI(client, roi); + folder2.addROIs(client, image, roi); } - List folders = image.getFolders(client); + List folders = image.getROIFolders(client); assertEquals(2, folders.size()); assertEquals(nImages, image.getROIs(client).size()); + for (FolderWrapper f : folders) f.reload(client); client.delete(folders); - assertEquals(0, image.getFolders(client).size()); + assertEquals(0, image.getROIFolders(client).size()); assertEquals(nImages, image.getROIs(client).size()); List rois = image.getROIs(client); diff --git a/src/test/java/fr/igred/omero/repository/ImageImportTest.java b/src/test/java/fr/igred/omero/repository/ImageImportTest.java index 19ddfe62..9a77c453 100644 --- a/src/test/java/fr/igred/omero/repository/ImageImportTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageImportTest.java @@ -103,9 +103,10 @@ void testReplaceAndDeleteImages() throws Exception { roi.addShape(rectangle); roi = image2.saveROIs(client, roi).get(0); - FolderWrapper folder = new FolderWrapper(client, "ReplaceTestFolder"); - folder.setImage(image2); - folder.addROI(client, roi); + FolderWrapper roiFolder = new FolderWrapper(client, "ReplaceTestFolder"); + roiFolder.addROIs(client, image2, roi); + FolderWrapper imgFolder = new FolderWrapper(client, "ReplaceTestImageFolder"); + imgFolder.addImages(client, image2); TableWrapper table = new TableWrapper(1, "ReplaceTestTable"); table.setColumn(0, "Name", String.class); @@ -122,6 +123,7 @@ void testReplaceAndDeleteImages() throws Exception { assertEquals(3, image3.getFileAnnotations(client).size()); assertEquals(1, image3.getMapAnnotations(client).size()); assertEquals(1, image3.getROIs(client).size()); + assertEquals(1, image3.getROIFolders(client).size()); assertEquals(1, image3.getFolders(client).size()); assertEquals("ReplaceTestTag1", image3.getTags(client).get(0).getName()); assertEquals("ReplaceTestTag2", image3.getTags(client).get(1).getName()); @@ -143,7 +145,8 @@ void testReplaceAndDeleteImages() throws Exception { client.delete(table); client.deleteFile(fileId); client.delete(roi); - client.delete(folder); + client.delete(roiFolder); + client.delete(imgFolder); assertEquals(1, images.size()); assertTrue(endImages.isEmpty()); @@ -188,8 +191,7 @@ void testReplaceAndUnlinkImages() throws Exception { roi = image2.saveROIs(client, roi).get(0); FolderWrapper folder = new FolderWrapper(client, "ReplaceTestFolder"); - folder.setImage(image2); - folder.addROI(client, roi); + folder.addROIs(client, image2, roi); TableWrapper table = new TableWrapper(1, "ReplaceTestTable"); table.setColumn(0, "Name", String.class); @@ -206,7 +208,7 @@ void testReplaceAndUnlinkImages() throws Exception { assertEquals(3, image3.getFileAnnotations(client).size()); assertEquals(1, image3.getMapAnnotations(client).size()); assertEquals(1, image3.getROIs(client).size()); - assertEquals(1, image3.getFolders(client).size()); + assertEquals(1, image3.getROIFolders(client).size()); assertEquals("ReplaceTestTag1", image3.getTags(client).get(0).getName()); assertEquals("ReplaceTestTag2", image3.getTags(client).get(1).getName()); assertEquals("ReplaceTest", image3.getValue(client, "Map")); From ee395f0149266dc9e97704853696f08e5e5114c0 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 22 Feb 2023 21:06:35 +0100 Subject: [PATCH 12/14] Add methods to retrieve map annotations from client and rename key-value pair methods --- src/main/java/fr/igred/omero/Client.java | 191 ++++++++++++++++-- .../fr/igred/omero/GenericObjectWrapper.java | 20 ++ .../omero/repository/DatasetWrapper.java | 49 ++++- .../GenericRepositoryObjectWrapper.java | 19 +- .../omero/repository/ProjectWrapper.java | 95 +++++---- src/test/java/fr/igred/omero/ClientTest.java | 6 +- .../omero/annotations/MapAnnotationTest.java | 61 ++++++ .../omero/repository/ImageImportTest.java | 4 +- .../fr/igred/omero/repository/ImageTest.java | 4 +- .../igred/omero/repository/ProjectTest.java | 1 - 10 files changed, 379 insertions(+), 71 deletions(-) create mode 100644 src/test/java/fr/igred/omero/annotations/MapAnnotationTest.java diff --git a/src/main/java/fr/igred/omero/Client.java b/src/main/java/fr/igred/omero/Client.java index cbd060ac..05efda96 100644 --- a/src/main/java/fr/igred/omero/Client.java +++ b/src/main/java/fr/igred/omero/Client.java @@ -18,6 +18,8 @@ package fr.igred.omero; +import fr.igred.omero.annotations.GenericAnnotationWrapper; +import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.TableWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; import fr.igred.omero.exception.AccessException; @@ -43,6 +45,7 @@ import omero.gateway.model.FolderData; import omero.gateway.model.GroupData; import omero.gateway.model.ImageData; +import omero.gateway.model.MapAnnotationData; import omero.gateway.model.PlateData; import omero.gateway.model.ProjectData; import omero.gateway.model.ScreenData; @@ -63,6 +66,7 @@ import java.util.stream.Collectors; import static fr.igred.omero.GenericObjectWrapper.distinct; +import static fr.igred.omero.GenericObjectWrapper.flatten; import static fr.igred.omero.GenericObjectWrapper.wrap; import static fr.igred.omero.exception.ExceptionHandler.handleServiceOrAccess; import static fr.igred.omero.exception.ExceptionHandler.handleServiceOrServer; @@ -440,12 +444,30 @@ public List getImages(String projectName, String datasetName, Stri } + /** + * Gets all images with the specified annotation from OMERO. + * + * @param annotation TagAnnotation containing the tag researched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws OMEROServerError Server error. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImages(GenericAnnotationWrapper annotation) + throws ServiceException, AccessException, OMEROServerError, ExecutionException { + return annotation.getImages(this); + } + + /** * Gets all images with a certain motif in their name from OMERO. * * @param motif Motif searched in an image name. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -460,35 +482,35 @@ public List getImagesLike(String motif) throws ServiceException, A /** - * Gets all images tagged with a specified tag from OMERO. - * * @param tag TagAnnotationWrapper containing the tag researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images tagged with a specified tag from OMERO. */ + @Deprecated public List getImagesTagged(TagAnnotationWrapper tag) throws ServiceException, AccessException, OMEROServerError, ExecutionException { - return tag.getImages(this); + return getImages(tag); } /** - * Gets all images tagged with a specified tag from OMERO. - * * @param tagId Id of the tag researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws OMEROServerError Server error. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images tagged with a specified tag from OMERO. */ + @Deprecated public List getImagesTagged(Long tagId) throws ServiceException, AccessException, OMEROServerError, ExecutionException { return getImagesTagged(getTag(tagId)); @@ -496,16 +518,16 @@ public List getImagesTagged(Long tagId) /** - * Gets all images with a certain key - * * @param key Name of the key researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images with a certain key */ + @Deprecated public List getImagesKey(String key) throws ServiceException, AccessException, ExecutionException { List images = getImages(); @@ -522,17 +544,42 @@ public List getImagesKey(String key) /** - * Gets all images with a certain key value pair from OMERO + * Gets all images with a certain key. * + * @param key Name of the key researched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws OMEROServerError Server error. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImagesWithKey(String key) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + List maps = getMapAnnotations(key); + + Collection> selected = new ArrayList<>(maps.size()); + for (MapAnnotationWrapper map : maps) { + selected.add(getImages(map)); + } + + return flatten(selected); + } + + + /** * @param key Name of the key researched. * @param value Value associated with the key. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images with a certain key value pair from OMERO */ + @Deprecated public List getImagesPairKeyValue(String key, String value) throws ServiceException, AccessException, ExecutionException { List images = getImages(); @@ -547,6 +594,32 @@ public List getImagesPairKeyValue(String key, String value) } + /** + * Gets all images with a certain key value pair from OMERO + * + * @param key Name of the key researched. + * @param value Value associated with the key. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws OMEROServerError Server error. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImagesWithKeyValuePair(String key, String value) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + List maps = getMapAnnotations(key, value); + + Collection> selected = new ArrayList<>(maps.size()); + for (MapAnnotationWrapper map : maps) { + selected.add(getImages(map)); + } + + return flatten(selected); + } + + /** * Gets the screen with the specified id from OMERO. * @@ -971,6 +1044,98 @@ public TagAnnotationWrapper getTag(Long id) throws OMEROServerError, ServiceExce } + /** + * Gets the list of map annotations available to the user. + * + * @return See above. + * + * @throws OMEROServerError Server error. + * @throws ServiceException Cannot connect to OMERO. + */ + public List getMapAnnotations() throws OMEROServerError, ServiceException { + List kvs = new ArrayList<>(0); + try { + kvs = getGateway().getQueryService(getCtx()).findAll(omero.model.MapAnnotation.class.getSimpleName(), null) + .stream() + .map(omero.model.MapAnnotation.class::cast) + .map(MapAnnotationData::new) + .map(MapAnnotationWrapper::new) + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); + } catch (ServerError | DSOutOfServiceException e) { + handleServiceOrServer(e, "Cannot get map annotations"); + } + return kvs; + } + + + /** + * Gets the list of map annotations with the specified key available to the user. + * + * @param key Name of the tag searched. + * + * @return See above. + * + * @throws OMEROServerError Server error. + * @throws ServiceException Cannot connect to OMERO. + */ + public List getMapAnnotations(String key) throws OMEROServerError, ServiceException { + String q = String.format("select m from MapAnnotation as m join m.mapValue as mv where mv.name = '%s'", key); + return findByQuery(q).stream() + .map(omero.model.MapAnnotation.class::cast) + .map(MapAnnotationData::new) + .map(MapAnnotationWrapper::new) + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); + } + + + /** + * Gets the list of map annotations with the specified key and value available to the user. + * + * @param key The required key. + * @param value The required value. + * + * @return See above. + * + * @throws OMEROServerError Server error. + * @throws ServiceException Cannot connect to OMERO. + */ + public List getMapAnnotations(String key, String value) + throws OMEROServerError, ServiceException { + String q = String.format("select m from MapAnnotation as m join m.mapValue as mv " + + "where mv.name = '%s' and mv.value = '%s'", key, value); + return findByQuery(q).stream() + .map(omero.model.MapAnnotation.class::cast) + .map(MapAnnotationData::new) + .map(MapAnnotationWrapper::new) + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); + } + + + /** + * Gets a specific map annotation (key/value pairs) from the OMERO database. + * + * @param id ID of the map annotation. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public MapAnnotationWrapper getMapAnnotation(Long id) throws ServiceException, ExecutionException, AccessException { + MapAnnotationData kv = null; + try { + kv = getBrowseFacility().findObject(getCtx(), MapAnnotationData.class, id); + } catch (DSOutOfServiceException | DSAccessException e) { + handleServiceOrAccess(e, "Cannot get map annotation with ID: " + id); + } + return new MapAnnotationWrapper(kv); + } + + /** * Deletes multiple objects from OMERO. * diff --git a/src/main/java/fr/igred/omero/GenericObjectWrapper.java b/src/main/java/fr/igred/omero/GenericObjectWrapper.java index cf391dd4..b593e712 100644 --- a/src/main/java/fr/igred/omero/GenericObjectWrapper.java +++ b/src/main/java/fr/igred/omero/GenericObjectWrapper.java @@ -132,6 +132,26 @@ public static > List distinct(Collection The objects type. + * + * @return Distinct objects list, sorted by ID. + */ + public static > + List flatten(Collection> lists) { + return lists.stream() + .flatMap(Collection::stream) + .collect(Collectors.toMap(U::getId, o -> o, (o1, o2) -> o1)) + .values() + .stream() + .sorted(Comparator.comparing(U::getId)) + .collect(Collectors.toList()); + } + + /** * Returns the wrapped DataObject. * diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index a4c79b19..c70c18c3 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -241,7 +241,7 @@ public List getImagesLike(Client client, String motif) * @param client The client handling the connection. * @param tag TagAnnotationWrapper containing the tag researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -260,7 +260,7 @@ public List getImagesTagged(Client client, TagAnnotationWrapper ta * @param client The client handling the connection. * @param tagId Id of the tag researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -286,19 +286,37 @@ public List getImagesTagged(Client client, Long tagId) } + /** + * @param client The client handling the connection. + * @param key Name of the key researched. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images in the dataset with a certain key + */ + @Deprecated + public List getImagesKey(Client client, String key) + throws ServiceException, AccessException, ExecutionException { + return getImagesWithKey(client, key); + } + + /** * Gets all images in the dataset with a certain key * * @param client The client handling the connection. * @param key Name of the key researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public List getImagesKey(Client client, String key) + public List getImagesWithKey(Client client, String key) throws ServiceException, AccessException, ExecutionException { Collection images = new ArrayList<>(0); try { @@ -324,6 +342,25 @@ public List getImagesKey(Client client, String key) } + /** + * @param client The client handling the connection. + * @param key Name of the key researched. + * @param value Value associated with the key. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images in the dataset with a certain key value pair from OMERO + */ + @Deprecated + public List getImagesPairKeyValue(Client client, String key, String value) + throws ServiceException, AccessException, ExecutionException { + return getImagesWithKeyValuePair(client, key, value); + } + + /** * Gets all images in the dataset with a certain key value pair from OMERO * @@ -331,13 +368,13 @@ public List getImagesKey(Client client, String key) * @param key Name of the key researched. * @param value Value associated with the key. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public List getImagesPairKeyValue(Client client, String key, String value) + public List getImagesWithKeyValuePair(Client client, String key, String value) throws ServiceException, AccessException, ExecutionException { Collection images = new ArrayList<>(0); try { diff --git a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java index ac3cbdf5..e8abb8f6 100644 --- a/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java @@ -451,6 +451,23 @@ public List getMapAnnotations(Client client) } + /** + * @param client The client handling the connection. + * @param key Name of the key. + * @param value Value associated to the key. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Adds a single Key-Value pair to the object. + */ + @Deprecated + public void addPairKeyValue(Client client, String key, String value) + throws ServiceException, AccessException, ExecutionException { + addKeyValuePair(client, key, value); + } + + /** * Adds a single Key-Value pair to the object. * @@ -462,7 +479,7 @@ public List getMapAnnotations(Client client) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public void addPairKeyValue(Client client, String key, String value) + public void addKeyValuePair(Client client, String key, String value) throws ServiceException, AccessException, ExecutionException { List kv = Collections.singletonList(new NamedValue(key, value)); MapAnnotationWrapper pkv = new MapAnnotationWrapper(kv); diff --git a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java b/src/main/java/fr/igred/omero/repository/ProjectWrapper.java index a8945a50..15e7b338 100644 --- a/src/main/java/fr/igred/omero/repository/ProjectWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ProjectWrapper.java @@ -243,7 +243,7 @@ public void removeDataset(Client client, DatasetWrapper dataset) * * @param client The client handling the connection. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -268,7 +268,7 @@ public List getImages(Client client) throws ServiceException, Acce * @param client The client handling the connection. * @param name Name searched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -282,12 +282,7 @@ public List getImages(Client client, String name) for (DatasetWrapper dataset : datasets) { lists.add(dataset.getImages(client, name)); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); - - return distinct(images); + return flatten(lists); } @@ -298,7 +293,7 @@ public List getImages(Client client, String name) * @param datasetName Expected dataset name. * @param imageName Expected image name. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -327,7 +322,7 @@ public List getImages(Client client, String datasetName, String im * @param client The client handling the connection. * @param motif Motif searched in an image name. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -341,12 +336,7 @@ public List getImagesLike(Client client, String motif) for (DatasetWrapper dataset : datasets) { lists.add(dataset.getImagesLike(client, motif)); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); - - return distinct(images); + return flatten(lists); } @@ -356,7 +346,7 @@ public List getImagesLike(Client client, String motif) * @param client The client handling the connection. * @param tag TagAnnotationWrapper containing the tag researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -371,12 +361,7 @@ public List getImagesTagged(Client client, TagAnnotationWrapper ta for (DatasetWrapper dataset : datasets) { lists.add(dataset.getImagesTagged(client, tag)); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); - - return distinct(images); + return flatten(lists); } @@ -386,7 +371,7 @@ public List getImagesTagged(Client client, TagAnnotationWrapper ta * @param client The client handling the connection. * @param tagId Id of the tag researched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -401,12 +386,25 @@ public List getImagesTagged(Client client, Long tagId) for (DatasetWrapper dataset : datasets) { lists.add(dataset.getImagesTagged(client, tagId)); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); + return flatten(lists); + } - return distinct(images); + + /** + * @param client The client handling the connection. + * @param key Name of the key researched. + * + * @return ImageWrapper list. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images in the project with a certain key + */ + @Deprecated + public List getImagesKey(Client client, String key) + throws ServiceException, AccessException, ExecutionException { + return getImagesWithKey(client, key); } @@ -422,20 +420,34 @@ public List getImagesTagged(Client client, Long tagId) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public List getImagesKey(Client client, String key) + public List getImagesWithKey(Client client, String key) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); Collection> lists = new ArrayList<>(datasets.size()); for (DatasetWrapper dataset : datasets) { - lists.add(dataset.getImagesKey(client, key)); + lists.add(dataset.getImagesWithKey(client, key)); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); + return flatten(lists); + } - return distinct(images); + + /** + * @param client The client handling the connection. + * @param key Name of the key researched. + * @param value Value associated with the key. + * + * @return ImageWrapper list. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @deprecated Gets all images in the project with a certain key value pair from OMERO. + */ + @Deprecated + public List getImagesPairKeyValue(Client client, String key, String value) + throws ServiceException, AccessException, ExecutionException { + return getImagesWithKeyValuePair(client, key, value); } @@ -452,20 +464,15 @@ public List getImagesKey(Client client, String key) * @throws AccessException Cannot access data. * @throws ExecutionException A Facility can't be retrieved or instantiated. */ - public List getImagesPairKeyValue(Client client, String key, String value) + public List getImagesWithKeyValuePair(Client client, String key, String value) throws ServiceException, AccessException, ExecutionException { Collection datasets = getDatasets(); Collection> lists = new ArrayList<>(datasets.size()); for (DatasetWrapper dataset : datasets) { - lists.add(dataset.getImagesPairKeyValue(client, key, value)); + lists.add(dataset.getImagesWithKeyValuePair(client, key, value)); } - List images = lists.stream() - .flatMap(Collection::stream) - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); - - return distinct(images); + return flatten(lists); } diff --git a/src/test/java/fr/igred/omero/ClientTest.java b/src/test/java/fr/igred/omero/ClientTest.java index fe6142b3..03d12f38 100644 --- a/src/test/java/fr/igred/omero/ClientTest.java +++ b/src/test/java/fr/igred/omero/ClientTest.java @@ -166,8 +166,10 @@ void testGetImagesKey() throws Exception { @Test void testGetImagesKeyValue() throws Exception { - List images = client.getImagesPairKeyValue("testKey1", "testValue1"); + List images = client.getImagesWithKeyValuePair("testKey1", "testValue1"); assertEquals(2, images.size()); + List images2 = client.getImagesPairKeyValue("testKey1", "testValue1"); + assertEquals(2, images2.size()); } @@ -183,7 +185,7 @@ void testGetImagesCond() throws Exception { String key = "testKey2"; /* Load the image with the key */ - List images = client.getImagesKey(key); + List images = client.getImagesWithKey(key); Collection imagesCond = new ArrayList<>(1); diff --git a/src/test/java/fr/igred/omero/annotations/MapAnnotationTest.java b/src/test/java/fr/igred/omero/annotations/MapAnnotationTest.java new file mode 100644 index 00000000..ac3e5c61 --- /dev/null +++ b/src/test/java/fr/igred/omero/annotations/MapAnnotationTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2020-2023 GReD + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin + * Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package fr.igred.omero.annotations; + + +import fr.igred.omero.UserTest; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +class MapAnnotationTest extends UserTest { + + + @Test + void testGetAllMapAnnotations() throws Exception { + List maps = client.getMapAnnotations(); + assertEquals(2, maps.size()); + } + + + @Test + void testGetSingleMapAnnotation() throws Exception { + MapAnnotationWrapper map = client.getMapAnnotation(4L); + assertEquals("testKey1", map.getContent().get(0).name); + assertEquals("testValue1", map.getContent().get(0).value); + } + + + @Test + void testGetSingleMapAnnotationByKey() throws Exception { + List maps = client.getMapAnnotations("testKey1"); + assertEquals(2, maps.size()); + assertEquals("testValue1", maps.get(0).getContent().get(0).value); + } + + + @Test + void testGetSingleMapAnnotationByKeyAndValue() throws Exception { + List maps = client.getMapAnnotations("testKey1", "testValue1"); + assertEquals(1, maps.size()); + } + +} diff --git a/src/test/java/fr/igred/omero/repository/ImageImportTest.java b/src/test/java/fr/igred/omero/repository/ImageImportTest.java index 9a77c453..58210f1b 100644 --- a/src/test/java/fr/igred/omero/repository/ImageImportTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageImportTest.java @@ -81,7 +81,7 @@ void testReplaceAndDeleteImages() throws Exception { TagAnnotationWrapper tag1 = new TagAnnotationWrapper(client, "ReplaceTestTag1", "Copy annotations"); image1.link(client, tag1); - image1.addPairKeyValue(client, "Map", "ReplaceTest"); + image1.addKeyValuePair(client, "Map", "ReplaceTest"); long fileId = image1.addFile(client, file); removeFile(file); @@ -168,7 +168,7 @@ void testReplaceAndUnlinkImages() throws Exception { TagAnnotationWrapper tag1 = new TagAnnotationWrapper(client, "ReplaceTestTag1", "Copy annotations"); image1.link(client, tag1); - image1.addPairKeyValue(client, "Map", "ReplaceTest"); + image1.addKeyValuePair(client, "Map", "ReplaceTest"); long fileId = image1.addFile(client, file); removeFile(file); diff --git a/src/test/java/fr/igred/omero/repository/ImageTest.java b/src/test/java/fr/igred/omero/repository/ImageTest.java index 72c2411f..6ddcae45 100644 --- a/src/test/java/fr/igred/omero/repository/ImageTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageTest.java @@ -231,8 +231,8 @@ void testAddKeyValuePair4() throws Exception { String value2 = "Value Test2"; Timestamp ts = Timestamp.from(Instant.now()); - image.addPairKeyValue(client, key1, value1); - image.addPairKeyValue(client, key2, value2); + image.addKeyValuePair(client, key1, value1); + image.addKeyValuePair(client, key2, value2); List maps = image.getMapAnnotations(client); diff --git a/src/test/java/fr/igred/omero/repository/ProjectTest.java b/src/test/java/fr/igred/omero/repository/ProjectTest.java index 939fc614..4c221556 100644 --- a/src/test/java/fr/igred/omero/repository/ProjectTest.java +++ b/src/test/java/fr/igred/omero/repository/ProjectTest.java @@ -253,7 +253,6 @@ void testGetImagesPairKeyValueInProject() throws Exception { ProjectWrapper project = client.getProject(PROJECT1.id); List images = project.getImagesPairKeyValue(client, "testKey1", "testValue1"); - assertEquals(2, images.size()); } From 21933538cc4576f42ad2cb0144435484912d6feb Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Wed, 22 Feb 2023 23:54:34 +0100 Subject: [PATCH 13/14] Add methods to retrieve repository objects from parents/children/annotations --- .../annotations/GenericAnnotationWrapper.java | 22 +++++ .../omero/repository/DatasetWrapper.java | 8 +- .../igred/omero/repository/ImageWrapper.java | 36 ++++++-- .../repository/PlateAcquisitionWrapper.java | 83 +++++++++++++++++++ .../igred/omero/repository/PlateWrapper.java | 42 +++++++++- .../igred/omero/repository/ScreenWrapper.java | 74 +++++++++++++++++ .../omero/repository/WellSampleWrapper.java | 54 ++++++++++++ .../igred/omero/repository/WellWrapper.java | 70 ++++++++++++++++ .../fr/igred/omero/repository/ImageTest.java | 24 +++++- .../repository/PlateAcquisitionTest.java | 47 ++++++++++- .../fr/igred/omero/repository/PlateTest.java | 24 ++++++ .../fr/igred/omero/repository/ScreenTest.java | 23 +++++ .../omero/repository/WellSampleTest.java | 30 +++++++ 13 files changed, 518 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java index 80286415..2c4f2393 100644 --- a/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/GenericAnnotationWrapper.java @@ -26,17 +26,20 @@ import fr.igred.omero.repository.DatasetWrapper; import fr.igred.omero.repository.FolderWrapper; import fr.igred.omero.repository.ImageWrapper; +import fr.igred.omero.repository.PlateAcquisitionWrapper; import fr.igred.omero.repository.PlateWrapper; import fr.igred.omero.repository.ProjectWrapper; import fr.igred.omero.repository.ScreenWrapper; import fr.igred.omero.repository.WellWrapper; import omero.RLong; import omero.gateway.model.AnnotationData; +import omero.gateway.model.PlateAcquisitionData; import omero.model.IObject; import java.sql.Timestamp; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; /** @@ -224,6 +227,25 @@ public List getPlates(Client client) } + /** + * Gets all plate acquisitions with this annotation from OMERO. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws OMEROServerError Server error. + */ + public List getPlateAcquisitions(Client client) + throws ServiceException, OMEROServerError { + List os = getLinks(client, PlateAcquisitionWrapper.ANNOTATION_LINK); + return os.stream() + .map(o -> new PlateAcquisitionWrapper(new PlateAcquisitionData((omero.model.PlateAcquisition) o))) + .collect(Collectors.toList()); + } + + /** * Gets all wells with this tag from OMERO. * diff --git a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java index c70c18c3..b0c83c1f 100644 --- a/src/main/java/fr/igred/omero/repository/DatasetWrapper.java +++ b/src/main/java/fr/igred/omero/repository/DatasetWrapper.java @@ -174,7 +174,7 @@ public List getProjects(Client client) * * @param client The client handling the connection. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -199,7 +199,7 @@ public List getImages(Client client) throws ServiceException, Acce * @param client The client handling the connection. * @param name Name searched. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -219,7 +219,7 @@ public List getImages(Client client, String name) * @param client The client handling the connection. * @param motif Motif searched in an image name. * - * @return ImageWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -615,7 +615,7 @@ public List importAndReplaceImages(Client client, String path) /** - * Refreshes the wrapped dataset. + * Refreshes the dataset. * * @param client The client handling the connection. * diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index e2e96cee..d7de9233 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -260,7 +260,7 @@ public List getDatasets(Client client) /** - * Retrieves the wells containing this image + * Retrieves the wells containing this image. * * @param client The client handling the connection. * @@ -285,7 +285,30 @@ public List getWells(Client client) throws AccessException, Service /** - * Retrieves the plates containing this image + * Returns the plate acquisitions linked to this image. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlateAcquisitions(Client client) + throws AccessException, ServiceException, ExecutionException { + List wells = getWells(client); + + Collection> acqs = new ArrayList<>(wells.size()); + for (WellWrapper w : wells) { + acqs.add(w.getPlateAcquisitions(client)); + } + return flatten(acqs); + } + + + /** + * Retrieves the plates containing this image. * * @param client The client handling the connection. * @@ -314,12 +337,13 @@ public List getPlates(Client client) throws AccessException, Servi */ public List getScreens(Client client) throws AccessException, ServiceException, ExecutionException, OMEROServerError { - List plates = getPlates(client); - Collection screens = new ArrayList<>(plates.size()); + List plates = getPlates(client); + + Collection> screens = new ArrayList<>(plates.size()); for (PlateWrapper plate : plates) { - screens.addAll(plate.getScreens(client)); + screens.add(plate.getScreens(client)); } - return distinct(screens); + return flatten(screens); } diff --git a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java index b97123b1..e8a49208 100644 --- a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java @@ -19,8 +19,10 @@ import fr.igred.omero.Client; +import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.annotations.GenericAnnotationWrapper; import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.PlateAcquisitionData; import omero.model.PlateAcquisitionAnnotationLink; @@ -28,7 +30,11 @@ import omero.model._PlateAcquisitionOperationsNC; import java.sql.Timestamp; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; /** @@ -140,6 +146,83 @@ public > void link(Client client, A annota } + /** + * Retrieves the screens containing the parent plates. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws OMEROServerError Server error. + */ + public List getScreens(Client client) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + PlateWrapper plate = client.getPlate(getRefPlateId()); + return plate.getScreens(client); + } + + + /** + * Returns the (updated) parent plate as a singleton list. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlates(Client client) + throws ServiceException, AccessException, ExecutionException { + return client.getPlates(getRefPlateId()); + } + + + /** + * Retrieves the wells contained in the parent plate. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getWells(Client client) + throws ServiceException, AccessException, ExecutionException { + return getPlates(client).iterator().next().getWells(client); + } + + + /** + * Retrieves the images contained in the wells in the parent plate. + * + * @param client The client handling the connection. + * + * @return See above + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImages(Client client) + throws ServiceException, AccessException, ExecutionException { + return getWells(client).stream() + .map(WellWrapper::getImages) + .flatMap(Collection::stream) + .collect(Collectors.toMap(GenericObjectWrapper::getId, i -> i, (i1, i2) -> i1)) + .values() + .stream() + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); + } + + /** * Returns the label associated to the plate acquisition. * diff --git a/src/main/java/fr/igred/omero/repository/PlateWrapper.java b/src/main/java/fr/igred/omero/repository/PlateWrapper.java index 5080743a..b9db3b87 100644 --- a/src/main/java/fr/igred/omero/repository/PlateWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateWrapper.java @@ -19,6 +19,7 @@ import fr.igred.omero.Client; +import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; @@ -163,7 +164,7 @@ public List getPlateAcquisitions() { * * @param client The client handling the connection. * - * @return WellWrapper list. + * @return See above. * * @throws ServiceException Cannot connect to OMERO. * @throws AccessException Cannot access data. @@ -184,6 +185,30 @@ public List getWells(Client client) throws ServiceException, Access } + /** + * Returns the images contained in the wells of this plate. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImages(Client client) + throws ServiceException, AccessException, ExecutionException { + return getWells(client).stream() + .map(WellWrapper::getImages) + .flatMap(Collection::stream) + .collect(Collectors.toMap(GenericObjectWrapper::getId, i -> i, (i1, i2) -> i1)) + .values() + .stream() + .sorted(Comparator.comparing(GenericObjectWrapper::getId)) + .collect(Collectors.toList()); + } + + /** * Returns the index indicating how to label a column. * @@ -301,4 +326,19 @@ public Length getWellOriginY(UnitsLength unit) throws BigResult { return data.getWellOriginY(unit); } + + /** + * Refreshes the plate. + * + * @param client The client handling the connection. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void refresh(Client client) + throws ServiceException, AccessException, ExecutionException { + data = client.getPlate(getId()).asDataObject(); + } + } diff --git a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java index 06ef38a5..73cd36ed 100644 --- a/src/main/java/fr/igred/omero/repository/ScreenWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ScreenWrapper.java @@ -28,11 +28,16 @@ import omero.gateway.model.ScreenData; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; import static fr.igred.omero.exception.ExceptionHandler.handleServiceOrAccess; +import static java.util.stream.Collectors.toMap; /** @@ -165,6 +170,75 @@ public List getPlates(String name) { } + /** + * Returns the plate acquisitions linked to this object, either directly, or through parents/children. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlateAcquisitions(Client client) + throws ServiceException, AccessException, ExecutionException { + refresh(client); + return getPlates().stream() + .map(PlateWrapper::getPlateAcquisitions) + .flatMap(Collection::stream) + .collect(toMap(GenericRepositoryObjectWrapper::getId, p -> p, (p1, p2) -> p1)) + .values() + .stream() + .sorted(Comparator.comparing(GenericRepositoryObjectWrapper::getId)) + .collect(Collectors.toList()); + } + + + /** + * Retrieves the wells linked to this object, either directly, or through parents/children. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getWells(Client client) + throws ServiceException, AccessException, ExecutionException { + List plates = getPlates(); + Collection> wells = new ArrayList<>(plates.size()); + for (PlateWrapper p : plates) { + wells.add(p.getWells(client)); + } + return flatten(wells); + } + + + /** + * Retrieves the images contained in this screen. + * + * @param client The client handling the connection. + * + * @return See above + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getImages(Client client) + throws ServiceException, AccessException, ExecutionException { + List plates = getPlates(); + Collection> images = new ArrayList<>(plates.size()); + for (PlateWrapper p : plates) { + images.add(p.getImages(client)); + } + return flatten(images); + } + + /** * Returns the description of the protocol. * diff --git a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java index ec98cf16..1a4b4e61 100644 --- a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java @@ -21,12 +21,15 @@ import fr.igred.omero.Client; import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import ome.model.units.BigResult; import omero.gateway.model.WellSampleData; import omero.model.Length; import omero.model.enums.UnitsLength; +import java.util.Collections; +import java.util.List; import java.util.concurrent.ExecutionException; @@ -58,6 +61,57 @@ public WellSampleData asWellSampleData() { } + /** + * Returns the screens containing the parent Well. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws OMEROServerError Server error. + */ + public List getScreens(Client client) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + return getWell(client).getScreens(client); + } + + + /** + * Returns the plates containing the parent Well. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlates(Client client) throws ServiceException, AccessException, ExecutionException { + return Collections.singletonList(getWell(client).getPlate()); + } + + + /** + * Returns the plate acquisitions linked to the parent Well. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlateAcquisitions(Client client) + throws ServiceException, AccessException, ExecutionException { + return getWell(client).getPlateAcquisitions(client); + } + + /** * Retrieves the well containing this well sample * diff --git a/src/main/java/fr/igred/omero/repository/WellWrapper.java b/src/main/java/fr/igred/omero/repository/WellWrapper.java index 82037e41..95ba71b6 100644 --- a/src/main/java/fr/igred/omero/repository/WellWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellWrapper.java @@ -18,9 +18,15 @@ package fr.igred.omero.repository; +import fr.igred.omero.Client; +import fr.igred.omero.exception.AccessException; +import fr.igred.omero.exception.OMEROServerError; +import fr.igred.omero.exception.ServiceException; import omero.gateway.model.WellData; import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; /** @@ -118,6 +124,25 @@ public List getWellSamples() { } + /** + * Refreshes this well and retrieves the screens containing it. + * + * @param client The client handling the connection. + * + * @return See above + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + * @throws OMEROServerError Server error. + */ + public List getScreens(Client client) + throws ServiceException, AccessException, ExecutionException, OMEROServerError { + refresh(client); + return getPlate().getScreens(client); + } + + /** * Returns the plate containing this Well. * @@ -128,6 +153,36 @@ public PlateWrapper getPlate() { } + /** + * Refreshes this well and returns the plate acquisitions linked to it. + * + * @param client The client handling the connection. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getPlateAcquisitions(Client client) + throws ServiceException, AccessException, ExecutionException { + refresh(client); + return client.getPlate(getPlate().getId()).getPlateAcquisitions(); + } + + + /** + * Retrieves the images contained in this well. + * + * @return See above. + */ + public List getImages() { + return getWellSamples().stream() + .map(WellSampleWrapper::getImage) + .collect(Collectors.toList()); + } + + /** * Returns the column used to indicate the location of the well on the grid. * @@ -267,4 +322,19 @@ public void setAlpha(Integer alpha) { data.setAlpha(alpha); } + + /** + * Refreshes the well. + * + * @param client The client handling the connection. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public void refresh(Client client) + throws ServiceException, AccessException, ExecutionException { + data = client.getWell(getId()).asDataObject(); + } + } diff --git a/src/test/java/fr/igred/omero/repository/ImageTest.java b/src/test/java/fr/igred/omero/repository/ImageTest.java index 6ddcae45..10bcd94a 100644 --- a/src/test/java/fr/igred/omero/repository/ImageTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageTest.java @@ -19,6 +19,7 @@ import fr.igred.omero.UserTest; +import fr.igred.omero.annotations.AnnotationList; import fr.igred.omero.annotations.FileAnnotationWrapper; import fr.igred.omero.annotations.MapAnnotationWrapper; import fr.igred.omero.annotations.TagAnnotationWrapper; @@ -63,14 +64,14 @@ class ImageTest extends UserTest { @Test - void testGetDatasets() throws Exception { - assertEquals(DATASET1.id, client.getImage(IMAGE1.id).getDatasets(client).get(0).getId()); + void testGetProjects() throws Exception { + assertEquals(PROJECT1.id, client.getImage(IMAGE1.id).getProjects(client).get(0).getId()); } @Test - void testGetProjects() throws Exception { - assertEquals(PROJECT1.id, client.getImage(IMAGE1.id).getProjects(client).get(0).getId()); + void testGetDatasets() throws Exception { + assertEquals(DATASET1.id, client.getImage(IMAGE1.id).getDatasets(client).get(0).getId()); } @@ -88,6 +89,14 @@ void testGetPlates() throws Exception { } + @Test + void testGetPlateAcquisitions() throws Exception { + final long id = 5L; + final String name = "PlateAcquisition Name 0"; + assertEquals(name, client.getImage(id).getPlateAcquisitions(client).get(0).getName()); + } + + @Test void testGetWells() throws Exception { final long wellId = 1L; @@ -98,6 +107,13 @@ void testGetWells() throws Exception { } + @Test + void testGetAnnotations() throws Exception { + AnnotationList annotations = client.getImage(IMAGE1.id).getAnnotations(client); + assertEquals(3, annotations.size()); + } + + @Test void testGetKeyValuePair1() throws Exception { ImageWrapper image = client.getImage(IMAGE1.id); diff --git a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java index 094b7e62..c948a5d2 100644 --- a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java @@ -30,6 +30,41 @@ class PlateAcquisitionTest extends UserTest { + @Test + void testGetScreens() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); + List screens = acq.getScreens(client); + assertEquals(1, screens.size()); + } + + + @Test + void testGetPlates() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); + assertEquals(PLATE1.id, acq.getPlates(client).get(0).getId()); + } + + + @Test + void testGetWells() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); + List wells = acq.getWells(client); + assertEquals(9, wells.size()); + } + + + @Test + void testGetImages() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); + List images = acq.getImages(client); + assertEquals(36, images.size()); + } + + @Test void testAddTagToPlateAcquisition() throws Exception { PlateWrapper plate = client.getPlate(PLATE1.id); @@ -38,12 +73,16 @@ void testAddTagToPlateAcquisition() throws Exception { TagAnnotationWrapper tag = new TagAnnotationWrapper(client, "Plate acq. tag", "tag attached to a plate acq."); acq.link(client, tag); - List tags = acq.getTags(client); + + List taggedAcqs = tag.getPlateAcquisitions(client); + List tags = acq.getTags(client); client.delete(tag); List checkTags = acq.getTags(client); assertEquals(1, tags.size()); assertEquals(0, checkTags.size()); + assertEquals(1, taggedAcqs.size()); + assertEquals(acq.getId(), taggedAcqs.get(0).getId()); } @@ -97,10 +136,10 @@ void testGetRefPlateId() throws Exception { PlateWrapper plate = client.getPlate(PLATE1.id); PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); - assertEquals(-1, acq.getRefPlateId()); - acq.setRefPlateId(PLATE1.id); + assertEquals(1, acq.getRefPlateId()); + acq.setRefPlateId(-1L); // Saving does not work: acq.saveAndUpdate(client); - assertEquals(PLATE1.id, acq.getRefPlateId()); + assertEquals(-1L, acq.getRefPlateId()); } diff --git a/src/test/java/fr/igred/omero/repository/PlateTest.java b/src/test/java/fr/igred/omero/repository/PlateTest.java index 34005df9..933eaad2 100644 --- a/src/test/java/fr/igred/omero/repository/PlateTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateTest.java @@ -30,6 +30,30 @@ class PlateTest extends UserTest { + @Test + void testGetScreens() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + List screens = plate.getScreens(client); + assertEquals(1, screens.size()); + } + + + @Test + void testGetWells() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + List wells = plate.getWells(client); + assertEquals(9, wells.size()); + } + + + @Test + void testGetImages() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + List images = plate.getImages(client); + assertEquals(36, images.size()); + } + + @Test void testGetWellsFromPlate() throws Exception { PlateWrapper plate = client.getPlate(PLATE1.id); diff --git a/src/test/java/fr/igred/omero/repository/ScreenTest.java b/src/test/java/fr/igred/omero/repository/ScreenTest.java index 1ad9fa3a..95845d36 100644 --- a/src/test/java/fr/igred/omero/repository/ScreenTest.java +++ b/src/test/java/fr/igred/omero/repository/ScreenTest.java @@ -33,6 +33,29 @@ class ScreenTest extends UserTest { + @Test + void testGetPlateAcquisitions() throws Exception { + ScreenWrapper screen = client.getScreen(SCREEN2.id); + assertEquals(2, screen.getPlateAcquisitions(client).size()); + } + + + @Test + void testGetWells() throws Exception { + ScreenWrapper screen = client.getScreen(SCREEN2.id); + List wells = screen.getWells(client); + assertEquals(8, wells.size()); + } + + + @Test + void testGetImages() throws Exception { + ScreenWrapper screen = client.getScreen(SCREEN2.id); + List images = screen.getImages(client); + assertEquals(16, images.size()); + } + + @Test void testGetPlatesFromScreen() throws Exception { ScreenWrapper screen = client.getScreen(SCREEN2.id); diff --git a/src/test/java/fr/igred/omero/repository/WellSampleTest.java b/src/test/java/fr/igred/omero/repository/WellSampleTest.java index 68c7e419..fb7d6727 100644 --- a/src/test/java/fr/igred/omero/repository/WellSampleTest.java +++ b/src/test/java/fr/igred/omero/repository/WellSampleTest.java @@ -21,6 +21,8 @@ import fr.igred.omero.UserTest; import org.junit.jupiter.api.Test; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -28,6 +30,34 @@ class WellSampleTest extends UserTest { + @Test + void testGetScreens() throws Exception { + WellWrapper well = client.getWell(1L); + WellSampleWrapper sample = well.getWellSamples().get(0); + List screens = sample.getScreens(client); + assertEquals(1, screens.size()); + assertEquals(SCREEN1.id, screens.get(0).getId()); + } + + + @Test + void testGetPlates() throws Exception { + WellWrapper well = client.getWell(1L); + WellSampleWrapper sample = well.getWellSamples().get(0); + List plates = sample.getPlates(client); + assertEquals(1, plates.size()); + assertEquals(well.getPlate().getId(), plates.get(0).getId()); + } + + + @Test + void testGetPlateAcquisitions() throws Exception { + WellWrapper well = client.getWell(1L); + WellSampleWrapper sample = well.getWellSamples().get(0); + List acqs = sample.getPlateAcquisitions(client); + assertEquals(1, acqs.size()); + } + @Test void testGetImage() throws Exception { final String name = "screen1.fake [screen1 2]"; From cec8a4983b8782a582ffc3e507c9fc8037f79610 Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Sun, 22 Jan 2023 17:25:14 +0100 Subject: [PATCH 14/14] Fix ROI names for 2D ROIs and use Strings for label/index grouping --- README.md | 3 +- .../igred/omero/annotations/TableWrapper.java | 104 ++++++++++-------- .../java/fr/igred/omero/roi/ROIWrapper.java | 57 +++++----- .../fr/igred/omero/roi/ROI2ImageJTest.java | 1 + 4 files changed, 90 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index f3fb7920..959aeac5 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,8 @@ List rois = image.getROIs(client); They can also be converted from or to ImageJ Rois: ```java -// The property is a string used to create 3D/4D ROIs in OMERO, by grouping shapes sharing the same value (e.g. local index). +// The property argument is the name of the ImageJ property used to create 3D/4D ROIs in OMERO, +// by grouping shapes sharing the same value (e.g. label/index). // The ROI name can be set/accessed using the property ROI.ijNameProperty(property). // The OMERO IDs are available through the property ROI.ijIDProperty(property). // The ijNameProperty() and ijIDProperty() methods append "_NAME" and "_ID" to the property (respectively). diff --git a/src/main/java/fr/igred/omero/annotations/TableWrapper.java b/src/main/java/fr/igred/omero/annotations/TableWrapper.java index feecd55e..33346c10 100644 --- a/src/main/java/fr/igred/omero/annotations/TableWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TableWrapper.java @@ -147,8 +147,8 @@ public TableWrapper(Client client, ResultsTable results, Long imageId, List - *

  • The ROI local IDs (indices, assumed by default)
  • - *
  • The ROI OMERO IDs (if indices do not map)
  • - *
  • The ROI names (if IDs do not map or if the column contains Strings)
  • - *
  • The ShapeData names (if the column contains Strings)
  • + *
  • The ROI local indices/labels (assumed by default)
  • + *
  • The ROI OMERO IDs (checked if labels do not map)
  • + *
  • The ROI names (checked if IDs do not map or if the column contains Strings)
  • + *
  • The ShapeData names (checked if the column contains Strings and ROI names do not map)
  • * * * @param roiCol Variable column containing ROI info - * @param index2roi ROI indices map + * @param label2roi ROI local labels/IDs map * @param id2roi ROI IDs map * @param name2roi ROI names map * @param shapeName2roi ROI shape names map @@ -283,22 +283,20 @@ private static void renameImageColumn(ResultsTable results) { * @return A ROIData column. */ private static ROIData[] propertyColumnToROIColumn(Variable[] roiCol, - Map index2roi, Map id2roi, + Map label2roi, Map name2roi, Map shapeName2roi) { ROIData[] roiColumn; if (isColumnNumeric(roiCol)) { - roiColumn = idColumnToROIColumn(roiCol, index2roi); + roiColumn = numericColumnToROIColumn(roiCol, label2roi); if (roiColumn.length == 0) roiColumn = idColumnToROIColumn(roiCol, id2roi); - if (roiColumn.length == 0) roiColumn = Arrays.stream(roiCol) - .map(Variable::toString) - .map(name2roi::get) - .toArray(ROIData[]::new); + if (roiColumn.length == 0) roiColumn = numericColumnToROIColumn(roiCol, name2roi); } else { - roiColumn = labelColumnToROIColumn(roiCol, name2roi, shapeName2roi, (m, s) -> s); + roiColumn = labelColumnToROIColumn(roiCol, name2roi, (m, s) -> s); + if (roiColumn.length == 0) roiColumn = labelColumnToROIColumn(roiCol, label2roi, (m, s) -> s); + if (roiColumn.length == 0) roiColumn = labelColumnToROIColumn(roiCol, shapeName2roi, (m, s) -> s); } - if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; return roiColumn; } @@ -325,28 +323,37 @@ private static ROIData[] idColumnToROIColumn(Variable[] roiCol, Map id2roi) { + ROIData[] roiColumn = Arrays.stream(roiCol) + .map(Variable::toString) + .map(id2roi::get).toArray(ROIData[]::new); + // If roiColumn contains null, we return an empty array + if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; + return roiColumn; + } + + + /** + * Creates a ROIData column from a Variable column containing the ROI OMERO IDs. + * + * @param roiCol Variable column containing ROI info + * @param label2roi ROI shape names map * * @return A ROIData column. */ private static ROIData[] labelColumnToROIColumn(Variable[] roiCol, - Map name2roi, - Map shapeName2roi, + Map label2roi, BiFunction, ? super String, String> filter) { ROIData[] roiColumn = Arrays.stream(roiCol) .map(Variable::getString) - .map(s -> filter.apply(shapeName2roi, s)) - .map(shapeName2roi::get) + .map(s -> filter.apply(label2roi, s)) + .map(label2roi::get) .toArray(ROIData[]::new); - if (Arrays.asList(roiColumn).contains(null)) { - roiColumn = Arrays.stream(roiCol) - .map(Variable::getString) - .map(s -> filter.apply(name2roi, s)) - .map(name2roi::get) - .toArray(ROIData[]::new); - } // If roiColumn contains null, we return an empty array if (Arrays.asList(roiColumn).contains(null)) roiColumn = EMPTY_ROI; return roiColumn; @@ -380,14 +387,14 @@ private static ROIData[] createROIColumn(ResultsTable results, .filter(r -> !r.getName().isEmpty()) .collect(toMap(ROIWrapper::getName, GenericObjectWrapper::asDataObject)); - Map index2roi = ijRois.stream() - .map(r -> new SimpleEntry<>(safeParseLong(r.getProperty(roiProperty)), - safeParseLong(r.getProperty(roiIdProperty)))) - .filter(p -> p.getKey() != null) - .filter(p -> p.getValue() != null) - .collect(toMap(SimpleEntry::getKey, - p -> id2roi.get(p.getValue()), - (x1, x2) -> x1)); + Map label2roi = ijRois.stream() + .map(r -> new SimpleEntry<>(r.getProperty(roiProperty), + safeParseLong(r.getProperty(roiIdProperty)))) + .filter(p -> p.getKey() != null) + .filter(p -> p.getValue() != null) + .collect(toMap(SimpleEntry::getKey, + p -> id2roi.get(p.getValue()), + (x1, x2) -> x1)); Map shape2roi = ijRois.stream() .map(r -> new SimpleEntry<>(r.getName(), @@ -401,7 +408,7 @@ private static ROIData[] createROIColumn(ResultsTable results, String[] headings = results.getHeadings(); if (results.columnExists(roiProperty)) { Variable[] roiCol = results.getColumnAsVariables(roiProperty); - roiColumn = propertyColumnToROIColumn(roiCol, index2roi, id2roi, name2roi, shape2roi); + roiColumn = propertyColumnToROIColumn(roiCol, id2roi, label2roi, name2roi, shape2roi); if (roiColumn.length != 0) results.deleteColumn(roiProperty); } if (roiColumn.length == 0 && results.columnExists(roiIdProperty)) { @@ -411,11 +418,18 @@ private static ROIData[] createROIColumn(ResultsTable results, } if (roiColumn.length == 0 && Arrays.asList(headings).contains(LABEL)) { Variable[] roiCol = results.getColumnAsVariables(LABEL); - roiColumn = labelColumnToROIColumn(roiCol, name2roi, shape2roi, (m, s) -> m.keySet() - .stream() - .filter(s::contains) - .findFirst() - .orElse(null)); + roiColumn = labelColumnToROIColumn(roiCol, shape2roi, (m, s) -> m.keySet() + .stream() + .filter(s::contains) + .findFirst() + .orElse(null)); + if (roiColumn.length == 0) { + roiColumn = labelColumnToROIColumn(roiCol, name2roi, (m, s) -> m.keySet() + .stream() + .filter(s::contains) + .findFirst() + .orElse(null)); + } } return roiColumn; @@ -473,8 +487,8 @@ public void addRows(Client client, ResultsTable results, Long imageId, List { /** - * Default IJ property to store ROI local IDs / indices. + * Default IJ property to store ROI local labels / indices. */ public static final String IJ_PROPERTY = "ROI"; @@ -97,7 +96,7 @@ public ROIWrapper(ROIData data) { /** * Checks the provided property. * - * @param property The property where 4D ROI local ID is stored. + * @param property The property where the 4D ROI local index/label is stored. * * @return The property, or the default value {@link #IJ_PROPERTY} (= {@value IJ_PROPERTY}) if it is null or empty. */ @@ -108,9 +107,10 @@ public static String checkProperty(String property) { /** - * Returns ID property corresponding to input local ID property (appends "_ID" to said property). + * Returns the ID property corresponding to the input local index/label property (appends "_ID" to said property). * - * @param property The property where 4D ROI local ID is stored, defaults to {@value IJ_PROPERTY} if null or empty. + * @param property The property where the 4D ROI local index/label is stored. Defaults to {@value IJ_PROPERTY} if null + * or empty. * * @return See above. */ @@ -121,10 +121,10 @@ public static String ijIDProperty(String property) { /** - * Returns the name property corresponding to input local ID property (appends "_NAME" to said property). + * Returns the ID property corresponding to the input local index/label property (appends "_NAME" to said property). * - * @param property The property where the 4D ROI local ID is stored, defaults to {@value IJ_PROPERTY} if null or - * empty. + * @param property The property where the 4D ROI local index/label is stored. Defaults to {@value IJ_PROPERTY} if null + * or empty. * * @return See above. */ @@ -150,7 +150,8 @@ public static List fromImageJ(List ijRois) { * Converts an ImageJ list of ROIs to a list of OMERO ROIs * * @param ijRois A list of ImageJ ROIs. - * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or empty. + * @param property The property used to store the 4D ROI local index/label. Defaults to {@value IJ_PROPERTY} if null + * or empty. * * @return The converted list of OMERO ROIs. */ @@ -163,8 +164,8 @@ public static List fromImageJ(List ijRois, Str * Converts an ImageJ list of ROIs to a list of OMERO ROIs using the provided constructor and shape converter. * * @param ijRois A list of ImageJ ROIs. - * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or - * empty. + * @param property The property used to store the 4D ROI local index/label. Defaults to {@value IJ_PROPERTY} if + * null or empty. * @param constructor A constructor to create ROI instances. * @param converter A function to convert an IJ Roi to a list of OMERO Shapes. * @@ -175,32 +176,28 @@ private static List fromImageJ(List ijRois, Supplier constructor, Function>> converter) { property = checkProperty(property); - Pattern intPattern = Pattern.compile("-?\\d+"); - Map rois4D = new TreeMap<>(); - Map names = new TreeMap<>(); + Map rois4D = new TreeMap<>(); + Map names = new TreeMap<>(); Map shape2roi = new TreeMap<>(); for (int i = 0; i < ijRois.size(); i++) { String value = ijRois.get(i).getProperty(property); String name = ijRois.get(i).getProperty(ijNameProperty(property)); - if (value != null && intPattern.matcher(value).matches()) { - long id = Long.parseLong(value); - rois4D.computeIfAbsent(id, v -> constructor.get()); - names.putIfAbsent(id, name); - shape2roi.put(i, rois4D.get(id)); + + ROIWrapper roi; + if (value != null && !value.trim().isEmpty()) { + roi = rois4D.computeIfAbsent(value, v -> constructor.get()); + names.putIfAbsent(value, name); } else { - shape2roi.put(i, constructor.get()); + roi = constructor.get(); + roi.setName(name); } + shape2roi.put(i, roi); } rois4D.forEach((id, roi) -> roi.setName(names.get(id))); - - for (Map.Entry entry : shape2roi.entrySet()) { - ij.gui.Roi ijRoi = ijRois.get(entry.getKey()); - ROIWrapper roi = entry.getValue(); - roi.addShapes(converter.apply(ijRoi)); - } + shape2roi.forEach((key, value) -> value.addShapes(converter.apply(ijRois.get(key)))); return shape2roi.values().stream().distinct().collect(Collectors.toList()); } @@ -221,7 +218,8 @@ public static List toImageJ(List rois) { * Converts an OMERO list of ROIs to a list of ImageJ ROIs * * @param rois A list of OMERO ROIs. - * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or empty. + * @param property The property used to store the 4D ROI local index/label. Defaults to {@value IJ_PROPERTY} if null + * or empty. * * @return The converted list of ImageJ ROIs. */ @@ -234,7 +232,8 @@ public static List toImageJ(List rois, String * Converts an OMERO list of ROIs to a list of ImageJ ROIs * * @param rois A list of OMERO ROIs. - * @param property The property used to store 4D ROI local IDs. Defaults to {@value IJ_PROPERTY} if null or empty. + * @param property The property used to store the 4D ROI local labels/IDs. Defaults to {@value IJ_PROPERTY} if null + * or empty. * @param groupRois Whether ImageJ Rois belonging to the same OMERO ROI should be grouped or not. * * @return The converted list of ImageJ ROIs. @@ -436,7 +435,7 @@ public List toImageJ() { /** * Convert ROI to ImageJ list of ROIs. * - * @param property The property where 4D ROI local ID will be stored. + * @param property The property where the 4D ROI local index will be stored. * * @return A list of ROIs. */ diff --git a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java index 2235f9c8..a8b453a1 100644 --- a/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java +++ b/src/test/java/fr/igred/omero/roi/ROI2ImageJTest.java @@ -59,6 +59,7 @@ void testROIsFromImageJ() { rectangle.setName("rectangle"); rectangle.setPosition(1, 2, 3); rectangle.setProperty("ROI", "24"); + rectangle.setProperty("ROI_NAME", ""); rois.add(rectangle); TextRoi textRoi = new TextRoi(3.0, 4.0, "Text");