From ce4af1ae26cc5755e5af12da4fa0fd418dea229b Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Fri, 1 Sep 2017 10:25:22 +0000
Subject: [PATCH] SSDM-5553 : Code generation for the UI done on the server
 side

SVN: 38689
---
 .../generic/server/api/v1/GeneralInformationService.java  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
index 6f4b5af455a..b3a318f12a7 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/api/v1/GeneralInformationService.java
@@ -1388,8 +1388,14 @@ public class GeneralInformationService extends AbstractServer<IGeneralInformatio
         querySampleTypeId.setParameter("sampleTypeCode", sampleTypeCode);
         int sampleTypeId = ((Number) querySampleTypeId.uniqueResult()).intValue();
 
-        SQLQuery querySampleCount = currentSession.createSQLQuery("SELECT COUNT(*) FROM samples_all WHERE saty_id = :sampleTypeId");
+        SQLQuery querySampleTypePrefix = currentSession.createSQLQuery("SELECT generated_code_prefix from sample_types WHERE code = :sampleTypeCode");
+        querySampleTypePrefix.setParameter("sampleTypeCode", sampleTypeCode);
+        String sampleTypePrefix = ((String) querySampleTypePrefix.uniqueResult());
+
+        SQLQuery querySampleCount =
+                currentSession.createSQLQuery("SELECT COUNT(*) FROM samples_all WHERE saty_id = :sampleTypeId AND code ~ :codePattern");
         querySampleCount.setParameter("sampleTypeId", sampleTypeId);
+        querySampleCount.setParameter("codePattern", "^" + sampleTypePrefix + "[0-9]+$");
         long sampleCount = ((Number) querySampleCount.uniqueResult()).longValue();
 
         return sampleCount;
-- 
GitLab