Skip to content
Snippets Groups Projects
Commit 5391c165 authored by buczekp's avatar buczekp
Browse files

[LMS-1457] added new sample tracking criteria

SVN: 15512
parent 0ecb0afb
No related branches found
No related tags found
No related merge requests found
Showing
with 219 additions and 27 deletions
......@@ -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);
......
......@@ -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;
}
}
......@@ -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
//
......
......@@ -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;
......
......@@ -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}.
*
......
......@@ -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()
......
/*
* 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;
}
}
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();
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment