From 750a907b2441a572f0151cb520dccfadd3a1ad1e Mon Sep 17 00:00:00 2001 From: tpylak <tpylak> Date: Mon, 23 May 2011 18:32:25 +0000 Subject: [PATCH] LMS-2251 adapt MatLab API SVN: 21447 --- .../dss/client/api/v1/IDataSetDss.java | 3 +- screening/source/java/OpenBISScreeningML.java | 27 +++- .../v1/IScreeningOpenbisServiceFacade.java | 26 +-- .../api/v1/ScreeningClientApiTester.java | 2 +- .../api/v1/ScreeningOpenbisServiceFacade.java | 35 +++-- .../java/BiozentrumMatLabApiTest.java | 78 +++++++++ .../java/OpenBISScreeningMLTest.java | 148 ++++++++++-------- .../v1/ScreeningOpenbisServiceFacadeTest.java | 84 +++++----- 8 files changed, 263 insertions(+), 140 deletions(-) create mode 100644 screening/sourceTest/java/BiozentrumMatLabApiTest.java diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/IDataSetDss.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/IDataSetDss.java index 00fddc7d947..a6ba5dab6c3 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/IDataSetDss.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/v1/IDataSetDss.java @@ -75,8 +75,7 @@ public interface IDataSetDss * the downloadDir containing the contents of the data set. * * @param overrideStoreRootPathOrNull A path, in the context of the local file system mounts, to - * the DSS' store root. If null, paths are returned in the context of the DSS' file - * system mounts. + * the DSS' store root. If null, datasets are copied to the downloadDir folder. * @param downloadDir The directory in which to place the contents of the data set if they must * be downloaded. * @return A File containing the contents of the data set. diff --git a/screening/source/java/OpenBISScreeningML.java b/screening/source/java/OpenBISScreeningML.java index 70cc12d816a..1d249397653 100644 --- a/screening/source/java/OpenBISScreeningML.java +++ b/screening/source/java/OpenBISScreeningML.java @@ -41,6 +41,7 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.FeatureVector 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.FeatureVectorWithDescription; +import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.Geometry; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetMetadata; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.ImageDatasetReference; import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.MaterialIdentifier; @@ -514,7 +515,8 @@ public class OpenBISScreeningML * * @param augmentedPlateCode The augmented plate code. * @return <code>{ images width, images height, number of tiles in the well, - * number of tiles rows, number of tiles columns }</code> . + * number of tiles rows, number of tiles columns, number of plate rows, number of plate columns }</code> + * . */ public static Object[][] getImagesMetadata(String augmentedPlateCode) { @@ -527,10 +529,13 @@ public class OpenBISScreeningML for (int i = 0; i < metaList.size(); ++i) { ImageDatasetMetadata meta = metaList.get(i); + ImageDatasetReference imageDatasetReference = imageDatasets.get(i); + Geometry plateGeometry = imageDatasetReference.getPlateGeometry(); result[i] = new Object[] { meta.getWidth(), meta.getHeight(), meta.getNumberOfTiles(), - meta.getTilesRows(), meta.getTilesCols() }; + meta.getTilesRows(), meta.getTilesCols(), + plateGeometry.getNumberOfRows(), plateGeometry.getNumberOfColumns() }; } return result; } @@ -650,7 +655,9 @@ public class OpenBISScreeningML /** * Loads data sets for specified plate code. For each data set the path to the root of the data * set is returned. If it is possible the path points directly into the data set store. No data - * is copied. Otherwise the data is retrieved from the data store server. + * is copied. Otherwise the data is retrieved from the data store server.<br> + * If the same dataset is loaded for the second time in one session it will be immediately + * returned from the local cache. * <p> * Matlab example: * @@ -664,16 +671,22 @@ public class OpenBISScreeningML * </pre> * * @param augmentedPlateCode The augmented plate code. + * @param datasetTypeCodePattern only datasets of the type which matche the specified pattern + * will be returned. To fetch all datasets specify ".*". + * @param overrideStoreRootPathOrNull A path, in the context of the local file system mounts, to + * the DSS' store root. If null, paths are returned in the context of the DSS' file + * system mounts. * @return Each row contains information about one data set: * <p> * <code>{ data set code, data set root path }</code> */ - public static Object[][] loadDataSets(String augmentedPlateCode) + public static Object[][] loadDataSets(String augmentedPlateCode, String datasetTypeCodePattern, + String overrideStoreRootPathOrNull) { checkLoggedIn(); Plate plateIdentifier = getPlate(augmentedPlateCode); - List<IDataSetDss> dataSets = openbis.getDataSets(plateIdentifier); + List<IDataSetDss> dataSets = openbis.getDataSets(plateIdentifier, datasetTypeCodePattern); Object[][] result = new Object[dataSets.size()][]; try { @@ -684,7 +697,9 @@ public class OpenBISScreeningML File file = new File(dataSetsDir, code); if (file.exists() == false) { - file = dataSet.getLinkOrCopyOfContents(null, dataSetsDir); + file = + dataSet.getLinkOrCopyOfContents(overrideStoreRootPathOrNull, + dataSetsDir); } result[i] = new Object[] { code, file.getPath() }; diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/IScreeningOpenbisServiceFacade.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/IScreeningOpenbisServiceFacade.java index 130c9cc4e28..1ed3d41ecab 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/IScreeningOpenbisServiceFacade.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/IScreeningOpenbisServiceFacade.java @@ -150,12 +150,12 @@ public interface IScreeningOpenbisServiceFacade * For the given <var>plateIdentifier</var> find all wells that are connected to it. */ public List<WellIdentifier> listPlateWells(PlateIdentifier plateIdentifier); - + /** * Returns all properties of specified well as a map. */ public Map<String, String> getWellProperties(WellIdentifier wellIdentifier); - + /** * Updates properties of specified well. */ @@ -164,12 +164,15 @@ public interface IScreeningOpenbisServiceFacade /** * Get proxies to the data sets owned by specified well. * + * @param datasetTypeCodePattern only datasets of the type which matche the specified pattern + * will be returned. To fetch all datasets specify ".*". * @throws IllegalStateException Thrown if the user has not yet been authenticated. * @throws EnvironmentFailureException Thrown in cases where it is not possible to connect to * the server. */ - public List<IDataSetDss> getDataSets(WellIdentifier wellIdentifier) - throws IllegalStateException, EnvironmentFailureException; + public List<IDataSetDss> getDataSets(WellIdentifier wellIdentifier, + String datasetTypeCodePattern) throws IllegalStateException, + EnvironmentFailureException; /** * Upload a new data set to the DSS for a well. @@ -189,15 +192,18 @@ public interface IScreeningOpenbisServiceFacade EnvironmentFailureException, IOException; /** - * Get proxies to the data sets owned by specified plate. + * Get proxies to the data sets of the specified type owned by specified plate. * + * @param datasetTypeCodePattern only datasets of the type which matche the specified pattern + * will be returned. To fetch all datasets specify ".*". * @throws IllegalStateException Thrown if the user has not yet been authenticated. * @throws EnvironmentFailureException Thrown in cases where it is not possible to connect to * the server. */ - public List<IDataSetDss> getDataSets(PlateIdentifier plateIdentifier) - throws IllegalStateException, EnvironmentFailureException; - + public List<IDataSetDss> getDataSets(PlateIdentifier plateIdentifier, + String datasetTypeCodePattern) throws IllegalStateException, + EnvironmentFailureException; + /** * Upload a new data set to the DSS for a plate. * @@ -214,7 +220,7 @@ public interface IScreeningOpenbisServiceFacade public IDataSetDss putDataSet(PlateIdentifier plateIdentifier, File dataSetFile, NewDataSetMetadataDTO dataSetMetadataOrNull) throws IllegalStateException, EnvironmentFailureException, IOException; - + /** * Converts the given list of {@link PlateWellReferenceWithDatasets} into a list of * {@link FeatureVectorDatasetWellReference}. @@ -566,5 +572,5 @@ public interface IScreeningOpenbisServiceFacade public List<PlateWellMaterialMapping> listPlateMaterialMapping( List<? extends PlateIdentifier> plates, MaterialTypeIdentifier materialTypeIdentifierOrNull); - + } \ No newline at end of file diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningClientApiTester.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningClientApiTester.java index a31a35940d0..a04792d5873 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningClientApiTester.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningClientApiTester.java @@ -246,7 +246,7 @@ public class ScreeningClientApiTester } for (WellIdentifier wellIdentifier : listPlateWells) { - List<IDataSetDss> dataSets = facade.getDataSets(wellIdentifier); + List<IDataSetDss> dataSets = facade.getDataSets(wellIdentifier, ".*"); if (dataSets.isEmpty() == false) { JOptionPane.showMessageDialog(TesterFrame.this, "Well " diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacade.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacade.java index 069dcc63bca..e818d7c3666 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacade.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacade.java @@ -93,7 +93,7 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa private final IScreeningApiServer openbisScreeningServer; private final IGeneralInformationService generalInformationService; - + private final IGeneralInformationChangingService generalInformationChangingService; private final IDssComponent dssComponent; @@ -190,7 +190,7 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa IGeneralInformationChangingService.class, serverUrl); return service; } - + ScreeningOpenbisServiceFacade(String sessionToken, IScreeningApiServer screeningServer, int minorVersion, final IDssServiceFactory dssServiceFactory, IDssComponent dssComponent, IGeneralInformationService generalInformationService, @@ -383,7 +383,7 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa checkASMinimalMinorVersion("listPlateWells", PlateIdentifier.class); return openbisScreeningServer.listPlateWells(sessionToken, plateIdentifier); } - + public Map<String, String> getWellProperties(WellIdentifier wellIdentifier) { Sample wellSample = openbisScreeningServer.getWellSample(sessionToken, wellIdentifier); @@ -394,7 +394,8 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa public void updateWellProperties(WellIdentifier wellIdentifier, Map<String, String> properties) { Sample wellSample = openbisScreeningServer.getWellSample(sessionToken, wellIdentifier); - generalInformationChangingService.updateSampleProperties(sessionToken, wellSample.getId(), properties); + generalInformationChangingService.updateSampleProperties(sessionToken, wellSample.getId(), + properties); } /** @@ -404,11 +405,12 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa * @throws EnvironmentFailureException Thrown in cases where it is not possible to connect to * the server. */ - public List<IDataSetDss> getDataSets(WellIdentifier wellIdentifier) - throws IllegalStateException, EnvironmentFailureException + public List<IDataSetDss> getDataSets(WellIdentifier wellIdentifier, + String datasetTypeCodePattern) throws IllegalStateException, + EnvironmentFailureException { final Sample wellSample = getWellSample(wellIdentifier); - return getDataSets(wellSample); + return getDataSets(wellSample, datasetTypeCodePattern); } /** @@ -418,22 +420,26 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa * @throws EnvironmentFailureException Thrown in cases where it is not possible to connect to * the server. */ - public List<IDataSetDss> getDataSets(PlateIdentifier plateIdentifier) - throws IllegalStateException, EnvironmentFailureException + public List<IDataSetDss> getDataSets(PlateIdentifier plateIdentifier, + String datasetTypeCodePattern) throws IllegalStateException, + EnvironmentFailureException { checkASMinimalMinorVersion("getPlateSample", PlateIdentifier.class); Sample sample = openbisScreeningServer.getPlateSample(sessionToken, plateIdentifier); - return getDataSets(sample); + return getDataSets(sample, datasetTypeCodePattern); } - private List<IDataSetDss> getDataSets(final Sample sample) + private List<IDataSetDss> getDataSets(final Sample sample, final String datasetTypeCodePattern) { final List<DataSet> dataSets = generalInformationService.listDataSetsForSample(sessionToken, sample, true); final List<IDataSetDss> result = new ArrayList<IDataSetDss>(); for (DataSet dataSet : dataSets) { - result.add(dssComponent.getDataSet(dataSet.getCode())); + if (dataSet.getDataSetTypeCode().matches(datasetTypeCodePattern)) + { + result.add(dssComponent.getDataSet(dataSet.getCode())); + } } return result; } @@ -490,7 +496,8 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa NewDataSetMetadataDTO dataSetMetadataOrNull, File dataSetFile) throws IOException { final NewDataSetMetadataDTO dataSetMetadata = - (dataSetMetadataOrNull == null) ? new NewDataSetMetadataDTO() : dataSetMetadataOrNull; + (dataSetMetadataOrNull == null) ? new NewDataSetMetadataDTO() + : dataSetMetadataOrNull; final DataSetOwner dataSetOwner = new DataSetOwner(DataSetOwnerType.SAMPLE, sample.getIdentifier()); final String dataSetFolderNameOrNull = null; @@ -499,7 +506,7 @@ public class ScreeningOpenbisServiceFacade implements IScreeningOpenbisServiceFa new NewDataSetDTO(dataSetMetadata, dataSetOwner, dataSetFolderNameOrNull, fileInfos); return dssComponent.putDataSet(newDataSet, dataSetFile); } - + private List<FileInfoDssDTO> getFileInfosForPath(File file) throws IOException { ArrayList<FileInfoDssDTO> fileInfos = new ArrayList<FileInfoDssDTO>(); diff --git a/screening/sourceTest/java/BiozentrumMatLabApiTest.java b/screening/sourceTest/java/BiozentrumMatLabApiTest.java new file mode 100644 index 00000000000..14e109d8d25 --- /dev/null +++ b/screening/sourceTest/java/BiozentrumMatLabApiTest.java @@ -0,0 +1,78 @@ +/* + * 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. + */ + +/** + * Integration tests of MatLab API on Biozentrum server. + * + * @author Tomasz Pylak + */ +public class BiozentrumMatLabApiTest +{ + public static void main(String[] args) + { + if (args.length == 0) + { + System.err + .println("Specify the password and optionally the plate identifier, mount point and dataset type pattern!"); + } + String passwd = args[0]; + String chosenPlate = "/TEST/KB01"; + String mountPoint = null; + String datasetTypePattern = "HCS_ANALYSIS_CELL_CLASSIFICATIONS_MAT"; + if (args.length > 1) + { + chosenPlate = args[1]; + } + if (args.length > 2) + { + mountPoint = args[2]; + } + + OpenBISScreeningML.login("admin", passwd, "http://bc2-openbis01.bc2.unibas.ch:8443"); + + Object[][] meta = OpenBISScreeningML.getImagesMetadata(chosenPlate); + System.out.println(String.format("Number of tiles: %s. Plate geometry %sx%s", meta[1][3], + meta[1][6], meta[1][7])); + + // fetch 3ed tile of well (1,1). The second call to fetch this image will return it from the + // local cache. + // The last optional parameter can specify a list of channels to load (otherwise all + // channels are loaded). + Object[][][] images = OpenBISScreeningML.loadImages(chosenPlate, 1, 1, 3); + System.out.println("Image path: " + images[1][1]); + + // properties of well (2,4) + Object[][] props = OpenBISScreeningML.getWellProperties(chosenPlate, 2, 4); + for (int i = 0; i < props.length; i++) + { + System.out.println(String.format("Property %s = %s ", props[i][0], props[i][1])); + } + + // save description of the well (2,4) + props = new Object[][] + { + { "DESCRIPTION", "hello example" } }; + OpenBISScreeningML.updateWellProperties(chosenPlate, 2, 4, props); + + // Loads dataset with classification results. + // OpenBIS store diretcory is mounted locally in "/mount/openbis/store", so no data are + // copied and just a path to the appropriate location + // is returned. + Object[][] datasets = + OpenBISScreeningML.loadDataSets(chosenPlate, datasetTypePattern, mountPoint); + System.out.println("Path to the first downloaded dataset: " + datasets[0][1]); + } +} diff --git a/screening/sourceTest/java/OpenBISScreeningMLTest.java b/screening/sourceTest/java/OpenBISScreeningMLTest.java index e8337604633..28d212ad45a 100644 --- a/screening/sourceTest/java/OpenBISScreeningMLTest.java +++ b/screening/sourceTest/java/OpenBISScreeningMLTest.java @@ -14,8 +14,6 @@ * limitations under the License. */ - - import java.io.File; import java.io.FilenameFilter; import java.io.IOException; @@ -55,8 +53,6 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellIdentifie import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition; /** - * - * * @author Franz-Josef Elmer */ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase @@ -70,7 +66,8 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase } }; - private Mockery context; + private Mockery context; + private IScreeningOpenbisServiceFacade openbis; private File tempDir; @@ -80,11 +77,11 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase private ExperimentIdentifier eId2; private IDataSetDss ds1; - + private IDataSetDss ds2; private IScreeningOpenbisServiceFacadeFactory facadeFactory; - + @BeforeMethod public void beforeMethod() { @@ -103,10 +100,10 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase { one(facadeFactory).tryToCreate("user", "password", "url"); will(returnValue(openbis)); - + one(openbis).listExperiments(); will(returnValue(Arrays.asList(eId1, eId2))); - + one(openbis).listPlates(); Plate p1 = new Plate("PLATE-1", "S", "s-1", eId1); Plate p2 = new Plate("PLATE-2", "S", "s-2", eId2); @@ -117,13 +114,13 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase OpenBISScreeningML.login("user", "password", "url"); tempDir = OpenBISScreeningML.tempDir.listFiles(FILTER_TEMP_DIR)[0]; } - + @AfterMethod public void afterMethod() { context.assertIsSatisfied(); } - + @Test public void testLogout() { @@ -137,13 +134,13 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase a.mkdirs(); FileUtilities.writeToFile(new File(a, "1.txt"), "one"); FileUtilities.writeToFile(new File(tempDir, "2.txt"), "two"); - + OpenBISScreeningML.logout(); - + assertEquals(false, tempDir.exists()); context.assertIsSatisfied(); } - + @Test public void testCheckLoggedInFailsBecauseOfMissingSessionTokenFile() { @@ -154,7 +151,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase } }); OpenBISScreeningML.logout(); - + try { OpenBISScreeningML.listExperiments(); @@ -163,10 +160,10 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase { assertEquals("Not logged in.", ex.getMessage()); } - + context.assertIsSatisfied(); } - + @Test public void testCheckLoggedInFailsBecauseOfInvalidSession() { @@ -182,7 +179,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase Login.OPENBIS_USER_FILE.getParentFile().mkdirs(); FileUtilities.writeToFile(Login.OPENBIS_TOKEN_FILE, "session-token-1"); FileUtilities.writeToFile(Login.OPENBIS_SERVER_URL_FILE, "url"); - + try { OpenBISScreeningML.listExperiments(); @@ -191,10 +188,10 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase { assertEquals("Login failed.", ex.getMessage()); } - + context.assertIsSatisfied(); } - + @Test public void testCheckLoggedInSucceed() { @@ -202,10 +199,10 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase { { exactly(2).of(openbis).logout(); - + one(facadeFactory).tryToCreate("session-token-1", "url"); will(returnValue(openbis)); - + one(openbis).listExperiments(); one(openbis).listPlates(); } @@ -214,14 +211,14 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase Login.OPENBIS_USER_FILE.getParentFile().mkdirs(); FileUtilities.writeToFile(Login.OPENBIS_TOKEN_FILE, "session-token-1"); FileUtilities.writeToFile(Login.OPENBIS_SERVER_URL_FILE, "url"); - + OpenBISScreeningML.listExperiments(); OpenBISScreeningML.logout(); - + assertEquals(false, Login.OPENBIS_TOKEN_FILE.exists()); context.assertIsSatisfied(); } - + @Test public void testListExperiments() { @@ -241,12 +238,12 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase assertEquals(2, experiments.length); context.assertIsSatisfied(); } - + @Test public void testListPlates() { Object[][] plates = OpenBISScreeningML.listPlates(); - + sort(plates); assertEquals("/S/PLATE-1", plates[0][0]); assertEquals("s-1", plates[0][1]); @@ -269,7 +266,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase assertEquals(2, plates.length); context.assertIsSatisfied(); } - + @Test public void testListPlatesByExperiment() { @@ -281,9 +278,9 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase { assertEquals("No experiment with that code found.", ex.getMessage()); } - + Object[][] plates = OpenBISScreeningML.listPlates("/S/P/E1"); - + sort(plates); assertEquals("/S/PLATE-1", plates[0][0]); assertEquals("s-1", plates[0][1]); @@ -297,7 +294,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase assertEquals(1, plates.length); context.assertIsSatisfied(); } - + @Test public void testGetWellProperties() { @@ -310,7 +307,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase WellIdentifier w2 = new WellIdentifier(plate1, new WellPosition(1, 2), "w2"); WellIdentifier w3 = new WellIdentifier(plate1, new WellPosition(2, 1), "w3"); will(returnValue(Arrays.asList(w1, w2, w3))); - + one(openbis).getWellProperties(w2); Map<String, String> properties = new LinkedHashMap<String, String>(); properties.put("answer", "42"); @@ -318,9 +315,9 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase will(returnValue(properties)); } }); - + Object[][] wellProperties = OpenBISScreeningML.getWellProperties("/S/PLATE-1", 1, 2); - + assertEquals("answer", wellProperties[0][0]); assertEquals("42", wellProperties[0][1]); assertEquals("name", wellProperties[1][0]); @@ -328,7 +325,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase assertEquals(2, wellProperties.length); context.assertIsSatisfied(); } - + @Test public void testUpdateWellProperties() { @@ -348,38 +345,46 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase one(openbis).updateWellProperties(w2, properties); } }); - - OpenBISScreeningML.updateWellProperties("/S/PLATE-1", 1, 2, new Object[][] {{"A", "42"}, {"B", "43"}}); - + + OpenBISScreeningML.updateWellProperties("/S/PLATE-1", 1, 2, new Object[][] + { + { "A", "42" }, + { "B", "43" } }); + context.assertIsSatisfied(); } - + @Test public void testLoadDataSets() { - final File dataSetFolder = new File(OpenBISScreeningML.tempDir, OpenBISScreeningML.DATASETS_FOLDER); + final File dataSetFolder = + new File(OpenBISScreeningML.tempDir, OpenBISScreeningML.DATASETS_FOLDER); final File ds1Folder = new File(dataSetFolder, "ds-1"); File ds2Folder = new File(dataSetFolder, "ds-2"); ds2Folder.mkdirs(); + final String datasetTypePattern = "blablaCode"; + final String mountPoint = "/mount/openbis/store"; context.checking(new Expectations() { { - one(openbis).getDataSets(new Plate("PLATE-1", "S", "s-1", eId1)); + one(openbis).getDataSets(new Plate("PLATE-1", "S", "s-1", eId1), + datasetTypePattern); will(returnValue(Arrays.asList(ds1, ds2))); - + one(ds1).getCode(); will(returnValue("ds-1")); - - one(ds1).getLinkOrCopyOfContents(null, dataSetFolder); + + one(ds1).getLinkOrCopyOfContents(mountPoint, dataSetFolder); will(returnValue(ds1Folder)); - + one(ds2).getCode(); will(returnValue("ds-2")); } }); - - Object[][] result = OpenBISScreeningML.loadDataSets("/S/PLATE-1"); - + + Object[][] result = + OpenBISScreeningML.loadDataSets("/S/PLATE-1", datasetTypePattern, mountPoint); + assertEquals("ds-1", result[0][0]); assertEquals(ds1Folder.getPath(), result[0][1]); assertEquals("ds-2", result[1][0]); @@ -387,14 +392,16 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase assertEquals(2, result.length); context.assertIsSatisfied(); } - + @Test public void testUpdateDataSet() { - final File dataSetFolder = new File(OpenBISScreeningML.tempDir, OpenBISScreeningML.DATASETS_FOLDER); + final File dataSetFolder = + new File(OpenBISScreeningML.tempDir, OpenBISScreeningML.DATASETS_FOLDER); final File ds1Folder = new File(dataSetFolder, "ds-1"); ds1Folder.mkdirs(); - final RecordingMatcher<NewDataSetMetadataDTO> metaDataMatcher = new RecordingMatcher<NewDataSetMetadataDTO>(); + final RecordingMatcher<NewDataSetMetadataDTO> metaDataMatcher = + new RecordingMatcher<NewDataSetMetadataDTO>(); context.checking(new Expectations() { { @@ -410,29 +417,32 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase { throw CheckedExceptionTunnel.wrapIfNecessary(ex); } - + one(ds1).getCode(); will(returnValue("DS-1")); } }); - + Object code = OpenBISScreeningML.uploadDataSet("/S/PLATE-1", ds1Folder.getPath(), "my-type", - new Object[][] {{"A", "42"}, {"B", "43"}}); - + new Object[][] + { + { "A", "42" }, + { "B", "43" } }); + assertEquals("DS-1", code); assertEquals("my-type", metaDataMatcher.recordedObject().tryDataSetType()); assertEquals("{A=42, B=43}", metaDataMatcher.recordedObject().getProperties().toString()); context.assertIsSatisfied(); } - + @Test public void testLoadImages() { final RecordingMatcher<List<PlateImageReference>> imgRefsMatcher1 = new RecordingMatcher<List<PlateImageReference>>(); final RecordingMatcher<List<PlateImageReference>> imgRefsMatcher2 = - new RecordingMatcher<List<PlateImageReference>>(); + new RecordingMatcher<List<PlateImageReference>>(); final Sequence sequence = context.sequence("load"); context.checking(new Expectations() { @@ -531,8 +541,9 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase } } }); - - Object[][][] result1 = OpenBISScreeningML.loadImages("/S/PLATE-1", 1, 2, 1, new String[] {"G"}); + + Object[][][] result1 = OpenBISScreeningML.loadImages("/S/PLATE-1", 1, 2, 1, new String[] + { "G" }); List<PlateImageReference> imgRefs1 = imgRefsMatcher1.recordedObject(); for (PlateImageReference plateImageReference : imgRefs1) { @@ -552,7 +563,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase "[G, 1, PLATE-1:A2, /S/PLATE-1, s-1, S, PLATE-1, 1, 2, /S/P/E1, e-1, S, P, E1, ds1]", Arrays.asList(result1[1][0]).toString()); assertEquals(1, result1[1].length); - + Object[][][] result2 = OpenBISScreeningML.loadImages("/S/PLATE-1", 1, 2); List<PlateImageReference> imgRefs2 = imgRefsMatcher2.recordedObject(); for (PlateImageReference plateImageReference : imgRefs2) @@ -568,7 +579,7 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase assertEquals("G", imgRefs2.get(2).getChannel()); assertEquals(0, imgRefs2.get(2).getTile()); assertEquals(3, imgRefs2.size()); - + assertEquals(2, result2.length); assertEquals("/images/img_PLATE-1_ds1_row1_col2_R_tile0.tiff", getImagePath(result2, 0)); assertEquals("Image for [dataset ds1, well [1, 2], channel R, tile 0] (2)", FileUtilities @@ -601,19 +612,18 @@ public class OpenBISScreeningMLTest extends AbstractFileSystemTestCase private String getImagePath(Object[][][] result, int i) { - return result[0][i][0].toString() - .substring(tempDir.getPath().length()); + return result[0][i][0].toString().substring(tempDir.getPath().length()); } - + private void sort(Object[][] entities) { Arrays.sort(entities, new Comparator<Object[]>() - { - public int compare(Object[] o1, Object[] o2) { - return o1[0].toString().compareTo(o2[0].toString()); - } - }); + public int compare(Object[] o1, Object[] o2) + { + return o1[0].toString().compareTo(o2[0].toString()); + } + }); } } diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java index dfb6d44e181..614686926e0 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/client/api/v1/ScreeningOpenbisServiceFacadeTest.java @@ -81,6 +81,8 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto.WellPosition; @Friend(toClasses = DssServiceRpcScreeningHolder.class) public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCase { + private static final String MY_DATA_SET_TYPE = "my-data-set"; + private static final class MockPlateImageHandler implements IPlateImageHandler { private final StringBuilder recorder = new StringBuilder(); @@ -465,7 +467,7 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas context.assertIsSatisfied(); } - + @Test public void testGetWellProperties() { @@ -479,13 +481,13 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas will(returnValue(new Sample(initializer))); } }); - + Map<String, String> wellProperties = facade.getWellProperties(wellIdentifier); - + assertEquals("{a=alpha}", wellProperties.toString()); context.assertIsSatisfied(); } - + @Test public void testUpdateWellProperties() { @@ -496,16 +498,17 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas { one(screeningService).getWellSample(SESSION_TOKEN, wellIdentifier); will(returnValue(new Sample(sampleInitializer()))); - - one(generalInformationChangingService).updateSampleProperties(SESSION_TOKEN, 42L, properties); + + one(generalInformationChangingService).updateSampleProperties(SESSION_TOKEN, + 42L, properties); } }); facade.updateWellProperties(wellIdentifier, properties); - + context.assertIsSatisfied(); } - + @Test public void testGetDataSetsOfAWell() { @@ -516,23 +519,25 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas one(screeningService).getWellSample(SESSION_TOKEN, wellIdentifier); Sample sample = new Sample(sampleInitializer()); will(returnValue(sample)); - - one(generalInformationService).listDataSetsForSample(SESSION_TOKEN, sample, true); + + one(generalInformationService).listDataSetsForSample(SESSION_TOKEN, sample, + true); DataSetInitializer initializer1 = dataSetInitializer(DATA_SET1); will(returnValue(Arrays.asList(new DataSet(initializer1)))); - + one(dssComponent).getDataSet(DATA_SET1); will(returnValue(ds1Proxy)); } }); - - List<IDataSetDss> dataSets = facade.getDataSets(wellIdentifier); - + + List<IDataSetDss> dataSets = + facade.getDataSets(wellIdentifier, ".*" + MY_DATA_SET_TYPE + ".*"); + assertSame(ds1Proxy, dataSets.get(0)); assertEquals(1, dataSets.size()); context.assertIsSatisfied(); } - + @Test public void testGetDataSetsOfAPlate() { @@ -554,13 +559,13 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas } }); - List<IDataSetDss> dataSets = facade.getDataSets(plateIdentifier); - + List<IDataSetDss> dataSets = facade.getDataSets(plateIdentifier, MY_DATA_SET_TYPE); + assertSame(ds1Proxy, dataSets.get(0)); assertEquals(1, dataSets.size()); context.assertIsSatisfied(); } - + @Test public void testPutDataSetForWell() throws IOException { @@ -571,14 +576,15 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas File dir = new File(dataSetRoot, "dir"); dir.mkdir(); FileUtilities.writeToFile(new File(dir, "hello.txt"), "hello world"); - final RecordingMatcher<NewDataSetDTO> dataSetMatcher = new RecordingMatcher<NewDataSetDTO>(); + final RecordingMatcher<NewDataSetDTO> dataSetMatcher = + new RecordingMatcher<NewDataSetDTO>(); context.checking(new Expectations() { { one(screeningService).getWellSample(SESSION_TOKEN, wellIdentifier); Sample sample = new Sample(sampleInitializer()); will(returnValue(sample)); - + one(dssComponent).putDataSet(with(dataSetMatcher), with(dataSetRoot)); will(returnValue(ds1Proxy)); } @@ -588,14 +594,15 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas HashMap<String, String> props = new HashMap<String, String>(); props.put("a", "b"); metaData.setProperties(props); - + IDataSetDss dataSet = facade.putDataSet(wellIdentifier, dataSetRoot, metaData); assertSame(ds1Proxy, dataSet); assertEquals("MY-TYPE", dataSetMatcher.recordedObject().tryDataSetType()); assertEquals(NewDataSetDTO.DEFAULT_DATA_SET_FOLDER_NAME, dataSetMatcher.recordedObject() .getDataSetFolderName()); - assertEquals(DataSetOwnerType.SAMPLE, dataSetMatcher.recordedObject().getDataSetOwner().getType()); + assertEquals(DataSetOwnerType.SAMPLE, dataSetMatcher.recordedObject().getDataSetOwner() + .getType()); assertEquals("/S/abc", dataSetMatcher.recordedObject().getDataSetOwner().getIdentifier()); assertEquals("{a=b}", dataSetMatcher.recordedObject().getProperties().toString()); List<FileInfoDssDTO> fileInfos = dataSetMatcher.recordedObject().getFileInfos(); @@ -609,7 +616,6 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas context.assertIsSatisfied(); } - @Test public void testPutDataSetForPlate() throws IOException { @@ -620,31 +626,33 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas File dir = new File(dataSetRoot, "dir"); dir.mkdir(); FileUtilities.writeToFile(new File(dir, "hello.txt"), "hello world"); - final RecordingMatcher<NewDataSetDTO> dataSetMatcher = new RecordingMatcher<NewDataSetDTO>(); + final RecordingMatcher<NewDataSetDTO> dataSetMatcher = + new RecordingMatcher<NewDataSetDTO>(); context.checking(new Expectations() - { { - one(screeningService).getPlateSample(SESSION_TOKEN, plateIdentifier); - Sample sample = new Sample(sampleInitializer()); - will(returnValue(sample)); - - one(dssComponent).putDataSet(with(dataSetMatcher), with(dataSetRoot)); - will(returnValue(ds1Proxy)); - } - }); + { + one(screeningService).getPlateSample(SESSION_TOKEN, plateIdentifier); + Sample sample = new Sample(sampleInitializer()); + will(returnValue(sample)); + + one(dssComponent).putDataSet(with(dataSetMatcher), with(dataSetRoot)); + will(returnValue(ds1Proxy)); + } + }); NewDataSetMetadataDTO metaData = new NewDataSetMetadataDTO(); metaData.setDataSetTypeOrNull("my-type"); HashMap<String, String> props = new HashMap<String, String>(); props.put("a", "b"); metaData.setProperties(props); - + IDataSetDss dataSet = facade.putDataSet(plateIdentifier, dataSetRoot, metaData); - + assertSame(ds1Proxy, dataSet); assertEquals("MY-TYPE", dataSetMatcher.recordedObject().tryDataSetType()); assertEquals(NewDataSetDTO.DEFAULT_DATA_SET_FOLDER_NAME, dataSetMatcher.recordedObject() .getDataSetFolderName()); - assertEquals(DataSetOwnerType.SAMPLE, dataSetMatcher.recordedObject().getDataSetOwner().getType()); + assertEquals(DataSetOwnerType.SAMPLE, dataSetMatcher.recordedObject().getDataSetOwner() + .getType()); assertEquals("/S/abc", dataSetMatcher.recordedObject().getDataSetOwner().getIdentifier()); assertEquals("{a=b}", dataSetMatcher.recordedObject().getProperties().toString()); List<FileInfoDssDTO> fileInfos = dataSetMatcher.recordedObject().getFileInfos(); @@ -657,7 +665,7 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas assertEquals("[/dir, /dir/hello.txt, /readme]", paths.toString()); context.assertIsSatisfied(); } - + private SampleInitializer sampleInitializer() { SampleInitializer initializer = new SampleInitializer(); @@ -673,7 +681,7 @@ public class ScreeningOpenbisServiceFacadeTest extends AbstractFileSystemTestCas private DataSetInitializer dataSetInitializer(String code) { DataSetInitializer initializer = new DataSetInitializer(); - initializer.setDataSetTypeCode("my-data-set"); + initializer.setDataSetTypeCode(MY_DATA_SET_TYPE); initializer.setExperimentIdentifier("/S/P/E"); initializer.setCode(code); return initializer; -- GitLab