From 755fb78ee21b21e9d45a8f6d281b718cfaf7c4a6 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Tue, 26 Oct 2010 14:24:42 +0000
Subject: [PATCH] SE-308, SE-311 new methods added to ISampleLister

SVN: 18447
---
 .../bo/samplelister/ISampleLister.java        | 23 +++++
 .../bo/samplelister/ISampleListingQuery.java  |  6 ++
 .../bo/samplelister/SampleLister.java         | 50 +++++++++++
 .../bo/samplelister/SampleListingWorker.java  |  4 +-
 .../dto/SampleRelationShipSkeleton.java       | 61 +++++++++++++
 .../generic/shared/dto/SampleSkeleton.java    | 86 +++++++++++++++++++
 6 files changed, 228 insertions(+), 2 deletions(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleRelationShipSkeleton.java
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleSkeleton.java

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleLister.java
index 4741b115586..ea822fab056 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleLister.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/ISampleLister.java
@@ -18,8 +18,11 @@ package ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister;
 
 import java.util.List;
 
+import ch.systemsx.cisd.common.collections.IValidator;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SampleRelationShipSkeleton;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SampleSkeleton;
 
 /**
  * A role for fast sample listing.
@@ -33,5 +36,25 @@ public interface ISampleLister
      * Returns a sorted list of {@link Sample}s that match given criteria.
      */
     public List<Sample> list(ListOrSearchSampleCriteria criteria);
+    
+    /**
+     * Returns the id of the relationship type of specified code. If code starts with an '$'
+     * it is interpreted as an internally defined relationship type.
+     * 
+     * @throws IllegalArgumentException if code not known.
+     */
+    public long getRelationshipTypeID(String code);
+
+    /**
+     * Returns all samples as skeletons (thats is, only primary and foreign keys) fulfilling
+     * specified criteria.
+     */
+    public List<SampleSkeleton> listSampleBy(IValidator<SampleSkeleton> criteria);
+    
+    /**
+     * Returns all sample relation ships as skeletons (thats is, only primary and foreign keys) fulfilling
+     * specified criteria.
+     */
+    public List<SampleRelationShipSkeleton> listSampleRelationShipsBy(IValidator<SampleRelationShipSkeleton> criteria);
 
 }
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 ca7fb9bfb49..3f625f05871 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
@@ -102,6 +102,12 @@ public interface ISampleListingQuery extends TransactionQuery, IPropertyListingQ
         { TypeMapper.class/* default */, LongSetMapper.class }, fetchSize = FETCH_SIZE)
     public DataIterator<SampleRelationRecord> getParentRelations(long relationshipId,
             LongSet childrenSampleIds);
+    
+    @Select(sql = "select id, saty_id, grou_id, dbin_id, expe_id from samples", fetchSize = FETCH_SIZE)
+    public DataIterator<SampleRecord> getSampleSkeletons();
+    
+    @Select(sql = "select * from sample_relationships", fetchSize = FETCH_SIZE)
+    public DataIterator<SampleRelationRecord> getSampleRelationshipSkeletons();
 
     //
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleLister.java
index 9b63edc9953..73a17efe293 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleLister.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleLister.java
@@ -16,12 +16,18 @@
 
 package ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister;
 
+import java.util.ArrayList;
 import java.util.List;
 
+import net.lemnik.eodsql.DataIterator;
+
+import ch.systemsx.cisd.common.collections.IValidator;
 import ch.systemsx.cisd.openbis.generic.server.business.bo.common.entity.SecondaryEntityDAO;
 import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCriteria;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SampleRelationShipSkeleton;
+import ch.systemsx.cisd.openbis.generic.shared.dto.SampleSkeleton;
 
 /**
  * A business object for providing lists of samples (more precisely sets of samples) for the purpose
@@ -58,4 +64,48 @@ public class SampleLister implements ISampleLister
         return SampleListingWorker.create(criteria, baseIndexURL, dao, referencedEntityDAO).load();
     }
 
+    public long getRelationshipTypeID(String code)
+    {
+        return SampleListingWorker.getRelationId(dao.getQuery(), code);
+    }
+
+    public List<SampleSkeleton> listSampleBy(IValidator<SampleSkeleton> criteria)
+    {
+        DataIterator<SampleRecord> sampleSkeletons = dao.getQuery().getSampleSkeletons();
+        List<SampleSkeleton> result = new ArrayList<SampleSkeleton>();
+        for (SampleRecord sampleRecord : sampleSkeletons)
+        {
+            SampleSkeleton sampleSkeleton = new SampleSkeleton();
+            sampleSkeleton.setId(sampleRecord.id);
+            sampleSkeleton.setExperimentID(sampleRecord.expe_id);
+            sampleSkeleton.setSpaceID(sampleRecord.grou_id);
+            sampleSkeleton.setTypeID(sampleRecord.saty_id);
+            sampleSkeleton.setDatabaseInstanceID(sampleRecord.dbin_id);
+            if (criteria.isValid(sampleSkeleton))
+            {
+                result.add(sampleSkeleton);
+            }
+        }
+        return result;
+    }
+
+    public List<SampleRelationShipSkeleton> listSampleRelationShipsBy(
+            IValidator<SampleRelationShipSkeleton> criteria)
+    {
+        DataIterator<SampleRelationRecord> records = dao.getQuery().getSampleRelationshipSkeletons();
+        List<SampleRelationShipSkeleton> result = new ArrayList<SampleRelationShipSkeleton>();
+        for (SampleRelationRecord record : records)
+        {
+            SampleRelationShipSkeleton skeleton = new SampleRelationShipSkeleton();
+            skeleton.setRelationShipTypeID(record.relationship_id);
+            skeleton.setParentSampleID(record.sample_id_parent);
+            skeleton.setChildSampleID(record.sample_id_child);
+            if (criteria.isValid(skeleton))
+            {
+                result.add(skeleton);
+            }
+        }
+        return result;
+    }
+
 }
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 8cbddd6bdb7..ca6ea1523fe 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
@@ -198,10 +198,10 @@ final class SampleListingWorker extends AbstractLister
         this.enrichDependentSamples = criteria.isEnrichDependentSamplesWithProperties();
         this.referencedEntityDAO = referencedEntityDAO;
         this.parentRelationhipTypeId =
-                getRelationId(BasicConstant.PARENT_CHILD_INTERNAL_RELATIONSHIP);
+                getRelationId(query, BasicConstant.PARENT_CHILD_INTERNAL_RELATIONSHIP);
     }
 
-    private long getRelationId(String fullRelationCode)
+    static long getRelationId(ISampleListingQuery query, String fullRelationCode)
     {
         return query.getRelationshipTypeId(CodeConverter.tryToDatabase(fullRelationCode),
                 CodeConverter.isInternalNamespace(fullRelationCode));
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleRelationShipSkeleton.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleRelationShipSkeleton.java
new file mode 100644
index 00000000000..89826b7026f
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleRelationShipSkeleton.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 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.dto;
+
+/**
+ *  Only primary and foreign keys of a sample relationship in the database.
+ *
+ * @author Franz-Josef Elmer
+ */
+public class SampleRelationShipSkeleton
+{
+    private long parentSampleID;
+    
+    private long childSampleID;
+    
+    private long relationShipTypeID;
+
+    public final long getParentSampleID()
+    {
+        return parentSampleID;
+    }
+
+    public final void setParentSampleID(long parentSampleID)
+    {
+        this.parentSampleID = parentSampleID;
+    }
+
+    public final long getChildSampleID()
+    {
+        return childSampleID;
+    }
+
+    public final void setChildSampleID(long childSampleID)
+    {
+        this.childSampleID = childSampleID;
+    }
+
+    public final long getRelationShipTypeID()
+    {
+        return relationShipTypeID;
+    }
+
+    public final void setRelationShipTypeID(long relationShipTypeID)
+    {
+        this.relationShipTypeID = relationShipTypeID;
+    }
+}
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleSkeleton.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleSkeleton.java
new file mode 100644
index 00000000000..79265eac888
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/SampleSkeleton.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2010 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.dto;
+
+/**
+ * Only primary and foreign keys of a sample in the database.
+ *
+ * @author Franz-Josef Elmer
+ */
+public class SampleSkeleton
+{
+    private long id;
+    
+    private Long databaseInstanceID;
+    
+    private Long spaceID;
+    
+    private long typeID;
+    
+    private Long experimentID;
+
+    public final long getId()
+    {
+        return id;
+    }
+
+    public final void setId(long id)
+    {
+        this.id = id;
+    }
+
+    public final Long getDatabaseInstanceID()
+    {
+        return databaseInstanceID;
+    }
+
+    public final void setDatabaseInstanceID(Long databaseInstanceID)
+    {
+        this.databaseInstanceID = databaseInstanceID;
+    }
+
+    public final Long getSpaceID()
+    {
+        return spaceID;
+    }
+
+    public final void setSpaceID(Long spaceID)
+    {
+        this.spaceID = spaceID;
+    }
+
+    public final long getTypeID()
+    {
+        return typeID;
+    }
+
+    public final void setTypeID(long typeID)
+    {
+        this.typeID = typeID;
+    }
+
+    public final Long getExperimentID()
+    {
+        return experimentID;
+    }
+
+    public final void setExperimentID(Long experimentID)
+    {
+        this.experimentID = experimentID;
+    }
+    
+}
-- 
GitLab