diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServer.java index 64357994dca5563d1d9e6c6e19732a27176027f0..5c769462274e70fd8eb385e97db42869997488ab 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServer.java @@ -30,6 +30,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.shared.ITrackingServer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCriteria; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewTrackingSampleCriteria; 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.basic.dto.TrackingSampleCriteria; @@ -78,6 +79,16 @@ public final class TrackingServer extends AbstractServer<ITrackingServer> implem return sampleLister.list(listerCriteria); } + public List<Sample> listSamples(String sessionToken, NewTrackingSampleCriteria criteria) + { + final Session session = getSession(sessionToken); + + final ISampleLister sampleLister = businessObjectFactory.createSampleLister(session); + final ListOrSearchSampleCriteria listerCriteria = new ListOrSearchSampleCriteria(criteria); + listerCriteria.setEnrichDependentSamplesWithProperties(true); + return sampleLister.list(listerCriteria); + } + public List<ExternalData> listDataSets(String sessionToken, TrackingDataSetCriteria criteria) { final Session session = getSession(sessionToken); diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServerLogger.java index 2de861168be7b887307fd070292acd52c5dbeaa8..674e16b4baf18ed6d510b6a5c876f77b4c6a1704 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/TrackingServerLogger.java @@ -22,6 +22,7 @@ import ch.systemsx.cisd.authentication.ISessionManager; import ch.systemsx.cisd.common.spring.IInvocationLoggerContext; import ch.systemsx.cisd.openbis.generic.shared.ITrackingServer; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewTrackingSampleCriteria; 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.basic.dto.TrackingSampleCriteria; @@ -63,4 +64,12 @@ final class TrackingServerLogger extends AbstractServerLogger implements ITracki return null; } + public List<Sample> listSamples(String sessionToken, NewTrackingSampleCriteria criteria) + { + logTracking(sessionToken, "list_samples", + "PROPERTY(%s) VALUE(%s) ALREADY_TRACKED_SIZE(%s)", criteria.getPropertyTypeCode(), + criteria.getPropertyValue(), criteria.getAlreadyTrackedSampleIds().size()); + return null; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java index db1e3483a00a9dd78661fef37421483e68968d27..6c664f0e22f78552f23cf3ac29a13c1525e7fb82 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleListingQuery.java @@ -25,6 +25,7 @@ import net.lemnik.eodsql.DataIterator; import net.lemnik.eodsql.EoDException; import net.lemnik.eodsql.Select; import net.lemnik.eodsql.TransactionQuery; +import net.lemnik.eodsql.TypeMapper; import net.lemnik.eodsql.spi.util.NonUpdateCapableDataObjectBinding; import org.apache.commons.lang.StringEscapeUtils; @@ -136,38 +137,39 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ * Returns the samples for all groups. */ @Select(sql = "select s.id, s.perm_id, s.code, s.expe_id, s.grou_id, s.dbin_id, " - + " s.registration_timestamp, s.pers_id_registerer, " - + " s.samp_id_generated_from, s.samp_id_part_of, s.saty_id, s.inva_id " - + " from samples s join sample_types st on s.saty_id=st.id" - + " join groups g on s.grou_id=g.id " - + " where st.is_listable and g.dbin_id=?{1} order by s.code", fetchSize = FETCH_SIZE) - public DataIterator<SampleRecord> getAllGroupSamples(long dbInstanceId); - + + " s.registration_timestamp, s.pers_id_registerer, " + + " s.samp_id_generated_from, s.samp_id_part_of, s.saty_id, s.inva_id " + + " from samples s join sample_types st on s.saty_id=st.id" + + " join groups g on s.grou_id=g.id " + + " where st.is_listable and g.dbin_id=?{1} order by s.code", fetchSize = FETCH_SIZE) + public DataIterator<SampleRecord> getAllGroupSamples(long dbInstanceId); + /** * Returns the samples for all groups that are assigned to an experiment. */ @Select(sql = "select s.id, s.perm_id, s.code, s.saty_id, s.expe_id, s.grou_id, s.dbin_id, " - + " s.samp_id_generated_from, s.registration_timestamp, s.modification_timestamp, " - + " s.pers_id_registerer, s.samp_id_part_of, s.inva_id " - + " from samples s join groups g on s.grou_id=g.id " - + " where s.expe_id is not null and g.dbin_id=?{1} " - + " order by s.code", fetchSize = FETCH_SIZE) - public DataIterator<SampleRecord> getAllGroupSamplesWithExperiment(long dbInstanceId); - + + " s.samp_id_generated_from, s.registration_timestamp, s.modification_timestamp, " + + " s.pers_id_registerer, s.samp_id_part_of, s.inva_id " + + " from samples s join groups g on s.grou_id=g.id " + + " where s.expe_id is not null and g.dbin_id=?{1} " + + " order by s.code", fetchSize = FETCH_SIZE) + public DataIterator<SampleRecord> getAllGroupSamplesWithExperiment(long dbInstanceId); + /** * Returns the samples for all groups and <var>sampleTypeId</var> */ @Select(sql = "select s.id, s.perm_id, s.code, s.expe_id, s.grou_id, s.dbin_id, " - + " s.registration_timestamp, s.pers_id_registerer, " - + " s.samp_id_generated_from, s.samp_id_part_of, s.saty_id, s.inva_id " - + " from samples s join groups g on s.grou_id=g.id " - + " where g.dbin_id=?{1} and s.saty_id=?{2}" - + " order by s.code", fetchSize = FETCH_SIZE) - public DataIterator<SampleRecord> getAllGroupSamplesForSampleType(long dbInstanceId, long sampleTypeId); - + + " s.registration_timestamp, s.pers_id_registerer, " + + " s.samp_id_generated_from, s.samp_id_part_of, s.saty_id, s.inva_id " + + " from samples s join groups g on s.grou_id=g.id " + + " where g.dbin_id=?{1} and s.saty_id=?{2}" + + " order by s.code", fetchSize = FETCH_SIZE) + public DataIterator<SampleRecord> getAllGroupSamplesForSampleType(long dbInstanceId, + long sampleTypeId); + /** - * Returns the samples for all groups and <var>sampleTypeId</var> that are - * assigned to an experiment. + * Returns the samples for all groups and <var>sampleTypeId</var> that are assigned to an + * experiment. */ @Select(sql = "select s.id, s.perm_id, s.code, s.saty_id, s.expe_id, s.grou_id, s.dbin_id, " + " s.samp_id_generated_from, s.registration_timestamp, s.modification_timestamp, " @@ -177,7 +179,7 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ + " order by s.code", fetchSize = FETCH_SIZE) public DataIterator<SampleRecord> getAllGroupSamplesForSampleTypeWithExperiment( long dbInstanceId, long sampleTypeId); - + // // Samples for experiment // @@ -219,6 +221,24 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ public DataIterator<SampleRecord> getNewSamplesForSampleType(long sampleTypeId, int lastSeenSampleId); + /** + * Returns all samples with a <var>propertyType</var> attached having specified + * <var>popertyValue</var>. Additionally id of the sample SHOULDN'T be in the specified + * set of ids. + */ + @Select(sql = "select s.id, s.perm_id, s.code, s.expe_id, s.grou_id, s.dbin_id, " + + " s.registration_timestamp, s.pers_id_registerer, " + + " s.samp_id_generated_from, s.samp_id_part_of, s.saty_id, s.inva_id " + + " from samples s where id in (" + + " select samp_id from sample_properties sp where sp.stpt_id in (" + + " select id from sample_type_property_types stpt where stpt.prty_id = " + + " (select id from property_types where code=?{1})" + + " ) and value=?{2}" + + " ) and not id = any(?{3})", parameterBindings = + { TypeMapper.class, TypeMapper.class, LongSetMapper.class }, fetchSize = FETCH_SIZE) + public DataIterator<SampleRecord> getSamplesWithPropertyValue(String propertyTypeCode, + String propertyValue, LongSet sampleIds); + // // Shared samples // diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java index 644614b1dbedec8e0b622f3e6b347a2dd6e646d3..f83b831566386ddd5934da8ab14a4d08a750704b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java @@ -46,7 +46,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Invalidation; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCriteria; @@ -54,6 +53,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListSampleCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper; @@ -214,6 +214,7 @@ final class SampleListingWorker retrievePrimaryBasicSamples(tryGetIteratorForExperimentSamples()); retrievePrimaryBasicSamples(tryGetIteratorForContainedSamples()); retrievePrimaryBasicSamples(tryGetIteratorForTrackedSamples()); + retrievePrimaryBasicSamples(tryGetIteratorForNewTrackedSamples()); if (operationLog.isDebugEnabled()) { watch.stop(); @@ -454,6 +455,18 @@ final class SampleListingWorker return query.getNewSamplesForSampleType(sampleTypeId, criteria.getLastSeenSampleId()); } + private Iterable<SampleRecord> tryGetIteratorForNewTrackedSamples() + { + final String propertyTypeCode = criteria.getPropertyTypeCode(); + if (propertyTypeCode == null) + { + return null; + } + final String propertyValue = criteria.getPropertyValue(); + return query.getSamplesWithPropertyValue(propertyTypeCode, propertyValue, + new LongOpenHashSet(criteria.getAlreadyTrackedSampleIds())); + } + private void retrievePrimaryBasicSamples(final Iterable<SampleRecord> sampleIteratorOrNull) { assert sampleList != null; diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ITrackingServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ITrackingServer.java index 823fc721c5cabe8ea7b3d9c9032ac3b14ccb6b5a..019c378334f16db634eb5735a643dd812eb883be 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ITrackingServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/ITrackingServer.java @@ -24,6 +24,7 @@ import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RoleSet; import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewTrackingSampleCriteria; 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.basic.dto.TrackingSampleCriteria; @@ -45,6 +46,16 @@ public interface ITrackingServer extends IServer @RolesAllowed(RoleSet.INSTANCE_ADMIN) public List<Sample> listSamples(final String sessionToken, final TrackingSampleCriteria criteria); + /** + * Lists samples using given criteria. + * + * @return a sorted list of {@link Sample}. + */ + @Transactional(readOnly = true) + @RolesAllowed(RoleSet.INSTANCE_ADMIN) + public List<Sample> listSamples(final String sessionToken, + final NewTrackingSampleCriteria criteria); + /** * For given sample {@link TechId} returns the corresponding list of {@link ExternalData}. * diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java index 3de4792ef2e6753c98a3d4ed0993d6c32aab7a9c..b8029c364c7803302902e5bdbdc850452e546b6a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java @@ -41,6 +41,8 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria private TrackingSampleCriteria trackingCriteria; + private NewTrackingSampleCriteria newTrackingCriteria; + private Collection<Long> sampleIds; private boolean enrichDependentSamplesWithProperties = false; @@ -59,6 +61,13 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria this.trackingCriteria = trackingCriteria; } + /** Creates criteria that delegates to given {@link NewTrackingSampleCriteria}. */ + public ListOrSearchSampleCriteria(NewTrackingSampleCriteria newTrackingCriteria) + { + assert newTrackingCriteria != null; + this.newTrackingCriteria = newTrackingCriteria; + } + /** Creates criteria for detailed search of samples with given ids. */ public ListOrSearchSampleCriteria(final Collection<Long> sampleIds) { @@ -73,6 +82,24 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria return sampleIds; } + // delegation to NewTrackingSampleCriteria + + public String getPropertyTypeCode() + { + return newTrackingCriteria == null ? null : newTrackingCriteria.getPropertyTypeCode(); + } + + public String getPropertyValue() + { + return newTrackingCriteria == null ? null : newTrackingCriteria.getPropertyValue(); + } + + public Collection<Long> getAlreadyTrackedSampleIds() + { + return newTrackingCriteria == null ? null : newTrackingCriteria + .getAlreadyTrackedSampleIds(); + } + // delegation to TrackingSampleCriteria public String getSampleTypeCode() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewTrackingSampleCriteria.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewTrackingSampleCriteria.java new file mode 100644 index 0000000000000000000000000000000000000000..e716a184bce74b17befba436f2939fd555396e95 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/NewTrackingSampleCriteria.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008 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.Collection; + +/** + * Criteria for tracking <i>samples</i> with a particular property having certain property value. + * <p> + * Parent and Container samples should be loaded according to {@link SampleType} hierarchy depths. + * All referenced samples should have all properties loaded. + * + * @author Piotr Buczek + */ +// NOTE: It doesn't implement IsSerializable as it is not supposed to be used on the GWT client side +public class NewTrackingSampleCriteria implements Serializable +{ + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + // TODO + // private final String sampleTypeCode; + + private final String propertyTypeCode; + + private final String propertyValue; + + private final Collection<Long> alreadyTrackedSampleIds; + + public NewTrackingSampleCriteria(String propertyTypeCode, String propertyValue, + Collection<Long> alreadyTrackedSampleIds) + { + assert propertyTypeCode != null; + assert propertyValue != null; + this.propertyTypeCode = propertyTypeCode; + this.propertyValue = propertyValue; + this.alreadyTrackedSampleIds = alreadyTrackedSampleIds; + } + + public String getPropertyTypeCode() + { + return propertyTypeCode; + } + + public String getPropertyValue() + { + return propertyValue; + } + + public Collection<Long> getAlreadyTrackedSampleIds() + { + return alreadyTrackedSampleIds; + } + +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/OpenbisClientTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/OpenbisClientTest.java index 3392cc61ec823765bbd1d8489b6ab677dc7396bf..eb0d2d5b3b8986a67cf150030c2bfeb142491d04 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/OpenbisClientTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/OpenbisClientTest.java @@ -1,6 +1,8 @@ package ch.systemsx.cisd.openbis.generic; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.apache.commons.lang.StringUtils; @@ -15,6 +17,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewTrackingSampleCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived; @@ -118,6 +121,18 @@ public class OpenbisClientTest trackingServer.listDataSets(session.getSessionToken(), dataSetCriteria); System.out .println(TrackingHelper.trackedEntitiesInformation(dataSets, EntityKind.DATA_SET)); + + final String propertyTypeCode = "IS_VALID"; + final String propertyValue = "true"; + final Collection<Long> alreadyTracked = Arrays.asList(new Long[] + { 986L, 987L }); + + final NewTrackingSampleCriteria newSampleCriteria = + new NewTrackingSampleCriteria(propertyTypeCode, propertyValue, alreadyTracked); + final List<Sample> newSamples = + trackingServer.listSamples(session.getSessionToken(), newSampleCriteria); + System.out + .println(TrackingHelper.trackedEntitiesInformation(newSamples, EntityKind.SAMPLE)); } /** @@ -215,8 +230,25 @@ public class OpenbisClientTest private static String toString(List<IEntityProperty> properties) { - // output just collection size or null if not initialized - return properties == null ? null : new Integer(properties.size()).toString(); + if (properties == null) + { + return null; + } else + { + final StringBuilder sb = new StringBuilder(); + sb.append("{"); + for (IEntityProperty property : properties) + { + sb.append(property.getPropertyType() + "=" + property.getValue() + ","); + } + if (properties.size() > 0) + { + sb.setLength(sb.length() - 1); + } + sb.append("}"); + return sb.toString(); + } } + } }