From 3057720a8364c3490a133e15890a3da4f4a1e8a1 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Thu, 4 Oct 2012 19:54:48 +0000 Subject: [PATCH] Rename DataStoreForDataSets to DataStoreURLforDataSets. Add method IDataSetLister.getDataStoreRemoteURLs(). SVN: 27000 --- .../api/v1/GeneralInformationService.java | 12 ++-- .../v1/GeneralInformationServiceLogger.java | 4 +- .../datasetlister/DataSetDownloadRecord.java | 4 +- .../datasetlister/DataSetLister.java | 33 ++++++++--- .../datasetlister/IDataSetLister.java | 16 ++++-- .../datasetlister/IDataSetListingQuery.java | 12 +++- .../datasetlister/DataSetListerTest.java | 56 +++++++++++++++---- .../api/v1/IGeneralInformationService.java | 4 +- ...Sets.java => DataStoreURLForDataSets.java} | 20 +++---- 9 files changed, 113 insertions(+), 48 deletions(-) rename openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/{DataStoreForDataSets.java => DataStoreURLForDataSets.java} (67%) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java index cbb24e6421d..7fc1af56e8e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java @@ -73,7 +73,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.Connections; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOption; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOptions; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; -import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreForDataSets; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreURLForDataSets; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Material; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MaterialIdentifier; @@ -588,26 +588,26 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio checkSession(sessionToken); final IDataSetLister lister = new DataSetLister(getDAOFactory()); - final List<DataStoreForDataSets> dataStores = - lister.getDataStoreBaseURLs(Collections.singletonList(dataSetCode)); + final List<DataStoreURLForDataSets> dataStores = + lister.getDataStoreDownloadURLs(Collections.singletonList(dataSetCode)); if (dataStores.isEmpty()) { return null; } - return dataStores.get(0).getDataStoreDownloadURL(); + return dataStores.get(0).getDataStoreURL(); } @Override @Transactional(readOnly = true) @RolesAllowed(value = { RoleWithHierarchy.SPACE_OBSERVER, RoleWithHierarchy.SPACE_ETL_SERVER }) - public List<DataStoreForDataSets> getDataStoreBaseURLs(String sessionToken, + public List<DataStoreURLForDataSets> getDataStoreBaseURLs(String sessionToken, List<String> dataSetCodes) { checkSession(sessionToken); final IDataSetLister lister = new DataSetLister(getDAOFactory()); - return lister.getDataStoreBaseURLs(dataSetCodes); + return lister.getDataStoreDownloadURLs(dataSetCodes); } @Override diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java index 575c3279981..ad517432705 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceLogger.java @@ -31,7 +31,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.Connections; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOption; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; -import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreForDataSets; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreURLForDataSets; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Material; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MaterialIdentifier; @@ -205,7 +205,7 @@ class GeneralInformationServiceLogger extends AbstractServerLogger implements } @Override - public List<DataStoreForDataSets> getDataStoreBaseURLs(String sessionToken, + public List<DataStoreURLForDataSets> getDataStoreBaseURLs(String sessionToken, List<String> dataSetCodes) { logAccess(sessionToken, "get-data-store-base-urls", "DATA_SETS(%s)", diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetDownloadRecord.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetDownloadRecord.java index ec71b786a1b..2014d64712d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetDownloadRecord.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetDownloadRecord.java @@ -17,7 +17,7 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.datasetlister; /** - * Type for storing the download ULR for a set of data sets; + * Type for storing the download and remote ULR for a set of data sets; * * @author Bernd Rinn */ @@ -25,5 +25,7 @@ class DataSetDownloadRecord { String download_url; + String remote_url; + String data_set_codes; } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java index 523c1aa289d..b8c778d2ce2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java @@ -29,12 +29,12 @@ import org.apache.commons.lang.StringUtils; import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.DatabaseContextUtils; -import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.IAuthorizationDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.DataSetInitializer; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOption; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOptions; -import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreForDataSets; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreURLForDataSets; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityRegistrationDetails; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityRegistrationDetails.EntityRegistrationDetailsInitializer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetKind; @@ -55,7 +55,7 @@ public class DataSetLister implements IDataSetLister private IDataSetListingQuery query; - public DataSetLister(IDAOFactory daoFactory) + public DataSetLister(IAuthorizationDAOFactory daoFactory) { this(QueryTool.getQuery(DatabaseContextUtils.getConnection(daoFactory), IDataSetListingQuery.class)); @@ -316,18 +316,35 @@ public class DataSetLister implements IDataSetLister } @Override - public List<DataStoreForDataSets> getDataStoreBaseURLs(List<String> dataSetCodes) + public List<DataStoreURLForDataSets> getDataStoreDownloadURLs(List<String> dataSetCodes) { final String[] dataSetCodesArray = dataSetCodes.toArray(new String[dataSetCodes.size()]); - final List<DataSetDownloadRecord> records = query.getDownloadInfos(dataSetCodesArray); - final List<DataStoreForDataSets> result = - new ArrayList<DataStoreForDataSets>(records.size()); + final List<DataSetDownloadRecord> records = query.getDownloadURLs(dataSetCodesArray); + final List<DataStoreURLForDataSets> result = + new ArrayList<DataStoreURLForDataSets>(records.size()); for (DataSetDownloadRecord r : records) { final String[] dataSetCodeArray = StringUtils.split(r.data_set_codes.substring(1, r.data_set_codes.length() - 1), ','); - result.add(new DataStoreForDataSets(r.download_url, dataSetCodeArray)); + result.add(new DataStoreURLForDataSets(r.download_url, dataSetCodeArray)); + } + return result; + } + + @Override + public List<DataStoreURLForDataSets> getDataStoreRemoteURLs(List<String> dataSetCodes) + { + final String[] dataSetCodesArray = dataSetCodes.toArray(new String[dataSetCodes.size()]); + final List<DataSetDownloadRecord> records = query.getRemoteURLs(dataSetCodesArray); + final List<DataStoreURLForDataSets> result = + new ArrayList<DataStoreURLForDataSets>(records.size()); + for (DataSetDownloadRecord r : records) + { + final String[] dataSetCodeArray = + StringUtils.split(r.data_set_codes.substring(1, r.data_set_codes.length() - 1), + ','); + result.add(new DataStoreURLForDataSets(r.remote_url, dataSetCodeArray)); } return result; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetLister.java index d24f99e3ff0..9857dd37a77 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetLister.java @@ -20,7 +20,7 @@ import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOptions; -import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreForDataSets; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreURLForDataSets; /** * @author pkupczyk @@ -38,10 +38,18 @@ public interface IDataSetLister DataSetFetchOptions dataSetFetchOptions); /** - * Returns the base URLs (download URLs) for a set of <var>dataSetCodes</var>. + * Returns the download URLs for a set of <var>dataSetCodes</var>. * - * @return The list of data stores, each with the list of data set codes it has stored. + * @return The list of data store download URLs, each with the list of data set codes it has + * stored. */ - public List<DataStoreForDataSets> getDataStoreBaseURLs(List<String> dataSetCodes); + public List<DataStoreURLForDataSets> getDataStoreDownloadURLs(List<String> dataSetCodes); + /** + * Returns the remote URLs for a set of <var>dataSetCodes</var>. + * + * @return The list of data store remote URLs, each with the list of data set codes it has + * stored. + */ + public List<DataStoreURLForDataSets> getDataStoreRemoteURLs(List<String> dataSetCodes); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetListingQuery.java index fae3a6d9d92..a83a31a6c2e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetListingQuery.java @@ -70,9 +70,15 @@ public interface IDataSetListingQuery extends BaseQuery public List<DataSetRelationRecord> getDataSetChildrenCodes(String[] dataSetCodes); @Select(sql = " select ds.download_url, array_agg(d.code::text) as data_set_codes" - + " from data d left join data_stores ds on ds.id=d.dast_id" - + " where d.code = any(?{1}) group by download_url", parameterBindings = + + " from data d left join data_stores ds on ds.id = d.dast_id" + + " where d.code = any(?{1}) group by ds.download_url", parameterBindings = { StringArrayMapper.class }) - public List<DataSetDownloadRecord> getDownloadInfos(String[] dataSetCodes); + public List<DataSetDownloadRecord> getDownloadURLs(String[] dataSetCodes); + + @Select(sql = " select ds.remote_url, array_agg(d.code::text) as data_set_codes" + + " from data d left join data_stores ds on ds.id = d.dast_id" + + " where d.code = any(?{1}) group by ds.remote_url", parameterBindings = + { StringArrayMapper.class }) + public List<DataSetDownloadRecord> getRemoteURLs(String[] dataSetCodes); } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetListerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetListerTest.java index cd969721383..d8f126d2483 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetListerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetListerTest.java @@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertTrue; +import static junit.framework.Assert.fail; import java.sql.SQLException; import java.util.ArrayList; @@ -47,7 +48,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOption; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOptions; -import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreForDataSets; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreURLForDataSets; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityRegistrationDetails; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalDataManagementSystem; @@ -115,17 +116,18 @@ public class DataSetListerTest extends AbstractDAOTest } @Test - public void testGetDataStoreBaseURLs() + public void testGetDataStoreURLs() { DatabaseConfigurationContext context = DatabaseContextUtils.getDatabaseContext(daoFactory); QueryTool .update(context.getDataSource(), - "update data_stores set download_url='http://download_1' where code='STANDARD'"); + "update data_stores set download_url='http://download_1',remote_url='http://remote_1'" + + " where code='STANDARD'"); final long newDataStoreId = (Long) QueryTool .select(context.getDataSource(), "insert into data_stores (id,dbin_id,code,download_url,remote_url,session_token)" - + " values (nextval('data_store_id_seq'),1,'DSS2','http://download_2','','') returning id") + + " values (nextval('data_store_id_seq'),1,'DSS2','http://download_2','http://remote_2','') returning id") .get(0).get("id"); QueryTool.update(context.getDataSource(), "update data set dast_id = ?{1} where code = ?{2}", newDataStoreId, @@ -140,15 +142,45 @@ public class DataSetListerTest extends AbstractDAOTest codes.add("20081105092259000-19"); codes.add("20081105092259000-20"); codes.add("20081105092259000-21"); - List<DataStoreForDataSets> result = lister.getDataStoreBaseURLs(codes); + List<DataStoreURLForDataSets> result = lister.getDataStoreDownloadURLs(codes); assertEquals(2, result.size()); - assertEquals("http://download_1", result.get(0).getDataStoreDownloadURL()); - assertEquals( - Arrays.asList("20081105092159188-3", "20081105092159111-1", "20081105092259000-19"), - result.get(0).getDataSetCodes()); - assertEquals("http://download_2", result.get(1).getDataStoreDownloadURL()); - assertEquals(Arrays.asList("20081105092259000-20", "20081105092259000-21"), result.get(1) - .getDataSetCodes()); + for (DataStoreURLForDataSets url : result) + { + if (url.getDataStoreURL().equals("http://download_1")) + { + assertEquals( + Arrays.asList("20081105092159188-3", "20081105092159111-1", + "20081105092259000-19"), + url.getDataSetCodes()); + } else if (url.getDataStoreURL().equals("http://download_2")) + { + assertEquals(Arrays.asList("20081105092259000-20", "20081105092259000-21"), url + .getDataSetCodes()); + } else + { + fail("URL " + url + " not expected."); + } + } + + result = lister.getDataStoreRemoteURLs(codes); + assertEquals(2, result.size()); + for (DataStoreURLForDataSets url : result) + { + if (url.getDataStoreURL().equals("http://remote_1")) + { + assertEquals( + Arrays.asList("20081105092159188-3", "20081105092159111-1", + "20081105092259000-19"), + url.getDataSetCodes()); + } else if (url.getDataStoreURL().equals("http://remote_2")) + { + assertEquals(Arrays.asList("20081105092259000-20", "20081105092259000-21"), url + .getDataSetCodes()); + } else + { + fail("URL " + url + " not expected."); + } + } } @Test diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java index 53f6c4db500..721500012e0 100644 --- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/IGeneralInformationService.java @@ -28,7 +28,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSet.Connections; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetFetchOption; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; -import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreForDataSets; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataStoreURLForDataSets; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Material; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.MaterialIdentifier; @@ -296,7 +296,7 @@ public interface IGeneralInformationService extends IRpcService * together with the data set codes that are in this data store. * @since 1.19 */ - public List<DataStoreForDataSets> getDataStoreBaseURLs(String sessionToken, + public List<DataStoreURLForDataSets> getDataStoreBaseURLs(String sessionToken, List<String> dataSetCodes); /** diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataStoreForDataSets.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataStoreURLForDataSets.java similarity index 67% rename from openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataStoreForDataSets.java rename to openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataStoreURLForDataSets.java index bc1c4a2df70..9d79a1645cb 100644 --- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataStoreForDataSets.java +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataStoreURLForDataSets.java @@ -23,36 +23,36 @@ import java.util.List; import ch.systemsx.cisd.base.annotation.JsonObject; /** - * The data store URL for a list of data sets. + * The data store URL for a set of data sets. * * @since 1.19 * @author Bernd Rinn */ -@JsonObject("DataStoreForDataSets") -public class DataStoreForDataSets implements Serializable +@JsonObject("DataStoreURLForDataSets") +public class DataStoreURLForDataSets implements Serializable { private static final long serialVersionUID = 1L; - private final String dataStoreDownloadURL; + private final String dataStoreURL; private final String[] dataSetCodes; - public DataStoreForDataSets(String dataStoreBaseURL, String[] dataSetCodes) + public DataStoreURLForDataSets(String dataStoreBaseURL, String[] dataSetCodes) { - this.dataStoreDownloadURL = dataStoreBaseURL; + this.dataStoreURL = dataStoreBaseURL; this.dataSetCodes = dataSetCodes; } /** - * The base URL of the data store (can be used for download from a client). + * The base URL of the data store. */ - public String getDataStoreDownloadURL() + public String getDataStoreURL() { - return dataStoreDownloadURL; + return dataStoreURL; } /** - * The list of data sets that can be found in this data store. + * A set of data sets that can be found in this data store. */ public List<String> getDataSetCodes() { -- GitLab