From 3f4539457e80db03c48ea2942a45374e26d411fc Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Mon, 19 Nov 2018 14:26:41 +0100
Subject: [PATCH] SSDM-6958: Bug in
 AuthorizationDataProvider.getEntityCollectionAccessData fixed and systemtest
 written for this bug

---
 .../AuthorizationDataProvider.java            |  8 ++++--
 .../systemtest/asapi/v3/GetSampleTest.java    | 26 +++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java
index ab001db8cae..6509e9e0352 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/authorization/AuthorizationDataProvider.java
@@ -9,6 +9,10 @@ import java.util.Set;
 
 import org.hibernate.Query;
 import org.hibernate.Session;
+import org.hibernate.engine.spi.QueryParameters;
+import org.hibernate.engine.spi.TypedValue;
+import org.hibernate.query.internal.NativeQueryImpl;
+import org.hibernate.query.internal.QueryParameterBindingsImpl;
 
 import ch.systemsx.cisd.common.action.IMapper;
 import ch.systemsx.cisd.openbis.generic.server.batch.BatchOperationExecutor;
@@ -306,8 +310,6 @@ final public class AuthorizationDataProvider implements IAuthorizationDataProvid
             IMapper<List<V>, List<?>> valuesMapperOrNull, IMapper<List<R>, List<R>> resultMapperOrNull)
     {
         Session session = daoFactory.getSessionFactory().getCurrentSession();
-        final Query query = session.getNamedQuery(queryName);
-        query.setReadOnly(true);
 
         final Set<R> fullResults = new HashSet<R>();
 
@@ -324,6 +326,8 @@ final public class AuthorizationDataProvider implements IAuthorizationDataProvid
                 {
                     List<?> mappedValues = valuesMapperOrNull != null ? valuesMapperOrNull.map(entities) : entities;
                     assertNoNullElements(mappedValues);
+                    Query query = session.getNamedQuery(queryName);
+                    query.setReadOnly(true);
                     query.setParameterList(parameterName, mappedValues);
 
                     List<R> singleResults = cast(query.list());
diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/GetSampleTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/GetSampleTest.java
index 4eca9d0cb88..2af16863e54 100644
--- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/GetSampleTest.java
+++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/GetSampleTest.java
@@ -77,6 +77,32 @@ import junit.framework.Assert;
  */
 public class GetSampleTest extends AbstractSampleTest
 {
+    @Test
+    public void testGetMoreThanThousandSamples()
+    {
+        // Given
+        String sessionToken = v3api.login(TEST_USER, PASSWORD);
+        List<SampleCreation> newSamples = new ArrayList<>();
+        for (int i = 0; i < 1024; i++) // size should be larger than BatchOperationExecutor.DEFAULT_BATCH_SIZE
+        {
+            SampleCreation creation = new SampleCreation();
+            creation.setCode("TEST_SAMPLE_" + (i + 1));
+            creation.setTypeId(new EntityTypePermId("CELL_PLATE"));
+            creation.setSpaceId(new SpacePermId("TEST-SPACE"));
+            newSamples.add(creation);
+        }
+        List<SamplePermId> sampleIds = v3api.createSamples(sessionToken, newSamples);
+        SampleFetchOptions fetchOptions = new SampleFetchOptions();
+        fetchOptions.withType();
+        fetchOptions.withSpace();
+
+        // When
+        Map<ISampleId, Sample> samples = v3api.getSamples(sessionToken, sampleIds, fetchOptions);
+
+        // Then
+        assertEquals(samples.size(), newSamples.size());
+    }
+
 
     @Test
     public void testGetByPermId()
-- 
GitLab