diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpPathResolverContext.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpPathResolverContext.java index 292b8ea7715169fab06cc91ae7569bf876c553b7..20cb0b0899f71900d0ce498dd28cfb1e34cb5aeb 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpPathResolverContext.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ftp/FtpPathResolverContext.java @@ -24,6 +24,8 @@ import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; 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.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExperimentFetchOptions; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; @@ -43,12 +45,13 @@ public class FtpPathResolverContext private final IETLLIMSService service; private final IGeneralInformationService generalInfoService; - + private final IFtpPathResolverRegistry resolverRegistry; private final Cache cache; - public FtpPathResolverContext(String sessionToken, IETLLIMSService service, IGeneralInformationService generalInfoService, + public FtpPathResolverContext(String sessionToken, IETLLIMSService service, + IGeneralInformationService generalInfoService, IFtpPathResolverRegistry resolverRegistry, Cache cache) { this.sessionToken = sessionToken; @@ -67,21 +70,26 @@ public class FtpPathResolverContext { return service; } - + public DataSet getDataSet(String dataSetCode) { DataSet dataSet = cache.getDataSet(dataSetCode); if (dataSet == null) { + DataSetFetchOptions fetchOptions = + new DataSetFetchOptions(DataSetFetchOption.BASIC, DataSetFetchOption.PARENTS, + DataSetFetchOption.CHILDREN); + List<DataSet> dataSetsWithMetaData = - generalInfoService.getDataSetMetaData(sessionToken, - Arrays.asList(dataSetCode)); + generalInfoService.getDataSetMetaData(sessionToken, Arrays.asList(dataSetCode), + fetchOptions); + dataSet = dataSetsWithMetaData.get(0); cache.putDataSet(dataSet); } return dataSet; } - + public List<ExternalData> listDataSetsByCode(List<String> codes) { List<String> codesToAskFor = new ArrayList<String>(); @@ -99,7 +107,8 @@ public class FtpPathResolverContext } if (codesToAskFor.isEmpty() == false) { - List<ExternalData> newDataSets = service.listDataSetsByCode(sessionToken, codesToAskFor); + List<ExternalData> newDataSets = + service.listDataSetsByCode(sessionToken, codesToAskFor); for (ExternalData newDataSet : newDataSets) { cache.putDataSet(newDataSet); @@ -108,7 +117,7 @@ public class FtpPathResolverContext } return dataSets; } - + public Experiment getExperiment(String experimentId) { Experiment experiment = cache.getExperiment(experimentId); @@ -116,7 +125,7 @@ public class FtpPathResolverContext { ExperimentIdentifier experimentIdentifier = new ExperimentIdentifierFactory(experimentId).createIdentifier(); - + List<Experiment> result = service.listExperiments(sessionToken, Collections.singletonList(experimentIdentifier), @@ -131,7 +140,7 @@ public class FtpPathResolverContext { return generalInfoService; } - + public IFtpPathResolverRegistry getResolverRegistry() { return resolverRegistry; 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 eac128965081bb3990adfbf1d745c201ced8a9ea..c9be5c259cfdb231e11ee75ada791efffe0f8c9e 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 @@ -50,7 +50,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.IRoleAssignmentTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleBO; import ch.systemsx.cisd.openbis.generic.server.business.bo.ISampleTable; import ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister.IDatasetLister; -import ch.systemsx.cisd.openbis.generic.server.business.bo.experimentlister.ExperimentLister; +import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.experimentlister.ExperimentLister; import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister; import ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.ISampleLister; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; @@ -392,10 +392,11 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements throw new IllegalArgumentException("ExperimentFetchOptions were null"); } - if (experimentFetchOptions.containsOnlyOption(ExperimentFetchOption.BASIC)) + if (experimentFetchOptions.isSubsetOf(ExperimentFetchOption.BASIC)) { ExperimentLister lister = - new ExperimentLister(daoFactory, getSession(sessionToken).getBaseIndexURL()); + new ExperimentLister(getDAOFactory(), getSession(sessionToken) + .getBaseIndexURL()); return lister.listExperiments(experimentIdentifiers, experimentFetchOptions); } else { @@ -431,7 +432,7 @@ public class ETLService extends AbstractCommonServer<IETLLIMSService> implements throw new IllegalArgumentException("ExperimentFetchOptions were null"); } - if (experimentFetchOptions.containsOnlyOption(ExperimentFetchOption.BASIC)) + if (experimentFetchOptions.isSubsetOf(ExperimentFetchOption.BASIC)) { ExperimentLister lister = new ExperimentLister(daoFactory, getSession(sessionToken).getBaseIndexURL()); 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 06210c711e93cb6504faa3f5007c601496f3c270..990b4ebd387e42e48d9548d4baac58b43133424a 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 @@ -36,6 +36,8 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; import ch.systemsx.cisd.openbis.generic.server.AbstractServer; import ch.systemsx.cisd.openbis.generic.server.business.IPropertiesBatchManager; +import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.datasetlister.DataSetLister; +import ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.datasetlister.IDataSetLister; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDataDAO; import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDatabaseInstanceDAO; @@ -45,6 +47,8 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.Translator; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ControlledVocabularyPropertyType; 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.DataSetFetchOptions; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project; @@ -189,7 +193,7 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio public int getMinorVersion() { - return 15; + return 16; } private Map<String, List<RoleAssignmentPE>> getRoleAssignmentsPerSpace() @@ -563,6 +567,49 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio return result; } + @Transactional(readOnly = true) + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) + @ReturnValueFilter(validatorClass = DataSetByExperimentIdentifierValidator.class) + @Capability("GET_DATA_SET_META_DATA") + public List<DataSet> getDataSetMetaData(String sessionToken, List<String> dataSetCodes, + DataSetFetchOptions dataSetFetchOptions) + { + if (sessionToken == null) + { + throw new IllegalArgumentException("SessionToken was null"); + } + if (dataSetCodes == null) + { + throw new IllegalArgumentException("DataSetCodes were null"); + } + if (dataSetFetchOptions == null) + { + throw new IllegalArgumentException("DataSetFetchOptions were null"); + } + + if (dataSetFetchOptions.isSubsetOf(DataSetFetchOption.BASIC, DataSetFetchOption.PARENTS, + DataSetFetchOption.CHILDREN)) + { + checkSession(sessionToken); + IDataSetLister lister = new DataSetLister(getDAOFactory()); + return lister.getDataSetMetaData(dataSetCodes, dataSetFetchOptions); + } else + { + List<DataSet> dataSetList = getDataSetMetaData(sessionToken, dataSetCodes); + if (dataSetList != null) + { + for (DataSet dataSet : dataSetList) + { + if (dataSet != null) + { + dataSet.setFetchOptions(new DataSetFetchOptions(DataSetFetchOption.values())); + } + } + } + return dataSetList; + } + } + @Transactional(readOnly = true) @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) @ReturnValueFilter(validatorClass = DataSetByExperimentIdentifierValidator.class) 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 e76544b02fbcf4e8e3c22347b6f1e22776652744..ad72b6754c02d81316cd8880fb3efcd2e033726f 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 @@ -29,6 +29,7 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ControlledVocabularyPropertyType.VocabularyTerm; 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.DataSetFetchOptions; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project; @@ -171,6 +172,15 @@ class GeneralInformationServiceLogger extends AbstractServerLogger implements return null; } + public List<DataSet> getDataSetMetaData(String sessionToken, List<String> dataSetCodes, + DataSetFetchOptions dataSetFetchOptions) + { + logAccess(sessionToken, "get-data-set-meta-data", + "DATA_SETS(%s), DATA_SETS_FETCH_OPTIONS(%s)", abbreviate(dataSetCodes), + dataSetFetchOptions); + return null; + } + public List<DataSet> searchForDataSets(String sessionToken, SearchCriteria searchCriteria) { logAccess(sessionToken, "search-for-data-sets", "SEARCH_CRITERIA(%s)", searchCriteria); 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 new file mode 100644 index 0000000000000000000000000000000000000000..136a17701f5b7fc728e895e7681eba2234aa29b8 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetLister.java @@ -0,0 +1,275 @@ +/* + * Copyright 2012 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.generic.server.business.bo.fetchoptions.datasetlister; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import net.lemnik.eodsql.QueryTool; + +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.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.EntityRegistrationDetails; +import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.EntityRegistrationDetails.EntityRegistrationDetailsInitializer; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ExperimentIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; +import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; + +/** + * @author pkupczyk + */ +public class DataSetLister implements IDataSetLister +{ + + private IDataSetListingQuery query; + + public DataSetLister(IDAOFactory daoFactory) + { + this(QueryTool.getQuery(DatabaseContextUtils.getConnection(daoFactory), + IDataSetListingQuery.class)); + } + + public DataSetLister(IDataSetListingQuery query) + { + if (query == null) + { + throw new IllegalArgumentException("Query was null"); + } + this.query = query; + } + + public List<DataSet> getDataSetMetaData(List<String> dataSetCodes, + DataSetFetchOptions dataSetFetchOptions) + { + if (dataSetCodes == null) + { + throw new IllegalArgumentException("DataSetCodes were null"); + } + if (dataSetFetchOptions == null) + { + throw new IllegalArgumentException("DataSetFetchOptions were null"); + } + if (!dataSetFetchOptions.isSubsetOf(DataSetFetchOption.BASIC, DataSetFetchOption.PARENTS, + DataSetFetchOption.CHILDREN)) + { + throw new IllegalArgumentException("Currently only " + DataSetFetchOption.BASIC + "," + + DataSetFetchOption.PARENTS + " and " + DataSetFetchOption.CHILDREN + + " fetch options are supported by this method"); + } + + String[] dataSetCodesArray = dataSetCodes.toArray(new String[dataSetCodes.size()]); + List<DataSetRecord> dataSetRecords = query.getDataSetMetaData(dataSetCodesArray); + + // create data set initializers + List<DataSetInitializer> dataSetInitializers = + createDataSetInitializers(dataSetRecords, dataSetCodesArray); + + // fill in parents + if (dataSetFetchOptions.isSupersetOf(DataSetFetchOption.PARENTS)) + { + enrichDataSetInitializersWithParents(dataSetInitializers, dataSetCodesArray); + } + + // fill in children + if (dataSetFetchOptions.isSupersetOf(DataSetFetchOption.CHILDREN)) + { + enrichDataSetInitializersWithChildren(dataSetInitializers, dataSetCodesArray); + } + + // create data sets + return createDataSets(dataSetInitializers, dataSetFetchOptions); + } + + private List<DataSet> createDataSets(List<DataSetInitializer> dataSetInitializers, + DataSetFetchOptions dataSetFetchOptions) + { + List<DataSet> dataSets = new ArrayList<DataSet>(dataSetInitializers.size()); + for (DataSetInitializer dataSetInitializer : dataSetInitializers) + { + DataSet dataSet = new DataSet(dataSetInitializer); + dataSet.setFetchOptions(dataSetFetchOptions); + dataSets.add(dataSet); + } + return dataSets; + } + + private List<DataSetInitializer> createDataSetInitializers(List<DataSetRecord> dataSetRecords, + String[] dataSetCodes) + { + if (dataSetRecords != null) + { + // put results in code to initializer map + Map<String, DataSetInitializer> dataSetMap = new HashMap<String, DataSetInitializer>(); + for (DataSetRecord dataSetRecord : dataSetRecords) + { + DataSetInitializer dataSet = createDataSetInitializer(dataSetRecord); + dataSetMap.put(dataSet.getCode(), dataSet); + } + + // put results in the same order as the list of data set codes + List<DataSetInitializer> dataSetList = + new ArrayList<DataSetInitializer>(dataSetMap.size()); + for (String dataSetCode : dataSetCodes) + { + DataSetInitializer dataSet = dataSetMap.get(dataSetCode); + if (dataSet == null) + { + throw new UserFailureException("Unknown data set " + dataSetCode); + } else + { + dataSetList.add(dataSet); + } + } + return dataSetList; + + } else + { + return Collections.emptyList(); + } + } + + private DataSetInitializer createDataSetInitializer(DataSetRecord dataSet) + { + DatabaseInstanceIdentifier experimentDatabaseIdentifier = + new DatabaseInstanceIdentifier(dataSet.die_is_original_source, dataSet.die_code); + + ExperimentIdentifier experimentIdentifier = + new ExperimentIdentifier(experimentDatabaseIdentifier.getDatabaseInstanceCode(), + dataSet.spe_code, dataSet.pre_code, dataSet.ex_code); + + DataSetInitializer initializer = new DataSetInitializer(); + initializer.setCode(dataSet.ds_code); + initializer.setDataSetTypeCode(dataSet.dt_code); + initializer.setContainerDataSet(dataSet.dt_is_container); + initializer.setRegistrationDetails(createDataSetRegistrationDetails(dataSet)); + initializer.setExperimentIdentifier(experimentIdentifier.toString()); + + if (dataSet.sa_code != null) + { + DatabaseInstanceIdentifier sampleDatabaseIdentifier = null; + if (dataSet.sa_dbin_id != null) + { + // we can reuse the database identifier because + // all related objects should belong to the same database + sampleDatabaseIdentifier = experimentDatabaseIdentifier; + } + + SpaceIdentifier sampleSpaceIdentifier = null; + if (dataSet.sps_code != null) + { + // we can reuse the database identifier because + // all related objects should belong to the same database + sampleSpaceIdentifier = + new SpaceIdentifier(experimentDatabaseIdentifier.getDatabaseInstanceCode(), + dataSet.sps_code); + } + + SampleIdentifier sampleIdentifier = + IdentifierHelper.createSampleIdentifier(sampleDatabaseIdentifier, + sampleSpaceIdentifier, dataSet.sa_code, dataSet.sac_code); + + initializer.setSampleIdentifierOrNull(sampleIdentifier.toString()); + } + + return initializer; + } + + private EntityRegistrationDetails createDataSetRegistrationDetails(DataSetRecord dataSet) + { + EntityRegistrationDetailsInitializer initializer = + new EntityRegistrationDetailsInitializer(); + initializer.setUserId(dataSet.pe_user_id); + initializer.setFirstName(dataSet.pe_first_name); + initializer.setLastName(dataSet.pe_last_name); + initializer.setEmail(dataSet.pe_email); + initializer.setRegistrationDate(dataSet.ds_registration_timestamp); + return new EntityRegistrationDetails(initializer); + } + + private void enrichDataSetInitializersWithParents(List<DataSetInitializer> dataSetInitializers, + String[] dataSetCodes) + { + List<DataSetRelationRecord> dataSetRelations = query.getDataSetParentsCodes(dataSetCodes); + + if (dataSetRelations != null && !dataSetRelations.isEmpty()) + { + Map<String, List<String>> childCodeToParentCodesMap = + new HashMap<String, List<String>>(); + + for (DataSetRelationRecord dataSetRelation : dataSetRelations) + { + List<String> parentCodes = childCodeToParentCodesMap.get(dataSetRelation.dc_code); + if (parentCodes == null) + { + parentCodes = new LinkedList<String>(); + childCodeToParentCodesMap.put(dataSetRelation.dc_code, parentCodes); + } + parentCodes.add(dataSetRelation.dp_code); + } + + for (DataSetInitializer dataSetInitializer : dataSetInitializers) + { + List<String> parentCodes = + childCodeToParentCodesMap.get(dataSetInitializer.getCode()); + dataSetInitializer.setParentCodes(parentCodes); + } + } + } + + private void enrichDataSetInitializersWithChildren( + List<DataSetInitializer> dataSetInitializers, String[] dataSetCodes) + { + List<DataSetRelationRecord> dataSetRelations = query.getDataSetChildrenCodes(dataSetCodes); + + if (dataSetRelations != null && !dataSetRelations.isEmpty()) + { + Map<String, List<String>> parentCodeToChildrenCodesMap = + new HashMap<String, List<String>>(); + + for (DataSetRelationRecord dataSetRelation : dataSetRelations) + { + List<String> childrenCodes = + parentCodeToChildrenCodesMap.get(dataSetRelation.dp_code); + if (childrenCodes == null) + { + childrenCodes = new LinkedList<String>(); + parentCodeToChildrenCodesMap.put(dataSetRelation.dp_code, childrenCodes); + } + childrenCodes.add(dataSetRelation.dc_code); + } + + for (DataSetInitializer dataSetInitializer : dataSetInitializers) + { + List<String> childrenCodes = + parentCodeToChildrenCodesMap.get(dataSetInitializer.getCode()); + dataSetInitializer.setChildrenCodes(childrenCodes); + } + } + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetRecord.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..c6170d7eca601793d20095ad3ebd6f3f18e694cb --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetRecord.java @@ -0,0 +1,63 @@ +/* + * Copyright 2012 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.generic.server.business.bo.fetchoptions.datasetlister; + +import java.util.Date; + +/** + * @author pkupczyk + */ +public class DataSetRecord +{ + + public Long ds_id; + + public String ds_code; + + public Date ds_registration_timestamp; + + public String dt_code; + + public Boolean dt_is_container; + + public String ex_code; + + public String sa_code; + + public String sa_dbin_id; + + public String sac_code; + + public String pe_first_name; + + public String pe_last_name; + + public String pe_email; + + public String pe_user_id; + + public String pre_code; + + public String spe_code; + + public String sps_code; + + public String die_code; + + public Boolean die_is_original_source; + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetRelationRecord.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetRelationRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..e0038e20fa7563db580ac1ce10fba5ab3a921c98 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetRelationRecord.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012 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.generic.server.business.bo.fetchoptions.datasetlister; + +/** + * @author pkupczyk + */ +public class DataSetRelationRecord +{ + + public String dp_code; + + public String dc_code; + +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..f8ada5c498053df63f73f97b8c79fa91c7915531 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetLister.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012 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.generic.server.business.bo.fetchoptions.datasetlister; + +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; + +/** + * @author pkupczyk + */ +public interface IDataSetLister +{ + + public List<DataSet> getDataSetMetaData(List<String> dataSetCodes, + DataSetFetchOptions dataSetFetchOptions); + +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..8110b82c716d342c859a7cb2fe8b84b98fc569dd --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/IDataSetListingQuery.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012 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.generic.server.business.bo.fetchoptions.datasetlister; + +import java.util.List; + +import net.lemnik.eodsql.BaseQuery; +import net.lemnik.eodsql.Select; + +import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.StringArrayMapper; + +/** + * @author pkupczyk + */ +public interface IDataSetListingQuery extends BaseQuery +{ + + public static final String RELATIONS_SQL = + "select dp.code as dp_code, dc.code as dc_code from data_set_relationships r inner join data dp on r.data_id_parent = dp.id inner join data dc on r.data_id_child = dc.id"; + + @Select(sql = "select" + + " ds.id as ds_id, ds.code as ds_code, ds.registration_timestamp as ds_registration_timestamp," + + " dt.code as dt_code, dt.is_container as dt_is_container," + + " ex.code as ex_code, " + + " sa.code as sa_code, sa.dbin_id as sa_dbin_id, sac.code as sac_code," + + " pe.first_name as pe_first_name, pe.last_name as pe_last_name, pe.email as pe_email, pe.user_id as pe_user_id," + + " pre.code as pre_code, spe.code as spe_code, sps.code as sps_code," + + " die.code as die_code, die.is_original_source as die_is_original_source" + + " from data ds inner join data_set_types dt on ds.dsty_id = dt.id" + + " inner join experiments ex on ds.expe_id = ex.id" + + " left outer join samples sa on ds.samp_id = sa.id" + + " left outer join persons pe on ds.pers_id_registerer = pe.id" + + " inner join projects pre on ex.proj_id = pre.id" + + " inner join spaces spe on pre.space_id = spe.id" + + " inner join database_instances die on spe.dbin_id = die.id" + + " left outer join spaces sps on sa.space_id = sps.id" + + " left outer join samples sac on sa.samp_id_part_of = sac.id" + + " where ds.code = any(?{1})", parameterBindings = + { StringArrayMapper.class }) + public List<DataSetRecord> getDataSetMetaData(String[] dataSetCodes); + + @Select(sql = RELATIONS_SQL + " where dc.code = any(?{1})", parameterBindings = + { StringArrayMapper.class }) + public List<DataSetRelationRecord> getDataSetParentsCodes(String[] dataSetCodes); + + @Select(sql = RELATIONS_SQL + " where dp.code = any(?{1})", parameterBindings = + { StringArrayMapper.class }) + public List<DataSetRelationRecord> getDataSetChildrenCodes(String[] dataSetCodes); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java similarity index 94% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentLister.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java index 1b12885193c699d7097f96d2fec8b0765277a6ad..0204a11526938f035e051b78c2a38a52e19e045e 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentLister.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.server.business.bo.experimentlister; +package ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.experimentlister; import java.util.ArrayList; import java.util.Collections; @@ -60,12 +60,12 @@ public class ExperimentLister implements IExperimentLister public ExperimentLister(IDAOFactory daoFactory, String baseIndexURL) { - this(daoFactory, QueryTool.getQuery(DatabaseContextUtils.getConnection(daoFactory), - IExperimentListingQuery.class), baseIndexURL); + this(daoFactory, baseIndexURL, QueryTool.getQuery( + DatabaseContextUtils.getConnection(daoFactory), IExperimentListingQuery.class)); } - public ExperimentLister(IDAOFactory daoFactory, IExperimentListingQuery query, - String baseIndexURL) + public ExperimentLister(IDAOFactory daoFactory, String baseIndexURL, + IExperimentListingQuery query) { if (daoFactory == null) { @@ -95,10 +95,10 @@ public class ExperimentLister implements IExperimentLister { throw new IllegalArgumentException("ExperimentFetchOptions were null"); } - if (!experimentFetchOptions.containsOnlyOption(ExperimentFetchOption.BASIC)) + if (!experimentFetchOptions.isSubsetOf(ExperimentFetchOption.BASIC)) { - throw new IllegalArgumentException( - "Currently only ExperimentFetchOption.BASIC is supported by this method"); + throw new IllegalArgumentException("Currently only " + ExperimentFetchOption.BASIC + + " fetch option is supported by this method"); } ExperimentIdentifiers identifiers = new ExperimentIdentifiers(experimentIdentifiers); @@ -122,10 +122,10 @@ public class ExperimentLister implements IExperimentLister { throw new IllegalArgumentException("ExperimentFetchOptions were null"); } - if (!experimentFetchOptions.containsOnlyOption(ExperimentFetchOption.BASIC)) + if (!experimentFetchOptions.isSubsetOf(ExperimentFetchOption.BASIC)) { - throw new IllegalArgumentException( - "Currently only ExperimentFetchOption.BASIC is supported by this method"); + throw new IllegalArgumentException("Currently only " + ExperimentFetchOption.BASIC + + " fetch option is supported by this method"); } ProjectIdentifiers identifiers = new ProjectIdentifiers(projectIdentifiers); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentRecord.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentRecord.java similarity index 94% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentRecord.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentRecord.java index 223481068fd5151db1a6b7f7912e41a9a1f6f22f..f7ed4090c8ab75691333891046f0b6354f0f5d43 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentRecord.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentRecord.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.server.business.bo.experimentlister; +package ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.experimentlister; import java.util.Date; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/IExperimentLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/IExperimentLister.java similarity index 93% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/IExperimentLister.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/IExperimentLister.java index 872ccea27ea9cb89c369884bd4fa515557adbee3..4389cf245b1c492d9a3c04c74df94153b66aaf3c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/IExperimentLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/IExperimentLister.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.server.business.bo.experimentlister; +package ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.experimentlister; import java.util.List; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/IExperimentListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/IExperimentListingQuery.java similarity index 97% rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/IExperimentListingQuery.java rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/IExperimentListingQuery.java index 4c390a1cb54abb5ade64f1a4512ef93ea28eddba..f6840a648399d8a7c4428bfbb1f629e61a94555a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/IExperimentListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/IExperimentListingQuery.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.server.business.bo.experimentlister; +package ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.experimentlister; import net.lemnik.eodsql.BaseQuery; import net.lemnik.eodsql.DataIterator; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOption.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOption.java index ddb163109877ca7c6ab6b5a279fc9fec8af32a7c..990f58da5e4b89b888f38bfd7b4aecca262df6e4 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOption.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOption.java @@ -19,7 +19,7 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; /** * @author pkupczyk */ -public enum ExperimentFetchOption +public enum ExperimentFetchOption implements FetchOption { BASIC, PROPERTIES, PROPERTIES_OF_PROPERTIES, SCRIPTS; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOptions.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOptions.java index 503af18e0d639e5fe090fbe9f6f36efcea62393a..c11a2c2afbde1021bda2aeed0656ad04d3da96c2 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOptions.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ExperimentFetchOptions.java @@ -16,90 +16,24 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; -import java.io.Serializable; -import java.util.HashSet; -import java.util.Set; - /** * @author pkupczyk */ -public class ExperimentFetchOptions implements Serializable +public class ExperimentFetchOptions extends FetchOptions<ExperimentFetchOption> { private static final long serialVersionUID = 1L; - private Set<ExperimentFetchOption> options = new HashSet<ExperimentFetchOption>(); - public ExperimentFetchOptions() { - this((ExperimentFetchOption[]) null); + super(); + addOption(ExperimentFetchOption.BASIC); } public ExperimentFetchOptions(ExperimentFetchOption... options) { - // add BASIC option by default + super(options); addOption(ExperimentFetchOption.BASIC); - - if (options != null) - { - for (ExperimentFetchOption option : options) - { - addOption(option); - } - } - } - - public void addOption(ExperimentFetchOption option) - { - if (option == null) - { - throw new IllegalArgumentException("Option cannot be null"); - } - options.add(option); - } - - public boolean containsOption(ExperimentFetchOption option) - { - return options.contains(option); - } - - public boolean containsOnlyOption(ExperimentFetchOption option) - { - return containsOption(option) && options.size() == 1; - } - - @Override - public String toString() - { - return options.toString(); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((options == null) ? 0 : options.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; - ExperimentFetchOptions other = (ExperimentFetchOptions) obj; - if (options == null) - { - if (other.options != null) - return false; - } else if (!options.equals(other.options)) - return false; - return true; } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java index 9a49f915fc0bf8050bf399f0dfb37ca94c00e03e..d9c5d3339c36e9de58f3d247bd672391d67261b0 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/identifier/IdentifierHelper.java @@ -101,6 +101,24 @@ public final class IdentifierHelper return createSampleIdentifier(databaseInstance, group, sampleCode); } + public final static SampleIdentifier createSampleIdentifier( + final DatabaseInstanceIdentifier databaseInstanceIdentifier, + SpaceIdentifier spaceIdentifier, String sampleCode, String sampleContainerCode) + { + String fullSampleCode = convertCode(sampleCode, sampleContainerCode); + + if (databaseInstanceIdentifier != null) + { + return new SampleIdentifier(databaseInstanceIdentifier, fullSampleCode); + } else if (spaceIdentifier != null) + { + return new SampleIdentifier(spaceIdentifier, fullSampleCode); + } else + { + return SampleIdentifier.createHomeGroup(fullSampleCode); + } + } + private static SampleIdentifier createSampleIdentifier( final DatabaseInstancePE databaseInstance, final SpacePE group, final String sampleCode) { diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceDatabaseTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceDatabaseTest.java index 8340f596884f4e0b35b5ec2ca33f8e06614c2132..6c7c774dd76454268d51af82f9dd72cc2667b66f 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceDatabaseTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ETLServiceDatabaseTest.java @@ -63,7 +63,7 @@ public class ETLServiceDatabaseTest extends AbstractDAOTest service.listExperiments(sessionToken, identifiers, new ExperimentFetchOptions()); assertEquals(1, result.size()); - assertTrue(result.get(0).getFetchOptions().containsOnlyOption(ExperimentFetchOption.BASIC)); + assertTrue(result.get(0).getFetchOptions().isSetOf(ExperimentFetchOption.BASIC)); } @Test @@ -77,11 +77,7 @@ public class ETLServiceDatabaseTest extends AbstractDAOTest ExperimentFetchOption.values())); assertEquals(1, result.size()); - - for (ExperimentFetchOption option : ExperimentFetchOption.values()) - { - assertTrue(result.get(0).getFetchOptions().containsOption(option)); - } + assertTrue(result.get(0).getFetchOptions().isSetOf(ExperimentFetchOption.values())); } @Test @@ -95,7 +91,7 @@ public class ETLServiceDatabaseTest extends AbstractDAOTest new ExperimentFetchOptions()); assertEquals(1, result.size()); - assertTrue(result.get(0).getFetchOptions().containsOnlyOption(ExperimentFetchOption.BASIC)); + assertTrue(result.get(0).getFetchOptions().isSetOf(ExperimentFetchOption.BASIC)); } @Test @@ -109,11 +105,7 @@ public class ETLServiceDatabaseTest extends AbstractDAOTest new ExperimentFetchOptions(ExperimentFetchOption.values())); assertEquals(1, result.size()); - - for (ExperimentFetchOption option : ExperimentFetchOption.values()) - { - assertTrue(result.get(0).getFetchOptions().containsOption(option)); - } + assertTrue(result.get(0).getFetchOptions().isSetOf(ExperimentFetchOption.values())); } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceDatabaseTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceDatabaseTest.java new file mode 100644 index 0000000000000000000000000000000000000000..52e60a72a33a76812abeca179c084f6e865612a8 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationServiceDatabaseTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2012 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.generic.server.api.v1; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAOTest; +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; + +/** + * @author pkupczyk + */ +public class GeneralInformationServiceDatabaseTest extends AbstractDAOTest +{ + @Resource(name = ResourceNames.GENERAL_INFORMATION_SERVICE_SERVER) + IGeneralInformationService service; + + private String sessionToken; + + @BeforeClass(alwaysRun = true) + public void init() throws SQLException + { + sessionToken = service.tryToAuthenticateForAllServices("test", "password"); + } + + @Test + public void testGetDataSetMetaDataWithBasicFetchOptions() + { + List<String> codes = new ArrayList<String>(); + codes.add("20081105092159188-3"); + codes.add("20081105092259000-19"); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + + List<DataSet> result = service.getDataSetMetaData(sessionToken, codes, fetchOptions); + + assertEquals(2, result.size()); + assertTrue(result.get(0).getFetchOptions().isSetOf(DataSetFetchOption.BASIC)); + assertTrue(result.get(1).getFetchOptions().isSetOf(DataSetFetchOption.BASIC)); + } + + @Test + public void testGetDataSetMetaDataWithAllFetchOptions() + { + List<String> codes = new ArrayList<String>(); + codes.add("20081105092159188-3"); + codes.add("20081105092259000-19"); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(DataSetFetchOption.values()); + + List<DataSet> result = service.getDataSetMetaData(sessionToken, codes, fetchOptions); + + assertEquals(2, result.size()); + assertTrue(result.get(0).getFetchOptions().isSetOf(DataSetFetchOption.values())); + assertTrue(result.get(1).getFetchOptions().isSetOf(DataSetFetchOption.values())); + } + +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..614168cbf6eb07f1c969b5d5dfb5005f372463c0 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/datasetlister/DataSetListerTest.java @@ -0,0 +1,212 @@ +/* + * Copyright 2009 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.generic.server.business.bo.fetchoptions.datasetlister; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertNotNull; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import javax.annotation.Resource; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.server.api.v1.ResourceNames; +import ch.systemsx.cisd.openbis.generic.server.business.bo.common.EntityListingTestUtils; +import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAOTest; +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.EntityRegistrationDetails; + +/** + * Test cases for {@link IDataSetListingQuery}. + * + * @author Piotr Kupczyk + */ +@Test(groups = + { "db", "dataset" }) +public class DataSetListerTest extends AbstractDAOTest +{ + + @Resource(name = ResourceNames.GENERAL_INFORMATION_SERVICE_SERVER) + IGeneralInformationService service; + + private IDataSetLister lister; + + private String sessionToken; + + @BeforeClass(alwaysRun = true) + public void init() throws SQLException + { + sessionToken = service.tryToAuthenticateForAllServices("test", "password"); + lister = + new DataSetLister(EntityListingTestUtils.createQuery(daoFactory, + IDataSetListingQuery.class)); + } + + @Test + public void testGetDataSetMetaDataForEmptyDataSetCodesShouldReturnEmptyList() + { + List<String> codes = new ArrayList<String>(); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + + List<DataSet> result = lister.getDataSetMetaData(codes, fetchOptions); + + assertEqualToDataSetMetaDataWithCodes(codes, fetchOptions, result); + } + + @Test + public void testGetDataSetMetaDataForExistingDataSetCodeShouldReturnDataSet() + { + List<String> codes = Collections.singletonList("20081105092159188-3"); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + + List<DataSet> result = lister.getDataSetMetaData(codes, fetchOptions); + + assertEqualToDataSetMetaDataWithCodes(codes, fetchOptions, result); + } + + @Test + public void testGetDataSetMetaDataForExistingDataSetCodesShouldReturnDataSets() + { + List<String> codes = new ArrayList<String>(); + codes.add("20081105092159188-3"); + codes.add("20081105092159111-1"); + codes.add("20081105092259000-19"); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + + List<DataSet> result = lister.getDataSetMetaData(codes, fetchOptions); + + assertEqualToDataSetMetaDataWithCodes(codes, fetchOptions, result); + } + + @Test + public void testGetDataSetMetaDataForExistingDataSetCodesWithParentsShouldReturnDataSetsWithParents() + { + List<String> codes = new ArrayList<String>(); + codes.add("20081105092159188-3"); + codes.add("20081105092159111-1"); + codes.add("20081105092259000-19"); + codes.add("20081105092259000-20"); + codes.add("20081105092259000-21"); + DataSetFetchOptions fetchOptions = + new DataSetFetchOptions(DataSetFetchOption.BASIC, DataSetFetchOption.PARENTS); + + List<DataSet> result = lister.getDataSetMetaData(codes, fetchOptions); + + assertEqualToDataSetMetaDataWithCodes(codes, fetchOptions, result); + } + + @Test + public void testGetDataSetMetaDataForExistingDataSetCodesWithChildrenShouldReturnDataSetsWithChildren() + { + List<String> codes = new ArrayList<String>(); + codes.add("20081105092159188-3"); + codes.add("20081105092159111-1"); + codes.add("20081105092259000-19"); + codes.add("20081105092259000-20"); + codes.add("20081105092259000-21"); + DataSetFetchOptions fetchOptions = + new DataSetFetchOptions(DataSetFetchOption.BASIC, DataSetFetchOption.CHILDREN); + + List<DataSet> result = lister.getDataSetMetaData(codes, fetchOptions); + + assertEqualToDataSetMetaDataWithCodes(codes, fetchOptions, result); + } + + @Test(expectedExceptions = UserFailureException.class) + public void testGetDataSetMetaDataForExistingAndNotExistingDataSetCodesShouldThrowException() + { + List<String> codes = new ArrayList<String>(); + codes.add("20081105092159188-3"); + codes.add("UNKNOWN-DATASET-CODE"); + DataSetFetchOptions fetchOptions = new DataSetFetchOptions(); + + lister.getDataSetMetaData(codes, fetchOptions); + } + + private void assertEqualToDataSetMetaDataWithCodes(List<String> expectedDataSetsCodes, + DataSetFetchOptions expectedFetchOptions, List<DataSet> actualDataSets) + { + assertEquals(expectedDataSetsCodes.size(), actualDataSets.size()); + + List<DataSet> expectedDataSets = + service.getDataSetMetaData(sessionToken, expectedDataSetsCodes); + + Iterator<DataSet> expectedIterator = expectedDataSets.iterator(); + Iterator<DataSet> actualIterator = actualDataSets.iterator(); + + // results should be returned in the same order + while (expectedIterator.hasNext() && actualIterator.hasNext()) + { + DataSet expectedDataSet = expectedIterator.next(); + DataSet actualDataSet = actualIterator.next(); + assertNotNull(expectedDataSet); + assertNotNull(actualDataSet); + assertEqualsToDataSet(expectedDataSet, expectedFetchOptions, actualDataSet); + } + } + + private void assertEqualsToDataSet(DataSet expected, DataSetFetchOptions expectedFetchOptions, + DataSet actual) + { + assertEquals(expected.getCode(), actual.getCode()); + assertEquals(expected.getExperimentIdentifier(), actual.getExperimentIdentifier()); + assertEquals(expected.getSampleIdentifierOrNull(), actual.getSampleIdentifierOrNull()); + assertEquals(expected.getDataSetTypeCode(), actual.getDataSetTypeCode()); + assertEquals(expected.isContainerDataSet(), actual.isContainerDataSet()); + assertEqualsToRegistrationDetails(expected.getRegistrationDetails(), + expected.getRegistrationDetails()); + + if (expectedFetchOptions.isSupersetOf(DataSetFetchOption.PARENTS)) + { + assertEquals(expected.getParentCodes(), actual.getParentCodes()); + } + + if (expectedFetchOptions.isSupersetOf(DataSetFetchOption.CHILDREN)) + { + assertEquals(expected.getChildrenCodes(), actual.getChildrenCodes()); + } + + assertEquals(expectedFetchOptions, actual.getFetchOptions()); + } + + private void assertEqualsToRegistrationDetails(EntityRegistrationDetails expected, + EntityRegistrationDetails actual) + { + assertFalse(expected == null ^ actual == null); + + if (expected != null && actual != null) + { + assertEquals(expected.getUserId(), actual.getUserId()); + assertEquals(expected.getUserFirstName(), actual.getUserFirstName()); + assertEquals(expected.getUserLastName(), actual.getUserLastName()); + assertEquals(expected.getUserEmail(), actual.getUserEmail()); + assertEquals(expected.getRegistrationDate(), actual.getRegistrationDate()); + } + + } +} \ No newline at end of file diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentListerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentListerTest.java similarity index 96% rename from openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentListerTest.java rename to openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentListerTest.java index 30aee1e038d003272c40557d9370e7ee5461d749..3397a37f37f45365ce8ffdd9539617a697cfee93 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/experimentlister/ExperimentListerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/fetchoptions/experimentlister/ExperimentListerTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.server.business.bo.experimentlister; +package ch.systemsx.cisd.openbis.generic.server.business.bo.fetchoptions.experimentlister; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; @@ -67,8 +67,9 @@ public class ExperimentListerTest extends AbstractDAOTest { sessionToken = service.tryToAuthenticate("test", "password").getSessionToken(); lister = - new ExperimentLister(daoFactory, EntityListingTestUtils.createQuery(daoFactory, - IExperimentListingQuery.class), service.getBaseIndexURL(sessionToken)); + new ExperimentLister(daoFactory, service.getBaseIndexURL(sessionToken), + EntityListingTestUtils.createQuery(daoFactory, + IExperimentListingQuery.class)); } @Test @@ -219,7 +220,7 @@ public class ExperimentListerTest extends AbstractDAOTest assertEqualsToExperimentType(expected.getExperimentType(), actual.getExperimentType()); assertEqualsToProject(expected.getProject(), actual.getProject()); assertEqualsToPerson(expected.getRegistrator(), actual.getRegistrator()); - assertTrue(actual.getFetchOptions().containsOnlyOption(ExperimentFetchOption.BASIC)); + assertTrue(actual.getFetchOptions().isSetOf(ExperimentFetchOption.BASIC)); } private void assertEqualsToExperimentType(ExperimentType expected, ExperimentType actual) diff --git a/openbis/sourceTest/sql/postgresql/100/008=data_all.tsv b/openbis/sourceTest/sql/postgresql/100/008=data_all.tsv index 60ab0fe410daf2e446d3d14aa67a53bf8fa0ff94..ca56ef59d64435807ada99e8d694fb4ab7b1c63d 100644 --- a/openbis/sourceTest/sql/postgresql/100/008=data_all.tsv +++ b/openbis/sourceTest/sql/postgresql/100/008=data_all.tsv @@ -13,3 +13,6 @@ 15 20110509092359990-12 2 \N 2011-05-09 10:22:59.203+02 2011-05-09 10:22:59.313+02 f t 2011-05-09 16:34:44.462776+02 8 1 t \N \N 2 13 \N 17 20110805092359990-17 2 \N 2008-11-05 09:21:59.203+01 2009-02-09 12:21:47.815468+01 f t 2009-03-23 15:34:44.462776+01 20 1 f 1044 \N \N \N \N 18 20081105092259000-18 2 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 8 1 t \N \N \N \N \N +19 20081105092259000-19 4 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 8 1 t \N 2 \N \N \N +20 20081105092259000-20 2 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 8 1 t \N 2 \N \N \N +21 20081105092259000-21 2 \N 2008-11-05 09:22:59.203+01 2008-11-05 09:22:59.313+01 f t 2009-03-23 15:34:44.462776+01 8 1 t \N 2 \N \N \N diff --git a/openbis/sourceTest/sql/postgresql/100/011=data_set_relationships_all.tsv b/openbis/sourceTest/sql/postgresql/100/011=data_set_relationships_all.tsv index 3b58d39d5d7081b5bca3821d3357ec8490a2c38a..7627ed55c5e01b6ad0243624949b9235be247457 100644 --- a/openbis/sourceTest/sql/postgresql/100/011=data_set_relationships_all.tsv +++ b/openbis/sourceTest/sql/postgresql/100/011=data_set_relationships_all.tsv @@ -9,3 +9,5 @@ 17 18 \N 2 4 1 2 9 1 +19 20 \N +19 21 \N diff --git a/openbis/sourceTest/sql/postgresql/100/027=external_data.tsv b/openbis/sourceTest/sql/postgresql/100/027=external_data.tsv index f226ab53cd71ff50107d51135b5fc95ffd26e531..88a584d92c7aabff3b5ae5684b0ae54cb9c31691 100644 --- a/openbis/sourceTest/sql/postgresql/100/027=external_data.tsv +++ b/openbis/sourceTest/sql/postgresql/100/027=external_data.tsv @@ -12,3 +12,5 @@ 15 contained/20110509092359990-12 8 1 4 U \N AVAILABLE \N \N f -50 t 17 a/4 4 1 4 U \N AVAILABLE \N \N f -50 t 18 xml/result-18 8 1 4 U \N AVAILABLE \N \N f -50 t +20 xml/result-20 8 1 4 U \N AVAILABLE \N \N f -50 t +21 xml/result-21 8 1 4 U \N AVAILABLE \N \N f -50 t 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 7dfe39a1ddcba54d5ca3f555c8e8d7c9e0271801..76d1d1d9c74e3e08c74bd564cf3922288398de2e 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 @@ -26,6 +26,7 @@ import ch.systemsx.cisd.common.api.IRpcService; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.ControlledVocabularyPropertyType; 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.DataSetFetchOptions; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Project; @@ -245,10 +246,23 @@ public interface IGeneralInformationService extends IRpcService */ public List<DataSet> getDataSetMetaData(String sessionToken, List<String> dataSetCodes); + /** + * Returns meta data for all specified data sets. Which parts of the data sets objects are + * fetched is controlled with the <code>dataSetFetchOptions</code> parameter. Available since + * minor version 16. + * + * @param dataSetCodes Codes of requested data sets. + * @param dataSetFetchOptions Options that control which parts of the data sets are fetched. + * @return result in the same order as the list of data set codes. + * @since 1.16 + */ + public List<DataSet> getDataSetMetaData(String sessionToken, List<String> dataSetCodes, + DataSetFetchOptions dataSetFetchOptions); + /** * Return all data sets matching a specified search criteria. Note, that for returned container - * data sets the contained data sets have only code, type and registration date set. Available since - * minor version 8. + * data sets the contained data sets have only code, type and registration date set. Available + * since minor version 8. * * @param searchCriteria the criteria used for searching. * @since 1.8 diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSet.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSet.java index a4ffeb4f6c8790d49ae31c73442b6310724add5e..e2416e15308209d18eb0c0e60255a9d510504a8d 100644 --- a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSet.java +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSet.java @@ -186,8 +186,7 @@ public final class DataSet implements Serializable public void setContainedDataSets(List<DataSet> containedDataSets) { this.containedDataSets = - (null == containedDataSets) ? new ArrayList<DataSet>() - : containedDataSets; + (null == containedDataSets) ? new ArrayList<DataSet>() : containedDataSets; } } @@ -215,6 +214,8 @@ public final class DataSet implements Serializable private EntityRegistrationDetails registrationDetails; + private DataSetFetchOptions fetchOptions; + /** * Creates a new instance with the provided initializer * @@ -460,4 +461,26 @@ public final class DataSet implements Serializable this.containedDataSets = containedDataSets; } + public DataSetFetchOptions getFetchOptions() + { + return fetchOptions; + } + + public void setFetchOptions(DataSetFetchOptions fetchOptions) + { + this.fetchOptions = fetchOptions; + if (fetchOptions != null) + { + if (fetchOptions.isSupersetOf(DataSetFetchOption.PARENTS, DataSetFetchOption.CHILDREN)) + { + setRetrievedConnections(EnumSet.of(Connections.PARENTS, Connections.CHILDREN)); + } else if (fetchOptions.isSupersetOf(DataSetFetchOption.PARENTS)) + { + setRetrievedConnections(EnumSet.of(Connections.PARENTS)); + } else if (fetchOptions.isSupersetOf(DataSetFetchOption.CHILDREN)) + { + setRetrievedConnections(EnumSet.of(Connections.CHILDREN)); + } + } + } } diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetFetchOption.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetFetchOption.java new file mode 100644 index 0000000000000000000000000000000000000000..95a2a9feb651e90dc98acb6833236cd680159da9 --- /dev/null +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetFetchOption.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012 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.generic.shared.api.v1.dto; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FetchOption; + +/** + * @author pkupczyk + */ +public enum DataSetFetchOption implements FetchOption +{ + + BASIC, PROPERTIES, PROPERTIES_OF_PROPERTIES, PARENTS, CHILDREN, CONTAINED + +} diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetFetchOptions.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetFetchOptions.java new file mode 100644 index 0000000000000000000000000000000000000000..6a8d3bb2cecdd69230305f53815ab9bb96ff5c77 --- /dev/null +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/api/v1/dto/DataSetFetchOptions.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012 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.generic.shared.api.v1.dto; + +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.FetchOptions; + +/** + * @author pkupczyk + */ +public class DataSetFetchOptions extends FetchOptions<DataSetFetchOption> +{ + + private static final long serialVersionUID = 1L; + + public DataSetFetchOptions() + { + super(); + addOption(DataSetFetchOption.BASIC); + } + + public DataSetFetchOptions(DataSetFetchOption... options) + { + super(options); + addOption(DataSetFetchOption.BASIC); + } + +} diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/FetchOption.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/FetchOption.java new file mode 100644 index 0000000000000000000000000000000000000000..7bd6d42088cb3a9c689a64b6c7879c47a5c30db7 --- /dev/null +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/FetchOption.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012 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.generic.shared.basic.dto; + +/** + * @author pkupczyk + */ +public interface FetchOption +{ + +} diff --git a/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/FetchOptions.java b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/FetchOptions.java new file mode 100644 index 0000000000000000000000000000000000000000..5872bec742edacbf4ec887074a8d2df499f66b86 --- /dev/null +++ b/openbis_api/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/FetchOptions.java @@ -0,0 +1,130 @@ +/* + * Copyright 2012 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.generic.shared.basic.dto; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * @author pkupczyk + */ +public class FetchOptions<T extends FetchOption> implements Serializable +{ + + private static final long serialVersionUID = 1L; + + private Set<T> optionsSet = new HashSet<T>(); + + public FetchOptions() + { + this((T[]) null); + } + + public FetchOptions(T... options) + { + if (options != null) + { + for (T option : options) + { + addOption(option); + } + } + } + + public void addOption(T option) + { + if (option == null) + { + throw new IllegalArgumentException("Option cannot be null"); + } + optionsSet.add(option); + } + + public boolean isSetOf(T... options) + { + if (options == null) + { + return optionsSet.isEmpty(); + } else + { + HashSet<T> anOptionsSet = new HashSet<T>(Arrays.asList(options)); + return optionsSet.equals(anOptionsSet); + } + } + + public boolean isSupersetOf(T... options) + { + if (options == null) + { + return true; + } else + { + HashSet<T> anOptionsSet = new HashSet<T>(Arrays.asList(options)); + return optionsSet.containsAll(anOptionsSet); + } + } + + public boolean isSubsetOf(T... options) + { + if (options == null) + { + return optionsSet.isEmpty(); + } else + { + HashSet<T> anOptionsSet = new HashSet<T>(Arrays.asList(options)); + return anOptionsSet.containsAll(optionsSet); + } + } + + @Override + public String toString() + { + return optionsSet.toString(); + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((optionsSet == null) ? 0 : optionsSet.hashCode()); + return result; + } + + @Override + @SuppressWarnings("rawtypes") + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + FetchOptions other = (FetchOptions) obj; + if (optionsSet == null) + { + if (other.optionsSet != null) + return false; + } else if (!optionsSet.equals(other.optionsSet)) + return false; + return true; + } + +}