commit 0c12e309ff3562ad1bac071877ffc6d6ab47ee9b
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Mon Jul 2 09:32:30 2018 +0200

    ref #7523 exteding CdmFilterablePagingProvider by Restrictions filter

diff --git a/src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java b/src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java
index 03e15a6d..0cc062e4 100644
--- a/src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java
+++ b/src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java
@@ -458,7 +458,7 @@ public class RegistrationRequiredDataInserter extends AbstractDataInserter {
             institution = instituteMap.get(office);
         } else {
 
-            Pager<AgentBase> pager = repo.getAgentService().findByTitle(Institution.class, office, MatchMode.EXACT, null, null, null, null, null);
+            Pager<AgentBase> pager = repo.getAgentService().findByTitleWithRestrictions(Institution.class, office, MatchMode.EXACT, null, null, null, null, null);
             if(!pager.getRecords().isEmpty()){
                 institution =  (Institution) pager.getRecords().get(0);
             } else {
diff --git a/src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java b/src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java
index 61a09f5f..69096d06 100644
--- a/src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java
+++ b/src/main/java/eu/etaxonomy/cdm/service/CdmFilterablePagingProvider.java
@@ -20,6 +20,7 @@ import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
 import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
+import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
 import eu.etaxonomy.cdm.persistence.query.MatchMode;
 import eu.etaxonomy.cdm.persistence.query.OrderHint;
 
@@ -49,6 +50,8 @@ public class CdmFilterablePagingProvider<T extends IdentifiableEntity, V extends
 
     private List<Criterion> criteria = new ArrayList<>();
 
+    private List<Restriction<?>> restrictions = new ArrayList<>();
+
 
     /**
      * @return the matchMode
@@ -116,16 +119,33 @@ public class CdmFilterablePagingProvider<T extends IdentifiableEntity, V extends
     public List<V> findEntities(int firstRow, String filter) {
 
         Integer pageIndex = firstRow / pageSize;
-        Pager<V> page = (Pager<V>) service.findByTitle(
-                type,
-                filter,
-                matchMode,
-                criteria,
-                pageSize,
-                pageIndex ,
-                orderHints,
-                initStrategy
-              );
+        Pager<V> page;
+        if(!restrictions.isEmpty() && criteria.isEmpty()){
+            page = (Pager<V>) service.findByTitleWithRestrictions(
+                    type,
+                    filter,
+                    matchMode,
+                    restrictions,
+                    pageSize,
+                    pageIndex ,
+                    orderHints,
+                    initStrategy
+                    );
+        } else if(restrictions.isEmpty() && !criteria.isEmpty()){
+            page = (Pager<V>) service.findByTitle(
+                    type,
+                    filter,
+                    matchMode,
+                    criteria,
+                    pageSize,
+                    pageIndex ,
+                    orderHints,
+                    initStrategy
+                    );
+        } else {
+            // this will never be reaced sind the size() method is always called before.
+            throw new RuntimeException("Citeria and Restrictions must not be used at the same time");
+        }
         if(logger.isTraceEnabled()){
             logger.trace("findEntities() - page: " + page.getCurrentIndex() + "/" + page.getPagesAvailable() + " totalRecords: " + page.getCount() + "\n" + page.getRecords());
         }
@@ -138,16 +158,33 @@ public class CdmFilterablePagingProvider<T extends IdentifiableEntity, V extends
     @Override
     public int size(String filter) {
 
-        Pager<V> page = (Pager<V>) service.findByTitle(
-                type,
-                filter,
-                matchMode,
-                criteria,
-                1,
-                0,
-                null,
-                null
-              );
+        Pager<V> page;
+        if(!restrictions.isEmpty() && criteria.isEmpty()){
+            page = (Pager<V>) service.findByTitleWithRestrictions(
+                    type,
+                    filter,
+                    matchMode,
+                    restrictions,
+                    1,
+                    0,
+                    null,
+                    null
+                  );
+        } else if(restrictions.isEmpty() && !criteria.isEmpty()){
+            page = (Pager<V>) service.findByTitle(
+                    type,
+                    filter,
+                    matchMode,
+                    criteria,
+                    1,
+                    0,
+                    null,
+                    null
+                  );
+        } else {
+            throw new RuntimeException("Citeria and Restrictions must not be used at the same time");
+        }
+
         if(logger.isTraceEnabled()){
             logger.trace("size() -  count: " + page.getCount().intValue());
         }
@@ -190,4 +227,21 @@ public class CdmFilterablePagingProvider<T extends IdentifiableEntity, V extends
     public List<Criterion> getCriteria() {
         return criteria;
     }
+
+    public void addCriterion(Criterion criterion){
+        criteria.add(criterion);
+    }
+
+    /**
+     * The list of restrictions is initially empty.
+     *
+     * @return the restrictions
+     */
+    public List<Restriction<?>> getRestrictions() {
+        return restrictions;
+    }
+
+    public void addRestriction(Restriction<?> restriction){
+        restrictions.add(restriction);
+    }
 }
