From 8f8d36d81f81bac3ae5a98bb947cca9154d70c23 Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Tue, 20 Dec 2011 14:20:36 +0000 Subject: [PATCH] LMS-2700 Added API support for finding the image formats available for an image SVN: 24068 --- screening/.gitignore | 2 + .../server/DssServiceRpcScreening.java | 67 ++++++++ .../server/DssServiceRpcScreeningLogger.java | 9 + .../api/v1/IDssServiceRpcScreening.java | 13 ++ .../DatasetImageRepresentationFormats.java | 124 ++++++++++++++ .../api/v1/dto/ImageRepresentationFormat.java | 156 ++++++++++++++++++ 6 files changed, 371 insertions(+) create mode 100644 screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/DatasetImageRepresentationFormats.java create mode 100644 screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/ImageRepresentationFormat.java diff --git a/screening/.gitignore b/screening/.gitignore index ed41e31c465..dfaab234c0b 100644 --- a/screening/.gitignore +++ b/screening/.gitignore @@ -3,3 +3,5 @@ /.updater /.dynamic_property_evaluator_queue /tmp +/dss-tmp +/indices-screening diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreening.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreening.java index 59e076ed698..72dc83707a7 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreening.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreening.java @@ -22,6 +22,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -65,6 +66,7 @@ import ch.systemsx.cisd.openbis.dss.shared.DssScreeningUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.CodeNormalizer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.DatasetImageRepresentationFormats; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureInformation; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVector; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDataset; @@ -78,6 +80,7 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.IImageSetMeta import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.IImageSetSelectionCriterion; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageChannel; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetMetadata; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageRepresentationFormat; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageSize; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageTransformationInfo; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.MicroscopyImageReference; @@ -103,6 +106,7 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.ImgCo import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.ImgFeatureDefDTO; import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.ImgImageDatasetDTO; import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.ImgImageTransformationDTO; +import ch.systemsx.cisd.openbis.plugin.screening.shared.imaging.dataaccess.ImgImageZoomLevelDTO; /** * Implementation of the screening API interface using RPC. The instance will be created in spring @@ -784,6 +788,69 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc return createPlateImageReferences(imageAccessor, dataSetIdentifier, wellPositions, channels); } + public List<DatasetImageRepresentationFormats> listAvailableImageRepresentationFormats( + String sessionToken, List<? extends IDatasetIdentifier> imageDatasets) + { + IImagingReadonlyQueryDAO queryInterface = getDAO(); + ArrayList<DatasetImageRepresentationFormats> result = + new ArrayList<DatasetImageRepresentationFormats>(imageDatasets.size()); + + // Get the database identifiers for the data sets + String[] permIds = new String[imageDatasets.size()]; + for (int i = 0; i < imageDatasets.size(); ++i) + { + permIds[i] = imageDatasets.get(i).getPermId(); + } + List<ImgImageDatasetDTO> primImageDatasets = + queryInterface.listImageDatasetsByPermId(permIds); + + // Convert this to a hash map for faster indexing + HashMap<String, ImgImageDatasetDTO> imageDataSetMap = + new HashMap<String, ImgImageDatasetDTO>(); + for (ImgImageDatasetDTO primImageDataSet : primImageDatasets) + { + imageDataSetMap.put(primImageDataSet.getPermId(), primImageDataSet); + } + + // Not an efficient way to execute this query, but it reuses the queries at our disposal + for (IDatasetIdentifier imageDataset : imageDatasets) + { + ImgImageDatasetDTO primImageDataSet = imageDataSetMap.get(imageDataset.getPermId()); + if (null == primImageDataSet) + { + List<ImageRepresentationFormat> emptyList = Collections.emptyList(); + DatasetImageRepresentationFormats datasetResult = + new DatasetImageRepresentationFormats(imageDataset, emptyList); + result.add(datasetResult); + continue; + } + List<ImgImageZoomLevelDTO> zoomLevels = + queryInterface.listImageZoomLevels(primImageDataSet.getId()); + List<ImageRepresentationFormat> formats = + convertZoomLevelsToRepresentationFormats(zoomLevels); + DatasetImageRepresentationFormats datasetResult = + new DatasetImageRepresentationFormats(imageDataset, formats); + result.add(datasetResult); + } + return result; + } + + private List<ImageRepresentationFormat> convertZoomLevelsToRepresentationFormats( + List<ImgImageZoomLevelDTO> zoomLevels) + { + ArrayList<ImageRepresentationFormat> results = new ArrayList<ImageRepresentationFormat>(); + for (ImgImageZoomLevelDTO zoomLevel : zoomLevels) + { + ImageRepresentationFormat result = + new ImageRepresentationFormat(zoomLevel.getIsOriginal(), zoomLevel.getWidth(), + zoomLevel.getHeight(), zoomLevel.getColorDepth(), + zoomLevel.getFileType()); + results.add(result); + } + + return results; + } + private IImagingDatasetLoader createImageLoader(IDatasetIdentifier dataSetIdentifier) { final String datasetCode = dataSetIdentifier.getDatasetCode(); diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningLogger.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningLogger.java index 66ad5352016..0573ed63ad5 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningLogger.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/server/DssServiceRpcScreeningLogger.java @@ -26,6 +26,7 @@ import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; import ch.systemsx.cisd.openbis.dss.screening.shared.api.v1.IDssServiceRpcScreening; import ch.systemsx.cisd.openbis.dss.screening.shared.api.v1.LoadImageConfiguration; import ch.systemsx.cisd.openbis.generic.shared.AbstractServerLogger; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.DatasetImageRepresentationFormats; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureInformation; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDataset; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference; @@ -254,4 +255,12 @@ public class DssServiceRpcScreeningLogger extends AbstractServerLogger implement return null; } + public List<DatasetImageRepresentationFormats> listAvailableImageRepresentationFormats( + String sessionToken, List<? extends IDatasetIdentifier> imageDatasets) + { + logAccess(sessionToken, "list_available_image_representation_formats", "DATA_SETS(%s)", + imageDatasets); + return null; + } + } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/shared/api/v1/IDssServiceRpcScreening.java b/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/shared/api/v1/IDssServiceRpcScreening.java index 3b06575c224..4f887d5b66a 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/shared/api/v1/IDssServiceRpcScreening.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/dss/screening/shared/api/v1/IDssServiceRpcScreening.java @@ -29,6 +29,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.authorization.Da import ch.systemsx.cisd.openbis.dss.generic.shared.api.internal.authorization.PrivilegeLevel; import ch.systemsx.cisd.openbis.dss.screening.shared.api.internal.authorization.DatasetIdentifierPredicate; import ch.systemsx.cisd.openbis.dss.screening.shared.api.internal.authorization.SingleDataSetIdentifierPredicate; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.DatasetImageRepresentationFormats; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureInformation; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDataset; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference; @@ -393,4 +394,16 @@ public interface IDssServiceRpcScreening extends IRpcService @AuthorizationGuard(guardClass = DatasetIdentifierPredicate.class) List<? extends IImageDatasetIdentifier> imageDatasets); + /** + * Return image representation formats available for the specified image datasets. + * + * @param imageDatasets The image data sets for which the representation formats are requested. + * @return A list with one entry for each in <b>imageDatasets</b>. + */ + @MinimalMinorVersion(10) + @DataSetAccessGuard + public List<DatasetImageRepresentationFormats> listAvailableImageRepresentationFormats(String sessionToken, + @AuthorizationGuard(guardClass = DatasetIdentifierPredicate.class) + List<? extends IDatasetIdentifier> imageDatasets); + } diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/DatasetImageRepresentationFormats.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/DatasetImageRepresentationFormats.java new file mode 100644 index 00000000000..720f950a3be --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/DatasetImageRepresentationFormats.java @@ -0,0 +1,124 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * A bean that lists all image representation formats available for a data set. + * + * @since 1.10 + * @author Chandrasekhar Ramakrishnan + */ +public class DatasetImageRepresentationFormats implements Serializable, + Comparable<DatasetImageRepresentationFormats> +{ + private static final long serialVersionUID = 1L; + + private final IDatasetIdentifier dataset; + + private final ArrayList<ImageRepresentationFormat> imageRepresentationFormats; + + /** + * Constructor. + * + * @param dataSet + * @param formats + */ + public DatasetImageRepresentationFormats(IDatasetIdentifier dataSet, + List<ImageRepresentationFormat> formats) + { + super(); + this.dataset = dataSet; + this.imageRepresentationFormats = new ArrayList<ImageRepresentationFormat>(formats); + } + + /** + * The data set the formats relate to. + */ + public IDatasetIdentifier getDataset() + { + return dataset; + } + + /** + * @return An immutable list containing the image representation formats for this data set. + */ + public List<ImageRepresentationFormat> getImageRepresentationFormats() + { + return Collections.unmodifiableList(imageRepresentationFormats); + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((dataset == null) ? 0 : dataset.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + DatasetImageRepresentationFormats other = (DatasetImageRepresentationFormats) obj; + if (dataset == null) + { + if (other.dataset != null) + { + return false; + } + } else if (dataset.equals(other.dataset) == false) + { + return false; + } + return true; + } + + public int compareTo(DatasetImageRepresentationFormats o) + { + return dataset.getDatasetCode().compareTo(o.getDataset().getDatasetCode()); + } + + @Override + public String toString() + { + ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + builder.append(dataset); + builder.append(imageRepresentationFormats); + return builder.toString(); + } + +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/ImageRepresentationFormat.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/ImageRepresentationFormat.java new file mode 100644 index 00000000000..ef49a97f580 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/api/v1/dto/ImageRepresentationFormat.java @@ -0,0 +1,156 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto; + +import java.io.Serializable; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +/** + * An image representation format is made up of its dimensions, bit depth, and file format. + * + * @since 1.10 + * @author Chandrasekhar Ramakrishnan + */ +public class ImageRepresentationFormat implements Serializable +{ + private static final long serialVersionUID = 1L; + + private boolean original; + + private Integer width; + + private Integer height; + + private Integer colorDepth; + + private String fileType; + + /** + * Constructor. + * + * @param original + * @param width + * @param height + * @param colorDepth + * @param fileType + */ + public ImageRepresentationFormat(boolean original, Integer width, Integer height, + Integer colorDepth, String fileType) + { + super(); + this.original = original; + this.width = width; + this.height = height; + this.colorDepth = colorDepth; + this.fileType = fileType; + } + + /** + * @return True if the format is the original format of the underlying image. + */ + public boolean isOriginal() + { + return original; + } + + /** + * @return The width of the image. + */ + public Integer getWidth() + { + return width; + } + + /** + * @return The height of the image. + */ + public Integer getHeight() + { + return height; + } + + /** + * @return The number of bits of color of the image. + */ + public Integer getColorDepth() + { + return colorDepth; + } + + /** + * @return The file type of the image. + */ + public String getFileType() + { + return fileType; + } + + @Override + public int hashCode() + { + HashCodeBuilder builder = new HashCodeBuilder(); + builder.append(original); + builder.append(width); + builder.append(height); + builder.append(colorDepth); + builder.append(fileType); + return builder.toHashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + + ImageRepresentationFormat other = (ImageRepresentationFormat) obj; + EqualsBuilder builder = new EqualsBuilder(); + builder.append(original, other.original); + builder.append(width, other.width); + builder.append(height, other.height); + builder.append(colorDepth, other.colorDepth); + builder.append(fileType, other.fileType); + return builder.isEquals(); + } + + @Override + public String toString() + { + ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + builder.append(original); + builder.append(width); + builder.append(height); + builder.append(colorDepth); + builder.append(fileType); + return builder.toString(); + } + +} -- GitLab