Skip to content
Snippets Groups Projects
Commit c26b66e3 authored by cramakri's avatar cramakri
Browse files

LMS-2333 Extended API to allow downloading transformed images.

SVN: 21976
parent a38e5814
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.IShareIdManager; ...@@ -56,6 +56,7 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.IShareIdManager;
import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.ServiceProvider;
import ch.systemsx.cisd.openbis.dss.generic.shared.dto.Size; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.Size;
import ch.systemsx.cisd.openbis.dss.screening.shared.api.v1.IDssServiceRpcScreening; 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.dss.shared.DssScreeningUtils; 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.CodeNormalizer;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData;
...@@ -101,7 +102,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -101,7 +102,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
/** /**
* The minor version of this service. * The minor version of this service.
*/ */
public static final int MINOR_VERSION = 7; public static final int MINOR_VERSION = 8;
/** /**
* NULL_SIZE encodes for "no thumbnails available" * NULL_SIZE encodes for "no thumbnails available"
...@@ -197,6 +198,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -197,6 +198,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
} }
try try
{ {
@SuppressWarnings("deprecation")
Map<String, File> datasetRoots = getRootDirectories(sessionToken, datasetCodes); Map<String, File> datasetRoots = getRootDirectories(sessionToken, datasetCodes);
List<ImageDatasetMetadata> result = new ArrayList<ImageDatasetMetadata>(); List<ImageDatasetMetadata> result = new ArrayList<ImageDatasetMetadata>();
for (IImageDatasetIdentifier dataset : imageDatasets) for (IImageDatasetIdentifier dataset : imageDatasets)
...@@ -416,16 +418,26 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -416,16 +418,26 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
return loadImages(sessionToken, imageReferences, tryAsSize(thumbnailSizeOrNull), true); return loadImages(sessionToken, imageReferences, tryAsSize(thumbnailSizeOrNull), true);
} }
public InputStream loadImages(String sessionToken, List<PlateImageReference> imageReferences,
LoadImageConfiguration configuration)
{
final Map<String, IImagingDatasetLoader> imageLoadersMap =
getImageDatasetsMap(sessionToken, imageReferences);
return loadImages(imageReferences, tryAsSize(configuration.getDesiredImageSize()),
configuration.isDesiredImageFormatPng(),
configuration.isOpenBisImageTransformationApplied(), imageLoadersMap);
}
private InputStream loadImages(String sessionToken, List<PlateImageReference> imageReferences, private InputStream loadImages(String sessionToken, List<PlateImageReference> imageReferences,
final Size sizeOrNull, final boolean convertToPng) final Size sizeOrNull, final boolean convertToPng)
{ {
final Map<String, IImagingDatasetLoader> imageLoadersMap = final Map<String, IImagingDatasetLoader> imageLoadersMap =
getImageDatasetsMap(sessionToken, imageReferences); getImageDatasetsMap(sessionToken, imageReferences);
return loadImages(imageReferences, sizeOrNull, convertToPng, imageLoadersMap); return loadImages(imageReferences, sizeOrNull, convertToPng, false, imageLoadersMap);
} }
private InputStream loadImages(List<PlateImageReference> imageReferences, private InputStream loadImages(List<PlateImageReference> imageReferences,
final Size sizeOrNull, final boolean convertToPng, final Size sizeOrNull, final boolean convertToPng, final boolean transform,
final Map<String, IImagingDatasetLoader> imageLoadersMap) final Map<String, IImagingDatasetLoader> imageLoadersMap)
{ {
final List<IContent> imageContents = new ArrayList<IContent>(); final List<IContent> imageContents = new ArrayList<IContent>();
...@@ -444,7 +456,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -444,7 +456,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
public IContent getContent() public IContent getContent()
{ {
return tryGetImageContent(imageAccessor, channelStackRef, channelCode, return tryGetImageContent(imageAccessor, channelStackRef, channelCode,
sizeOrNull, convertToPng); sizeOrNull, convertToPng, transform);
} }
})); }));
} }
...@@ -494,7 +506,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -494,7 +506,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
new HashMap<String, IImagingDatasetLoader>(); new HashMap<String, IImagingDatasetLoader>();
imageLoadersMap.put(dataSetIdentifier.getDatasetCode(), imageAccessor); imageLoadersMap.put(dataSetIdentifier.getDatasetCode(), imageAccessor);
return loadImages(imageReferences, size, true, imageLoadersMap); return loadImages(imageReferences, size, true, false, imageLoadersMap);
} }
public InputStream loadThumbnailImages(String sessionToken, public InputStream loadThumbnailImages(String sessionToken,
...@@ -526,7 +538,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -526,7 +538,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
public IContent getContent() public IContent getContent()
{ {
return tryGetImageContent(imageAccessor, channelStackRef, channelCode, return tryGetImageContent(imageAccessor, channelStackRef, channelCode,
sizeOrNull, true); sizeOrNull, true, false);
} }
})); }));
} }
...@@ -620,6 +632,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -620,6 +632,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
private IImagingDatasetLoader createImageLoader(IDatasetIdentifier dataSetIdentifier) private IImagingDatasetLoader createImageLoader(IDatasetIdentifier dataSetIdentifier)
{ {
String datasetCode = dataSetIdentifier.getDatasetCode(); String datasetCode = dataSetIdentifier.getDatasetCode();
@SuppressWarnings("deprecation")
File rootDir = getRootDirectory(datasetCode); File rootDir = getRootDirectory(datasetCode);
IImagingDatasetLoader imageAccessor = createImageLoader(datasetCode, rootDir); IImagingDatasetLoader imageAccessor = createImageLoader(datasetCode, rootDir);
return imageAccessor; return imageAccessor;
...@@ -917,12 +930,12 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -917,12 +930,12 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
private IContent tryGetImageContent(IImagingDatasetLoader imageAccessor, private IContent tryGetImageContent(IImagingDatasetLoader imageAccessor,
final ImageChannelStackReference channelStackReference, String channelCode, final ImageChannelStackReference channelStackReference, String channelCode,
Size thumbnailSizeOrNull, boolean convertToPng) Size thumbnailSizeOrNull, boolean convertToPng, boolean transform)
{ {
try try
{ {
return ImageChannelsUtils.getImage(imageAccessor, channelStackReference, channelCode, return ImageChannelsUtils.getImage(imageAccessor, channelStackReference, channelCode,
thumbnailSizeOrNull, convertToPng); thumbnailSizeOrNull, convertToPng, transform);
} catch (EnvironmentFailureException e) } catch (EnvironmentFailureException e)
{ {
operationLog.error("Error reading image.", e); operationLog.error("Error reading image.", e);
...@@ -987,6 +1000,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc ...@@ -987,6 +1000,7 @@ public class DssServiceRpcScreening extends AbstractDssServiceRpc<IDssServiceRpc
private IImagingDatasetLoader createImageLoader(String datasetCode) private IImagingDatasetLoader createImageLoader(String datasetCode)
{ {
@SuppressWarnings("deprecation")
File datasetRoot = getRootDirectory(datasetCode); File datasetRoot = getRootDirectory(datasetCode);
return createImageLoader(datasetCode, datasetRoot); return createImageLoader(datasetCode, datasetRoot);
} }
......
...@@ -22,6 +22,7 @@ import java.util.List; ...@@ -22,6 +22,7 @@ import java.util.List;
import ch.systemsx.cisd.base.image.IImageTransformerFactory; import ch.systemsx.cisd.base.image.IImageTransformerFactory;
import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; 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.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.generic.shared.AbstractServerLogger;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDataset; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDataset;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVectorDatasetReference;
...@@ -217,4 +218,12 @@ public class DssServiceRpcScreeningLogger extends AbstractServerLogger implement ...@@ -217,4 +218,12 @@ public class DssServiceRpcScreeningLogger extends AbstractServerLogger implement
return null; return null;
} }
public InputStream loadImages(String sessionToken, List<PlateImageReference> imageReferences,
LoadImageConfiguration configuration)
{
logAccess(sessionToken, "load_images", "IMAGE_REFERENCES(%s) CONFIGURATION(%s)",
imageReferences, configuration);
return null;
}
} }
...@@ -233,6 +233,39 @@ public interface IDssServiceRpcScreening extends IRpcService ...@@ -233,6 +233,39 @@ public interface IDssServiceRpcScreening extends IRpcService
@AuthorizationGuard(guardClass = SingleDataSetIdentifierPredicate.class) IDatasetIdentifier dataSetIdentifier, @AuthorizationGuard(guardClass = SingleDataSetIdentifierPredicate.class) IDatasetIdentifier dataSetIdentifier,
String channel, ImageSize thumbnailSizeOrNull); String channel, ImageSize thumbnailSizeOrNull);
/**
* Provide images for a given list of image references (specified by data set code, well
* position, channel and tile). The result is encoded into one stream, which consist of multiple
* blocks in a format: (<block-size><block-of-bytes>), where block-size is the block size in
* bytes encoded as one long number. The number of blocks is equal to the number of specified
* references and the order of blocks corresponds to the order of image references. If
* <code>convertToPng==true</code>, the images will be converted to PNG format before being
* shipped, otherwise they will be shipped in the format that they are stored on the server.
*
* @since 1.3
*/
/**
* Provide images for a given list of image references (specified by data set code, well
* position, channel and tile). The format and properties of the returned images are configured
* by the configuration.
* <p>
* The options are described in {@link LoadImageConfiguration}.
* <p>
* The encoding of the result is described in
* {@link IDssServiceRpcScreening#loadImages(String, List)}.
*
* @see IDssServiceRpcScreening#loadImages(String, List)
* @see LoadImageConfiguration
* @since 1.8
*/
@MinimalMinorVersion(8)
@DataSetAccessGuard
public InputStream loadImages(
String sessionToken,
@AuthorizationGuard(guardClass = DatasetIdentifierPredicate.class) List<PlateImageReference> imageReferences,
LoadImageConfiguration configuration);
/** /**
* Provide thumbnail images for specified microscopy data set. If no thumbnails are stored on * Provide thumbnail images for specified microscopy data set. If no thumbnails are stored on
* the server, this method will return an empty stream. Images of all tiles are delivered. * the server, this method will return an empty stream. Images of all tiles are delivered.
......
/*
* 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.dss.screening.shared.api.v1;
import java.io.Serializable;
import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageSize;
/**
* A DTO for transmitting information about how the images should be loaded. The parameters that can
* be controlled include image size, format (PNG or original), and the application of image
* transformations stored in openBIS.
* <p>
* The default configuration is to retrieve images in their original size and format (i.e., not
* converted to PNG), without the openBIS image transformation applied.
* <p>
* Providing a non-null desired size will instruct the image loader to return images that maintain
* the aspect ratio of the original and fit in the desired size.
*
* @author Chandrasekhar Ramakrishnan
*/
public class LoadImageConfiguration implements Serializable
{
private static final long serialVersionUID = 1L;
private ImageSize desiredImageSizeOrNull = null;
private boolean desiredImageFormatPng = false;
private boolean openBisImageTransformationApplied = false;
/**
* The desired size of the image. Null if the original size is requested.
* <p>
* The actual size of the returned image will have the same aspect ratio as the original, and
* thus might not be exactly the same as the desired size, but will fit in the desired size.
*
* @return The desired size of the image or null if the original size is to be returned.
*/
public ImageSize getDesiredImageSize()
{
return desiredImageSizeOrNull;
}
/**
* Set the desired size of the image.
* <p>
* The actual size of the returned image will have the same aspect ratio as the original, and
* thus might not be exactly the same as the desired size, but will fit in the desired size.
*
* @param desiredImageSizeOrNull Pass in the desired size or null if you want the image to have
* its original size.
*/
public void setDesiredImageSize(ImageSize desiredImageSizeOrNull)
{
this.desiredImageSizeOrNull = desiredImageSizeOrNull;
}
/**
* Should the image be converted from its original format to PNG?
*
* @return True if the image should be converted to PNG; false if it should be left in its
* original format.
*/
public boolean isDesiredImageFormatPng()
{
return desiredImageFormatPng;
}
/**
* Set whether the image should be converted from its original format to PNG.
*
* @param desiredImageFormatPng Pass in true if the image should be converted to PNG; false if
* it should be left in its original format.
*/
public void setDesiredImageFormatPng(boolean desiredImageFormatPng)
{
this.desiredImageFormatPng = desiredImageFormatPng;
}
/**
* Should the image transformation stored in openBIS be applied to the image?
*
* @return True if the image transformation should be applied; false if the original image
* should be returned.
*/
public boolean isOpenBisImageTransformationApplied()
{
return openBisImageTransformationApplied;
}
/**
* Set whether the image transformation stored in openBIS should be applied.
*
* @param openBisImageTransformationApplied Pass in true if the transformation should be
* applied; false otherwise.
*/
public void setOpenBisImageTransformationApplied(boolean openBisImageTransformationApplied)
{
this.openBisImageTransformationApplied = openBisImageTransformationApplied;
}
@Override
public String toString()
{
return "LoadImageConfiguration [desiredImageSizeOrNull=" + desiredImageSizeOrNull
+ ", desiredImageFormatPng=" + desiredImageFormatPng
+ ", openBisImageTransformationApplied=" + openBisImageTransformationApplied + "]";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment