From 73a75eeb51fa60d55fe67dfc085d0fa927a6dc0c Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Thu, 11 Aug 2011 08:55:27 +0000 Subject: [PATCH] [LMS-2442] changed listing share ids for to list also trashed data sets SVN: 22473 --- .../openbis/generic/server/ETLService.java | 30 ++++++++----------- .../DatasetCodeWithShareIdRecord.java | 13 ++++++++ .../bo/datasetlister/DatasetLister.java | 18 +++++++++++ .../bo/datasetlister/IDatasetLister.java | 10 ++++++- .../datasetlister/IDatasetListingQuery.java | 6 ++++ .../generic/shared/IETLLIMSService.java | 2 +- .../generic/shared/dto/DataSetShareId.java | 10 +++++-- 7 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetCodeWithShareIdRecord.java diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java index 02eced725d8..36367ca9638 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/ETLService.java @@ -65,7 +65,6 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.SearchableEntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSet; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetArchivingStatus; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetTypeWithVocabularyTerms; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataStoreServiceKind; @@ -810,24 +809,13 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements return SampleTranslator.translate(sampleTable.getSamples(), ""); } - public List<DataSetShareId> listShareIds(String sessionToken, String dataStore) + public List<DataSetShareId> listShareIds(String sessionToken, String dataStoreCode) throws UserFailureException { - // FIXME trashed data sets are not listed - List<ExternalData> dataSets = loadDataSets(sessionToken, dataStore); - ArrayList<DataSetShareId> shareIds = new ArrayList<DataSetShareId>(); - for (ExternalData dataSet : dataSets) - { - DataSetShareId dataSetShareId = new DataSetShareId(); - dataSetShareId.setDataSetCode(dataSet.getCode()); - DataSet ds = dataSet.tryGetAsDataSet(); - if (ds != null) - { - dataSetShareId.setShareId(ds.getShareId()); - } - shareIds.add(dataSetShareId); - } - return shareIds; + Session session = getSession(sessionToken); + IDatasetLister datasetLister = businessObjectFactory.createDatasetLister(session); + DataStorePE dataStore = loadDataStore(session, dataStoreCode); + return datasetLister.listAllDataSetShareIdsByDataStore(dataStore.getId()); } public List<SimpleDataSetInformationDTO> listDataSets(String sessionToken, String dataStoreCode) @@ -872,14 +860,20 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements private List<ExternalData> loadDataSets(String sessionToken, String dataStoreCode) { Session session = getSession(sessionToken); + DataStorePE dataStore = loadDataStore(session, dataStoreCode); IDatasetLister datasetLister = businessObjectFactory.createDatasetLister(session); + return datasetLister.listByDataStore(dataStore.getId()); + } + + private DataStorePE loadDataStore(Session session, String dataStoreCode) + { DataStorePE dataStore = getDAOFactory().getDataStoreDAO().tryToFindDataStoreByCode(dataStoreCode); if (dataStore == null) { throw new UserFailureException(String.format("Unknown data store '%s'", dataStoreCode)); } - return datasetLister.listByDataStore(dataStore.getId()); + return dataStore; } public List<DeletedDataSet> listDeletedDataSets(String sessionToken, diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetCodeWithShareIdRecord.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetCodeWithShareIdRecord.java new file mode 100644 index 00000000000..46d384f486e --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetCodeWithShareIdRecord.java @@ -0,0 +1,13 @@ +package ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister; + +import ch.rinn.restrictions.Private; +import ch.systemsx.cisd.openbis.generic.server.business.bo.common.CodeRecord; + +/** + * A record object representing one row of the dataset table. + */ +@Private +public class DatasetCodeWithShareIdRecord extends CodeRecord +{ + public String share_id; // can be NULL in case of container(virtual) data sets +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetLister.java index 78643ef264e..d326d3d342f 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/DatasetLister.java @@ -71,6 +71,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.LocatorType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingDataSetCriteria; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetShareId; import ch.systemsx.cisd.openbis.generic.shared.translator.DataStoreTranslator; /** @@ -349,6 +350,22 @@ public class DatasetLister extends AbstractLister implements IDatasetLister return enrichDatasets(query.getDatasetsByDataStoreId(dataStoreID)); } + public List<DataSetShareId> listAllDataSetShareIdsByDataStore(long dataStoreID) + { + List<DataSetShareId> results = new ArrayList<DataSetShareId>(); + + DataIterator<DatasetCodeWithShareIdRecord> records = + query.getAllDatasetsWithShareIdsByDataStoreId(dataStoreID); + for (DatasetCodeWithShareIdRecord record : records) + { + DataSetShareId dataSetShareId = new DataSetShareId(); + dataSetShareId.setDataSetCode(record.code); + dataSetShareId.setShareId(record.share_id); + results.add(dataSetShareId); + } + return results; + } + public List<ExternalData> listByTrackingCriteria(TrackingDataSetCriteria criteria) { DataIterator<DatasetRecord> dataSets; @@ -816,4 +833,5 @@ public class DatasetLister extends AbstractLister implements IDatasetLister return result; } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetLister.java index aa833813abd..59351c943fd 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetLister.java @@ -27,6 +27,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ArchiverDataSetCriteria import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingDataSetCriteria; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetShareId; /** * A class for fast dataset listing. @@ -79,10 +80,16 @@ public interface IDatasetLister List<ExternalData> listByDatasetCode(Collection<String> datasetCodes); /** - * Lists all data sets of specified data store. Unenriched data sets will be returned. + * Lists all data sets of specified data store. Unenriched data sets will be returned (FIXME - + * the last sentence is not true). */ List<ExternalData> listByDataStore(long dataStoreID); + /** + * Lists {@link DataSetShareId}s of all data sets (even those in trash) in specified data store. + */ + List<DataSetShareId> listAllDataSetShareIdsByDataStore(long dataStoreID); + /** @return datasets with given ids */ List<ExternalData> listByDatasetIds(Collection<Long> datasetIds); @@ -101,4 +108,5 @@ public interface IDatasetLister * @return properties of given type for given dataset ids */ Map<Long, GenericEntityPropertyRecord> fetchProperties(List<Long> ids, String propertyTypeCode); + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java index ee65ebfd815..1561631f7d3 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/datasetlister/IDatasetListingQuery.java @@ -199,6 +199,12 @@ public interface IDatasetListingQuery extends TransactionQuery, IPropertyListing @Select(sql = SELECT_ALL + " where data.dast_id = ?{1}", fetchSize = FETCH_SIZE) public DataIterator<DatasetRecord> getDatasetsByDataStoreId(long dataStoreId); + // NOTE: we list ALL data sets (even those in trash) using data_all table here + @Select(sql = "SELECT code, share_id FROM data_all LEFT OUTER JOIN external_data " + + "ON data_all.id = external_data.data_id WHERE data_all.dast_id = ?{1}", fetchSize = FETCH_SIZE) + public DataIterator<DatasetCodeWithShareIdRecord> getAllDatasetsWithShareIdsByDataStoreId( + long dataStoreId); + /** * Returns the children dataset ids of the specified datasets. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IETLLIMSService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IETLLIMSService.java index 1624225b8ea..4f9a81821a8 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IETLLIMSService.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/IETLLIMSService.java @@ -422,7 +422,7 @@ public interface IETLLIMSService extends IServer, ISessionProvider throws UserFailureException; /** - * Lists share ids of all data sets belonging to chosen data store. + * Lists share ids of all data sets belonging to chosen data store (even the ones in trash!). // TODO */ @Transactional(readOnly = true) @RolesAllowed(RoleWithHierarchy.SPACE_ETL_SERVER) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetShareId.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetShareId.java index f6b6a662f9d..b616df6fdaf 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetShareId.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/DataSetShareId.java @@ -22,13 +22,13 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ServiceVersionHolder; /** * Share id of a data set. - * + * * @author Franz-Josef Elmer */ public class DataSetShareId implements Serializable { private static final long serialVersionUID = ServiceVersionHolder.VERSION; - + private String dataSetCode; private String shareId; @@ -53,4 +53,10 @@ public class DataSetShareId implements Serializable this.shareId = dataSetShareId; } + @Override + public String toString() + { + return "DataSetShareId [dataSetCode=" + dataSetCode + ", shareId=" + shareId + "]"; + } + } -- GitLab