From 3746fbeef673a762094363713d52aea76c16fd83 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 12 Sep 2016 14:30:04 -0500 Subject: [PATCH 1/5] Rework plate naming priorities so that reader-supplied names can be used The user specified name is typically non-null, even if the user did not explicitly enter a plate name. This attempts to distinguish between "real" user specified names and default names based upon the imported file name. The default names appear to come from ome.formats.importer.ImportFixture, but changes were not made there so as to not affect non-SPW imports. --- .../src/ome/formats/model/WellProcessor.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/components/blitz/src/ome/formats/model/WellProcessor.java b/components/blitz/src/ome/formats/model/WellProcessor.java index 2d411744325..df573109b0f 100644 --- a/components/blitz/src/ome/formats/model/WellProcessor.java +++ b/components/blitz/src/ome/formats/model/WellProcessor.java @@ -95,16 +95,29 @@ private Plate validatePlate(int plateIndex) { Plate plate = (Plate) container.sourceObject; String userSpecifiedPlateName = store.getUserSpecifiedName(); String userSpecifiedPlateDescription = store.getUserSpecifiedDescription(); + + // precedence order for plate naming: + // + // 1. user specified, if not default name of imported file + // 2. reader supplied, if not null + // 3. user specified (name of imported file) + // 4. "Plate" if (userSpecifiedPlateName != null) { - plate.setName(rstring(userSpecifiedPlateName)); - } - if (userSpecifiedPlateDescription != null) { - plate.setDescription(rstring(userSpecifiedPlateDescription)); + String currentFile = store.getReader().getCurrentFile(); + if (!currentFile.endsWith(userSpecifiedPlateName) || + plate.getName() == null) + { + plate.setName(rstring(userSpecifiedPlateName)); + } } if (plate.getName() == null) { log.warn("Missing plate name for: " + container.LSID); plate.setName(rstring("Plate")); } + + if (userSpecifiedPlateDescription != null) { + plate.setDescription(rstring(userSpecifiedPlateDescription)); + } if (plate.getRows() == null) { plate.setRows(rint(1)); } From 94575d51d788872c15e6abac2a887d29814c47ef Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Wed, 21 Sep 2016 19:47:57 -0500 Subject: [PATCH 2/5] Update Plate/Image naming to match new design proposal This removes the automatic setting of user-specified names in the importer, so that later calls to retrieve the user-specified name are guaranteed to return only what the user actually specified (or null by default). Plate and Image names supplied by the reader are trusted when the user has not specified a name. The name(s) will be set to the relative path of the imported file only if both the user- and reader-specified names are null. The issue of 255 character limits on name fields has not been addressed here, but a comment has been added so that it's easier to go back to later. --- .../ome/formats/importer/ImportCandidates.java | 9 +-------- .../ome/formats/importer/ImportFixture.java | 1 - .../src/ome/formats/model/PixelsProcessor.java | 15 ++++++++++++++- .../src/ome/formats/model/WellProcessor.java | 18 +++++------------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/components/blitz/src/ome/formats/importer/ImportCandidates.java b/components/blitz/src/ome/formats/importer/ImportCandidates.java index b326aeda38c..b0da382dd9f 100644 --- a/components/blitz/src/ome/formats/importer/ImportCandidates.java +++ b/components/blitz/src/ome/formats/importer/ImportCandidates.java @@ -437,14 +437,7 @@ protected ImportContainer singleFile(File file, ImportConfig config) ic.setDoThumbnails(config.doThumbnails.get()); ic.setNoStatsInfo(config.noStatsInfo.get()); String configImageName = config.userSpecifiedName.get(); - if (configImageName == null) - { - ic.setUserSpecifiedName(file.getName()); - } - else - { - ic.setUserSpecifiedName(configImageName); - } + ic.setUserSpecifiedName(configImageName); ic.setUserSpecifiedDescription(config.userSpecifiedDescription.get()); ic.setCustomAnnotationList(config.annotations.get()); return ic; diff --git a/components/blitz/src/ome/formats/importer/ImportFixture.java b/components/blitz/src/ome/formats/importer/ImportFixture.java index 78a09d52e30..a8fab2ba22c 100644 --- a/components/blitz/src/ome/formats/importer/ImportFixture.java +++ b/components/blitz/src/ome/formats/importer/ImportFixture.java @@ -112,7 +112,6 @@ public void doImport() throws Throwable { ic = new ImportContainer(file, fads.get(file), null, null, null, null); - ic.setUserSpecifiedName(file.getAbsolutePath()); library.importImage(ic, 0, 0, 1); /* library.importImage(file, 0, 0, 1, file.getAbsolutePath(), diff --git a/components/blitz/src/ome/formats/model/PixelsProcessor.java b/components/blitz/src/ome/formats/model/PixelsProcessor.java index c871263e458..1faa8fa9a5e 100644 --- a/components/blitz/src/ome/formats/model/PixelsProcessor.java +++ b/components/blitz/src/ome/formats/model/PixelsProcessor.java @@ -27,6 +27,7 @@ import static ome.formats.model.UnitsFactory.makeLength; +import java.io.File; import java.sql.Timestamp; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -124,6 +125,8 @@ public void process(IObjectContainerStore store) throws ModelException { } // Ensure that the Image name is set + + // name supplied by user String userSpecifiedName = store.getUserSpecifiedName(); if (userSpecifiedName != null) { userSpecifiedName = userSpecifiedName.trim(); @@ -131,7 +134,9 @@ public void process(IObjectContainerStore store) throws ModelException { userSpecifiedName = null; } } + // name that will actually be set on the Image String saveName = ""; + // name supplied by the reader String imageName; if (image.getName() != null && image.getName().getValue() != null) { imageName = image.getName().getValue().trim(); @@ -150,9 +155,17 @@ public void process(IObjectContainerStore store) throws ModelException { } saveName += " [" + imageName + "]"; } - } else { + } else if (imageName != null) { saveName = imageName; } + else { + saveName = reader.getCurrentFile(); + saveName = saveName.substring(saveName.lastIndexOf(File.separator) + 1); + if (reader.getSeriesCount() > 1) { + saveName += " [" + imageIndex + "]"; + } + } + // TODO: remove this if/when name is switched to TEXT in the DB if (saveName != null && saveName.length() > 255) { saveName = '…' + saveName.substring(saveName.length() - 254); } diff --git a/components/blitz/src/ome/formats/model/WellProcessor.java b/components/blitz/src/ome/formats/model/WellProcessor.java index df573109b0f..20664997f26 100644 --- a/components/blitz/src/ome/formats/model/WellProcessor.java +++ b/components/blitz/src/ome/formats/model/WellProcessor.java @@ -26,6 +26,7 @@ import static omero.rtypes.rint; import static omero.rtypes.rstring; +import java.io.File; import java.util.LinkedHashMap; import java.util.List; @@ -96,23 +97,14 @@ private Plate validatePlate(int plateIndex) { String userSpecifiedPlateName = store.getUserSpecifiedName(); String userSpecifiedPlateDescription = store.getUserSpecifiedDescription(); - // precedence order for plate naming: - // - // 1. user specified, if not default name of imported file - // 2. reader supplied, if not null - // 3. user specified (name of imported file) - // 4. "Plate" if (userSpecifiedPlateName != null) { - String currentFile = store.getReader().getCurrentFile(); - if (!currentFile.endsWith(userSpecifiedPlateName) || - plate.getName() == null) - { - plate.setName(rstring(userSpecifiedPlateName)); - } + plate.setName(rstring(userSpecifiedPlateName)); } if (plate.getName() == null) { log.warn("Missing plate name for: " + container.LSID); - plate.setName(rstring("Plate")); + String filename = store.getReader().getCurrentFile(); + filename = filename.substring(filename.lastIndexOf(File.separator) + 1); + plate.setName(rstring(filename)); } if (userSpecifiedPlateDescription != null) { From cc042d8861385d2cf393834a37831d0cec8a1055 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Fri, 9 Dec 2016 10:03:45 -0600 Subject: [PATCH 3/5] Revert PixelsProcessor changes so that naming for Images is unchanged --- .../src/ome/formats/model/PixelsProcessor.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/components/blitz/src/ome/formats/model/PixelsProcessor.java b/components/blitz/src/ome/formats/model/PixelsProcessor.java index 1faa8fa9a5e..8270fc74836 100644 --- a/components/blitz/src/ome/formats/model/PixelsProcessor.java +++ b/components/blitz/src/ome/formats/model/PixelsProcessor.java @@ -125,8 +125,6 @@ public void process(IObjectContainerStore store) throws ModelException { } // Ensure that the Image name is set - - // name supplied by user String userSpecifiedName = store.getUserSpecifiedName(); if (userSpecifiedName != null) { userSpecifiedName = userSpecifiedName.trim(); @@ -134,9 +132,11 @@ public void process(IObjectContainerStore store) throws ModelException { userSpecifiedName = null; } } - // name that will actually be set on the Image + if (userSpecifiedName == null) { + File originalFile = new File(reader.getCurrentFile()); + userSpecifiedName = originalFile.getName(); + } String saveName = ""; - // name supplied by the reader String imageName; if (image.getName() != null && image.getName().getValue() != null) { imageName = image.getName().getValue().trim(); @@ -155,17 +155,9 @@ public void process(IObjectContainerStore store) throws ModelException { } saveName += " [" + imageName + "]"; } - } else if (imageName != null) { + } else { saveName = imageName; } - else { - saveName = reader.getCurrentFile(); - saveName = saveName.substring(saveName.lastIndexOf(File.separator) + 1); - if (reader.getSeriesCount() > 1) { - saveName += " [" + imageIndex + "]"; - } - } - // TODO: remove this if/when name is switched to TEXT in the DB if (saveName != null && saveName.length() > 255) { saveName = '…' + saveName.substring(saveName.length() - 254); } From 9c7b9a2d20b361d1f78d562c4b19ce30077d5dfa Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Fri, 9 Dec 2016 10:24:22 -0600 Subject: [PATCH 4/5] Clean up relative path name calculation --- components/blitz/src/ome/formats/model/WellProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/blitz/src/ome/formats/model/WellProcessor.java b/components/blitz/src/ome/formats/model/WellProcessor.java index 20664997f26..d5bc8b710a1 100644 --- a/components/blitz/src/ome/formats/model/WellProcessor.java +++ b/components/blitz/src/ome/formats/model/WellProcessor.java @@ -103,7 +103,7 @@ private Plate validatePlate(int plateIndex) { if (plate.getName() == null) { log.warn("Missing plate name for: " + container.LSID); String filename = store.getReader().getCurrentFile(); - filename = filename.substring(filename.lastIndexOf(File.separator) + 1); + filename = new File(filename).getName(); plate.setName(rstring(filename)); } From 7508291a8fbd043e324da375a625d6a296aba922 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 16 Jan 2017 10:33:17 -0600 Subject: [PATCH 5/5] Additional check for null/empty plate name values This should result in plate names defaulting to the relative file name if a reader sets the plate name to an empty string. --- components/blitz/src/ome/formats/model/WellProcessor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/blitz/src/ome/formats/model/WellProcessor.java b/components/blitz/src/ome/formats/model/WellProcessor.java index d5bc8b710a1..2c2494c8850 100644 --- a/components/blitz/src/ome/formats/model/WellProcessor.java +++ b/components/blitz/src/ome/formats/model/WellProcessor.java @@ -100,7 +100,9 @@ private Plate validatePlate(int plateIndex) { if (userSpecifiedPlateName != null) { plate.setName(rstring(userSpecifiedPlateName)); } - if (plate.getName() == null) { + if (plate.getName() == null || plate.getName().getValue() == null || + plate.getName().getValue().isEmpty()) + { log.warn("Missing plate name for: " + container.LSID); String filename = store.getReader().getCurrentFile(); filename = new File(filename).getName();