From b8d3f185bdade98023be07fe5a095c6401d45da1 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Mon, 19 Apr 2010 12:47:29 +0000
Subject: [PATCH] [LMS-1457] added sample type to new sample tracking criteria

SVN: 15514
---
 .../generic/server/TrackingServer.java        | 11 -------
 .../bo/samplelister/ISampleListingQuery.java  | 31 ++++++-------------
 .../bo/samplelister/SampleListingWorker.java  | 19 +++---------
 .../generic/shared/ITrackingServer.java       | 10 ------
 .../basic/dto/ListOrSearchSampleCriteria.java | 26 +++-------------
 .../basic/dto/NewTrackingSampleCriteria.java  | 17 +++++++---
 .../openbis/generic/OpenbisClientTest.java    | 11 ++-----
 7 files changed, 33 insertions(+), 92 deletions(-)

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 5c769462274..f5387f43e0b 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
@@ -33,7 +33,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCrite
 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;
 import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
 
 public final class TrackingServer extends AbstractServer<ITrackingServer> implements
@@ -69,16 +68,6 @@ public final class TrackingServer extends AbstractServer<ITrackingServer> implem
     // ITrackingServer
     //
 
-    public List<Sample> listSamples(String sessionToken, TrackingSampleCriteria 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<Sample> listSamples(String sessionToken, NewTrackingSampleCriteria criteria)
     {
         final Session session = getSession(sessionToken);
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 6c664f0e22f..ba087160e66 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
@@ -211,33 +211,22 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ
     //
 
     /**
-     * Returns all samples of sample type with given <var>sampleTypeId</var> that are newer than
-     * sample with given id (<var>lastSeenSampleId</var>).
+     * 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 s.saty_id=?{1} and s.id > ?{2}", fetchSize = FETCH_SIZE)
-    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 ("
+            + "   from samples s where s.saty_id=?{1} and 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);
+            + "                     (select id from property_types where code=?{2})"
+            + "              ) and value=?{3}" 
+            + "       ) and not id = any(?{4})", parameterBindings =
+        { TypeMapper.class, TypeMapper.class, TypeMapper.class, LongSetMapper.class }, fetchSize = FETCH_SIZE)
+    public DataIterator<SampleRecord> getSamplesWithPropertyValue(long sampleTypeId,
+            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 f83b8315663..5c0dd088dbf 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
@@ -213,7 +213,6 @@ final class SampleListingWorker
         retrievePrimaryBasicSamples(tryGetIteratorForSharedSamples());
         retrievePrimaryBasicSamples(tryGetIteratorForExperimentSamples());
         retrievePrimaryBasicSamples(tryGetIteratorForContainedSamples());
-        retrievePrimaryBasicSamples(tryGetIteratorForTrackedSamples());
         retrievePrimaryBasicSamples(tryGetIteratorForNewTrackedSamples());
         if (operationLog.isDebugEnabled())
         {
@@ -443,27 +442,17 @@ final class SampleListingWorker
         }
     }
 
-    private Iterable<SampleRecord> tryGetIteratorForTrackedSamples()
+    private Iterable<SampleRecord> tryGetIteratorForNewTrackedSamples()
     {
-        final String sampleTypeCode = criteria.getSampleTypeCode();
-        if (sampleTypeCode == null)
+        if (criteria.getSampleTypeCode() == null)
         {
             return null;
         }
-        Long sampleTypeId =
+        final long sampleTypeId =
                 referencedEntityDAO.getSampleTypeIdForSampleTypeCode(criteria.getSampleTypeCode());
-        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,
+        return query.getSamplesWithPropertyValue(sampleTypeId, propertyTypeCode, propertyValue,
                 new LongOpenHashSet(criteria.getAlreadyTrackedSampleIds()));
     }
 
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 019c378334f..2cdcf55c0bf 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
@@ -27,7 +27,6 @@ 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;
 
 /**
  * Definition of the client-server interface for tracking creation of samples and datasets.
@@ -37,15 +36,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingSampleCriteria;
 public interface ITrackingServer extends IServer
 {
 
-    /**
-     * 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 TrackingSampleCriteria criteria);
-
     /**
      * Lists samples using given criteria.
      * 
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 b8029c364c7..6da353863cc 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
@@ -39,8 +39,6 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria
 
     private ListSampleCriteria listCriteria;
 
-    private TrackingSampleCriteria trackingCriteria;
-
     private NewTrackingSampleCriteria newTrackingCriteria;
 
     private Collection<Long> sampleIds;
@@ -54,13 +52,6 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria
         this.listCriteria = listCriteria;
     }
 
-    /** Creates criteria that delegates to given {@link TrackingSampleCriteria}. */
-    public ListOrSearchSampleCriteria(TrackingSampleCriteria trackingCriteria)
-    {
-        assert trackingCriteria != null;
-        this.trackingCriteria = trackingCriteria;
-    }
-
     /** Creates criteria that delegates to given {@link NewTrackingSampleCriteria}. */
     public ListOrSearchSampleCriteria(NewTrackingSampleCriteria newTrackingCriteria)
     {
@@ -84,6 +75,11 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria
 
     // delegation to NewTrackingSampleCriteria
 
+    public String getSampleTypeCode()
+    {
+        return newTrackingCriteria == null ? null : newTrackingCriteria.getSampleTypeCode();
+    }
+
     public String getPropertyTypeCode()
     {
         return newTrackingCriteria == null ? null : newTrackingCriteria.getPropertyTypeCode();
@@ -100,18 +96,6 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria
                 .getAlreadyTrackedSampleIds();
     }
 
-    // delegation to TrackingSampleCriteria
-
-    public String getSampleTypeCode()
-    {
-        return trackingCriteria == null ? null : trackingCriteria.getSampleTypeCode();
-    }
-
-    public int getLastSeenSampleId()
-    {
-        return trackingCriteria == null ? null : trackingCriteria.getLastSeenSampleId();
-    }
-
     // delegation to ListSampleCriteria
 
     @Override
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
index e716a184bce..cdfb0116423 100644
--- 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
@@ -20,7 +20,8 @@ import java.io.Serializable;
 import java.util.Collection;
 
 /**
- * Criteria for tracking <i>samples</i> with a particular property having certain property value.
+ * Criteria for tracking <i>samples</i> of particular type with certain property set to specified
+ * value.
  * <p>
  * Parent and Container samples should be loaded according to {@link SampleType} hierarchy depths.
  * All referenced samples should have all properties loaded.
@@ -32,8 +33,7 @@ public class NewTrackingSampleCriteria implements Serializable
 {
     private static final long serialVersionUID = ServiceVersionHolder.VERSION;
 
-    // TODO
-    // private final String sampleTypeCode;
+    private final String sampleTypeCode;
 
     private final String propertyTypeCode;
 
@@ -41,16 +41,23 @@ public class NewTrackingSampleCriteria implements Serializable
 
     private final Collection<Long> alreadyTrackedSampleIds;
 
-    public NewTrackingSampleCriteria(String propertyTypeCode, String propertyValue,
-            Collection<Long> alreadyTrackedSampleIds)
+    public NewTrackingSampleCriteria(String sampleTypeCode, String propertyTypeCode,
+            String propertyValue, Collection<Long> alreadyTrackedSampleIds)
     {
         assert propertyTypeCode != null;
         assert propertyValue != null;
+        assert sampleTypeCode != null;
+        this.sampleTypeCode = sampleTypeCode;
         this.propertyTypeCode = propertyTypeCode;
         this.propertyValue = propertyValue;
         this.alreadyTrackedSampleIds = alreadyTrackedSampleIds;
     }
 
+    public String getSampleTypeCode()
+    {
+        return sampleTypeCode;
+    }
+
     public String getPropertyTypeCode()
     {
         return propertyTypeCode;
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 eb0d2d5b3b8..a57464ddcc1 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/OpenbisClientTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/OpenbisClientTest.java
@@ -22,7 +22,6 @@ 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;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingDataSetCriteria;
-import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TrackingSampleCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
 import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer;
 
@@ -106,15 +105,8 @@ public class OpenbisClientTest
         SessionContextDTO session = trackingServer.tryToAuthenticate(USER_ID, USER_PASSWORD);
 
         final String sampleTypeCode = "CELL_PLATE";
-        final int lastSeenSampleId = 1000; // compare with 0
         final int lastSeenDataSetId = 0; // compare with 3
 
-        final TrackingSampleCriteria sampleCriteria =
-                new TrackingSampleCriteria(sampleTypeCode, lastSeenSampleId);
-        final List<Sample> samples =
-                trackingServer.listSamples(session.getSessionToken(), sampleCriteria);
-        System.out.println(TrackingHelper.trackedEntitiesInformation(samples, EntityKind.SAMPLE));
-
         final TrackingDataSetCriteria dataSetCriteria =
                 new TrackingDataSetCriteria(sampleTypeCode, lastSeenDataSetId);
         final List<ExternalData> dataSets =
@@ -128,7 +120,8 @@ public class OpenbisClientTest
             { 986L, 987L });
 
         final NewTrackingSampleCriteria newSampleCriteria =
-                new NewTrackingSampleCriteria(propertyTypeCode, propertyValue, alreadyTracked);
+                new NewTrackingSampleCriteria(sampleTypeCode, propertyTypeCode, propertyValue,
+                        alreadyTracked);
         final List<Sample> newSamples =
                 trackingServer.listSamples(session.getSessionToken(), newSampleCriteria);
         System.out
-- 
GitLab